seriously simple basic loop question

Hi,
I’ve done plenty of arduino sketches but can’t see the problem with the code here. I was doing a simple piece of code to check the operation of a 16x2 LCD. When ‘i’ reaches 30, it resets to 0 – it looks like the board (duemilanove) is resetting itself.

Any ideas please? Is there some other interrupt at play?

Thank you.

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

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int i=0;
void setup() {
  lcd.begin(16, 2);// set up the LCD's number of rows and columns: 
  lcd.setCursor(0,0);//column, row
  lcd.print("LCD test");
  
 }//end setup

void loop() {
 lcd.setCursor(4,1);
 lcd.print(i, DEC);
 delay(1000);
 i++;
}//end loop

I don't see anything wrong, either. There are some things I'd try. Change the delay to a shorter value. Does the value at which I resets change?

Add Serial.begin() to setup() and Serial.print() and Serial.println() statements to setup() and loop() to see whether setup() gets called again, and to see what value i really gets to.

Remove the , DEC bit from the lcd.print() statement. The LiquidCrystal class derives from the Print class. As a result, it knows how to print ints correctly.

Thanks for that.

Changing loop time did not affect the behaviour -- every 30 seconds a reset occurred. I powered the board from an external supply, disconnecting it from the USB, and the problem disappeared. Looks like the PC was resetting the USB/COM port, but I don't know why yet.

Thanks again.

Interesting... could it be something related to power saving settings ? Perhaps the OS doesn't see "activity" (i.e. data) on a usb port it assumes nothing is connected to it, so it shuts it down to save battery. If I'm right, putting a Serial.println() in loop would "fix" the issue.