You are viewing an older revision! See the latest version

RS Display Board

Hot new App!!

Connect your mbed to the internet via an Ethernet cable, when plugged into the dispBoB. Import this program, then type a short message into this web app. The message you typed then shows up on the dispBoB!! Cool or what! Source code here

This is a purpose built breakout board, utilizing the PCA9635 IO bus expander as an LED driver. The dispBoB library requires the inclusion of the PCA9635 library in order to function correctly.

API

Import library

Public Member Functions

dispBoB (PinName sda, PinName scl, PinName en)
Create a dispBoB object defined on the I2C master bus.
void init (void)
Initialise device.
virtual void cls (void)
Clear screen.
virtual void locate (char pos)
Set cursor position.
void scroll (string str, float speed)
Write a scrolling string (right to left) to display.
void bus (short leds)
Same functionality as the bus() function on the PCA9635.
int putc (int c)
Write a character to the display.
int printf (const char *format,...)
Write a formated string to the LCD.

Libraries

dispBoB

PCA9635

Additional notes

The following ASCII encoded characters are supported:

0123456789
ABCDEFGHIJKLMNOPQRSTUVWXYZ
abcdefghijklmnopqrstuvwxyz
! ' ( ) { } [ ] - _ .

Information

, is not supported

Example Projects

The display is very simple to interface. Simply download this file and this file

Next, in the includes section of your .cpp file type #include "dispBoB.h"

All of the constructor/function definitions can be found here.

1 - Simple Clock

#include "mbed.h"
#include "dispBoB.h"

dispBoB db(p28, p27, p26);              //instantiate dispBoB object

int main() {

/****UNIX TIMESTAMP STUFF****/

    set_time(1309776930);               //set UNIX timestamp -  it's Mon, 04 Jul 2011 10:55:30 GMT where I am
    
    while(1){                           //loop forever
        time_t rawtime = time(NULL);    //update to instantaneous time
        
        char buffer[32];                //create a local char array object called buffer
        strftime(buffer, 32, "%H.%M.%S\n", localtime(&rawtime)); //store string formated time, suitable for dispBoB to buffer

/****dispBoB STUFF****/

        db.locate(0);                   //position cursor to initial position
        db.printf("%s", buffer);        //print buffer to dispBoB
    }
}

The current UNIX timestamp can be found here.

/media/uploads/d_worrall/_scaled_db1_004.jpg

2 - Counter

This next small project demonstrates how the mbed can be interfaced with a small laser to create a counter, which increments every time the beam is broken. The digital input is connected to pin 12 of the mbed and requires a pull-up resistor, which can be activated from within the mebd itself

#include "mbed.h"
#include "dispBoB.h"

dispBoB db(p28, p27, p26);              //instantiate a dispBoB object
InterruptIn laser(p12);                 //set up the laser as an external interrupt

int counter = 0;                        //set the counter object to zero

void count(){                           //function to call upon breaking of beam
    counter++;                          //increment counter object
    db.locate(0);
    db.printf("%06d", counter);         //send counter info to dispBoB and display
}

int main() {
    laser.mode(PullUp);                 //activate internal pull up
    db.cls();                           //clear screen
    laser.rise(&count);                 //attach count() to interrupt 
    db.printf("%06d", counter);         //display an inital count "000000"
}

3 - Digital thermometer

The TMP102 temperature sensor use an I2C interface to connect to external devices. Its library can be found here. The following code shows yet again, how simple it is to implement the code for the dispBOB with other devices

#include "mbed.h"
#include "dispBoB.h"
#include "TMP102.h"

dispBoB db(p28, p27, p26);          //instantiate a dispBoB object
TMP102 temperature(p9, p10, 0x90);  //instantiate a TMP102 object

int main() {                        
    db.cls();                       //clear screen
    while(1){
        db.locate(0);               //position to start
        db.printf("%f", temperature.read());  //print temperature
        wait(1);                    //wait 1 second before looping
    }
}

4 - Real-time FTSE100 data

Now this is exciting and really demonstrates the power of the mbed as an intelligent interfacing device! In the office, I'm constantly checking the BBC headlines (probably shouldn't tell the boss), the current FTSE100 data and all the real-time data that the internet has to offer. So wouldn't it be just brilliant to have it displaying on the dispBoB all the time, so that I don't have to distract myself from whatever I'm doing?

What you need

  • mbed
  • mbed 7 Segment Display Board aka dispBoB
  • Ethernet Cable (RJ45 jack etc.)
  • A website with PHP support (don't worry about this yet)
  • A spare Ethernet socket to the world wide web....

/media/uploads/d_worrall/_scaled_dsc01400.jpg

What you DON'T need

  • PHP skillz
  • FTSE100 Knowledge

/media/uploads/d_worrall/_scaled_dsc01399.jpg

A quick briefing on screen-scraping

In order to access the current FTSE100 index (it's actually 15mins delayed, but I mean 'current' to the outside world instead of to financiers working in the City) I need to first of all find a good reliable source of FTSE100 data.

Here seems fairly good. Now the data I really want is the number in the top right hand corner.

Yahoo Finance

If you right click and select View Page Source the source code for the webpage should pop up and in here it should be possible to find the number I want...

...Some time later...

It happens to be placed between 2 html tags <span id="yfs_l10_^ftse"> and </span>. So what I want to do is get my mbed to scour through the source code, find these tags and strip out the important number in between (This is called screen-scraping). Then it can post it to the dispBoB to satisfy my addiction to real-time FTSE100 data.

But the mbed runs on C and string-handling would be done better in some other language. So I decide to get somebody else to do the donkey work. I'll offload the task of screen-scraping to some poor server out there in the cyber-world.

PHP Funtimes

I've never written a web application before and I managed this in one morning, so you should be able to do it in no time. I signed up for free web-hosting with these people. After that, I created a new domain name http://www.mbed.net16.net/ and then through the helpful file manager application created a new .php file within the public_html directory. I called it dispBoBApp.php, but you can call it whatever you like.

Being a PHP noob I then did a quick google search and read-up on all things PHP basic.

Here is my web programme ##

PHP

<?php

$url = "http://uk.finance.yahoo.com/q?s=^FTSE";      //assign url to variable

$data = file_get_contents($url);                     //declarations
$ftse100_id_start = '<span id="yfs_l10_^ftse">';
$ftse100_id_end = '</span>';
$comma = ',';

$start = strpos($data,$ftse100_id_start)+25;         //figure out tag positions
$end = strpos($data,$ftse100_id_end,$start);
$ripped_data = substr($data,$start,$end-$start);     //copy through data between tags

$comma_pos = strpos($ripped_data, $comma);           //locate and rip out any annoying commas
$ripped_data = substr_replace($ripped_data, "", $comma_pos, 1);

print $ripped_data;

?>

Here is the resulting webpage. If you access it during the week during working hours it should show the FTSE100 index. What's even more exciting, is that if you wait a couple of seconds and refresh the page, the number changes!! Perfect!

Next, all I have to do is connect the mbed to the web and stream off this number.

It actually reads off the source code for the webpage I just created, but 000webhost.com have stuck a bit of extra code on the end for their own purposes.

Server generated source code

6018.52
<!-- www.000webhost.com Analytics Code -->
<script type="text/javascript" src="http://analytics.hosting24.com/count.php"></script>
<noscript><a href="http://www.hosting24.com/"><img src="http://analytics.hosting24.com/count.php" alt="web hosting" /></a></noscript>
<!-- End Of Analytics Code -->

So in my mbed code I'm going to still have to do a bit of parsing, just it will be much less labour intensive than had I just screen-scraped directly from yahoo finance. Well actually that's where I went wrong. If I use the sscanf() function from the stdio.h library I can tell my mbed to read off numbers until it sees something which isn't a number i.e. a line break, and then chuck everything it's just read into a new variable, say int value. Sorted!

mbed code

A quick browse through the mbed cookbook reveals this page on HTTPClients and Ethernet connexions. The example code is a bit fluffy, but useful for developing, so I merge/copy and paste it with/into my code and add dispBoB in the declares area.

Import program

00001 #include "mbed.h"
00002 #include "EthernetNetIf.h"
00003 #include "HTTPClient.h"
00004 #include "dispBoB.h"
00005 #include "stdio.h"
00006 
00007 EthernetNetIf eth; 
00008 HTTPClient http;
00009 dispBoB db(p28, p27, p26);
00010   
00011 int main() {
00012 
00013     EthernetErr ethErr = eth.setup();           //Setup ethernet connection
00014     if(ethErr) return -1;
00015   
00016     db.init();                                  //initialise screen
00017     db.cls();
00018     
00019     HTTPText txt;                               //instantiate HTTPStream object
00020     while(1){
00021         HTTPResult r = http.get("http://mbed.net16.net/v1/dispBoBApp.php", &txt);   //load page into buffer
00022         if(r==HTTP_OK){
00023             string str = txt.gets();            //load web page into string
00024 
00025             char buf[10];                       //instantiate buffer and string to store FTSE100
00026             string value;                                  
00027             str.copy(buf,9,0);                  //load buffer with chunk of web page
00028 
00029             sscanf(buf, "%s", value);           //scan until decimal point
00030             
00031             db.scroll("FTSE100", 0.2);          //print info to dispBoB
00032             db.locate(0);
00033             db.printf("%s", value);                    
00034         }
00035         wait(2);                                //wait 2 seconds before looping, so we don't pester the servers too much
00036     }
00037 }
00038 
00039 
00040 
00041 
00042 
00043 
00044 

So now I have a real-time update of the FTSE100 right in front of me all day.

Here's an exciting clip of me setting up the mbed and finally getting it to display the FTSE100 index!


All wikipages