cubeberg 540 Posted July 9, 2013 Share Posted July 9, 2013 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. fbLikes_BB.js.txt 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, Rickta59, yyrkoon and 1 other 4 Quote Link to post Share on other sites
spirilis 1,265 Posted July 9, 2013 Share Posted July 9, 2013 Haha! That is awesome. Good work! Quote Link to post Share on other sites
bluehash 1,581 Posted July 13, 2013 Share Posted July 13, 2013 That is a lot of likes. cubeberg 1 Quote Link to post Share on other sites
cubeberg 540 Posted July 13, 2013 Author Share Posted July 13, 2013 That is a lot of likes. You should see it now! She's at almost 1400 - apparently she's pretty good at marketing. Quote Link to post Share on other sites
eskimobob 1 Posted July 15, 2013 Share Posted July 15, 2013 Nice idea cubeberg 1 Quote Link to post Share on other sites
cubeberg 540 Posted August 16, 2013 Author Share Posted August 16, 2013 FYI - had to redo my BBB the other day - script still worked on a clean 6-20-13 image. Quote Link to post Share on other sites
bluehash 1,581 Posted October 3, 2013 Share Posted October 3, 2013 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. Quote Link to post Share on other sites
cubeberg 540 Posted October 3, 2013 Author Share Posted October 3, 2013 Thanks! Looks like eetimes featured the article too. Quote Link to post Share on other sites
yyrkoon 250 Posted October 4, 2013 Share Posted October 4, 2013 Very cool Quote Link to post Share on other sites
Kunal Raunak 0 Posted May 14, 2014 Share Posted May 14, 2014 @@cubeberg i also want to do this project.. can u please help me ?? i am beginner in this beagle bone.. Quote Link to post Share on other sites
cubeberg 540 Posted May 18, 2014 Author Share Posted May 18, 2014 @@Kunal Raunak - do you have the hardware available? I'm not sure if the displays are still available on ebay or not. Quote Link to post Share on other sites
Kunal Raunak 0 Posted May 19, 2014 Share Posted May 19, 2014 @@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 Quote Link to post Share on other sites
viveksoni95 0 Posted June 12, 2014 Share Posted June 12, 2014 Is this possible using a pyhton script.. ? If yes the how ? Quote Link to post Share on other sites
cubeberg 540 Posted June 12, 2014 Author Share Posted June 12, 2014 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. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.