Pages: [1]   Go Down
Author Topic: Can I I2C wire two Arduinos with USB cables on both?  (Read 1232 times)
0 Members and 1 Guest are viewing this topic.
Curitiba - Brazil
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi!

It's my first topic here and I spent the day searching on the web for it: I have 2 Arduinos (Seeduino R3 and Arduino Leonardo) that needs to be connected together via I2C but at the same time both via USB serial to the computer. And I never have seen such a thing.

My questions are:

1. Will it work, since both need to share the 5V and GND and both are with their own power supply (via USB)? I didn't try it just because I think it can harm the boards.

2. I tried to just connect the two cables for SCL and SDA without the 5V and GND and it all went fine when running the wire lib skecthes. Will it work on a long run or with a more complex program? Could this damage my Arduinos in anyway?

Anyone can help me?

Thank you,  smiley-wink

Mario
« Last Edit: January 28, 2013, 02:43:51 pm by mariocarta » Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 108
Posts: 5144
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
1. Will it work, since both need to share the 5V and GND and both are with their own power supply (via USB)? I didn't try it just because it think it can harm the boards.

The only other connection needed (besides the SDA and SCL lines) is GND. There's no need to connect the 5V.

Quote
2. I tried to just connect the two cables for SCL and SDA without the 5V and GND and it all went fine when running the wire lib skecthes. Will it work on a long run or with a more complex program? Could this damage my Arduinos in anyway?

That probably worked because you're using the same computer for the two Arduinos. That way they already share a common ground (over the USB connection). Just because of this you cannot damage your Arduinos.
Logged

Curitiba - Brazil
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The only other connection needed (besides the SDA and SCL lines) is GND. There's no need to connect the 5V.

OK, I will try it! smiley-grin

Quote
That probably worked because you're using the same computer for the two Arduinos. That way they already share a common ground (over the USB connection). Just because of this you cannot damage your Arduinos.

Good to know. I usually use my Mac Pro connected to my Leonardo and PowerBook to the other when coding, just to don't have to be switching between ports and boards on the Arduino app. Luckly, this time, I was too lazy to turn on the PowerBook and did all in the Mac Pro. I'll be on the safe side next time and ground both together...

I understand that this works with only 2 devices connected. More than this I'll need pull-up resistors connecting SDA and SCL to the 5V. I'm planning, in this setup, to add a I2C RTC to the Leonardo. So, will I need to make a pull-up from the  Leonardo's 5V, anyone or neither? Or this setup won't work at all?

Would you mind to share your source of information? I want to learn more about I2C from a complete source (I went crazy yesterday seeking for this information).

And how do I +Karma you? I can't see any button here for this...

Thanks a lot!
« Last Edit: January 18, 2013, 09:20:54 am by mariocarta » Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 518
Posts: 26378
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Don't forget 4.7K pullup resistors on the SDA/SCL lines on one board (not needed on  both).
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Switzerland
Offline Offline
Faraday Member
**
Karma: 108
Posts: 5144
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I understand that this works with only 2 devices connected. More than this I'll need pull-up resistors connecting SDA and SCL to the 5V. I'm planning, in this setup, to add a I2C RTC to the Leonardo. So, will I need to make a pull-up from the  Leonardo's 5V, anyone or neither? Or this setup won't work at all?

This works up to over 100 devices connected together (theoretically). You need pull-ups once per bus (again theoretically, for a few devices and a short bus this is correct). Adding the RTC should be no problem, just connect GND, SDA, SCL and Vcc (to power the RTC).

Quote
Would you mind to share your source of information? I want to learn more about I2C from a complete source (I went crazy yesterday seeking for this information).

There wasn't one single source of information, you get some experience if you work with it and read the forum  smiley.

Logged

Curitiba - Brazil
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you again!

I've just realised that to have the system working all the time, I will need to have, besides the 2 USB cables for serial communication, 2 power supplies (for when the computer is disconnected). There's anyway that I could use only one PS, say, for the Seeeduino R3, but keeping the features discussed above? (2 USB cables and I2C connection between both and the RTC)

If not, can the Leonardo "login the network" as a slave at anytime, i.e., when the computer starts and be recognized?

I need the Leonardo only to send my Mac keystrokes and shortcuts, for automation with Keyboard Maestro. I wouldn't need one more Arduino unless the EasyVR Shield were compatible with Leonardo. But also it would be great to have the IRRemote and VirtualWire libs running on different Arduinos, since they are incompatible (I think it has something to do with timers) and the workaround was to substitute VirtualWire with MANCHESTER for RF communications (yeah, I have anothers Arduinos receiving commands), which is far inferior than VW.

I hope I'm not asking too much...   smiley-sweat
« Last Edit: January 18, 2013, 05:16:32 pm by mariocarta » Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 108
Posts: 5144
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I've just realised that to have the system working all the time, I will need to have, besides the 2 USB cables for serial communication, 2 power supplies (for when the computer is disconnected). There's anyway that I could use only one PS, say, for the Seeeduino R3, but keeping the features discussed above? (2 USB cables and I2C connection between both and the RTC)

If you supply one Arduino, you can just connect the other with GND and 5V pins (on both MCs) and you have power for both. This works if the second Arduino doesn't pull too much power (the RTC is absolutely no problem).

Quote
If not, can the Leonardo "login the network" as a slave at anytime, i.e., when the computer starts and be recognized?

To wich network? In the previous posts you haven't had any network equipment involved. And what does "slave" mean in this context?

Quote
I wouldn't need one more Arduino unless the EasyVR Shield were compatible with Leonardo.

Unfortunately there doesn't seem to be any documentation about that shield. The library is fully compatible with the Leonardo, my guess is, the shield is too. At least I couldn't find any specification that would rule against that. Do you have a schematic of the shield (I couldn't find one)? The EasyVR module is completely compatible with the Arduino Leonardo. If the shield isn't done too badly it should be as well.
Logged

Curitiba - Brazil
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
If you supply one Arduino, you can just connect the other with GND and 5V pins (on both MCs) and you have power for both. This works if the second Arduino doesn't pull too much power (the RTC is absolutely no problem).

Sharing the 5V between them with USB cables connected to both? Could it be done? Is there some kind of protection as it has when you connect both USB and power supply?

 
Quote
To wich network? In the previous posts you haven't had any network equipment involved. And what does "slave" mean in this context?

I'm sorry, I didn't know how to name it, I meant the I2C "network"...

Quote
Unfortunately there doesn't seem to be any documentation about that shield. The library is fully compatible with the Leonardo, my guess is, the shield is too. At least I couldn't find any specification that would rule against that. Do you have a schematic of the shield (I couldn't find one)? The EasyVR module is completely compatible with the Arduino Leonardo. If the shield isn't done too badly it should be as well.

As I said on the original post for the EasyVR Shield problem: I changed the pins to 8/9 instead of 12/13 and while normal operation it works fine (with some few bugs). But Leonardo can't operate as a brigde between the Shield and the EasyVR Commander app (used to upload, voice commands to the module). Neither in PC mode (there are jumpers in the shield to choose which mode to use), used to upload soundtables, as it was expected, since the Arduino is held in reset just to interface the module thru the USB serial using the default pins (12/13).

The official answer to this question via email is that:
Quote
the leonardo has differences in the pinout.
Please check the following pages where the differences are.

http://arduino.cc/en/Guide/ArduinoLeonardo
http://arduino.cc/en/Reference/Serial

You need to change the pins accordingly.
which didn't get me very far, since there are no explanations about the pin diferences, only that Leo uses Serial1 instead of Serial to connect... I already tried changing on the libs, but without any changes.


Thank you for your constant help!
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 108
Posts: 5144
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Sharing the 5V between them with USB cables connected to both? Could it be done? Is there some kind of protection as it has when you connect both USB and power supply?

If the USB connection goes to the same computer you shouldn't have a problem. Else disconnect the 5V connection between the two Arduinos if you connect the other USB line.

I2C is not a network, it's a bus. And a slave cannot "login" to that bus, it just listens on the bus for commands from the master and replies if it's instructed to do so.

Quote
But Leonardo can't operate as a brigde between the Shield and the EasyVR Commander app (used to upload, voice commands to the module). Neither in PC mode (there are jumpers in the shield to choose which mode to use), used to upload soundtables, as it was expected, since the Arduino is held in reset just to interface the module thru the USB serial using the default pins (12/13).

That's something completely different. It seems that the PC mode just connects the serial interface of the EasyVR module to the pins 0 and 1 of the Arduino. Because the Leonardo has a completely different way of communicating with the PC over USB, this doesn't work out of the box. Do you know a what baudrate theat EasyVR Commander is communicating with the module?

To help you further with this stuff, I need the schematics of the EasyVR shield. If I don't know how this stuff is interconnected I'm always guessing and that's more than boring. Provide a link to the schematics of that shield.
Logged

Curitiba - Brazil
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
And a slave cannot "login" to that bus, it just listens on the bus for commands from the master and replies if it's instructed to do so.
So it's just need to be set as a slave for instructions purposes only! smiley-grin

Quote
Do you know a what baudrate theat EasyVR Commander is communicating with the module?
When at SW bridge mode, the same as the serial monitor:
Code:
 if (bridge.check())
  {
    cli();
    bridge.loop(0, 1, 12, 13);
  }
  // run normally
  Serial.begin(9600);
  //while(!Serial); //for when I need to debug the setup via serial monitor.
  
  port.begin(9600);

  if (!easyvr.detect())
  {
    Serial.println("EasyVR not detected!");
    for (;;);
  }

  easyvr.setPinOutput(EasyVR::IO1, LOW);
  Serial.println("EasyVR detected!");


But from the manual:
Quote
The initial configuration at power on is 9600 baud, 8 bit data, No parity, 1 bit stop. The baud rate can be changed later to operate in the range 9600 - 115200 baud.

When in PC mode, from the manual, again:
Quote
The full speed used is 230400 bit/s, but the option “Slow transfer” can be used to reduce it to 115200, for better compatibility with slower serial adapters2. One adapter that can go to full speed is the SmartVR DevBoard. Otherwise any USB/Serial adapter with TTL/CMOS interface can be used for updating the flash. The EasyVR Shield can be used for the download, provided that the jumper (J12) is in UP position.

Quote
To help you further with this stuff, I need the schematics of the EasyVR shield.
I asked the support guy via email for this, let's see what he replies!

Thanks!
« Last Edit: January 23, 2013, 08:00:57 pm by mariocarta » Logged

Curitiba - Brazil
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So, I finally got his answer and he sent me these schematics:
https://www.dropbox.com/s/6tk037c5u8g8pz1/EasyVR_Shield_R1D_sch.pdf

I hope that has anything that helps!

Cheers!
« Last Edit: January 28, 2013, 02:43:03 pm by mariocarta » Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 108
Posts: 5144
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I guess it should work with the EasyVR Command if you set it to slow mode and load the following sketch to the Leonardo before using it:

Code:
void setup() {
  Serial.begin(115200);
  Serial1.begin(115200);
}

void loop() {
  if (Serial.available()) {
    Serial1.write(Serial.read());
  }
  if (Serial1.available()) {
    Serial.write(Serial1.read());
  }
}

This is just copying data from the USB to the hardware serial and vice versa. Configure the jumper for hardware serial, also during the EasyVR Commander session.

The only problem that may still exist is the RST line. It's connected to the RESET line of the Arduino. If the EasyVR Commander controls that line via the DTR of the serial interface, I don't have a solution for that shield. Then it's probably easier to just buy a standard UNO for this shield.
Logged

Curitiba - Brazil
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks!

I'll try it! But I think that this means that I'll have to connect pins 0 and 1 from both together (the shield is now only connected via RST, GND, 5V pins 12 to 8 and 13 to 9 to the arduino). No biggie... jumper wires for the job!

Later I tell you what happened... smiley

Edit: It didn't work as well...

But I'm resigned. No big deal. I can always change it with the seeeduino everytime I want to update the soundtable or voice commands...

Thank for your willing to help all the time! I learned so much from here and the manuals!
« Last Edit: January 29, 2013, 04:02:30 pm by mariocarta » Logged

Pages: [1]   Go Up
Jump to: