Problem with two I2C devices

Hello,

I work on an Arduino Mega 2560. I use a humidity/temperature sensor (HTU21DF) and a Serial Oled Screen (DigoleSerialDisp DS160128COLED-46). These two use I2C connection. They have different adress and they are connected in parallel.

My program is for now really simple, I get temperature and humidity by the Adafruit library HTU21DF (Note : I also try with different library than this one) I send it to a Http server by a 3G module and display it on my oled screen.

So, there is the problem : my system works perfectly but then the screen freeze for no reason randomly (it could happen after 1min or 1h of execution).

However, the program still running (the 3G module send data to the cloud each 5 seconds and I can check it from my navigator). And on the navigator, I receive temperature and humidity data correctly.

If I unplugged / replugged my screen, it works again.

If I unplugged my HTU module and remove it from my code, my screen has no displaying problem after few hours of execution.

I also changed my Wire library many times, it doesn't to change anything...

I change all of my devices (I also pass on a Arduino uno), nothing happened...

If you have any idea, I'm more than interrested !

It could be a programming error but without seeing the programming it will be hard to tell.

Could also be a hardware problem.
What is the combined pull-up resistance on your I2C lines.
I know the Mega has 10k resistors, the Uno has none.
If you use cable to connect to the devices, what is the length and what is the total cable capacitance.
Leo..

Based on I2C specs, non of the devices should have pull up resisters. But in real world some devices do have pull up resistors.
Based on I2C specs, you should place the two pull up resistors on the wires yourself.

If your devices do have pull up resisters built onboard, it could be that there are to many on the network. Check your devices. The I2C network is designed for short distance wiring (about 2 meters). If you have a long wire, it could cause problems.

It does not make a difference if the resistors are located on the wires or on the devices.
You should however know the I2C specs of the devices and the total pull-up resistance you have in your circuit.

Wire length is not important. Bus (wire) capacitance is.
Cat-6 wire is 51pf/meter (wire pair).
AFAIK, standard I2C specs <=400pf and <=3mA pull-up (1k6).
If you run clock and ground over different pairs, you could have upto ~7meters (total) length.

I actually have a home lighting system running 24/7, without problems, with ~7meters of Cat-6 between a Mega and two I2C devices.
Leo…

There is a lot of information on the internet about the WIRE library "hanging" or "freezing" at times.

Here are just two links:
http://forum.arduino.cc/index.php/topic,19624.0.html

Hi all, thank you for your replies !

johnwasser:
It could be a programming error but without seeing the programming it will be hard to tell.

[quote author=Archibald
link=msg=2393558 date=1442020077]
There is a lot of information on the internet about the WIRE library “hanging” or “freezing” at times.

Here are just two links:
http://forum.arduino.cc/index.php/topic,19624.0.html
http://www.gammon.com.au/forum/?id=10896&reply=7#reply7
[/quote]

Obviously, it’s not a programming error because it’s the screen whose freezing. The program still running (It keep send me data via 3G). And if I unplugged/replugged the screen, data is updating on it again.

However, there is my code (it’s quite simple) :

#define _Digole_Serial_I2C_

#include <Wire.h>
#include <SoftwareSerial.h>
#include "Adafruit_HTU21DF.h"
#include "DigoleSerialDisp.h"

HTU21D htu = HTU21D();
DigoleSerialDisp display(&Wire, 0x27);

void setup()
{
	Serial.begin(9600);
	htu.begin();

	display.begin();
	display.clearScreen();
}

void loop()
{
	display.setPrintPos(0, 0);
	display.println(htu.readHumidity());
	display.println(htu.readTemperature());

	delay(10);
}

My installation is also pretty simple and the wiring doesn’t up to 50cm.

I notice that once the screen freezes, if I unplugged/replugged it, it freeze again later but between 10seconds or 1min this time.

I have no electronical knowledge so if I have to put pull-up resistor, could you indicate me where I have to put them ?

I had first try on a Particle system, on a photon (https://docs.particle.io/guide/getting-started/start/photon/) and I had exactly the same problem.

(Sorry for my bad english)

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you please post a picture of your project?

How are you powering all the hardware?

Tom..... :slight_smile:

Hi Tom

Here is a picture of my system in attachment files. The top part above the I2C network is about a dust captor and a simple switch.

My system is powered by an external source which provide 9V / 1A.

The I2C network is powered by the 5V pin of the Mega (4.97V get on multimeter).

Is that the Adafruit TH sensor.
Datasheet shows 3.3volt only.
Leo…

Hi,

Where you have the jumpers from the sensor and the display coming together, can you spread the rows out so you have a vacant row between lines, that is instead of power and data lines being in side by side rows place a blank row between them.
You might have some crosstalk.

Also the humdity sensor breakout is..

so we spun up a breakout board that includes the Filtered version (the white bit of plastic which is a PTFE filter to keep the sensor clean), a 3.3V regulator and I2C level shifting circuitry. This lets you use it safely with any kind of microcontroller with 3.3V-5V power or logic.

The display can pull up to 110mA, not sure what the 5V of the mega is able to supply....
Tom.... :slight_smile:

TomGeorge:
The display can pull up to 110mA, not sure what the 5V of the mega is able to supply....

Good question.
110mA should be no problem with a 9volt supply on the DC socket, but there is also a shield on top of the Mega.
Not sure if that's drawing power from Vin or from 5volt.
OP could feel the temp of the regulator next to the DC socket.

I still think OP should try two 4k7 pull-up resistors on the I2C bus.
One from 5volt to clock, and one from 5volt to data.
Leo..

Now, it seems that it freeze the entire system after long hour of execution. This is more problematic.

I will try to put two 4k7 pull-up resistor this week, I have only 1k here with me.

I'm getting you informed, thank you guys ! :slight_smile:

Hi,
The display is connected to the 5V of the arduino or the 9V supply?

Tom.... :slight_smile:

The I2C network is 5V powered. By the way, the display has a voltage working range of 3.0V to 9.0V

Hi,
You symptoms appear to me to be a slowly overheating 5V regulator on the mega board.

With display and G3 and sensor ,I'd say its well and truly on the cards.

The G3 will probably put a heavy load on the 5V when it transmits, so if the regulator is near its maximum limits when just idling, then going into transmit may cause it to drop out of regulation.

Tom.... :slight_smile:
Not sure where the 5v regulator is on the mega but if you know, place your finger on it after it has been on for a while, or when your display locks up and see if its hot.

Tom.... :slight_smile:

You might want to get a regulated 5V power supply and connect power and ground lines to your shield and any other boards from it, of course connecting ground from that to ground on the Mega as well. Distribute power and ground, less will need to come through the Mega which has a limit.

This year I’ve gotten into DC-DC converters. You can drop 12V to 5V and instead of 7V of that being converted to HEAT, most is converted to current. A 3A buck converter can be had for < $2.
If you’re running on batteries, converters should be just about required. :o

Hi all !

So today I put two 4k7 pull-up resistors on the I2C bus (one from 5v to SCL, and one from 5v to SDA). Nothing changed, the display freezed.

I checked the 5V regulator on the arduino but it isn't particulary hot..

I'm running out of ideas..

Just for the heck of it, try this change.

void loop()
{
	display.setPrintPos(0, 0);
	int hum = htu.readHumidity();
	int tem = htu.readTemperature();

	delay(10);

	display.println(hum);
	display.println(tem);
}

"I notice that once the screen freezes, if I unplugged/replugged it, it freeze again later but between 10seconds or 1min this time."
I am not sure if the screen freezes, or the processor stops working. Your code seems not to have a "blink LED function" that would let us know if the processor is still running. Can you add that function so we can tell if the processor is halted or running?