Hi everyone,
in my preject based on arduino MKR GSM 1400 I am using an AM2315 (Temp/Humidity), an HP206c barometer and an SI1145 sunlight sensor.
If I upload my sketch defining and using each sensor alone they work well and reply with right values.
Apparently AM2315 seems to work fine always, alone and with the other, one or both barometer and sulnlight sensor.
Other two work only alone or only with AM2315.
If I define and use both together SI1145 and HP206c they stop to work. They reply to the inital check but values are incorrect.
Physical BUS is always te same. 2 pullup reristor of 2K are mounted and since every sensor works well when used alone (but all are connected anyway) I think it is not a physical problem.
I mean I tried each sensor alone defining and querying it when all sensors are still connected to the bus.
I2C default slave addresses are all different as specified on datasheets:
AM2315 - 0xB8
SI1145 - 0x60
HP206c - 0xEC
I don't know what to do anymore.
Thank you for any suggestion.
3.3V / 4k7 + 3.3V / 2k2 = 2.2mA
It should stay below 3mA.
Can you give links to the other modules or do you use the bare sensor chips ?
Perhaps those modules have level shifters, or pullup resistors or something else.
The AM2315 is "recommended" for 5V. According to the datasheet it operates at a voltage of 3.5 to 5.5V. That is a problem. But your tests show that the AM2315 is the one that is always working A bad I2C device can disturb the I2C bus for others, so anything is possible.
How long are the wires for the I2C bus ?
It could be a problem in the sketch, but I can not say for sure that it is not a physical problem. Did you try both sensors when the AM2315 is removed from the bus ?
Can you show your sketch ?
Can you also tell which libraries you use ? (where do they come from, how did you install them).
3.3V / 4k7 + 3.3V / 2k2 = 2.2mA
It should stay below 3mA.
About internal pullup resistor, I turn them off using
digitalWrite(SDA, LOW); digitalWrite(SCL, LOW);
Can you give links to the other modules or do you use the bare sensor chips ?
Perhaps those modules have level shifters, or pullup resistors or something else.
The AM2315 is "recommended" for 5V. According to the datasheet it operates at a voltage of 3.5 to 5.5V. That is a problem. But your tests show that the AM2315 is the one that is always working A bad I2C device can disturb the I2C bus for others, so anything is possible.
I2C pull up resistor and all I2C sensors are 5V powered --> So 5V/2K = 2.5mA Could be a problem?
Wires are quite long; About 2meters in total. (I know I2C isn't a good bus for long wire but AM2315 comes with 60cm wire and my project is a weather station, I cant keep all inside a box!)
Anyway, sensor alone works, so it works.
I tried both sensors without AM2315 linked and they work only alone. Together they stop to work.
Into the sketch I copied what is write in examples (am2315test, HP20x_demo, SI1145DEMO).
For AM2315 I use >Wire.h> and <Adafruit_AM2315.h>;
for SI1145 I use <Wire.h>, "Arduino.h" and "SI114X.h";
for HP206c I use <HP20x_dev.h>, "Arduino.h", <Wire.h> and <KalmanFilter.h>.
The 4k7 pullup resistors are not the internal pullup resistors in the processor, they are smd resistors soldered on the MKR board as you can see in the schematic.
The Connector Carrier uses a LSF0108 to make a 5V I2C bus. The "Grove" modules have level shifters to make it a 3.3V I2C for the sensors.
I assume that you have added the 2k2 pullup resistors at the 5V I2C of the "Grove" connectors.
Let's do some math for the combined pullup:
MKR board: 3.3V / 4k7
Connector Carrier: ?
Extra: 5V / 2k2
AM2315: no pullup resistors
SI1145: 5V / 4k7 + 3.3V / 4k7 (4k7 on both sides of the level shifter)
HP206c: 5V / 10k + 3.3V / 10k (10k on both sides of the level shifter)
Total: 5.5mA
That is too much. Most I2C devices don't mind a little more sink current, but perhaps those two sensors don't like it.
Remove the 2k2 and try if that makes a difference.
When there is a problem with the I2C bus, you better start to reduce the total length for SDA and SCL to a maximum of 50cm.
Do you use a cable for the I2C bus ? The Adafruit AM2315 has a cable, that already weakens the I2C bus.
The I2C bus was designed to be used on the same pcb board. It was not designed to go through a cable.
That is too much. Most I2C devices don't mind a little more sink current, but perhaps those two sensors don't like it.
Remove the 2k2 and try if that makes a difference.
Done, and the bus worked worse.
Than I try to replace 2k2 resistors with a 1K670 resistors and seem to work better; but not perfectly.
I mean, assuming that AM2315 works always, with or without pull-up resistors, without resistors the barometer and the SI1145 don't work al all. No value are displayed.
Using 1K670 resistors the barometer seems to work, showing acceptable values and SI1145 show values though not acceptable.
Anyway, the bus stay instable as somethimes values fall to 0.
So, it seems that the bus need more current.
Otherwise, in order to preserve sensors I will try a couple of MOD-000028 I2C bus extender.
At now I can't make wires shorter than a meter.
When the sink current is more than 3mA, then you are fixing a problem by creating a new problem.
Even without the 2k2 resistors, the sink current is too much. You have to remove more pullup resistors.
Since you use a 3.3V board and the Groove I2C bus is a 5V I2C bus, the I2C signals are shifted up from the board to the Grove bus, that makes the signal weaker.
On the module the Grove I2C bus signals are shifted down to 3.3V for the sensor, that also makes the signal weaker.
Two level shifters after each other is terribly bad. I have some explanation here: Be carefull with I2C level shifters.
You can blame the Grove I2C bus for making it unreliable.