Week Eleven: Networking and Communications
I decided to work with I2C this week since it's useful.
I made a new board with the ATTiny44--basically the same as the one from 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. The only real change on this board is that I added 10K pull-up resistors on SCL and SDA.
Here are the tracesand outlinefor the Fab module.
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 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.
The first thing I tried to do was to use the Arduino Wire library. 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.
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).
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.
It seemed to work. Here's the SDA line, where the chip is continuously sending the number 2:
I thought it would be straightforward to program the slave, but first of all even though there is a "https://github.com/adafruit/TinyWireM/," there is no "https://github.com/adafruit/TinyWireS/". But I did find what looked like code from the same author here.
Next, the sample code included with the library wouldn't compile:
/Users/madeleine/Documents/Arduino/libraries/TinyWireS/usiTwiSlave.c: In function 'usiTwiSlaveInit':
/Users/madeleine/Documents/Arduino/libraries/TinyWireS/usiTwiSlave.c:313: error: 'DDR_USI' undeclared (first use in this function)
/Users/madeleine/Documents/Arduino/libraries/TinyWireS/usiTwiSlave.c:313: error: (Each undeclared identifier is reported only once
/Users/madeleine/Documents/Arduino/libraries/TinyWireS/usiTwiSlave.c:313: error: for each function it appears in.)
/Users/madeleine/Documents/Arduino/libraries/TinyWireS/usiTwiSlave.c:313: error: 'PORT_USI_SCL' undeclared (first use in this function)
/Users/madeleine/Documents/Arduino/libraries/TinyWireS/usiTwiSlave.c:313: error: 'PORT_USI_SDA' undeclared (first use in this function)
...
Based on this thread I found (in Italian) it looked like the problem was that some device-dependent #defines for the ATTinyX4 family were missing. I checked this by trying to compile for ATTiny45 and yep, it worked. So I downloaded the fix posted in the thread and tried again.
I also had to make sure to put #include <usiTwiSlave.h> before #include <TinyWireS.h>. That got rid of the earlier errors. But it still didn't compile:
In file included from Tiny44_slave.ino:1:
/Users/madeleine/Documents/Arduino/libraries/TinyWireS/usiTwiSlave.h:55: error: variable or field 'usiTwiSlaveInit' declared void
/Users/madeleine/Documents/Arduino/libraries/TinyWireS/usiTwiSlave.h:55: error: 'uint8_t' was not declared in this scope
/Users/madeleine/Documents/Arduino/libraries/TinyWireS/usiTwiSlave.h:56: error: variable or field 'usiTwiTransmitByte' declared void
/Users/madeleine/Documents/Arduino/libraries/TinyWireS/usiTwiSlave.h:56: error: 'uint8_t' was not declared in this scope
/Users/madeleine/Documents/Arduino/libraries/TinyWireS/usiTwiSlave.h:57: error: 'uint8_t' does not name a type
I'm out of time to keep debugging, but I think it might be easier to do this by milling some new boards with ATMegas and using the Arduino Wire library than to keep working through whatever other issues there are with this code.