You are viewing an older revision! See the latest version

RS Display Board

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.

Functionality

The library is set up such that it is possible to illuminate individual LEDs or simply send strings to the display, for which there are two separate options.

void write(string str) - this simply displays a 6 character long max. string statically.

void scroll(string str, float speed) - this takes strings of any length and scrolls them across the display, each frame lasts for a duration, specified by the speed parameter.

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 what 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 look at the source file. It's massive! Passing all that data through my little mbed and parsing it all is going to give it one hell of a headache. 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.webatu.com/ and then through the helpful file manager application created a new .php file with in 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
     
    $url = "http://uk.finance.yahoo.com/q?s=^FTSE";    //assign url to variable
     
    $data = file_get_contents($url);                   //load url into variable
    $ftse100_id_start = '<span id="yfs_l10_^ftse">';   //assign start position tag
    $ftse100_id_end = '</span>';                       //assign end position tag
    $comma = ',';                                      //assign a variable equal to an ASCII comma
                                                       //dispBoB doesn't like commas so I'll strip them out too
    $start = strpos($data,$ftse100_id_start);          //return position of first html tag
    $end = strpos($data,$ftse100_id_end,$start) + 7;   //return position of second html tag
    $ripped_data = substr($data,$start,$end-$start);   //copy data in between tags into variable $ripped_data
     
    $ripped_data = substr_replace($ripped_data, "", 0, 25);          //blank out first tag data
    $comma_pos = strpos($ripped_data, $comma);                       //blank out any annoying commas
    $ripped_data = substr_replace($ripped_data, "", $comma_pos, 1);  //blank out second tag data
     
    print $ripped_data;                                //print resulting FTSE100 data to web
     
    ?>

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.


All wikipages