Gregory Hildstrom Projects Publications Resume Links Contact About Google+ Facebook Youtube Donate




SparkFun SerLCD V2.5 on Arduino

My first project after getting a hello-world LED to work on an Arduino was to get a 16x2 character black-on-green SparkFun SerLCD V2.5 to show some useful output. Most of the tutorials on this use the software serial library, which I have no interest in, or the examples seem somewhat lacking. The Arduino Uno has one hardware serial port and my Arduino Mega 2560 has four hardware serial ports that I plan to take full advantage of.

It is important to note that the two special command bytes in the data sheet, 0x7C and 0xFE, are very different and the distinction is not well documented. The 0x7C configuration command byte is for configuration commands that result in data being saved in the EEPROM, like brightness or splash screen state. The 0xFE extended command byte is for extended commands that do not result in data being saved in the EEPROM, like clearing the screen or positioning the cursor. So, a small delay after 0x7C commands is necessary to wait for the EEPROM write, but no delay is necessary after 0xFE commands in my 9600bps testing.

I created a class to make working with the LCD easier. This class also makes it easy to use multiple LCDs or quickly change the serial port. Here are the class and test code in my Arduino Sketch:
class SparkFunSerLCD{			//basic lcd class
public:
	SparkFunSerLCD();		//default constructor
	HardwareSerial *serial;		//pointer to serial port
	void brightness(uint8_t);	//set backlight brightness
	void splash();			//update splash screen
	void clear();			//clear the screen
	void position(uint8_t);		//set the cursor position
};

SparkFunSerLCD::SparkFunSerLCD(){
}

void SparkFunSerLCD::brightness(uint8_t b){
	if(b>=128 && b<=157){
		serial->print(0x7C,BYTE);
		serial->print(b,BYTE);
		delay(10);
	}
}

void SparkFunSerLCD::splash(){
	serial->print(0x7C,BYTE);
	serial->print(0x0A,BYTE);
	delay(10);
}

void SparkFunSerLCD::clear(){
	serial->print(0xFE,BYTE);
	serial->print(0x01,BYTE);
}

void SparkFunSerLCD::position(uint8_t p){
	serial->print(0xFE,BYTE);
	if(p<16)
		serial->print(p+128,BYTE);
	else if(p<32)
		serial->print(p+48+128,BYTE);
	else
		serial->print(128,BYTE);
}

SparkFunSerLCD lcd;				//instantiate an LCD object

void setup(){
	Serial1.begin(9600);			//set serial port speed
	lcd.serial = &Serial1;			//set pointer to serial port
	delay(500);				//wait for splash screen

	lcd.brightness(145);			//set backlight brightness
	lcd.clear();				//clear the screen
	lcd.position(0);			//line 0 character 0
	lcd.serial->print("Hildstrom");		//first line text
	lcd.position(16);			//line 1 character 0
	lcd.serial->print("Engineering");	//second line text
	lcd.splash();				//save new splash screen
	delay(3000);				//marvel at the new splash screen
}

void loop(){					//stress test the SerLCD
	lcd.clear();
	lcd.position(0);
	lcd.serial->print("blahblahblahblah");
	lcd.position(16);
	lcd.serial->print("BLAHBLAHBLAHBLAH");
	lcd.position(0);
	lcd.serial->print("1234567890123456");
	lcd.position(16);
	lcd.serial->print("6543210987654321");
}

Here is my portable tinkering station, which makes it extremely easy to go from the couch to the workbench. It consists of a Dell Inspiron Mini 10 with high capacity battery, Arduino Mega 2560, Radio Shack breadboard, and a SparkFun SerLCD all mounted on semi-finished 12"x27" 1/2" plywood.


Here is a closer shot of the LCD and the connections. The red wire is connected from 5V on the Arduino to VCC on the SerLCD. The black wire is connected from GND on the Arduino to GND on the SerLCD. The green wire is connected from the TX1 18 (Serial1) on the Arduino to the RX on the SerLCD.