Multiple devices on RS232 / serial line

UPDATE: THIS IS BULLSHIT! IT WORKED ONLY WITH TWO ATTINYS, THREE ATE TOO MUCH SIGNAL.
SOLUTION'S HERE!

This is continuation of Multiple encoders with ATmega.

This time I turned Eagle on...
Usually you shouldn't connect multiple devices on one serial line, but in certain situations this connection will work. In my setup there is only one master: Arduino Uno. Main principle is that only one slave - ATtiny talks at a time. Otherwise you'll get some jibberish.
In order to maintain this network I had to develop code, that will send encoder data only after specific character was received ('b' in attached code). Other characters are ignored. Data is send as one byte for simplicity: it will be MIDI device so it'll work on 7bit values mostly. Arduino reads data, and clears it's buffer if necessary (while (Serial.available()) Serial.read();). Then  Arduino sends another value for another ATtiny.

To sum it up: Arduino sends specified value: address of one ATtiny, than this ATtiny, and only this one talks, the rest ignored that message, Arduino waits until end of transmission and send another's slave address.

Code for ATtiny is here, on github.
And arduino's example code.

Comments