Introduction: Raspberry Pi Stock Ticker With Surplus Store LCD
In this Instructable, I create a scrolling stock ticker with the Raspberry Pi.
I found an LCD in the surplus store that didn't have much information, but after some searching and playing around, saw that it was based of the popular HD44780U. This is a 16 character LCD, and looks like 16x1 unit
DENSITRON 2
617ASNG0441
0201 TAIWAN
However, it seems to function as an 8x2 (display is like 1234567812345678).
I used Adafruit's tutorial to set it up - see http://learn.adafruit.com/drive-a-16x2-lcd-directly-with-a-raspberry-pi/overview for more information - I'll not repeat how to set up the circuit here. The main difference is that this LCD has only 15 leads, not 16, and the last 15th lead is for a non-existent backlit display. Ignore the 16th lead in Adafruit's setup.
I also used Adafruit's python library for character LCD displays - Adafruit_CharLCD.py - however, I had to make a few important modifications for my needs. First of all, I made some changes for it to support the 8x2 display (to automatically scroll over to the 2nd line when the first 8 characters have been filled up).
I also modified it to support any arbitrary length string, by displaying 16 (8x2) characters at a time, and then going to the next 16, and so on, until the end.
I also added another method to support scrolling text. With a simple call, the LCD will do a marquee type scrolling of the text. The caller can provide it any arbitrary length string without worrying about scrolling details. I tried to search for any existing work doing this already, but could not, so hopefully this will help others looking for something similar.
Now that I have scrolling text supported on the 8x2 LCD using Raspberry Pi, the next step is to get stock data (I used yahoo for the data).
I used the pycurl library to invoke yahoo's api and get the results - thanks to http://www.gummy-stuff.org/Yahoo-data.htm for the pointers in the right direction.
To install pycurl on your raspberry pi distribution, do the following:
sudo apt-get install python-pycurl
The url for getting stock data is http://download.finance.yahoo.com/d/quotes.csv?s=^IXIC&f=sghn (see the above site for what kind of fields you would like to retrieve) s = stock symbol, g = Day's Low, h = Day's high, n = stock name (it is recommended to have the name as the last field, as names can sometimes have quotes ", which can throw off your parsing of the fields).
I've attached the source code for stockTicker.py - as you can see, it is quite straightforward, and the call to the lcd is simple.
I've also attached my modifications to Adafruit_CharLCD.py - replace that in your environment with this file (first back that up, by copying it to Adafruit_CharLCD.py.bak (that's the convention I use)).
Enjoy!
PS - Can't seem to upload the video to Instructables - I uploaded it to YouTube instead - here's the link - http://www.youtube.com/watch?v=0xPcbMepSuk
I found an LCD in the surplus store that didn't have much information, but after some searching and playing around, saw that it was based of the popular HD44780U. This is a 16 character LCD, and looks like 16x1 unit
DENSITRON 2
617ASNG0441
0201 TAIWAN
However, it seems to function as an 8x2 (display is like 1234567812345678).
I used Adafruit's tutorial to set it up - see http://learn.adafruit.com/drive-a-16x2-lcd-directly-with-a-raspberry-pi/overview for more information - I'll not repeat how to set up the circuit here. The main difference is that this LCD has only 15 leads, not 16, and the last 15th lead is for a non-existent backlit display. Ignore the 16th lead in Adafruit's setup.
I also used Adafruit's python library for character LCD displays - Adafruit_CharLCD.py - however, I had to make a few important modifications for my needs. First of all, I made some changes for it to support the 8x2 display (to automatically scroll over to the 2nd line when the first 8 characters have been filled up).
I also modified it to support any arbitrary length string, by displaying 16 (8x2) characters at a time, and then going to the next 16, and so on, until the end.
I also added another method to support scrolling text. With a simple call, the LCD will do a marquee type scrolling of the text. The caller can provide it any arbitrary length string without worrying about scrolling details. I tried to search for any existing work doing this already, but could not, so hopefully this will help others looking for something similar.
Now that I have scrolling text supported on the 8x2 LCD using Raspberry Pi, the next step is to get stock data (I used yahoo for the data).
I used the pycurl library to invoke yahoo's api and get the results - thanks to http://www.gummy-stuff.org/Yahoo-data.htm for the pointers in the right direction.
To install pycurl on your raspberry pi distribution, do the following:
sudo apt-get install python-pycurl
The url for getting stock data is http://download.finance.yahoo.com/d/quotes.csv?s=^IXIC&f=sghn (see the above site for what kind of fields you would like to retrieve) s = stock symbol, g = Day's Low, h = Day's high, n = stock name (it is recommended to have the name as the last field, as names can sometimes have quotes ", which can throw off your parsing of the fields).
I've attached the source code for stockTicker.py - as you can see, it is quite straightforward, and the call to the lcd is simple.
I've also attached my modifications to Adafruit_CharLCD.py - replace that in your environment with this file (first back that up, by copying it to Adafruit_CharLCD.py.bak (that's the convention I use)).
Enjoy!
PS - Can't seem to upload the video to Instructables - I uploaded it to YouTube instead - here's the link - http://www.youtube.com/watch?v=0xPcbMepSuk