Control LCD Text Over Web Interface (Arduino)

November 8, 2009

Here is my second project on the Arduino.

I had the idea to expand the LCD project that I previously posted here to add a little bit of customization.

What I did was set it up so that I could type in text on a web page (remotely) and have it show up on the Arduino.

I set up a small PHP script that will allow you to enter text, which is then saved to a text file. I run a Python script that checks that file for changes every ten seconds. If it detects changes, it will write VIA serial to the Arduino and give it the text to send.

Below is a video demonstration. See it on YouTube here.

Here is the code:

index.php:

<?php

$filename = “lcd.txt”;

?>

Insert text to show on the arduino LCD:

<form method=”GET”>
<input type=”text” name=”textToShow” />
<input type=”submit” value=”Submit” />
</form>

<?php

if(isset($_GET['textToShow'])){

?>

<br /><br />
The following text should be displayed on the LCD:

<?php

echo $_GET['textToShow'];

$file = fopen($filename, “w”);
fwrite($file, $_GET['textToShow']);
fclose($file);

}

?>

<br /><br />
To see the contents of <?=$filename;?>, click <a href=”<?=$filename;?>”>here</a>.

serialChecker.py:


import serial
import time
import urllib

# Create serial connection to arduino
ser = serial.Serial(‘COM4′, 9600, timeout=0)
url = ‘link-to-lcd.txt (can be remote)’
previousMessage = ”;

while(True):
message = urllib.urlopen(url).read()
if(previousMessage != message):
ser.write(message)
previousMessage = message
print message
time.sleep(10)

Arduino Code:

#include <LiquidCrystal.h>

// LiquidCrystal display with:
// RS, EN, D4, D5, D6, D7
// or: RS, R/W, EN, D4, D5, D6, D7
// or: RS, EN, D0, D1, D2, D3, D4, D5, D6, D7
// or: RS, R/W, EN, D0, D1, D2, D3, D4, D5, D6, D7

// In this case, the minimum: RS, EN, D4, D5, D6, D7
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

void setup()
{
Serial.begin(9600);

lcd.begin(2,16);
}

void loop()
{
if(Serial.available() > 0){
lcd.clear();
lcd.setCursor(0,0);

for(int i = 0; Serial.available() > 0; i++){
if(i == 16){
lcd.setCursor(0,1);
}
lcd.print(Serial.read(), BYTE);
}
}
delay(1000);
}

6 Responses to “Control LCD Text Over Web Interface (Arduino)”

  1. Wow that’s really cool! I’ve got to test that sometime!

  2. Hi, what are the outputs that you are using in this example?

    I mean… “pin o – 13″ what number, how many outputs?

  3. I’m just using standard LCD hookups based on Adafruit’s setup guide.

  4. Hello,

    I got a python error:
    message = urllib.urlopen.read
    with the cursor on “message”
    IdentationError: expected an indented block…

    i just copied and pasted your code..

  5. of course it was indentation error :P

  6. Ah, yes. WordPress isn’t the best place for me to be pasting code. It messes up the indentation at times.

Leave a Reply