Skip to content

Instantly share code, notes, and snippets.

@ravenlp
Created June 17, 2013 05:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ravenlp/5794749 to your computer and use it in GitHub Desktop.
Save ravenlp/5794749 to your computer and use it in GitHub Desktop.
Simple Arduino code used to show data on the lcd shield over a serial connection. Ideal to have the output of a script (Node/Ruby/Pyhon etc) shown on a pretty lcd screen
/*
LiquidCrystal Library - Serial Input
*/
/*
This example code is in the public domain.
http://arduino.cc/en/Tutorial/LiquidCrystalSerial
*/
// include the library code:
#include <LiquidCrystal.h>
char c[33];
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
void setup(){
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// initialize the serial communications:
Serial.begin(9600);
}
void loop()
{
// when characters arrive over the serial port...
if (Serial.available()) {
// wait a bit for the entire message to arrive
delay(100);
// clear the screen
lcd.clear();
// read all the available characters
int i = 0;
while (Serial.available() > 0) {
c[i++] = Serial.read();
//lcd.write();
//data += Serial.read();
}
// Clear the rest
for(; i < 33; i++){
c[i] = ' ';
}
//Print the first row
for( i = 0; i < 16; i++){
lcd.write(c[i]);
}
//Print the second row
lcd.setCursor(0,1);
for( i = 16; i < 33; i++){
lcd.write(byte(c[i]));
}
}
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment