Jump to content

  •  

Photo

Facebook Like Counter, 7 Segment display and Cloud9


  • Please log in to reply
13 replies to this topic

#1 cubeberg

cubeberg

    Member

  • Members
  • PipPip
  • 25 posts

Posted 09 July 2013 - 01:41 PM

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.  

Attached File  FBLikeRunning.jpg   83.88KB   13 downloads

(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.

 

Attached File  fbLikes_BB.js.txt   3.54KB   23 downloads

 

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++) 
        v++; 
}

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);
    SPI_delay(SPISPEED);
    console.log('send');
    console.log(data);
    //b.shiftOut(dout,clk,b.gLSBFIRST,data,dataSent());
    
    console.log('bitbang out');
    var c = 0;
    while(c<8)
    {
        //LSB First
        if(data&0x01)
        {
            b.digitalWrite(dout, b.HIGH);
            console.log('high');
        }
        else
        {
            b.digitalWrite(dout, b.LOW);
            console.log('low');
        }
        data>>=1;
        //SPI_delay(SPISPEED);
        b.digitalWrite(clk,b.LOW);
        //SPI_delay(SPISPEED);
        b.digitalWrite(clk,b.HIGH);
        //SPI_delay(SPISPEED);
        c++;
    }
    
    
    if(hold === false)
    {
        SPI_delay(SPISPEED);
        console.log('releasing hold');
        b.digitalWrite(stb, b.HIGH);
        SPI_delay(SPISPEED);
    }
}
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');
    b.digitalWrite(dout,b.HIGH);
    b.digitalWrite(clk,b.HIGH);
    b.digitalWrite(stb,b.HIGH);
    

    
    sendData(0x02, false);
    sendData(0x40, false);
    //sendData(0x72, false); //test mode
    sendData(0x8F, false);
    console.log('init done');
}
function displayVal(toOutput)
{
    console.log(toOutput);
    var b = require('bonescript');
    console.log(toOutput.toString()[0]);
    likes = toOutput.toString();
    
    var ones = 0, tens = 0, hund = 0, thou = 0;
    
    console.log(likes.length);
    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;
    
    console.log('sending');
    sendData(0xC0, 1); //begin first digit
    sendData(segments[thou],false);
    sendData(0xC2,1);
    sendData(segments[hund],false);
    sendData(0xC4, 1);
    sendData(segments[tens],false);
    sendData(0xC6, 1);
    sendData(segments[ones],false);
}

//setTimeout(function(){ initDisplay();},100);
initDisplay();
displayVal("0000");

setInterval(function(){

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

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


// write data to request body

req.end();

},2000);

  • bluehash, yyrkoon, spirilis and 1 other like this

#2 spirilis

spirilis

    Advanced Member

  • Moderators
  • 143 posts
  • LocationMaryland, USA

Posted 09 July 2013 - 02:03 PM

Haha!  That is awesome.  Good work!



#3 bluehash

bluehash

    Administrator

  • Administrators
  • 183 posts

Posted 13 July 2013 - 11:12 AM

That is a lot of likes. 


  • cubeberg likes this

#4 cubeberg

cubeberg

    Member

  • Members
  • PipPip
  • 25 posts

Posted 13 July 2013 - 01:53 PM

That is a lot of likes. 

You should see it now!  She's at almost 1400 - apparently she's pretty good at marketing.



#5 Eskibrew

Eskibrew

    Newbie

  • Members
  • Pip
  • 8 posts

Posted 15 July 2013 - 12:43 PM

Nice idea :)


  • cubeberg likes this

#6 cubeberg

cubeberg

    Member

  • Members
  • PipPip
  • 25 posts

Posted 16 August 2013 - 09:56 PM

FYI - had to redo my BBB the other day - script still worked on a clean 6-20-13 image.  



#7 bluehash

bluehash

    Administrator

  • Administrators
  • 183 posts

Posted 03 October 2013 - 02:57 AM

congrats on getting featured on bb.org!

 

 

FYI - had to redo my BBB the other day - script still worked on a clean 6-20-13 image.  



#8 cubeberg

cubeberg

    Member

  • Members
  • PipPip
  • 25 posts

Posted 03 October 2013 - 01:46 PM

Thanks!  Looks like eetimes featured the article too.



#9 yyrkoon

yyrkoon

    Advanced Member

  • Members
  • PipPipPip
  • 170 posts

Posted 04 October 2013 - 03:24 PM

Very cool :)



#10 Kunal Raunak

Kunal Raunak

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 14 May 2014 - 10:09 AM

@cubeberg  i also want to do this project.. can u please help me ?? :)  i am beginner in this beagle bone..



#11 cubeberg

cubeberg

    Member

  • Members
  • PipPip
  • 25 posts

Posted 18 May 2014 - 12:36 PM

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



#12 Kunal Raunak

Kunal Raunak

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 19 May 2014 - 11:20 AM

@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 :)



#13 viveksoni95

viveksoni95

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 12 June 2014 - 03:22 PM

Is this possible using a pyhton script.. ? If yes the how ?



#14 cubeberg

cubeberg

    Member

  • Members
  • PipPip
  • 25 posts

Posted 12 June 2014 - 04:06 PM

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.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users