I just re-wired a project, and after doing so none of my IC2 devices seem to be working. I have a UNO board with a CCS811 air quality sensor and a BH1750 light sensor hooked up to the A4 & 5 ports on the board. After the re-wiring, the CCS811 sensor that was already being used in this project stopped working, only reporting a "I2C_ERROR" when the same code is run. When I tried to hook up the light sensor, I tried using a few libraries, and the most successful only gave me random characters ([[[[[[[F[[[P), and others did not give me anything back at all. I tried to use a I2C device scanner, which did not find anything (I can provide the code if necessary), and I then tested the A4 and A5 ports with this thread here: https://forum.arduino.cc/index.php?topic=385961.0 . This told me that the two plugs are fine, and my wiring seems correct. Any ideas or suggestions?
Thank you in advance!
Post your codes please.
The BH1750 and the CCS811 are 3.3V sensors and the Arduino Uno is a 5V board. How did you fix that ?
To test the I2C bus, always use a I2C Scanner. When the I2C Scanner can not find a sensor, then you don't need to test a library. It must be found before you can go on.
When a sensor is not connected then some libraries return zero or a random number or a strange text. That is not reliable.
It seems that your I2C bus is not working.
Koepel:
The BH1750 and the CCS811 are 3.3V sensors and the Arduino Uno is a 5V board. How did you fix that ?
I was using the 3.3v port on the board to power the two sensors, and it was working with the CCS811 before. I did test the A4 and A5 ports on the board (the one that most tutorials say to use) using a jumper in-between them to test the input and output, which looked fine, but I don't know if those can still work while the I2C circuit its fried. What could I do to test the I2C circuit? The board also has what look like dedicated SDA and SCL ports, but they did not work with my code, and I do not know what I would have to change.
Thank you for your response!
The Arduino Uno has A4, A5 and also SDA, SCL pins. They are the same, they are connected to each other.
Can you give a link or a photo to the sensor modules that you use ?
Do you use long wires or a cable for the I2C bus ?
The internal pullup resistor is enabled by the Wire library and that could lift the SDA and SCL to 5V. Some sensors don't like that. With a 4k7 external pullup resistor to 3.3V and ignoring the specifications in the datasheet, it might work. However as soon as, for example, a 5V I2C display is connected, everything changes.
You better use a I2C level shifter or buy a Arduino 3.3V board, for example one of the MKR boards.
Your code or any library is not important at this moment. You need a I2C Scanner sketch and try to make the I2C bus work.
To analyze the I2C bus, a Logic Analyzer is very helpful.
Can you get a new Arduino board and an other I2C sensor ? Some I2C devices work with 3.3V and 5V, for example the RTC DS3231. If something is broken, then you first need something that is working. Use only the I2C Scanner.
I will continue testing, but I think that the problem is that the two devices are asking for two different voltages from the I2C bus. That still does not explain the original not working, but it is a start.
My two sensors:
http://wiki.sunfounder.cc/index.php?title=GY-302_BH1750_Digital_Light_Intensity_Module
(new)
(original)
My wires where not very long, but I did use a few short wires to make things neater.
I think that a level converter is the only path left to take, I will try that and update when I get it and if I got it working or if it still doesn't work. Also, is a logic analyzer something I can just code into the arduino or is that a different piece of hardware?
Thanks for the help!
It is possible to destroy 3.3V sensors by attempting to interface them with 5V Arduinos, and the fatal damage does not necessarily occur immediately. It is best to use a 3.3V Arduino with 3.3V sensors, second best is level shifters.
If you can't get them to work with level shifters in your original setup, time to buy new sensors.
Many of us have all made that mistake and marked it up to learning.
Both modules have 4k7 pullup resistors to 3.3V on the module for both SDA and SCL.
The current to pull a signal low is: 3.3V / (4k7 // 4k7) = 1.4 mA
That is okay, it should be below 3 mA.
The means the SDA and SCL are pulled towards the 3.3V and the internal pullup resistor on the Arduino Uno is not enough to damage the sensors. So you have luck 8) Connecting them to the Arduino Uno did not damage them.
The BH1750 module has a voltage regulator. When you power the VCC of the module with 3.3V, the BH1750 might be running at 3.2V and the 4k7 pullup resistors are connected to that 3.2V. That might not be enough for the Arduino Uno which needs 3.5V for SDA and SCL to see it as a high level (according to the datasheet). In real life, it should still work.
You can make it better if you connect the VCC of that module to 5V.
The Sparkfun sensor module does not have a voltage regulator, you must connect its VCC to 3.3V or else the sensor will be broken.
Conclusion: It is not so bad after all, it should work. A I2C level shifter prefents all these problems, so I suggest you use one.
It seems that something is broken. Perhaps one or two sensors, perhaps the Arduino board, perhaps all three. You need new hardware. It happened to me as well a few times when I started with Arduino.
Koepel:
It seems that something is broken. Perhaps one or two sensors, perhaps the Arduino board, perhaps all three. You need new hardware. It happened to me as well a few times when I started with Arduino.
Should we guess that something is broken; or should we look for broken things following well established troubleshooting guide lines?