In my "simple" project, I'm using a Nano (from AZ Delivery), an I2C Screen (Écran OLED I2C - 1,3 pouces – AZ-Delivery) and a BMP_280 I2C temperature sensor.
All is functionning (sensor, screen) but sometimes (from one our to some days), my Nano freezes and nothing is functionning. I need to reboot it.
I'm using <U8x8lib.h> and <Adafruit_BMP280.h> includes.
My question is to know if there is a problem with the I2C bus and if these libraries manage correctly the slave state of my 2 equipments ?
In your opinion, do the freeze comes from data collision (I try to read before the other slave ha terminated read or write) ?
Are they functions in these two libraries that ensure the bus is clean before trying to use by the other slave ?
Is there temporisation to respect when using two slaves ?
etc ... ?
Please, give me paths for reflection.
Of course, I can give you my code if you want.
Thanks a lot.
Your Nano is a 5V board with 5V signals.
The BMP280 is a 3.3V sensor.
A OLED is for 3.3V, but it will not get damaged too quickly with 5V. Only Adafruit makes OLED display that is compatible with 5V. An OLED is known to be able to disturb the I2C bus for others. That is what they do.
That is already four problems, and you are not the only one with these problems.
Some have also long cables or two level shifters in the I2C path. Then it will never work. Perhaps you need to buy an other display.
Can you remove the OLED and get the BMP280 working ?
Does your BMP280 module have onboard level shifters ?
The Wire library is okay and you can use the other libraries without problem. They operate only on their own device, even if everything is connected to the same I2C bus.
Hello Koepel and thanks for you attention. Here are my remarks:
-if the signals are not compatible (3.3 vs 5.0), do you think the problem could come from this difference too ?
-if I remove my OLED to test, I'm not sure to see the issue because the problem can make 1 day to arrive.
-I'm really glad to hear to problem seems to be general. I started pulling my hair out !
I 'm trying to check my module to see if it could work at 5.0 v and if not, try to use a 3.3/5.0 converter.
Thanks for your return. Have a nice day.
Please a link to where you bought the BMP280 module.
It could already be damaged.
The freezing could be a problem in your sketch, but the Wire library can halt a sketch. Since you have a OLED and a voltage mismatch, it is most likely a I2C problem.
Do you use long wires or a cable ? The worst thing is SDA and SCL next to each other in a flat ribbon cable.
In Arduino IDE 1.8.13 (the newest version), they put anti-freeze in the Wire library. But it is not turned on by default.
See this: ArduinoCore-avr/Wire.cpp at master · arduino/ArduinoCore-avr · GitHub
I think calling setWireTimeout() without parameter (default parameters will be used) after Wire.begin() should solve most problems.
When the Wire libraries catches a bus problem and the timeout kicks in, then the data is not valid. Do bad things happen in your sketch with bad data ?
My BMP-280 comes from Az-Delivery (Capteur barométrique GY-BMP280 pour la mesure de la pression atmosphér – AZ-Delivery).
I precise too that in my case I use BMP-280 and OLE libraries (<U8x8lib.h> and <Adafruit_BMP280.h>).
So, I do not manage my devices with Wire.begin()/Wire.end() commands but with these commands instead:
/* Create devices */
U8X8_SH1106_128X64_NONAME_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE);
/* Init screen and print data on screen */
u8x8.drawString(0, 0, "Bla bla");
/* Init and read temp */
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */
Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */
Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */
Adafruit_BMP280::FILTER_X16, /* Filtering. */
Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */
Another idea: I saw that sometimes resitors are added on SCK and SDA pins. Do you think this is a good idea in my case ?
Your BMP280 module has already 10k pullup resistors. The OLED might also have pullup resistors on its board.
Your BMP280 module is not compatible with a Arduino Nano. The BMP280 might already be damaged.
The OLED is also for a 3.3V I2C bus, but it will not break with a 5V I2C, it will disturb the I2C bus for others.
You need a level shifter between the Arduino Nano and the BMP280/OLED. Then you only can hope that the BMP280 and the OLED don't hate each other too much.
I did not look at the code in your sketch. You can start with an example that comes with the library.
In the doc (non official), I see that about my OLED:
"The OLED screen and SH1106 driver chip operate in the 3.3V range. But there is an on-board 3.3V voltage regulator, which means that these screens can operate in the 5V range.".
But, in doubt, I just installed a 3.3/5.0 V convertor between my Nano, my BMP280 and my OLED too.
Hope that resolves my freeze problem. Thanks again.
I will tell you.
Have a nice day.
One fail in a year for the I2C bus is acceptable for a test setup. For the final project there should be no I2C problems at all. If you still get I2C problems, can you make a photo of everything with the wiring ?
The problem is the I2C bus, not the power for the OLED. The OLED itself runs at 3.3V, so for the best result the SDA and SCL for the OLED should be 3.3V signals as well.
Since my last modification (add a 3.3/5.0 V convertor), my system is working without freezing. It seems to be the problem/solution. Hope this is really over.
Big thanks a lot for your time. Have a nice day.
Since my last modification (add a 3.3/5.0 V convertor), my system is working without freezing.
I have the same problems with 1.3" I2C SH1106 Oled in combination with a I2C DS3231 RTC. It worked fine till i switched on or off my soldering-iron.. So this randomness can be a refrigirator swithing on, for instance..
With the same library i have no single problem with SSD1306 Oleds They seem to be more forgiving, dealing with distortions on the SDA and SCL lines..
Both displays have pull-up resistors so what can be the difference??
Anyway, i will try this 3.3V and see if this solves it as i still have loads of SH1106 (received them for the ordered SSD1306.. )
@TechGraphix, you should have started a new topic because your problem might need an other solution. This is sometimes called hijacking of a thread.
The I2C bus is weak (because of the pullup resistors to make the signal high) and is designed to be used on the same pcb board.
The I2C bus should work all the time 100%, the basic I2C protocol can not deal with glitches and noise.
The OLED displays disturb the I2C bus for others. That is what they do. They should be connected to a 3.3V I2C bus.
Perhaps the SH1106 behaves worse than the SSD1306. Perhaps the SSD1306 does not cause any problems. I don't know, I just see a lot of problems on this forum as soon as a OLED is connected to a I2C bus.
The DS3231 works at 3.3V and at 5V, however some modules have a charging circuit that will damage the battery at 5V.
To solve your problem we need to know:
- How is the Arduino powered ? Could it be a bad power supply that passes on the glitches from the mains ? Could it be a cheap USB cable and the Arduino 5V pin is below 4.5V ?
- How is your grounding ? Is there somewhere a bad GND connecting or long wires ?
- Which Arduino board do you use ?
- How long are the wires for the I2C bus ? Do you use a cable ? What kind of cable ?
- Do you use a breadboard with jumper wires ? Breadboards often make bad contacts and jumper wires can be broken.
- Can you give a link to the modules that you use ? Preferably a link to where you bought them.