![]() I modified the Tiny85_Temp.pde example slightly (told the code what pin my LED was on, removed some lines to test the bare minimum functionality) and programmed the new board (the one with the pull-ups) using the Arduino IDE and the FabISP. Instead of making new boards with different microprocessors, I looked for other people's software solutions, and found this TinyWireM library, which extends Wire for ATTiny devices (masters only). But I got compiler errors right away with Arduino's sample code, and eventually figured out that Wire isn't supported on ATTiny chips-it's written for ATMega with hardware I2C modules. The first thing I tried to do was to use the Arduino Wire library. The assignment was to have at least two nodes in the network, so I need a master and two slaves, but before milling a third board I decided to try to get the first two to talk to each other. We only need one pull-up on each line, so I can reuse the board from Week 5 as a second node in the network. The only real change on this board is that I added 10K pull-up resistors on SCL and SDA. Week 5, since we already have SCL (the clock line), SDA (the data line), and power and ground available to other boards on the 2x3 ISP header. I made a new board with the ATTiny44-basically the same as the one from I decided to work with I2C this week since it's useful. This post is about sending 16 bit and 32 bit numbers over I2C.Week Eleven: Networking and Communications This post is about a problem sending more than 1 byte with the Arduino I2C. If you enjoyed this post you might also enjoy these posts: Int i = Wire.read() // receive a byte as character While(Wire.available()) // slave may send less than requested Wire.requestFrom(4, 1) // request 1 byte from slave device address 4 Serial.begin(9600) // start serial for output Wire.begin() // join i2c bus (address optional for master) Gets called when the ATtiny receives an i2c request TinyWireS.onReceive(receiveEvent) // not using this TinyWireS.begin(I2C_SLAVE_ADDRESS) // join i2c network ![]() #define I2C_SLAVE_ADDRESS 0x4 // Address of the slave ![]() The Mega requests data from the ATtiny, which returns a number and then increments it. Now, just program the ATtiny 85 and the Arduino Mega with the following code and voila. This isn’t like RX/TX pins where you need to cross them. Connect the SDA pin on one to the SDA pin on the other and the SCL pin on one to the SCL pin on the other. Controllerįor my example, I’m using an ATtiny85 and an Arduino Mega2560. As a refresher, here is the pinout for the ATtiny85.Īnd here is the SDA and SCL pins for various microcontrollers. If this folder doesn’t already exist, create it. This is by default in Documents/Arduino/libraries. Click the download zip button and then unzip the folder into the libraries folder in your Arduino folder. The first thing to do is download the ATtiny85 i2c slave library. I read dozens of “tutorials” about it from around the web and couldn’t find a nice simple example. The only problem is that I’ve never used i2c with the ATtiny series before. Since I’ll have several of these sensors I need them to be cheap and the ATtiny85 jumped to mind. I’m working on a project where I need several sensors that communicate back to a central processor.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |