Jump to content

Facebook Like Counter, 7 Segment display and Cloud9

Recommended Posts

For my first BBB project, I created a Facebook Likes counter.  My wife wrote a romance book recently and has been obsessing about the number of likes on her facebook page.  Using my BBB and a SPI 4 digit 7-segment display (found on ebay a while back) - I wrote a simple Cloud9/Node.js script to regularly update the display.  


(Sorry for the brightness on the display - it's really hard to get a good picture of a display that's scanned)


The script is dropped in the startup folder for Cloud9, so it runs on boot and updates every 2 seconds.  I had to use a bit-bang interface for the SPI because the clock polarity for shiftOut for BoneScript was wrong.  I tried fixing the BoneScript function, but couldn't get it working.  Values are retrieved from Facebook's OpenGraph interface in a JSON format - so it's easily parsed.




I will mention - I was having trouble until I installed AdaFruit's BBB IO Python library.  I'm not quite sure if the library fixed something, or if I just fixed something simple in my code.  At this point - I haven't tried wiping my system to see if that's the case.


Way over-powered for what it's doing - but my wife loves it, and the BBB still has plenty of power left over to run other processes when I get to it.  It's pretty cool to see it jump up regularly.  For now, it sits under our TV.  I plan to add some other counters later - books sold, etc.

var http = require('http');
var b = require('bonescript');

var likes = "";

var options = {
  hostname: 'graph.facebook.com',
  port: 80,
  path: '/authorjlberg?fields=likes',
  method: 'GET'

var dout = "P8_12";
var clk = "P8_14";
var stb = "P8_16";
var dout = "USR0";
var clk = "USR1";
var stb = "USR2";
var SPISPEED = 1;
 function SPI_delay() 
     var v; var i; 
     for (i = 0; i < SPISPEED/2; i++) 

function dataSent()
    console.log('data sent');

var segments= new Array(0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x77, 0x7c, 0x58, 0x5e, 0x79, 0x71);
function sendData(data, hold)
    b.digitalWrite(stb, b.LOW);
    console.log('bitbang out');
    var c = 0;
        //LSB First
            b.digitalWrite(dout, b.HIGH);
            b.digitalWrite(dout, b.LOW);
    if(hold === false)
        console.log('releasing hold');
        b.digitalWrite(stb, b.HIGH);
function initDisplay()
    //console.log('init' + dout);
    b.pinMode(dout, b.OUTPUT);//, 7, 'disabled',  'slow');
    //   console.log('init2');
    b.pinMode(clk, b.OUTPUT);//, 7, 'disabled',  'slow');
    //   console.log('init3');
    b.pinMode(stb, b.OUTPUT);//, 7, 'disabled',  'slow');
    //   console.log('init4');

    sendData(0x02, false);
    sendData(0x40, false);
    //sendData(0x72, false); //test mode
    sendData(0x8F, false);
    console.log('init done');
function displayVal(toOutput)
    var b = require('bonescript');
    likes = toOutput.toString();
    var ones = 0, tens = 0, hund = 0, thou = 0;
    if(likes.length >3)
        thou=Math.floor(likes /1000)%10;
    if(likes.length >2)
        hund = Math.floor(likes /100)%10;
    if(likes.length > 1)
        tens = Math.floor(likes /10)%10;
    if(likes.length > 0)
        ones = likes % 10;
    sendData(0xC0, 1); //begin first digit
    sendData(0xC4, 1);
    sendData(0xC6, 1);

//setTimeout(function(){ initDisplay();},100);


var req = http.request(options, function(res) {
  console.log('STATUS: ' + res.statusCode);
  //console.log('HEADERS: ' + JSON.stringify(res.headers));
  res.on('data', function (chunk) {
    console.log('BODY: ' + chunk);
    var fbObject = JSON.parse(chunk);

req.on('error', function(e) {
  console.log('problem with request: ' + e.message);

// write data to request body



Share this post

Link to post
Share on other sites

@@Kunal Raunak - do you have the hardware available?  I'm not sure if the displays are still available on ebay or not.

@@cubeberg yes sir i got beaglebone , i will get that display anyhow.. Actually sir u did for facebook like counter,  my professor has given me project to do on number of tweets on twitter so i have to get more display instaed of 4, i think i will get that.. Sir i want your help in this project, it is very difficult for me.. I am not getting where to start and what code to write ..  :( I dont know much about beaglebone also ..Can u sir please give me your social media link(like fb or google +) in the message so that we can chat on this project.. I will be very glad if u guide me.. Eagerly Waiting for your reply :)

Share this post

Link to post
Share on other sites

I believe so.  I did try to use hardware SPI with Python but didn't really get anywhere, but that was early-on.  I believe the python libraries should be further developed at this point.  I don't know anything about getting it started though. Adafruit appears to have a library for the BBB that might be a good starting point.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now