Go Down

Topic: HD44780 Doesn't Reinit After Power Off/On (Read 3806 times) previous topic - next topic

mdenzien


I bought an Adafruit HD44780 board (Standard LCD 16x2 + extras), wired it up to an Arduino Uno according to their tutorial and tested it out with the LiquidCrystal/HelloWorld sketch. Everything AOK so far. But, when I power off the Arduino and then power it on again, the LCD display doesn't come back. I get a line of rectangles on the display but no text. If I hit the Arduino reset button, the LCD display comes back just fine.

This was a problem awhile back but was apparently fixed in Arduino-0017's LiquidCrystal library. Here is the old post:

http://arduino.cc/forum/index.php/topic,46538.0.html

I am using Arduino-0022. As far as I know everything else I've done is plain vanilla, though I used hookup wire rather than headers+breadboard to connect the LCD to the Arduino.

I've already tried putting a delay(1000); into setup() thinking that Arduino's setup() was running well before the LCD had a chance to finish starting up. This had no effect.

Any ideas about what might be going on, or what I could look at to get past this? (very much a noob here but any ideas would be appreciated).

floresta

Quote
I am using Arduino-0022.
Are you sure you are also using the current version of the LiquidCrystal library.  This problem was fixed with version 0017 and should not exhibit the behavior you are seeing.  You might try downloading a new copy of the IDE to make sure.

Quote
I've already tried putting a delay(1000); into setup() thinking that Arduino's setup() was running well before the LCD had a chance to finish starting up. This had no effect.
A good idea, but it won't have the desired effect because the LCD initialization occurs when you invoke the library - which happens before setup.

Don

mdenzien


Thanks Don for your quick reply.

I re-downloaded Arduino-0022 and retried with same results.

Based on your comment about library initialization running before reset, I added the delay to LiquidCrystal::init() so I could get the delay to happen when the LiquidCrystal constructor runs. This had no effect either. (Interestingly, delay() hangs at this point but delayMicroseconds() does not).

I wanted to prove that setup() was actually running when I turned the Arduino back on. So, I added a pushbutton with pull-up resistor wired to pin 2, plus the following version of the HelloWorld sketch:

// include the library code:
#include <LiquidCrystal.h>

#define RS 7
#define ENABLE 8
#define D0 9
#define D1 10
#define D2 11
#define D3 12

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(RS, ENABLE, D0, D1, D2, D3);

int lastButton;
long resetTime;

void setup() {
 
  //wait until pushbutton is pressed to get started:
  pinMode(2, INPUT);
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
  do {} while (digitalRead(2) == HIGH);
  for (int i = 0; i < 5; i++) {
    digitalWrite(13, HIGH);
    delay(50);
    digitalWrite(13, LOW);
    delay(50);
  }
 
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
 
  lastButton = HIGH;
  resetTime = 0;
}

void loop() {
 
  int button = digitalRead(2);
  if (button == LOW && lastButton == HIGH) {
     lcd.init(1, RS, 255, ENABLE, D0, D1, D2, D3, 0, 0, 0, 0);
     lcd.begin(16, 2);
     lcd.print("Re-hello, world!");
     resetTime = millis();
  }
  lastButton = button;
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print((millis() - resetTime)/1000);
}

So when you upload the sketch, it sits there until you press the button. Upon button press you get 5 quick blinks of the on-board LED, then the LCD display kicks in.

When I unplug the Arduino, then plug it in again, pressing the pushbutton doesn't make the LED blink. Makes me think that when you power up the Arduino to run the sketch that's already there, setup() doesn't run.

Notice that in the above sketch I'm allowing a pushbutton press to reinitialize the LCD. This works fine when the Arduino has not been powered off, and has no effect when it's turned back on after being powered off.

I tried the same sketch and LCD setup on two different Uno boards and got the same behavior.

So, questions are: Is the Arduino supposed to run setup() again when it's powered up again after being powered off? If not, do I need to force a reset of the Arduino each time it's turned on in order to get the LCD to work?

Thanks again for your help!

liudr

Arduino should run setup every time it is powered on. So you're saying that you power on arduino then there is no response after button push, but after you upload code again it works? If you hit reset button after a successful run of the LCD, will your LCD reinitialize or not? Is the problem only showing when you power on arduino via USB or both USB and ac adapter?

mdenzien


So you're saying that you power on arduino then there is no response after button push, but after you upload code again it works?

Yes.


If you hit reset button after a successful run of the LCD, will your LCD reinitialize or not?

Yes. It reinitializes when you hit Arduino reset, but only if the power hasn't been disconnected yet.


Is the problem only showing when you power on arduino via USB or both USB and ac adapter?

I currently don't have an AC adapter but I have a 9.6VDC battery. I get the same results using either USB or the battery.

As a further test, I disconnected RS, ENABLE and D0 through D4 from the Arduino. I left the backlight and LCD power connections in place. When I do this, the Arduino DOES do a reset when it is powered back on. So, the problem seems related to having the LCD fully connected when Arduino is re-powered.

Could I be dealing with a defective LCD display? Would it we worth trying to contact Adafruit about this?

Thanks again...

mdenzien

Oops, my bad... It was D0 through D3 that I disconnected. No D4 connection present...

liudr

Ok, what pins are you using to connect arduino to the lcd?

mdenzien


RS:  LCD4 --> Ard D7
ENABLE: LCD6 --> Ard D8
D0: LCD11 --> Ard D9
D1: LCD12 --> Ard D10
D2: LCD13 --> Ard D11
D3: LCD14 --> Ard D12

LCD 1, 5, and 16 grounded
LCD 3 to pot wiper
LCD 2 and 15 to 5V

liudr

That looks right. Any pictures you can share?

mdenzien


I  could take a pic I guess but I have a feeling that it's not the wiring. I fired a note to Adafruit and they agreed to send me another LCD. Hopefully that'll take care of it.

Thanks for posting back, I appreciate your looking at this...

liudr

Alright. Please get back to us so we have a closure to this problem. I bought one display from adafruit. It works OK but the display is very sluggish, not a defect though. Without back light the text is almost invisible, unless you take it outdoors. It's the blue screen. I'm not recommending it. Now I use yellow screen and black characters. It's much easier to read without back light indoors in the day and requires very little power on back light to read at night.

Here is a shield I made using such displays, just FYI:

http://liudr.wordpress.com/shields/phi-2-shield/

mdenzien


Well it's a bit embarrassing, but the original LCD I had seems to be working now. I was going ahead with trying to develop a sketch and had occasion to change the Arduino pin assignments that the LCD uses. (I intend to use Adafruit's data logger shield and I believe that pins 10-13 are needed for the SD card interface.) So, I moved the LCD to pins 4-9 and now when I reboot the Arduino, the LCD comes back alive. I'm not sure why the pin assignments should make a difference.  There probably were (and still are?) subtle problems with my wiring.

Right now my breadboard is quite a spaghetti-ball of wires. Doesn't give me a warm fuzzy feeling that all the connections are electrically sound. Does one sometimes have to build a more permanent setup before even trying to write a sketch, just to make sure the circuitry is sound?

And, I have many other questions - though I'm not sure where I should post them. Perhaps someone could direct me to the best place to ask these:

*  Is it really feasible to do an Arduino project that uses all the digital pins? The circuit I have now uses digital pins 0-9 and analog pins 0-2. I intend to use digital 10-13 and analog 4-5 for the logger shield. Is there an unwritten rule that says don't go above a certain number of pins? If so, I might need a Mega for this project.

*  I now have a digital pin 0 that is "frozen" in the HIGH position. I'm trying to use pin 0 as a pushbutton input. Near as I can tell, I have a pull-down resistor in place, but I'm seeing a voltage of about 4.5 between pin 0 and ground when the switch is open. Pressing the button brings it up to 5v, but pin 0 never goes low. Another wiring problem? (As above, there are a lot of digital pins in use already. Am I going above a current limit of some kind?)

*  Is it feasible/reliable to run the LCD display off of a shift register? Since all the LCD pins are outputs, this might reduce the number of digital pins required from 6 to 3. Though, I assume that some changes to the LiquidCrystal library would be needed to make this work. Might also be dicey to mesh the timing of the shift register with that of the LCD.

Thank you for any guidance you can provide.

floresta

Quote
So, I moved the LCD to pins 4-9 ...

Most likely your actual pin configuration and your pin definitions got out of whack at some point.

Quote
Doesn't give me a warm fuzzy feeling that all the connections are electrically sound.

I've run into flaky breadboard connections a few times, but not on any of my original 30+ year old ones from EL Instruments.

Quote
...though I'm not sure where I should post them.

Here?

Quote
Is there an unwritten rule that says don't go above a certain number of pins?

No

Quote
I now have a digital pin 0 that is "frozen" in the HIGH position.

Pins 0 and 1 are permanently connected to the serial interface circuitry used for downloading sketches so their use is limited in some applications.  This is a good case for the ardunio-oids that use separate FTDI cables or boards.

Quote
Is it feasible/reliable to run the LCD display off of a shift register?

Absolutely.  Do a search for 'shift register LCD'.

Don

liudr

Besides the answers floreta offered, I have this product you may try to unclutter breadboards. It is a product I designed.

Self promotion warning :)

Here
http://liudr.wordpress.com/gadget/phi-connect/

It will drastically clean up your board and make switching between your projects easy as snap.

mdenzien


Thank you gentlemen for your comments.

Pins 0 and 1 are permanently connected to the serial interface circuitry used for downloading sketches so their use is limited in some applications.  This is a good case for the ardunio-oids that use separate FTDI cables or boards.

Very interesting. I wonder what the designers had in mind. At any rate, I changed the pin 0 wiring to use a pull-up resistor instead of a pull-down, then in my sketch I test for LOW instead of HIGH to detect a button press and it works as intended. I wonder if it would screw up again if I started using Serial in the sketch.

Quote
Do a search for 'shift register LCD'.

Will do. Thanks for the tip.


Besides the answers floreta offered, I have this product you may try to unclutter breadboards. It is a product I designed.

Useful product. Looks like I'm going to have to start checking out your blog as well.

Mike

Go Up