News LCD Display

RSSLCD
Live RSS news feeds displayed on a text LCD. Larger Image

This Internet of Things example uses mbed's networking features to display live RSS news feeds on the LCD. It is based on earlier networking examples from the cookbook that read a web page and the Text LCD library to display characters on a text LCD. CNN Technology news is used for the live RSS feed.

/media/uploads/4180_1/cnn-newsroomatl.jpg
CNN Newsroom in Atlanta

Wiring

The same hardware and wiring setup is used as the Internet LCD Clock, Weather LCD Display andGeolocation LCD Display.

Ethernet Magjack Connector

MbedSparkfun Ethernet Breakout
TD+P1
TD-P2
RD+P7
RD-P8

Note: Different magjack connectors can use different pin outs even though they look the same. These pins are for connectors from Sparkfun in 2011. If you are having trouble with your initial network setup, try this example code first. Once it works, it will confirm correct wiring on the connector (at least on the input side). Magjack Pinouts are posted for other common connectors. More connections to the unused pins including one to 3.3V and a capacitor should be added for long cables, but this setup works well with short cables. If you still get the net error message, make sure that DHCP service is enabled for your mbed. On some networks, you need to add the module's MAC address to enable the DHCP server to give it an IP address. It times out with an error, if no IP address is returned in about fifteen seconds. If the news does not display on the LCD after seeing "net OK", you may have DNS problems or a very slow network.

Text LCD

Mbed pinsText LCD pins
GNDGND
5V or 3.3V*VCC
VO to GND via 1k resistor
P15RS
GNDRW
P16E
N/CD0
N/CD1
N/CD2
N/CD3
P17D4
P18D5
P19D6
P20D7

Where N/C is not connected and the top left pin of the TextLCD’s header is GND and the right most pin is D7 in the LCD orientation shown in the images above. The resistor sets the contrast and some LCDs may need a different value or a contrast adjust potentiometer. See Text LCD for additional help, if needed.

(*) Note: some older LCDs may use 5V, but 3.3V is more common on current LCDs. If you cannot find a data sheet to confirm this, try 3.3V first and if the display is still blank (after double checking all other connections and code) it might need 5V. To save jumper wires, this setup uses the four bit interface to transfer ASCII characters to the LCD.

Example Code

RSS_News_Display

#include "mbed.h"
#include "EthernetNetIf.h"
#include "HTTPClient.h"
#include "TextLCD.h"
//CNN Tech News RSS Feed - get web page with XML
// displays titles on LCD  from XML "<title>....title text...</title>"
TextLCD lcd(p15, p16, p17, p18, p19, p20); // rs, e, d0-d3
EthernetNetIf eth;
HTTPClient http;
HTTPResult result;
bool completed = false;
void request_callback(HTTPResult r) {
    result = r;
    completed = true;
}

int main() {
    char *tstartXML = "<title>"; //RSS XML start title
    char *tendXML ="</title>"; //RSS XML end title
    char *tsptr;
    char *teptr;
    int i=0,j=0;
    // the eth and HTTP code has be taken directly from the HTTPStream documentation page
    // see http://mbed.org/cookbook/HTTP-Client-Data-Containers
    lcd.cls();
    lcd.printf("net setup");
    EthernetErr ethErr = eth.setup();
    if (ethErr) {
        lcd.printf("\n\r net error");
        return -1;
    }
    lcd.printf("\n\r net ok");
    HTTPStream stream;
    char BigBuf[2048 + 1] = {0};
    stream.readNext((byte*)BigBuf, 2048); //Point to buffer for the first read
    //CNN Tech News RSS Feed - get web page with XML
    HTTPResult r = http.get("HTTP://rss.cnn.com/rss/cnn_tech.rss", &stream, request_callback);
    while (!completed) {
        Net::poll(); // Polls the Networking stack
        if (stream.readable()) { // check for end of file
            BigBuf[stream.readLen()] = 0; // Transform this buffer in a zero-terminated char* string
            tsptr = BigBuf;
            // displays titles on LCD  from XML "<title>....title text...</title>"
            do {
                tsptr = strstr(tsptr,tstartXML); // find <title> in string - NULL if not
                teptr = strstr(tsptr,tendXML); // find <\title> in string - NULL if not
                if (tsptr!=NULL) tsptr = tsptr + strlen(tstartXML);// move to char after "<title>"
                if ((tsptr!=NULL)&&(teptr!=NULL)) {
                    i=0;
                    // loop to scroll characters slowly across LCD
                    for (j=0; (j+15)<(strlen(tsptr)-strlen(teptr)); j++) {
                        lcd.cls(); // clear screen before writing a new line
                        // loop to output a line on the LCD
                        for (i=0; ((i<16)&&(tsptr[i+j-1] != '<')); i++) {
                            lcd.putc(tsptr[i+j]);
                        }
                        if (j==0) wait(1.2); //add first line delays for scroll timing
                        wait(.2); //delay for character scroll timing
                    }
                    wait(.4);
                    lcd.cls(); //clear LCD between news items
                    wait(.2);
                }
            } while (tsptr!=NULL); // No more "<title>"s in BigBuf to display
            stream.readNext((byte*)BigBuf, 2048); //Buffer has been read, now we can put more data in it
        }
    }
    if (result == HTTP_OK) {
        lcd.cls();
        lcd.printf(" Read complete\n\r");
    } else {
        lcd. printf(" Error %d\n", result);
        return -1;
    }
}



Import programNews_LCD_display

Live RSS news feeds are displayed on a basic text LCD See http://mbed.org/users/4180_1/notebook/news-lcd-display/



A small portion of the RSS news feed web page containing XML is seen below. The data displayed on the LCD is the title. The format is "<title>....title text.....</title>". The code uses ad hoc parsing with strstr (i.e., this searches a large string for a substring) to find the "<title>' and "</title>" strings in the read buffer. The data on the web page is too large in many cases to read all of it into a memory buffer given mbeds RAM size, so it is split into several smaller buffers for each read and processed as the data streams in.

Example_RSS_XML_news_item

<pubDate>Fri, 20 Apr 2012 15:49:58 EDT</pubDate>
<feedburner:origLink>http://www.cnn.com/2012/04/20/tech/social-media/facebook-privacy-policy/index.html?eref=rss_tech</feedburner:origLink></item>
<item>
<title>Debate reopens on violent video games</title>
<guid isPermaLink="false">http://www.cnn.com/2012/04/19/tech/gaming-gadgets/games-violence-norway-react/index.html?eref=rss_tech</guid>
<link>http://rss.cnn.com/~r/rss/cnn_tech/~3/gLgxLndGOFU/index.html</link>
<description>Norway's alleged mass killer testified on Thursday that he played video games as a way to train for a shooting spree that killed 77 people last summer. In particular, Anders Behring Breivik said at his trial that he played "Call of Duty: Modern Warfare 2" as a means of shooting practice, according to CNN's report.&lt;div class="feedflare"&gt;
&lt;a href="http://rss.cnn.com/~ff/rss/cnn_tech?a=gLgxLndGOFU:VNLHDpHwbuM:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/rss/cnn_tech?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://rss.cnn.com/~ff/rss/cnn_tech?a=gLgxLndGOFU:VNLHDpHwbuM:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/rss/cnn_tech?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://rss.cnn.com/~ff/rss/cnn_tech?a=gLgxLndGOFU:VNLHDpHwbuM:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/rss/cnn_tech?i=gLgxLndGOFU:VNLHDpHwbuM:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://rss.cnn.com/~ff/rss/cnn_tech?a=gLgxLndGOFU:VNLHDpHwbuM:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/rss/cnn_tech?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://rss.cnn.com/~ff/rss/cnn_tech?a=gLgxLndGOFU:VNLHDpHwbuM:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/rss/cnn_tech?i=gLgxLndGOFU:VNLHDpHwbuM:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/rss/cnn_tech/~4/gLgxLndGOFU" height="1" width="1"/&gt;</description>

Video Demo


In the video above, mbed is powered up and obtains an IP address from the DHCP server. Net OK appears on the LCD. It then opens and reads a portion of the web page, searches for news items displaying them as they are found on the LCD and reads through the rest of the web page. When it reaches the end of the web page, "Read Complete" is displayed.

Ideas for further enhancements

1. Add a loop to keep reading and displaying the RSS feed.
2. Add other RSS news feed to cycle through.
3. Add code to display the description text after each title.
4. Add pushbuttons to select different RSS feeds or stop the display and show the description.
5. Instead of pushbuttons, use touch switch input or an IR remote.
6. Experiment with different scrolling ideas.
7. Use a Google RSS news feed. Google also has several RSS news feeds and news can be searched to generate a new RSS feed. Here is an example https://news.google.com/news/feeds?q=mbed&output=rss.
8. Items that span across a read buffer boundary will not be displayed. Modify the code to add this feature and reduce the buffer size to 512B.
9. Use Power over Ethernet (PoE) to power the device and avoid the extra wires for power. Sparkfun has one PoE option.
10. Upgrade to a larger display such as a color LCD or VGA.
11. Instead of ad hoc parsing code, use an XML parser like SPXML to read the RSS news items. Some RSS feeds have web pages that are too large to save in memory and streaming of data through the parser will be required. It could also be written to a file for demos in a prototype, but small flash devices can wear out with constant use, so such an approach would not work out well long term for a product.


3 comments on News LCD Display:

12 May 2012

Good work Jim, finally got News_LCD_Display working. Somehow, I must not have downloaded all the libraries the first time. Had to slow the scroll speed by 0.1 sec, and maybe add a 0.1 second to LCD clear delay. Do you think a 4 x 20 LCD HD44780 would work? Hard to find one at 3.3 volts. Thanks, Don DeGregori.

13 May 2012

Nice project ! There is also the nokia 6610 version for displaying more news !!! http://mbed.org/users/shrutibhagat/notebook/rss-feed-on-nokia-lcd-6610/

19 May 2012

Quote:

Good work Jim, finally got News_LCD_Display working. Somehow, I must not have downloaded all the libraries the first time. Had to slow the scroll speed by 0.1 sec, and maybe add a 0.1 second to LCD clear delay. Do you think a 4 x 20 LCD HD44780 would work? Hard to find one at 3.3 volts. Thanks, Don DeGregori.

Interesting that you had to slow it down, was that a recent LCD. Is the TextLCD library is too fast for some of them? I used some older 5V LCDs from some boards we no longer use and they work just fine with mbed's outputs. The LCD had 5V power (VU) - with 3.3V to power the LCD it was always blank. They all seem to use the same controller chip, but it must come in 5V and 3.3V versions and also perhaps different clock speeds?

Please log in to post comments.