Let's Make Robots!

Interfacing two arduinos in the same robot

I'm wondering if I can make two arduinos interface with each other i.e. one for the servos and another one for sensor reading and receiving commands by RF (no need for tx-rx). Sorta like a master and slave thing. I would just want actually to make variables that both arduinos can read and write. Is it possible by hooking the tx rx pins together?


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

I have 4 Arduinos in my robot! All talking through I2C interface. One is a servo controller, another is a motor controller... So what you want to do is possible. You can even use serial instead of I2C and use the same command format that I used, the only thing that changes is the I2C_send function and of course, the I2C_receive function to use the serial interface. If serial is what you chose to use, I advise to avoid the hardware serial and use software serial instead (on any pins). This way you don't have to unplug the boards when uploading code.

So, I'm guessing one benefit of using I2C is not having problems with adjusting timers?  SoftwareSerial will utilize some timers as will all the rest of the serial libraries (they just grab different ones).  Some Servo libraries will mess with the timers two, making some combinations completely incompatible.

Does I2C bypass all the melarky?

Yes, that's the idea. TWI (I2C) has a hardware implementation in ATmegas so it can run in the background. For the ATtinys, there is a USI that can be configured as TWI and there are libraries (Master and Slave) that can be used in Arduino for the favourite ATtiny84. Take a look at the code for my robot, all modules use the same format, each one becomes Master when needs to send some commands to a Slave. Each module runs it's own code while listening for commands addressed to it, then executes the received command, responds if needed and resumes the main code. So my modules do not work in pure Slave mode like in a regular I2C sensor, because executing a command takes time and the response to the Master can't be imediate. I didn't want the Master to keep polling the Slave to get the message "Done".

I had to go the I2C route in my robot especially because Servo uses Timer1 and there were conflicts with software serial, encoder interrups would make servos jitter at a higher speed, voice recognition was getting stuck in a listenning loop preventing other code to run, so I decided to split the hardware functions in different hardware modules. A Propeller would not have a problem with all this, since each hardware function can be run indipendentaly in a different cog. I wish I could program the Propeller in Arduino instead of having to learn Spin. (I have a hard time learning programming languages.)

Hi Markamas,

Yes it is.. Strangly I've never done this directly (ie. wired connection) ,however, I have tried every virtual serial library Arduino has in order to do Wireless serial connections.

When some of the wireless serial libraries are used, Servo's or PWM is affected (a real pain).

I would think hooking an actual physical wire and using the Arduino's regular Serial.print/read would work fine.

see here : http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1222019250


Another method would be to use the I2C but whichever you prefer....

Will I need anything else besides two arduinos?

For I2C

Although the Wire library that runs the I2C comms says it turns on the internal pull up resistors, it is a good practice to use external resistors on only one Arduino (the one that acts mostly as a Master). Connect one 4k7 resistor from the SCL (Serial CLock) pin to Vcc and one 4k7 resistor from SDA (Serial DAta) pin to Vcc. All other boards or sensors will be connected in parallel on these 2 pins plus GND and Vcc. Make sure you don't swap the pins like you would do for the serial interface.