Let's Make Robots!

I2C vs Serial

I hereby submit another plea to the robot gods out there:

I've read a lot of very informative info on both i2c and serial communication as a way for one IC to control others. My question is: which will work better for my needs?

My plan is to make a robot that has a seperate IC for each aspect of its behavior (movement, communication, etc.). So which is faster? cheaper? fewer wires? easier to program? I'm sure both have pros and cons.

Okay, go.

Comment viewing options

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

From my understanding, if you're using a picaxe, serial communication commands like serin, it will make the program stop everything else until it receives the serial data.  If you use i2c on the other hand, it seems like the slave microcontrollers can keep running their own program while the i2c does its own thing.  Can someone else confirm this?  

If that's the case, serial communication might introduce some lag, depending on your application.  

I have been experimenting with I2C using the picaxes, and I believe only the 28X, 40X1, and one or two others can be configured as slaves.  For example, the 18X is supposed to be able to use I2C (and it does) however, it can only be a master.  So if you're planning on running multiple slave microcontrollers, make sure you have the microcontrollers that can be slaves if that's what you are going to use them for.


Do you need a point-to-point communication systems or a bus?  I suspect that the bus structure (and addressability) that you get with I2C will be more useful.  Plus, you can get chips that diredctly implement I2C interfaces, such as temperature sensors and ADC chips.  I2C is a two wire system with just a couple of pull-up resistors and either 100kHz or 400kHz clock.  The address space allows for 127 devices on one bus, although in practice you probably won't use more than perhaps ten or so.

I agree with you on delegating some tasks to other processors. That also helps circumvent the problems you might exect when you want to use 1 proc for PWM, servos and communication. I don't know about fewer wires though.

@gsandaya: even with I2C your program will be interrupted for a brief periode while the processor is dealing with the communication. it is still a serial processor and a serial bus.

Still: I'd go for i2C because it's build in the 18X, 28X1 and 40X1. This means you don't have to think about things like collision detection (when 2 devices transmit at the same time) because your picaxe will handle all that stuff. If you don't mind using a 28X1 for every slavedevice: go with I2C.

There are also advantages to using Serin and serout over I2C. For one thing, I2C uses two fixed pins for I2C. This means you can only communicate over one I2C bus with one chip. If you want to communicatie with lots of devices, you're I2C bus will get very busy. This is OK if you have only one master. With serial, you can set up one pin of your 28X1 to transmit servo positions to a 14M (or three 14Ms) and use another 2 pins to request data from a couple of 08Ms that handle sensor inputs. 

By the way: You don't need your program to wait for a serial transmission if you use an interrupt to detect the start of a transmission. (see serial picaxe communication to find out how) 

I'd say you'll probably end up using I2C anyway, to talk to sensors, EEPROMs or displays. If you have a few tasks that are better handled by smaller picaxes (08M with a motor driver, 14M with some servos, etc) you can allways add a serial bus for that.