I'm working on a project where i connect LEGO Mindstorms NXT robot with Arduino usin the I2C protocol. And i want also to connect some sensors to the Arduino board, so it will be something like this: Mindstorms <--> Arduino <--> Sensor.
I want Arduino to be the slave in the communicaction with the robot, and to be the master in the communication with the sensors. Is this possible? Can i do both simultaneously?
I know that for I2C communication i have to use the pins 4 and 5 of the analog input, and i'm using Arduino MEGA board.
Thanks a lot (and i apologise for my english, it's not perfect).
You can do nothing simultaneously on a single processor, you do them sequentially very fast so it looks like simultaneously.
Yes, you're right. Is what i wanted to say: first Arduino is the slave and receives instructions from de Mindstorm, and then is the master for the sensors, sending the instructions to them. It's not simulatenous.
It is not those pins on a mega it is pins 20 & 21
Oooops! I was confused because i've just been reading about the Arduino Duemilanove board. Thanks!
The arduino can be a slave and a master at the same time. Also the arduino supports multi masters on the same bus.
The big question: dose the mind storm support multi masters.
It is worth a try.
Mindstorm doesn't support multi masters. I think i'm going to do this using software I2C, using two analog pins of Arduino to communicate with the sensors, and the two I2C pins to communicate with the robot.
One trick my be to poll your slave just after the mind storm polls you.
The thought process is that the mind storm polls it's slave (your arduino) in a regular cycle. If the bus is idle just after the poll, you may have time to poll your slave.
The Lego uses a 3v3 I2C bus and the sensors might need a 5V bus so you will need some hardware bus level shifters.
Actually you can use this snag to your advantage. Since you'll need a level shifter use an IC like a TXS0102 that has an output enable pin. Once the mindstorm is done communicating with the Arduino, drive the output enable LOW and force the bus between the mindstorm and Arduino into a Hi-Z state. If the mindstorm tries to poll the Arduino it won't get a response and will leave you free to communicate with the rest of the sensors. Just make sure the sensors are all wired downstream of the level shifter. Also if the sensors can handle Fast Mode (400kHz) bump up the I2C speed when communicating with them, that should minimize timing concerns.
One trick my be to poll your slave just after the mind storm polls you.
That's an option that i was thinking about, but i'm not shure if it will works. I will try it
ally you can use this snag to your advantage. Since you'll need a level shifter use an IC like a TXS0102 that has an output enable pin. Once the mindstorm is done communicating with the Arduino, drive the output enable LOW and force the bus between the mindstorm and Arduino into a Hi-Z state. If the mindstorm tries to poll the Arduino it won't get a response and will leave you free to communicate with the rest of the sensors. Just make sure the sensors are all wired downstream of the level shifter. Also if the sensors can handle Fast Mode (400kHz) bump up the I2C speed when communicating with them, that should minimize timing concerns.