Scrolling LCD text on Arduino/Raspberry Pi

As part of my Raspberry Pi/Arduino internet radio project, I’m tinkering with getting the display to show something other than the station name and the time and date – the weather, for example.

Now we’ve been having quite a lot of weather lately, and sometimes it won’t fit in the 16 characters my LCD display will show at a time (at least on one line).

My display is an Arduino shield, and I’m using nanpy to get the Raspberry Pi to send text to the display and read button presses. I couldn’t work out if nanpy supports LCD scrolling, so I’ve written a function of my own that takes a string; if it’s 16 characters or less, it just displays it on the bottom line of the LCD. If it’s longer than 16 characters, it scrolls it across the display and then leaves the first 16 characters on the screen. This means the function finishes running and you can get on with something else.

Here’s the Python code for scrolling text on an Arduino LCD controlled via nanpy (weather code will follow, but I have it working!). I added the extra space to the end of the text being scrolled, as without it, it seemed to leave a trail of the last character.

import string
import time
from nanpy import Arduino
from nanpy import (OneWire, Lcd)

# set up Hobbytronics Arduino LCD shield
lcd = Lcd([8, 9, 4, 5, 6, 7], [16, 2])

def scrollText( scrollBlurb ):
   if len(scrollBlurb) > 16:
     padding = " " * 16
     oldText = scrollBlurb
     scrollBlurb = padding + scrollBlurb + " "
     for i in range (0, len(scrollBlurb)):
      lcd.printString(scrollBlurb[i:(i+16)], 0, 1)
      time.sleep(0.35)
     lcd.printString(oldText[:16], 0, 1)
   else:
     lcd.printString(scrollBlurb, 0, 1)

scrollText("some very long text that won't fit on the screen")
This entry was posted in Arduino, Debian, Raspberry Pi, Raspbian and tagged , , , , , . Bookmark the permalink.

Leave a Reply