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!