Question about i2c communications between Arduinos with Moto

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
lucgallant
 
Posts: 39
Joined: Sat Mar 15, 2014 12:21 pm

Question about i2c communications between Arduinos with Moto

Post by lucgallant »

Hi there,

I've got two Arduino Unos.

The first (master) one has the i2c LCD backpack attached with address 0.

The second (slave) has the motor shield attached with one stepper motor attached. Motor shield is address 0x60. The slave Arduino is given address 4.

Both Arduinos are powered from different wall adapters (9V, 12V), and, they are both connected to the USB ports of my PC.

Whenever I make the connection between both Arduinos, as such:

http://arduino.cc/en/Tutorial/MasterReader

Both units freeze up. It seems that having the ground connected leads to issues as well. Disconnecting the backpack does not change anything.

Maybe I've got a blatantly obvious ground loop, I thought I'd ask here before spending hours pinpointing where things are wrong. to make the link.

Anyway I'd like to get both units to communicate serially so that I can use one of them purely for motor control.

Any ideas would be greatly appreciated. Thanks!

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

Re: Question about i2c communications between Arduinos with

Post by adafruit_support_bill »

One problem is that the Arduino can't be both a master and a slave at the same time. The one with the motor shield needs to be a master to control the motor shield.

You might want to consider something like the software i2c library to set up a secondary i2c bus for the inter-arduino communication.

lucgallant
 
Posts: 39
Joined: Sat Mar 15, 2014 12:21 pm

Re: Question about i2c communications between Arduinos with

Post by lucgallant »

Thanks for the feedback. I'm struggling a little bit here.

I get what you're saying about the Uno not being able to be a Master and Slave at once.

But my issue is, even if I strip the motor shield off, disable all its code, and make that Uno the slave, as soon as I connect pin 5 to pin 5 and pin 4 to pin 4, both devices lock up. I've still got the backpack attached to the master Uno. I thought of using Software Serial but it only has an option for Master, whereas I would want to create a new slave on the Motor Controller (Uno #2).

I thought that maybe instead of using i2c, I'd just use digital I/O instead, but I am facing problems there too.

I followed the analogWrite tutorial (http://arduino.cc/en/Reference/analogWrite) to get a PWM output on Uno #1 connected to Analog In 0 on Uno #2, to try and get values that way, but even with both grounds connected, my analog input values bounce all over the place, as though there is no common ground. When I apply 3.3 V or 5 V to the analog input, works beautifully, regardless of where the 3.3 V or 5 V is coming from (Uno #1 or Uno #2).

Any tips would be appreciated. Thanks.

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

Re: Question about i2c communications between Arduinos with

Post by adafruit_support_bill »

as soon as I connect pin 5 to pin 5 and pin 4 to pin 4, both devices lock up.
Have you tried with the Master/Slave example code at the Arduino site? http://arduino.cc/en/Tutorial/MasterWriter
I thought of using Software Serial but it only has an option for Master, whereas I would want to create a new slave on the Motor Controller (Uno #2).
Serial is peer-to-peer. There is master/slave at that level, but you can implement whatever protocol you want on top of it.
PWM output on Uno #1 connected to Analog In 0 on Uno #2, ... my analog input values bounce all over the place
A PWM output without any filtering is going to do that. http://ww1.microchip.com/downloads/en/A ... 00538c.pdf

lucgallant
 
Posts: 39
Joined: Sat Mar 15, 2014 12:21 pm

Re: Question about i2c communications between Arduinos with

Post by lucgallant »

Thanks a lot for the feedback.

I disconnected everything from both Unos, and tried the Master/Slave example code. It works well.

I thought that maybe the lcd constructor was doing a Wire.begin which was conflicting with my other Wire code, but that isn't what it was.

It seems that as soon as I hook up the lcd backpack to the A4/A5 pins, the communication between both Unos stops.

In any case, since both Unos are i2c masters (one for the lcd backpack and future RTC chip, and the other for the motor shield), I think I'm going to give SoftwareSerial a go, on different ports. I just hope it doesn't give me issues with the GPS....

I will try and RC filter on the PWM out to analog input, to see if I can get success there. (http://provideyourown.com/2011/analogwr ... o-voltage/)

Anyway thanks again, this has definitely been a slog but I think I'm getting somewhere. Getting anxious to post my final product, in the new year...

lucgallant
 
Posts: 39
Joined: Sat Mar 15, 2014 12:21 pm

Re: Question about i2c communications between Arduinos with

Post by lucgallant »

Hi there,

I've spent a considerable amount of time trying out the SoftwareSerial. The code looks very simple, and I've made the hardware connections, however, I can't seem to avoid resetting the arduino.

So I'm using this code exactly: http://www.arduino.cc/en/Reference/SoftwareSerial):

Code: Select all

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup()  
{
  // Open serial communications and wait for port to open:
  Serial.begin(57600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  Serial.println("Goodnight moon!");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(4800);
  mySerial.println("Hello, world?");
}

void loop() // run over and over
{
  if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());
}
I've got the exact same code on both Arduino Uno's. One is on COM8, the other on COM9.

Whenever I type anything into the Serial text box and press enter, it resets the other Uno.

And with the code above, if I don't comment out the println statements, the continuous resetting of both Unos is flooding the Serial port, making matters worse, etc.

If I comment out the print statements in the one Uno's setup() function, and I just type something in the box and press enter, it reruns the setup() function on the other Arduino, so it is resetting.

I've read countless topics on the Uno resetting due to the DTR being connected to the reset pin, but usually that's only when the Serial Monitor is opened. I just don't understand why it's resetting under these circumstances. In the Arduino Reference page it doesn't say anything about putting the 10 uF capacitor to prevent resets...

Anyway, any types are again appreciated. Thanks.

EDIT: I've got both Uno's connected to each other - Pin 10 on #1, to Pin 11 on #2. Pin 11 on #1, to pin 10 on #2. I've tried pull up or pull down resistors on these lines with no changes noted...

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

Re: Question about i2c communications between Arduinos with

Post by adafruit_support_bill »

I don't see anything there that should cause a reset. Try disconnecting things one-by-one and see if you can narrow down the possible sources of the problem.

lucgallant
 
Posts: 39
Joined: Sat Mar 15, 2014 12:21 pm

Re: Question about i2c communications between Arduinos with

Post by lucgallant »

I feel really stupid.

I also apologize for wasting your time....

Somehow while waking up this morning I had a revelation of some changed code I did while putting together my main program.

In my program I used the PCIntChange library to make it easy to do push button interrupts on any pin. In using this library, I commented out line 304 define inside SoftwareSerial.cpp, which disabled the PCINT0_vec ISR.... In doing this I disabled the pin change interrupt for D8 to D13, effectively disabling SoftwareSerial on all those pins.

I re-enabled that ISR in SoftwareSerial.cpp, it's now all good on pins 10 and 11. I also tried moving to pins 2 and 3, and re-disabling that ISR in SoftwareSerial, and it's good as well.

Anyway this reinforces the lesson that libraries are best left unchanged... I'll forge on from here... Thanks again.

Edit: I still don't know why this would reboot the Uno - I would have thought that it simply wouldn't do anything instead. Anyway, at least it is resolved.

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

Return to “Arduino”