So I have a weird issue... I basically have built a launchpad with an Arduino Nano and a controller with the same that connects to it via I2c and it works great however, for some reason it will only work if both Nanos are connected to a computer through USB?
Without the controller running USB even though it's battery-powered will not work at all? It still registers the signal etc as I have feedback of that from an LED.
The I2C bus has three wires: SDA, SCL, GND. Did you connect the GNDs ?
Are there long wires between the Arduino and the controller. The I2C is not meant to go into a cable.
If the I2C bus is not the problem, then perhaps how everything is powered or the grounding is a problem.
Can you make a drawing that shows the wires, the battery, the distances and so on ?
Can you show your sketch, perhaps you should check with every Wire.endTransmission() and every Wire.requestFrom() if you are actually communicating with the controller.
What is the controller ? Do you have a schematic ?
So I didn't realise this, do I literally just have to run a ground between them? I didn't know if it had to connect them both together with it or just have to have the obvious ground connection anyway, I didn't think it was a problem just because it worked if you get me.
Also, they are short cables about 25cm and don't seem to be a problem when it is connected to the PCs.
Sorry, I don't have a diagram yet I will try and get one tomorrow!
And the controller is just another Arduino Nano, sorry I didn't state that properly above! It's basically just sending a number if it switches number it changes state so really simple in that aspect.
Hope this info helps for now thanks for replying so fast!
The I2C bus is not that kind of bus. They are two different logic level signals that only exist when there is a GND.
Can you show the sketch of the Master and the Slave ?
If the cable is flat ribbon cable (or an other cable) and SDA is next to SCL, then 25cm is already too long. The I2C bus can not handle crosstalk between SDA and SCL.
Okay, I understand but if it's working when they are plugged into a PC surely they are talking correctly right?
And I will do a diagram today for you I am just in the process of it now. and no I haven't got pull up resistors. I knew I should add them but space is a big problem on the boards as they are packed. I tried it without them and it worked so I am here now with that other issue I presume this is the cause but its the fact they work when connected that baffles me!
The internal pullup resistors are 30k or 50k or so. Even if they are in each Arduino board, then it is still a high value. Can you add 4k7 pullup resistors at the Master ?
When SDA or SCL are low, then a Arduino board pulls that signal strong to GND.
When SDA or SCL are high, then the resistor keeps the signal high. That means the high level is vulnerable for noise.
You can draw something on a piece of paper and make a photo of it.
A few pixels, only 206 pixel height ?
What are the green and yellow wire ? I hope those are not SDA and SCL. The SDA and SCL have no meaning without GND.
@nathanielevans I don't know the details, but it's probably the case that when both Nanos are connected to the PC, their grounds are connected together via their USB leads and the PC.
When you unplug one or both from the PC, their grounds are no longer connected together. Just try connecting the two grounds together with a piece of wire, and then we'll know.
The I2C bus can not handle crosstalk between SDA and SCL. Keep those away from each other. The SDA and SCL can be close (or even paired with) a GND wire. That will give extra capacitance, but that is less of a problem. The pullup resistors can be lowered and the bus speed can be lowered when the capacitance gets too large.
There is a official I2C document UM10204 shows on page 60 to keep SDA away from SCL.
And then there is my wiki, where I collect the I2C things.