wire + LiquidCrystal + serial = hangup???

I just started playing with the Arduino, and I'm having a problem. I am trying to use the wire library to interface the HMC6352 compass module and the LiquidCrystal library to display results. I am also communicating over serial.

These three things (wire, LiquidCrystal and serial) sometimes give me random hangups and weirdness. The hangups always seem to occur at the wire.begin() line, but they only occur if all three components are used.
Sometimes, adding a simple line (like serial.println("a") somewhere in the sketch will suddenly cause everything to work.

The simplest sketch I can come up with that hangs is below. If I include the serial.println line, the sketch will run. If I comment it out, it doesn't run. Can someone try this out on their own arduino to check? Anybody know what's going on here?

I'm using Arduino 17 and an arduino nano.

#include <Wire.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int ledPin = 13; // LED connected to digital pin 13

void setup()
pinMode(ledPin, OUTPUT);
//Serial.println("a"); // uncommenting this line will cause sketch to run properly


void loop()
digitalWrite(ledPin, HIGH); // check for quick blinky
delay(100); // to see if sketch runs
digitalWrite(ledPin, LOW);

I'm not too sure the libraries are going to cause problems, I haven't tried to use them together.. but, it sounds like you're running into power issues.

If so, they're generally called "Brown Outs" which is basically just a reset from not having enough power.

How are you powering everything? Need to keep in mind, you can only supply about 500 ma from your USB port, I believe most LCD's use about 200 ma ish including the backlight LED, and I'm not too sure about the compass module.

Try disconnecting one of them, from the board, and just let the program run, if it runs for a while without any resets, I'm going with power. BUT, if it does reset, then you're going to have to wait for somebody else, cause I'm not sure :smiley:

Good luck!:slight_smile:

The Nano is connected and powered by USB to a little EEE PC. I had thought of the power issue as well, and already tried disabling the LCD backlight (80 mA, i think it was). Anyway, it didn't help, the behavior is the same...

Try changing this line:

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

Add an extra read/write pin parameter (I'll use 6, but apparently you can use any unused pin):

LiquidCrystal lcd(12, 6, 11, 5, 4, 3, 2);

This seems to work for me