Two Arduino's in Master/Slave with a motor shield stack

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
knightstalker
 
Posts: 5
Joined: Mon Aug 11, 2014 12:15 am

Two Arduino's in Master/Slave with a motor shield stack

Post by knightstalker »

I am kinda stuck here and appreciate the future help I know I will get.
I have two arduino's set up as a Master/Slave. The Master has an LCD shield and keypad for input.
The Slave has a motor shield on it only and a connection to the Master through the I2C.

The Master/slave connection is working fine without the motor shield and data is sent to the slave and can be processed.
The shield is set with the default address 0x60 and the master addresses the slave through the wire library as address 4.

Once the motor shield is attached to the slave all communication stops and the master stops executing after the setup function runs.

Any ideas?
Thanks

User avatar
Franklin97355
 
Posts: 23912
Joined: Mon Apr 21, 2008 2:33 pm

Re: Two Arduino's in Master/Slave with a motor shield stack

Post by Franklin97355 »

The shield uses i2c as a slave with the Arduino being master. I'm not sure the Arduino can operate as both master and slave unless there is a software solution using different pins for each device.

User avatar
knightstalker
 
Posts: 5
Joined: Mon Aug 11, 2014 12:15 am

Re: Two Arduino's in Master/Slave with a motor shield stack

Post by knightstalker »

You make a very good point. I remember reading about that in another post. I will see about reversing roles and still getting the input to flow to the master.

I will post my results. In the mean time any other suggestions?

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: Two Arduino's in Master/Slave with a motor shield stack

Post by adafruit_support_mike »

The I2C spec allows for devices that switch between master and slave, and for multiple masters on the same bus.

That said, it doesn't happen automatically. There's a whole bus-contention protocol and a set of strategies for a device that changes roles to announce what it's going to do. I don't know how much if any of that is built into the Wire library, so you might have to roll a lot of low-level protocol code for yourself.

In practice, you'll find life a lot simpler if you use a Serial connection for the communication between the two Arduinos and reserve I2C for the Motor Shield.

User avatar
knightstalker
 
Posts: 5
Joined: Mon Aug 11, 2014 12:15 am

Re: Two Arduino's in Master/Slave with a motor shield stack

Post by knightstalker »

That sounds like a viable solution. The question I have is can I communicate with multiple arduinos in a spoke and hub configuration? I am not that familiar with the serial communication and the arduino. I imagine I can use software and develop a token system to communicate with the right arduino. Thanks for the reply and I will post my results.

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: Two Arduino's in Master/Slave with a motor shield stack

Post by adafruit_support_mike »

BANNED wrote:The question I have is can I communicate with multiple arduinos in a spoke and hub configuration?
Ah.. that's new requirement, and it changes the topology of the network.

Serial connections are one-to-one. Each device expects to have complete control over its TX line. Trying to share a TX line between two devices would cause problems when one wants to send the line HIGH and the other wants to pull the line LOW.

You can probably make a one-to-many network using SoftSerial connections by having all the slave devices set their TX pins to INPUT. Give each slave device a unique address, and have them all listen to a shared RX line (the master's TX line). When a slave device reads its address on its RX line, it can set its TX pin to OUTPUT and transmit data back to the master, then set its TX pin back to INPUT once the transaction is done.

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Two Arduino's in Master/Slave with a motor shield stack

Post by adafruit_support_bill »

There is also a "Soft i2c" library out there. You could use a secondary i2c bus for the inter-processor communication.

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

Return to “Arduino Shields from Adafruit”