5

I am using I2C to communicate between a collection of ATtiny85s that are acting as controllers for various parts of a system and the "Main Brain" -- a RaspberryPi. Most of the ATtiny85s only have a couple of free pins left (usually Pins 1 and 2 -- the reset and the pin that can't be used for PWM) so I can't use something like a DIP switch to directly set device IDs. I'd rather not hardcode the device IDs when I push code to the tinys but I can't think of a good, simple, and reliable way to do it otherwise. Anyone here have a suggestion?

1

You could use the analog input on pin 1.

Have a table in your code to map voltage thresholds to I2C IDs.

Then build a voltage divider circuit as input that you can adjust with switches or by installing different resistors.

  • This is along the lines of what I was thinking. Maybe I could use the TinyDebugSerial to report the selected value as I adjust a variable resistor or something. – ThatAintWorking Nov 21 '14 at 1:19
  • Someone just suggested I use a R-2R resistor ladder with a DIP switch to create a predictable and reliable analog value. If I can figure out the circuit, this seems like the way to go. – ThatAintWorking Nov 21 '14 at 14:06
  • If you're going this route then maybe you should use a DS4303 or DS4305 instead of a full DAC. – Ignacio Vazquez-Abrams Nov 21 '14 at 18:40
  • I ended up going with a block of jumpers tied to different resistors to vary the voltage. I connected the jumper block to Pin 1 (so I could use Pin 2 for TinySerialDebug) and then used analogRead() to read the value of Pin 1 and map that to an set of I2C addresses. – ThatAintWorking Nov 25 '14 at 22:59
6

Put the address in EEPROM. It's still "on the chip" but it can be programmed independent of the flash, and can be changed on the fly if deemed appropriate.

  • Can you give an example or a link to an example of how to program the EEPROM at "install time" separate from when I load my code on the ATtiny85? I am using the Arduino IDE to do my programming if that makes a difference. – ThatAintWorking Nov 21 '14 at 1:02
  • 1
    Blank EEPROM cells have a value of 0xFF, so if your code detects that it's using that address then it should enter a special mode where a I2C master can connect to it and tell it the new address, and then it can perform the actions described in the "EEPROM Data Memory" subsection of the "AVR Memories" section of the datasheet to write the new address to EEPROM and then begin normal operation. – Ignacio Vazquez-Abrams Nov 21 '14 at 1:19
  • 1
    Make sure you program the EESAVE fuse, so the contents of the eeprom are preserved when uploading new code. – Gerben Nov 21 '14 at 16:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.