Help with an I2C issue, RTC and LCD

Hi -

Im having some trouble debugging a problem I see with my arduino uno r3 using wire.h and a I2C comm with a RTC and a LCD.

The code and circuit is attached), but basically its a key pad controller for an alarm system and its working good except every day or so the LCD locks up (or prints crazy char like ##$&@#####). The end result is either odd characters or a watchdog timeout and a reboot which clears the issue.

After reading a bit, I found an old post from 2010 which talks about "I2C freezes" and some solutions with modifying the wire.h lib? Is this still a know bug? link

I looked at the clk and data on the scope, and it looks like its a crisp rise and fall signal.... pics attached.

anyone have experience / suggestions on why im experiencing this lock up? open to all help....

AG

fail mode.jpg

working.jpg

clock.jpg

data.jpg

Alarm_r2.pdf (76 KB)

Master_keypad_r16.ino (18.3 KB)

Hi, welcome to the forum.
Thanks for all the information :slight_smile:
I noticed that no one answered your first post :cry: Did you fix the serial data issue ? You can start a new topic for that, if possible pinpoint the problems to a single problem.

Well, yes, sadly the Wire library is still blocking when the signals on the I2C bus are not okay.
I have to disagree on the crisp signals. When SDA and SCL are in a flat ribbon cable, a pulse of the clock could inject into the data signal. That would destroy the I2C communication.

Are you sure that the sketch is locked up because of the I2C bus, or is only the display going haywire ?

Can you give a link to the display ?

Is that an official Arduino Uno board ?

There are a number of things you can do:

  • Split the wires of the flat ribbon cable to the display. It may be less pretty, but it is necessary.
  • I don't see 100nF decoupling capacitors at the 5V and 12V. You could add a few.
  • The output of the Arduino Uno (Ctrl ARM Req, WD Ctrl) is not protected. A 100 ohm resistor would do.
  • Is the voltage regulator on the Uno board getting hot ? You could use the OKI-78SR to power the Uno at the 5V pin. But you need a protection diode from 5V to VIN to protect the voltage regulator on the Arduino Uno against reverse voltage.
  • You could throw in a capacitor of 47uF or 100uF at the 5V pin of the Arduino and the 5V pin of the RTC. This may seem strange, but when there is a problem with capacitors on the board and in the modules, an extra capacitor does help a lot.
  • What kind of buzzer is it ? A piezo element (the round disc) ? You have to use a 120 ohm resistor to a piezo element.
  • The 12V from the adaptor is going into the wire without any filter. There can be a lot of electric noise that could cross-talk into the other signals. I would use a LC filter (capacitor + ferrite-with-coil + capacitor) at the incoming 12V at the Arduino Uno. And also a filter near the Arduino Mega 2560, before it is put onto the cable.

Peter_n - Hi and thank you for your detailed write up. I will provide some more detail and go thru this line by line below. Lets table my first post, it was for work and this project is for my house... which is far cooler on and gets priority :slight_smile:

I have to disagree on the crisp signals. When SDA and SCL are in a flat ribbon cable, a pulse of the clock could inject into the data signal. That would destroy the I2C communication.

I cant tell if the data line on the Oscope from my last post picture looks good or not? Not to show my age, but im having trouble reading the phosphorus scope. Im accustom to the digital scopes at work :smiling_imp: My scope at the house was a free-be. Splitting the ribbon cable is a good test.

Are you sure that the sketch is locked up because of the I2C bus, or is only the display going haywire ?

There are 2 fail modes:
1 - the char issue ("haywire") as pictured does not always lock up the UNO and it seems as if its just garbage on the LCD... some times it clears and some times it sticks and trips the watchdog. I can not reproduce this... bummer

2 - LCD freeze, the HH:MM:SS stops and the Uno locks up for sure. No I/O operation and the watchdog in the sketch times out, with a reboot. I can reproduce this very easy by loading down the clk or data on the I2c with a 0.1 cap across A5 and A4.

More info - I have a few sections in my code were I used delay(500) :frowning: and not a getmills type counter loop. When this executes, I do see the I2C go silent (as expected) and then come back up. Is this proper? or could that be causing issues?

Can you give a link to the display ?

Yes - its a cheap one link , this was just to get me off the ground. Now that im up and running. I would consider buying a better model if you know of one?

Is that an official Arduino Uno board ?

Yes sir, R3 UNO.

Split the wires of the flat ribbon cable to the display. It may be less pretty, but it is necessary.

wow- probably the best place to start. ill give that a try today.

I don't see 100nF decoupling capacitors at the 5V and 12V. You could add a few.

That was my first thought, but after probing with the scope, the 5 and 12 were clean. Good point & design practice. I added a few to the schematic (maybe take a look, rev3 attached)

The output of the Arduino Uno (Ctrl ARM Req, WD Ctrl) is not protected. A 100 ohm resistor would do.

Correct, but did you see the 1k Res on the Mega side? its part of the low pass filter. so i think im covered.

Is the voltage regulator on the Uno board getting hot ? You could use the OKI-78SR to power the Uno at the 5V pin. But you need a protection diode from 5V to VIN to protect the voltage regulator on the Arduino Uno against reverse voltage.

Its running cool, but I know what your saying. I may go that route in the end. See the Rev3 schematic PDF.

You could throw in a capacitor of 47uF or 100uF at the 5V pin of the Arduino and the 5V pin of the RTC. This may seem strange, but when there is a problem with capacitors on the board and in the modules, an extra capacitor does help a lot.

100% correct, I always do that in a PCB layout next to IC power pins ... I am actually embarrassed I did not do this here on the bread board. Guess I trusted the RTC designer had robust built in power filtering caps.

What kind of buzzer is it ? A piezo element (the round disc) ? You have to use a 120 ohm resistor to a piezo element.

its a piezo. For now im removing the buzzer to try and isolate my problem. Previously, I took a look at the A3 pin when it was on and off and did see some noise when active. So I put a resistor and cap on there. See the Rev3 schematic PDF.

The 12V from the adaptor is going into the wire without any filter. There can be a lot of electric noise that could cross-talk into the other signals. I would use a LC filter (capacitor + ferrite-with-coil + capacitor) at the incoming 12V at the Arduino Uno. And also a filter near the Arduino Mega 2560, before it is put onto the cable.

On Monday, I will try this if the problem still persist. the OKI-78SR does a nice job of cleaning up the power but that red cat5 is going right under the LCD which could be a problem.

thanks again for your help

AG

Alarm_r3.pdf (80.6 KB)

That picture of SDA can be bad and can be good. When the SDA is for example high and the SCL changes state, a tiny spike could cross-talk into SDA. That tiny spike might destroy the I2C communication.
Just remember: never have SDA and SCL side by side in a flat ribbon cable, they don't like each other that much.

I think everything is pointing in the direction of the display.
http://www.sainsmart.com/sainsmart-iic-i2c-twi-serial-2004-20x4-lcd-module-shield-for-arduino-uno-mega-r3.html
Are there any capacitors at the 5V and GND on that I2C board of the display ?
Split the wires, add that 100nF capacitor somehow and perhaps a larger capacitor as well on that mini board, and let it run.

About those 100 ohm at the output: it is to protect the Arduino Uno against spikes from the cable. An output might be low impedance, but spikes can be nasty :smiling_imp:

Some have reported that the voltage regulator was blown when an Arduino board was powered at the 5V pin. That is why a protection diode is needed from 5V to VIN.

I don't mean electric noise to the 5V, because that the OKI-78SR can filter a lot, but I mean that the 12V from the adapter is on the cable, and noise is spread on the other wires.
I see it like this: In the next room is a cheap not-certified switching power supply, in another room is someone using a hairdryer. Your mains is polluted with all kind of crazy things, and your adapter passes some of that on to the 12V. That is going directly on the cable, and the electrical pollution is spreading like bacteria all over your system.

On this page is a link to an I2C library that doesn't hang.

Hi Nick -

On this page is a link to an I2C library that doesn't hang.

I'm trying to understand your I2C rev2 - the lib http://www.gammon.com.au/Arduino/I2C_Rev2.zip has the example HMC5883L but I cant get it to compile? should it? right from down load?

or am I on the wrong path?

AG

I noticed that too, it is a little outdated.
Replace the include WProgram.h with Arduino.h.

Updated my page to have the Rev5 version of the library instead of Rev2.

Thankyou.

So forgive me but im trying to use the I2C.h lib as a replacement in for wire.h in my master program. I would expect a few errors compiling in my sketch and am trying to correct them.. but getting overwhelmed. It seems like I would need to re-code all my RTC and LCD libs to use the I2C.h? Im using
LiquidCrystal_I2C & RTClib.

Is there an example sketch which uses the I2C.h and does a simple write char to LCD? Then I could try that with the LCD im using from the post above to see how I do.

thanks in advance

AG

Overwhelmed by what? Post your sketch. Post the errors you get.

Ok - below is the error and how i got there (see attachment for code + lib)

  1. I opened Master_keypad_r16 and did a save as Master_keypad_X
  2. In Master_keypad_X, removed the "wire.h" and wire.xxx lines and replaced them with I2C.h and I2C.XXX
  3. complied, saw some errors in the "LiquidCrystal_I2C.cpp" so I removed the "wire.h" and wire.xxx lines and replaced them with I2C.h and I2C.XXX
  4. Errors below

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
Arduino: 1.0.6 (Windows 7), Board: "Arduino Uno"
C:\Users\agentile\Documents\Arduino\libraries\LiquidCrystal_I2C\LiquidCrystal_I2C.cpp: In member function 'void LiquidCrystal_I2C::init_priv()':
C:\Users\agentile\Documents\Arduino\libraries\LiquidCrystal_I2C\LiquidCrystal_I2C.cpp:72: error: expected unqualified-id before '.' token
C:\Users\agentile\Documents\Arduino\libraries\LiquidCrystal_I2C\LiquidCrystal_I2C.cpp: In member function 'void LiquidCrystal_I2C::expanderWrite(uint8_t)':
C:\Users\agentile\Documents\Arduino\libraries\LiquidCrystal_I2C\LiquidCrystal_I2C.cpp:265: error: expected unqualified-id before '.' token
C:\Users\agentile\Documents\Arduino\libraries\LiquidCrystal_I2C\LiquidCrystal_I2C.cpp:266: error: expected unqualified-id before '.' token
C:\Users\agentile\Documents\Arduino\libraries\LiquidCrystal_I2C\LiquidCrystal_I2C.cpp:268: error: expected unqualified-id before '.' token

alarm_I2c.zip (45.4 KB)

Hi - just wanted to provide an update on this topic.

1 - added a set of 4.7k pull ups to the I2C and stuck with the stock wire.h lib.

2 - ESD on the key pad was an issue and will reproduce the garble LCD text but not a full lock up with watchdog time out, so I added Suppressors IC and 5.1 zener diodes on all I/Os.

3 - took a few readings on the digital scope, with I2C read enabled. Signals looked acceptable and I don't feel that was the root cause of the lock ups. I did notice a TON of traffic on the buss and setting the signal trigger to missed starts, was seeing a few (more than I expected)

4 - Final Resolution - re-wrote initial sketch and put in more counters and timers to limit the "lcd.print" and RTC reads on the I2c to 1000ms using the blink without delay method. Yes, i know fail on my part for not seeing these originally.

Testing of items 1-4 above has resulted good results, without any lock ups or bad text in the past 2 weeks of uptime.

Still open is the issue where wire.lib will still lock up if I put some cap on the line or hold a pin low, but I choose to accept this as results from testing over the past weeks was acceptable.

thanks for all the help