Skip to main content
Everything

Arduino Twitter LCD

By March 20, 20105 Comments

Not that I’m busy or anything, but I saw this,  this, then this, then this and decided I HAD to build a twitter enabled door sign /office messaging system.

With a little help, as I’m a python noob, I have this up  and running.

I’d been wanting to play with Arduno for a while, and do have some minimal electronic skills, so off to ebay I went.

I bought an Arduino Duemilanove and a Sparkfun Serial 16×2 LCD, and some wire.

I soldered the wires on to the Serial LCD (it has a slot for a 3 pin JST connector – couldn’t find one in Maplin).

You then connect the VVD pin to the 5v pin(I had the 5v version of the LCD), GND to GND and RX to RX.

Upload the ardino code using the arduino interface from http://www.arduino.cc/

Code below – it isn’t auto updating yet, but it will be – EDIT now it is, improvements welcomed. LCDDoorsign.zip

This does occasionally stop working with a peer reset connection error –  presumably an issue on the twitter api side – I need to way to stop this halting everything / automatically restart the script…

Here’s a video showing the sign in action…


Nice modifications would be to do this on a massive screen and let it include @ so people can tweet to your sign.

Or include an PIR  / Proximity detector and auto tweet when triggered. Endless possibilities – but this is what I wanted.

Mine will be going on the wall outside Oxford Digital Media’s offices in Oxford.

Enjoy, and huge thanks to everyone who came before.

You’ll need py-serial and py-twitter installed on your computer to run this.

Arduino Code – stolen from http://dawes.wordpress.com/2009/12/23/twitter-to-lcd/

#include <SoftwareSerial.h>
#define txPin 2
int incomingByte = 0;&nbsp;&nbsp; &nbsp;// for incoming serial data
SoftwareSerial LCD = SoftwareSerial(0, txPin);
// since the LCD does not send data back to the Arduino, we should only define the txPin
void setup()
{
Serial.begin(9600);
pinMode(txPin, OUTPUT);
LCD.begin(9600);
}
void loop()
{
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
LCD.print(incomingByte,BYTE);
}
}

#include <SoftwareSerial.h>
#define txPin 2
int incomingByte = 0;&nbsp;&nbsp; &nbsp;// for incoming serial data
SoftwareSerial LCD = SoftwareSerial(0, txPin);// since the LCD does not send data back to the Arduino, we should only define the txPin
void setup(){ Serial.begin(9600); pinMode(txPin, OUTPUT); LCD.begin(9600);}
void loop(){ if (Serial.available() > 0) { // read the incoming byte: incomingByte = Serial.read(); LCD.print(incomingByte,BYTE); }}


Adapted code from http://dawes.wordpress.com/2009/12/23/twitter-to-lcd/ – to make it actually run 🙂

#!/usr/bin/env python

# encoding: utf-8

“””

TweetLCD.py

This twitter-to-LCD script implements two functions for displaying

text on a Sparkfun Serial LCD.

scrollText – allows long lines of text to be scrolled along the top of the

LCD pageText – allows long text to be paged up. First the top line is

written, then the bottom line, then the lines shift up, and more text is

written on the bottom line.

Created by Andrew M.C. Dawes on 2009-12-18.

Copyright (c) 2009, 2010 Andrew M.C. Dawes.

Some rights reserved. License: Creative Commons GNU GPL:

http://creativecommons.org/licenses/GPL/2.0/

“””

import serial

import time

import threading

import twitter

SERIALPORT = “/dev/tty.usbserial-A800ep5H” # this is my USB serial port YMMV

def pageText(textString, sPort):

botLine = “”

cursor = 0

for letter in textString:

# print letter, cursor     # this is for debugging

sPort.write(letter)

if cursor > 15:

# I’m printing in second line so keep track of what I write

botLine = botLine + letter

# print botLine

# page the bottom line up to top, clear bottom, and write

if cursor == 31:

# print “cursor wrap”

sPort.write(‘\xFE\x80’) # wrap to start of first line

sPort.write(botLine) # what was on the bottom (now on top)

sPort.write(”                “)

sPort.write(‘\xFE\xC0’) # skip to beginning of second line

botLine = “”

cursor = 15 # reset to beginning of second line

cursor = cursor + 1

time.sleep(0.05) # set this delay to a comfortable value

# The quick brown fox jumped over t|he lazy yellow dog.

#letter:  t

#sPort      The quick brown f

#botLine    ox jumped over t

#cursor 31

def scrollText(textString, sPort):

cursor = 0

firstPass = True # test whether this is the first 16 characters

for letter in textString:

if firstPass == False:

sPort.write(‘\xFE\x18’) # scroll left one spot at each letter

# print letter, cursor    # this is for debugging

sPort.write(letter)

if cursor == 15:

# I’m printing the last visible character

sPort.write(‘\xFE\x90’) # jump cursor to 2nd column of 16

# once the first row is filled, we need to scroll

firstPass = False

if cursor == 31:

sPort.write(‘\xFE\xA0’) # jump cursor to 3rd column

if cursor == 39:

# start over, there are only 40 characters in memory

cursor = -1

sPort.write(‘\xFE\x80’) # original character address

cursor = cursor + 1

time.sleep(0.5) # adjust this to a comfortable value

def main():

sPort = serial.Serial(SERIALPORT, 9600)

time.sleep(0.1)

sPort.write(‘\xFE\x01’) # clear the LCD screen

while(True):

time.sleep(0.1)

sPort.write(‘\xFE\x80′) # goto 0 position

api = twitter.Api()

status = api.GetUserTimeline(user=’doorsign’, count=1)[0]

# textstring = “11111111111111112222222222222222\

#                33333333333333334444444444444444”

textstring = “” + status.text

#scrollText(textstring, sPort) # choose one of these

pageText(textstring,sPort) # two options

time.sleep(2)

sPort.write(‘\xFE\x01’) # clear the screen (in preparation to repeat)

sPort.close()

threading.Timer(3, main).start()

if __name__ == ‘__main__’:

main()

time.sleep(20)

5 Comments

Leave a Reply