Go Down

Topic: Problem with I2C senzor BH1750 - Arduino freezes (Read 295 times) previous topic - next topic

cevepe

The BH1750 sensor runs for a few hours (10-19 hours) and then the Arduino NANO freezes. It does not measure other sensors (wind, UV) until I disconnect this sensor. I tried to puncture the cables and there should be no short circuit. I tried two BH1750 sensors and always the same. I replaced the Arduino and still the same. I can't handle it anymore. I use a simple code: https://pastebin.com/720uyQrE
I only have one sensor connected to I2C (A4, A5). Can you advise what to do with it? I don't know what to do anymore. I have a CAT 5E cable barely 1 meter long.

Koepel

#1
Jun 29, 2020, 06:59 pm Last Edit: Jul 02, 2020, 08:38 pm by Koepel
The Arduino Nano is a 5V board with a 5V I2C bus.
The BH1750FVI is a 3.3V sensor.
That is a mismatch and that should be fixed when there is a problem.

Can you give a link to your BH1750 modules ? (a link to where you bought it).

Wich library do you use ?
This one ? https://github.com/PeterEmbedded/BH1750FVI
That library does not have delays, you should take care of the time that the sensor needs.

The I2C bus was not designed to go through a cable. That means any cable is wrong (unless it works ;) ).
Do you put SDA and SCL on the same twisted pair ? Crosstalk between SCL and SCL is the worst and can not be solved by a slower I2C bus. A slower bus can be made with Wire.setClock(50000);
What other signals are going through that cable ? Is the cable shielded ?

What is your pullup resistors ? What other modules are connected to the I2C bus ? Do those have pullup resistors ? Did you calculate the total pullup ?

Are those other sensors connected with other cables ?

Do you use Arduino IDE 1.8.13 ?
From version 1.8.13 on, there is a timeout for the I2C bus, but it is not turned on by default yet. The explanation is in the Wire.cpp file.
Could you add that timeout ?
Code: [Select]
Wire.begin();
Wire.setClock( 50000);  // optional, lower speed to 50kHz
Wire.setWireTimeout( 5000, true);  // in microsecond, timeout for faulty I2C bus.


You see, there is a lot to do to make the I2C bus reliable. You could have 10 things that makes the I2C bus unreliable.

enjoyneering

#2
Jul 02, 2020, 04:44 pm Last Edit: Jul 02, 2020, 04:44 pm by enjoyneering
better BH1750FVI library is here - https://github.com/enjoyneering/BH1750FVI

Go Up