I searched the forum but didn't find anything for my problem.
I followed these instrunctions in Instructables website but instead I used an Arduino Mega and an Arduino Leonardo. I load the examples given though I cant' establish a connection between them.
I connected Leonardo SCL with Mega SCL/21 and Leo SDA with Mega SDA/20. Also I connected one random ground for each.
Both Arduinos are connected to my computer's USBs at the same time for power (COM3 and COM11) and I don't know if that could be a problem.
Instructables are often just about useless. I'm not about to wade through 47 links and shitloads of advertising to find the code you used on each Arduino. You post the code or live with the problem.
Did you at least run the I2C scanner on both Arduinos to make sure everything was connected correctly?
So I connect 2 Arduinos and from 1 Arduino I send anything to another where I load the scanner code and if it gets anything it prints it on screen. Or I don't have to load code to the first Arduino but only the scanner code to any of them?
Sorry but I am new...
where I load the scanner code and if it gets anything it prints it on screen.
No. The scanner sketch simply reports the address of any connected I2C devices. Run it on the Mega, when the Leonardo is connected (and running the current sketch). Does the Mega see the Leonardo?
Can you load the Slave sketch into the Slave ?
Either that instructables Slave sketch or the second sketch on this page : https://www.arduino.cc/en/Tutorial/MasterReader
After that, upload the i2c_scanner in the Master and it should detect the Slave. As soon as the Slave is detected, the I2C communication is working and after that you need a good sketch.
The I2C between two Arduino boards has a few things that you must know. A global variable that is changed in the onRequest or onReceive handler must be 'volatile' and you may not use the Serial in the onRequest or onReceive handler. That means that both examples (the instructables and the Arduino example) are both wrong.
Did you know that you can develop both sketches at the same time ?
Start the Arduino IDE, select the serial port and move it to one side of the screen.
Start another instance of the Arduino IDE, select the other serial port.
Then both Arduino IDE work independent of each other, and they both have also each their own serial monitor.
Could you describe exactly what your are doing ? Did you load the Slave sketch into the Slave ? which Slave sketch ? Please be very specific, don't mention the page, but tell us which sketch on that page.
Do you have a I2C sensor or some other I2C device, just to check that the i2c_scanner should see it.
If Arduino IDE 1.6.6 still can't make it work, there must be something we are missing.
Perhaps one of the wires is broken ?
Can you load the Slave sketch into the Slave ?
Either that instructables Slave sketch or the second sketch on this page : https://www.arduino.cc/en/Tutorial/MasterReader
After that, upload the i2c_scanner in the Master and it should detect the Slave. As soon as the Slave is detected, the I2C communication is working and after that you need a good sketch.
I loaded l2C scanner to Leonardo and Slave to MEGA. Both messages "Scanning... No I2C devices found"
Is there a specific way to declare which one is the master and which one is the slave?
Blank ? If it is not wired correctly then nothing is found. But if the i2c_scanner sketch halts, then the SDA and SCL are shortcut to each other or one of them is shortcut to ground.