I just got a Spark Fun serial enable LCD for use with my power monitor project. The problem is that if I just leave the LCD screen plugged in and I upload new code, or I just hit the reset button the screen just dies out on me. I'm running the LCD over a soft serial connection. If after I've performed a reset I pull the ground then plug it back in I'm in business, which makes me think it may be something in my setup loop but I'm not finding what it could be. Anyone have any ideas? The code I'm using is found below:
#include <SoftwareSerial.h>
//setup my pins
#define rxPin 5
#define txPin 4
#define Relay 7
//initialize my interrupt
volatile int state = LOW;
//initialize my software serial port.
SoftwareSerial LCD = SoftwareSerial(rxPin, txPin);
byte pinState = 0;
void setup()
{
//define my pinmodes
pinMode(Relay, OUTPUT);
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
//attach my interupt
attachInterrupt(0, control, CHANGE);
// set the data rate for the SoftwareSerial port
LCD.begin(9600);
delay(100);
//turn backlight on
backlightOn();
//clear the screen
clearLCD();
}
void loop()
{
digitalWrite(Relay, state);
selectLineOne();
LCD.print("Relay status: ");
LCD.print(state);
delay(500);
}
void control()
{
state = !state;
}
void clearLCD(){
LCD.print(0xFE, BYTE); //command flag
LCD.print(0x01, BYTE); //clear command.
}
void backlightOn(){ //turns on the backlight
LCD.print(0x7C, BYTE); //command flag for backlight stuff
LCD.print(157, BYTE); //light level.
}
void backlightOff(){ //turns off the backlight
LCD.print(0x7C, BYTE); //command flag for backlight stuff
LCD.print(128, BYTE); //light level for off.
}
void backlight50(){ //sets the backlight at 50% brightness
LCD.print(0x7C, BYTE); //command flag for backlight stuff
LCD.print(143, BYTE); //light level for off.
}
void serCommand(){ //a general function to call the command flag for issuing all other commands
LCD.print(0xFE, BYTE);
}
//SerialLCD Functions
void selectLineOne(){ //puts the cursor at line 0 char 0.
LCD.print(0xFE, BYTE); //command flag
LCD.print(128, BYTE); //position
}
void selectLineTwo(){ //puts the cursor at line 2 char 0.
LCD.print(0xFE, BYTE); //command flag
LCD.print(192, BYTE); //position
}