Two arduinos talking over I2C

Hello,

I have tried to connect two arduinos using I2c protocol : https://www.youtube.com/watch?v=Jndb2vpAWwU Unfortunately it did not work and I dont know why :( .

I have also tried this one :http://arduino.cc/en/Tutorial/MasterWriter. Also no succsses.

*I have connected all grounds together , *I am almost electrical engineer now so I know somthing about electrisity but I can't make this work. I really need those arduinos to talk to each other.

Here is the link to what I did:

https://drive.google.com/folderview?id=0B_9n0eOGDfdkfjhpdlZLMWsyTHA0MW1ncDZjSGJ5ZE5GQTNRLXNIdXd3eTdlRndTRHhJWFk&usp=sharing

Thanx, Michael

All you are saying here is “I tried this and it did not work”
How can someone tell what you did wrong?

Post your code, post a schematic, post a photograph no more than 1000 pixels wide.

I have posted a video there on the google drive. Code is compied from the youtube video(Human HardDrive)

mike_mara: I have posted a video there on the google drive link.

Sorry but I thought you wanted help. Looks like I was wrong. Good luck.

If you want somthing to read and not to watch it’s ok I will write it down.

I had a project which connected 2 Arduinos in a similar way to what you are looking to do. Picture of the Ftritzing sketch here

The full project and code is here - it may or may not help... but I thought that the picture above is more likely to help you out.

If you could post your code and include a sketch which shows how you have hooked it all up - that would help. Much easier to read on the forum than through a wobbly camera.

Connecting two 5V rails together is not a good idea. Missing out the pull up resistors is not a good idea.

Two arduinos talking over I2C protocol.

So as I mantioned before, I have used HumanHarddrive youtube webinar to create this : Arduino Tutorial #10: Arduino to Arduino I2C - YouTube.

Two arduinos were implemented. I named them “Master” and “Slave”.

Here is the code for Master:


//i2c Master Code(UNO)
#include <Wire.h>

void setup()
{
Serial.begin(9600);

Wire.begin();
}

void loop()
{
while(Serial.available())
{
char c = Serial.read();

if(c == ‘H’)
{
Wire.beginTransmission(5);
Wire.write(‘H’);
Wire.endTransmission();
}
else if(c == ‘L’)
{
Wire.beginTransmission(5);
Wire.write(‘L’);
Wire.endTransmission();
}
}
}

Here is the code for Slave:


//i2c Slave Code(Uno)
#include <Wire.h>

void setup()
{
Wire.begin(5);
Wire.onReceive(receiveEvent);

pinMode(13,OUTPUT);
digitalWrite(13,LOW);
}

void loop()
{
}

void receiveEvent(int howMany)
{
while(Wire.available())
{
char c = Wire.read();

if(c == ‘H’)
{
digitalWrite(13,HIGH);
}
else if(c == ‘L’)
{
digitalWrite(13,LOW);
}
}
}


I have connected my computer to Master (seriel) just as in the added photo and in the “HumanHarddrive”. Unfortunatly slave’s 13 led does not respond.

*My schematic is attached in next comment.
*Pull up resistors are 4.7k.

the link for schematic:

https://drive.google.com/file/d/0B_9n0eOGDfdkOF9XZWdLTzVCTU0/view?usp=sharing

ScottC, I have tried to do simillar assembly : http://arduino.cc/en/Tutorial/MasterWriter. It also didn't work for me. I dont know what is wrong. I have a scop at home but I see no clock pulse comming out of any arduino.

mike_mara, Watching those movies and trying to see what the code is, that was inconvenient. When you show your sketch, please use the code tags. Code tags are explained on this page at number 7 : http://forum.arduino.cc/index.php/topic,148850.0.html

First of all, you don't have to connect the USB to either the Master or the Slave, you can connect both ! Connect the Master to the computer, start the Arduino IDE, select the com port of the Master. After that, also connect the Slave (use a USB hub if you have to), start another instance of the Arduino IDE, select the com port of the Slave. Now you have two Arduino IDE running at the same time, and you can open both serial monitors.

I don't see the fault in your sketch or the hardware. Perhaps the breadboard has bad contacts. You could move everything to a different location on the breadboard.

Could you turn on the led in the receiveEvent() ?

void receiveEvent(int howMany)
{
  digitalWrite( 13, HIGH);   // ADDED FOR TEST

 while(Wire.available())
 {
  ...

As soon as you send something, it should turn on.

If that is not working, let's do something even more basic. Run the i2c_scanner on the Master. http://playground.arduino.cc/Main/I2cScanner Measure the SCL and SDA on the Master at the SCL and SDA pins and A4 and A5 pins. They both should have pulses.

I could not tell from your video whether the RX lights were flashing when you sent the 'H' from the Serial Monitor. Also could not tell whether your Serial Monitor was using the same Baud rate as that programmed in your code... sorry - just need to confirm some basic stuff.

Grumpy Mike said that leaving out the pull-up resistors was not a good idea. And he would know better than me. However, I followed the Arduino website here, and there were no indications of a pull-up resistor being used. I followed that schematic and it worked for me... but like I said... Grumpy Mike has advised against that - so you might want to find out why there is a pull-up resistor there, and what effect it has.

Also - you have connected the 5V of the master to the 5V of the Slave. I'm pretty sure your setup will work, but it bypasses the 5V regulator - so this is not a good idea as you could fry many components within the Arduino board (if you haven't done so already) if the voltage exceeds 5V.

I connected 5V of the MASTER Arduino to the VIN of the SLAVE Arduino.

The MasterWriter is not the best example there is. I think it is very confusing. An example with sending an 16-bit integer would be more useful.

The Arduino Wire library enables the internal weak pullup resistors at the moment. Those are very weak pullup resistors, and maybe in the future the Wire library will no longer do that.

Connecting both 5V pin is not a good idea, but I do that myself for a short test. I don't mind two voltage regulators fighting over the same 5V, or one that has a reverse voltage. If one of those boards would have an external power supply to the power jack, that could cause trouble in that situation.

%$#, I just can't make it work :( I dont know why.I am fighting with it for 5 days already. Can anyone talk to me privatly I promise to make a full report on this problem.

I am electrical engineering student and It's a small but very needed part of my graduation project. I can't finish without two arduinos talking to each other.

Please, If someone has the time to talk to me via Email, skype or facebook I will be more then happy.

*I have posted (google drive) another two videos 00006 and 00007 trying to accomplish this with two computers for two arduinos, no luck.

*I have also tried to use this I2C scanner but it just shows "scanning" for alot of time as if It can find nothing.

*If you people help me here I promise to support arduino not only because of your help but also because I love it so much.

Google drive: https://drive.google.com/folderview?id=0B_9n0eOGDfdkfjhpdlZLMWsyTHA0MW1ncDZjSGJ5ZE5GQTNRLXNIdXd3eTdlRndTRHhJWFk&usp=sharing

My email : mike.marachov@gmail.com Mike

Make sure you use pull up resistors.

See: http://www.gammon.com.au/i2c

.

My pull ups are 4.7k

When you use the i2c_scanner, does it say "Scanning..." and nothing else ? That means that the sketch is halted, which means that your hardware I2C bus is wrong.

Are they official Arduino boards ? Check the boards one by one. There is probably a shortcut of: SDA to GND SCL to GND SDA to SCL SDA to AREF

Run the i2c_scanner on both, without something connected to the pins. The one that halts the sketch is the bad board.

________________Problem Solved_____________________

Look what I found...http://forum.arduino.cc/index.php?topic=231914.0

I #$#en hate this this chinese chip retailers.