Adafruit MotorShield and I2C Problem

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
macx
 
Posts: 2
Joined: Mon Jan 12, 2015 10:32 pm

Adafruit MotorShield and I2C Problem

Post by macx »

My project couples an Arduino UNO I2C master with an Arduino Mega I2C slave. The UNO is the control computer and the Mega is the robotics servo computer.

The Mega has 2 Adafruit motor shields driving 8 servo motors. In stand alone mode the Mega works great. When the I2C connection is made and the UNO and Mega are started, the Mega code hangs at the Motorshield initialization. Re-starting the UNO allows the Mega to proceed with a normal initialization.

My question: Since the Mega is controlling the motorshields via I2C and is thus a master can the Mega also be designated an I2C slave for the UNO ? Is the configuration allowable / reliable in theory?

User avatar
tdicola
 
Posts: 1074
Joined: Thu Oct 17, 2013 9:11 pm

Re: Adafruit MotorShield and I2C Problem

Post by tdicola »

I think it's going to be really tricky since the Arduino I2C library isn't really designed to change from master to slave and vice versa. The begin function for the library calls out that it should only be called once, but you need to call it to set the device as master or slave.

I think you'll have a much easier time if you make a serial link between the Uno and Mega. If it's only the Uno sending commands to the Mega then you could just get away with one extra wire between the two, a TX pin from the Uno to an RX on the Mega. The software serial library should work great for sending and receiving commands too. That way the Mega can be the I2C master for the servo shields, yet still listen and receive commands from the Uno on the serial link.

User avatar
macx
 
Posts: 2
Joined: Mon Jan 12, 2015 10:32 pm

Re: Adafruit MotorShield and I2C Problem

Post by macx »

Thanks for the quick reply. The motor library moves the shield's I2C statements out of the sketch file and you confirmed what my scope was showing. I will take your recommendation and implement serial connectivity. That will allow me to retain my existing data protocol with little modification and keep the head alive ;-)

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”