Social Tree

Basic Concept

Creating a Tree that, instead of water and minerals, thrive on “likes” from it’s very own facebook page.

The Social Tree is a physical sculpture made of wood and electronics with a leaf attached to one of its branches. It that will have it’s own Facebook Page where it will post pre written messages asking for more attention (likes) from other users. If no likes are given, the sculpture will release is “leaf” and will post how sad it is.

Fabrication of the Foam and Wood prototypes HERE.

ICM – PCOM – Fabrication

This project started as a Physical Computing experiment on creating physical consequences from our social media actions. During Fabrication classes I developed several prototypes on how the project would look like. But my greatest challenge was to find the software solution to bridge Facebook to Arduino and the Social Tree.

At first this wasn’t my idea for an ICM project, but as I showed the early stages of “Social Tree” to my colleagues, I received amazing feedback and Ideas on how this project could grow for my finals…and beyond.

So I decided to make this my ICM project as well. This wasn’t an easy decision, since I really looked forward developing other ideas, but I also believe the “Social Tree” can provide me with the knowledge and challenges needed to further improve my current programming skills.

For the fabrication of the wooden prototypes and the final structure see here:

SETTING UP SOLENOID PUSH MOTORs

Controlling A Solenoid Valve With Arduino

28/11/2017

My tiny tiny 5 V solenoids arrived. They are the cutest things! But I was

29/11/2017

Breakthrough! During the middle of Danni Rozen class I managed to make my nano solenoid disengage its electromagnet, dropping a weight simulation the leaf falling! I was so happy. Strange to describe how I felt, but there’s certainly a joy of seeing something you imagined coming to life. It was just a nail on a piece of thread attached to the solenoid shaft, but the clinging sound of it hitting the table gave me a happiness rush. Now I must be ready to endure the forthcoming setbacks that are certain to happen.

I already envisioning future improvements on this yet unfinished project. For once, i’d like to make the social tree fully wireless. For now it will be probably connected to an arduino and a computer. But I could use a wireless microcontroller like this amazing ESP8266

or the ESP32 (that can run criptography, allowing for https and accessing Facebook).

03/12/2017

Interfacing with Facebook

With the help of my colleague Dan Oved, I created a Facebook Developer account and set up a placeholder JSON interface with facebook.

Goals of the Facebook-Arduino-Social Tree interface:

  • create a Facebook Page and profile for the Social Tree.
  • create a system that post’s pre written messages on the Social Tree page
  • check the number of new “likes” every given time.
  • If no new like in the last couple of seconds/minutes – send a signal to the arduino to activate the solenoid, detaching the leaf.
  • Post message informing that the leaf fell.
  • Post message when leaf is reattached – (this might be problematic, since I don’t have a mechanism that is able to detect if the leaf is connected or not. I can only inform if the solenoid is activated)

examples online:

http://www.instructables.com/id/DIY-Facebook-notifier-with-Arduino-Arduino-Faceb/

http://www.instructables.com/id/Control-Arduino-With-Facebook-The-Easy-way/

How To Set Up Arduino Web Control Without An Ethernet Shield

SKOLTI lab

http://www.skolti.com/lab/exp8/eng/ 

Changing the color of a LED using Facebook and ESP32 microcontroler

Setting up Facebook Developer Account

With the help of Dan Oved, I set my Facebook developer account. This is necessary in order to get the PIN number that will allow my program to access facebook. I also used the youtube video ” Changing the color of a LED using Facebook and ESP32 microcontroler” by user ALSW (linked above)

  • Inside the Facebook Dev, I created a new APP, called “SocialTreeBeta”
  • Each app has it’s own ID number
  • Inside the Facebook Developer page, go to “Graph API Explorer”
  • There I generated a new token. Facebook will ask for several different permissions. I chose a few I believed were going to be useful. Not sure if it will work! The token last only for a while
  • Now I can access any part of my Facebook account by choosing any field and pressing “send”. I can see all comments, likes, states, etc – How will I be able to check only one page?
  • On the “GET” field, I changed from “ME” to the “SocialTreeBeta” Pin code – this way I can access data just for this app…I think
  • ..
  • …. realized the code from the video above is mostly focused on using the ESP32 cryptography feature. So I try to go back to Dan’s method – creatind a Node app to simulate the facbook connection for now….so, time to learn node!
  • When to NPM repository to setup my Node app
  • Node Installed – Running things from Node Command Prompt.
  • Realized I don’t know NODE….back to another example
  • Trying to adapt this code “MAKER: Track Facebook Likes with Arduino
    • This example used an ethernet shield and a LCD screen.
    • The code for the Ethernet connections seems to be very different…back to looking for other examples
  • Started looking for examples that don’t use an Ethernet Shield, but I’m really struggling now. Just found out that my ICM final is tomorrow! Thought it would be next week.
  • Calling for HELP – Dan is helping me with our initial JSON solution

JSON

  • Browsing through the facebook documentation we found how to query for the number of likes  (fan_count)
  • We used the graph API to access the information – this time directly on the browser (private IDs and codes are in BOLD):

https://graph.facebook.com/v2.11/SOCIAL TREE PAGE ID/?access_token=APP ID|APP TOKEN&fields=fan_count

  • The above request gave back the following:

{
“fan_count”: 0,
“id”: “1804701356496677”
}

  • Now we must find a way to make our JSON code (index.js) request this data
  • Found this simple request

var request = require(‘request’);
request(‘http://www.google.com’, function (error, response, body) {
console.log(‘error:’, error); // Print the error if one occurred
console.log(‘statusCode:’, response && response.statusCode); // Print the response status code if a response was received
console.log(‘body:’, body); // Print the HTML for the Google homepage.
});

  • The request code above consist of 3 functions: error, response, body
  • body has no parameters, so we had to parse it in JSON

request(‘https://graph.facebook.com/v2.11/1804701356496677/?access_token=APPID|TOKEN&fields=fan_count’, function (error, response, body) {
console.log(‘error:’, error); // Print the error if one occurred
console.log(‘statusCode:’, response && response.statusCode); // Print the response status code if a response was received
console.log(‘body:’, body); // Print the HTML for the Google homepage.
var parsedBody = JSON.parse(body);
console.log(‘parsed json:’, parsedBody)

console.log(“fan count:”, parsedBody.fan_count)
});
}

  • Run the code on the JSON terminal (node index.js)
  • It returned the following

statusCode: 200
body: {“fan_count”:0,”id”:”1804701356496677″}
parsed json: { fan_count: 0, id: ‘1804701356496677’ }
fan count: 0

  • Now I have a function than can access the page and its like count
  • Next challenge is to use this information inside the Arduino program in order to activate the solenoid if no new like is added after a certain amount of time.
  • I have to write the number of likes  (fan count) to serial.
    • Back to “Serial Communications Basics” at the ITP PCOMP help page
    • And “Serial Communication with NODE.JS”
      • Installed the NPM Serial Port, but found out it was already installed. Figuring out, why the ITP Pcomp Node lab example didn’t work
      • tried to run the Node example that would give me the ports, but it returned an error.
      • Stuck in here.

Finals Presentation Dec 6, 2017

  • Presented my Finals. Had to show how it would work. Made a good case for it. Should be thankful to prof. Adaora Udoji and her “Speak & Storytelling” classes – she really helped me nail the pitch for the Social Tree.
  • BACK TO NODE
    • just realized – after a quick nap – that the reason why I couldn’t get the SerialPort information from node was…the Arduino Serial Monitor was open! I know it had to be closed, but I couldn’t see that a stance of it was still open.
    • Also: I sometimes forget to save Node files as (FILENAME).JS – I forget the “js” extension.
    • Kept following the ITP PCOMP – Serial Communication NODE lab
    • managed to install the npm serialport – it returned the serial port name = COM5 (in my case)

Setting up Serial Communications Dec 11, 2017

What I have so far:

  • A rough wooden prototype with a working solenoid and a weight attached to it. It is connected to an Arduino running a simple timer when I give him some input on the terminal:

A post shared by Gabriel Brasil (@gabriel.m.brasil) on Arduino basic Code just for activating the Solenoid:

void setup() {
Serial.begin(9600); // initialize serial communications
pinMode(12, OUTPUT); // set digital pin 11 to be an output, to control the LED
}

void loop() {
if (Serial.available() > 0) {
char input = Serial.read(); // read first available byte into a variable
if (input == ‘H’) { // if the variable equals H, or ASCII 72
digitalWrite(12, HIGH); // turn on the LED
delay(100); //gab: added timer
digitalWrite(12, LOW);
}
if (input == ‘L’) { // if the variable equals L, or ASCII 76
digitalWrite(12, LOW); // turn off the LED
}
}
}

  • A working Node code that connects to the Social Tree Facebook page and get its “Fan Count”/Number of likes

What Is missing:

  • Interface  between Node and the Arduino Code
  • Some kind of feedback on how long until the solenoid is activated (leaf will drop)
  • Build the final shape of the object
  • Automatic Facebook page posting – messages telling that a “drop” is imminent, unless someone else likes the page.

UX Conundrum: Act for Passivity

In this project a very interesting UX conundrum is required: The user need to act in order for NOTHING to happen! The user needs to keep liking – different users actually – in order for the “leaf” not to drop.

Node debugging

  • Trying to follow the ITP PCOMP Serial Communication Lab – NODE, but I’m getting errors most of the time: “SerialPort is not defined”
  • Reading the SerialPort library NPM help page.
    • Here I know where to name the port (COM5 in my case) and it seems to be working.
    • the PCOMP Lab example had errors:
      • varserialport = require('serialport');// include the library// get port name from the command line:varportName = process.argv[2];
        var myPort = new SerialPort(portName, 9600);
        Fixed using the NPM examples.
      • var SerialPort = require(‘serialport’);// include the library
        // get port name from the command line:
        var portName = process.argv[2];
        var myPort = new SerialPort(‘COM5’, ‘9600’);

Controlling Arduino with NODE and Johny Five library

While researching how to access the Arduino through NODE on the “Arduino Experimenters Guide to NODEJS”, I’ve learned about the Johny Five Library

This library have several APIs to connect with ARDUINO or other microcontrollers.

Using Johny Five Library

  • Followed the guidelines to install the Johnny-Five library
  • Tried to run the tutorial node Blink example, changing the port name to the one I’m currently using. But it returned a time-out error.
  • It could be a firmware issue with my Sparkfun Redboard microcontroller. Looked at the Johnny-Five documentation about it.
  • Had to install a bunch of npm libraries for Windows – firmware for python (I think)
    • Install Node.js >= 0.10.x 32 bit (unless anyone can confirm success with 64 bit)
    • npm --add-python-to-path install --global --production windows-build-toolsInstall node-gyp npm install -g node-gypafter some trial and error, managed to make the Johnny Five Strobe LED example work.
  • copy and pasted the blink code inside the LikeCounter code: both seem to work. LED blinks and number of “likes” is shown.
  • My colleague M.H managed to make both functions – the LED ON and Facbook API – to talk to one another. This is the code:

var numberLikes = 0;
var led;

var request = require(‘request’);
var five = require(“johnny-five”);

var board = new five.Board();

board.on(“ready”, function() {

led = new five.Led(13);
});

function intervalFunction() {
//numberLikes++;
//console.log(numberLikes);
// get number of likes fro facebook api
// write number of likes to serial

request(‘https://graph.facebook.com/v2.11/1804701356496677/?access_token=XXXXXTOKENWASHEREXXXXXXXX&fields=fan_count’, function (error, response, body)
{
console.log(‘error:’, error); // Print the error if one occurred
console.log(‘statusCode:’, response && response.statusCode); // Print the response status code if a response was received
console.log(‘body:’, body); // Print the HTML for the Google homepage.
var parsedBody = JSON.parse(body);
console.log(‘parsed json:’, parsedBody)

console.log(“fan count:”, parsedBody.fan_count)

numberLikes = parsedBody.fan_count;

});
if (numberLikes > 2){
led.on();

}
else if (numberLikes <= 2){
led.off();
}

 

Creating the Timer

Now that I have the interface between Facebook and Arduino working, I need to check if the number of likes changes in a certain amount of time.

In pseudo-code it would be something like this:

Check the number of likes

If number of  number of likes now is bigger than number of likes a few seconds ago: do nothing

else: activate the Led/Solenoid/Droptheleaf and then turn off the solenoid again.

repeat

It seems to be a simple code, but I can’t make it work…I don’t know how to make it work. Mainly, I don’t know how to store the old information and compare it to the new.

maybe this is what I need:

var lastValue = 0;
$(function () {


    if (lastValue > originalValue){
        console.log ("Increasing");
    }
    else if (lastValue < originalValue) {
        console.log("Decreasing");
    }
    lastValue = originalValue;            

}); When I applied to my code..IT WORKED!:

if (oldLikes >= newLikes){
led.on(1000);
led.stop();
led.off();

 

}
else if (oldLikes < newLikes){
led.off();
}

oldLikes = newLikes;

  • BUG on NODE: I was trying to debug the values of oldLike and newLike with a console.log, but it didn’t show on the terminal. I then changed the original console.log messages…and nothing happened! I had to ” save file as”  again, it worked. For some reason CTRL-S wasn’t saving.
  • BUG on the Electronics/Timing
    • currently the function turns the solenoid off (dropping the leaf) and then turns on again – this prevents overheating and allows for replacing the leaf.
    • But it is turning on and off to fast – a fraction of a second, even though I used: led

Creating the timer and final presentation – Dec 13, 2017

Managed to create a physical clock, that shows how long until the dropping the “leaf/flower”, while resetting if a new like is detected!!!

 

 

 

var oldLikes = 0;
var newLikes;
var led;
var servo;
var x =0;

var request = require(‘request’);
var five = require(“johnny-five”);

//var numberLikes = 0;

var board = new five.Board();

board.on(“ready”, function() {

led = new five.Led(13);
servo = new five.Servo(10);

 

//turns LED/Solenoid off when exiting program. This is to avoid overheating
this.on(“exit”, function() {
led.off();
servo.min()
});

this.repl.inject({
servo: servo
});
// servo.sweep();
// servo.to(90);
});

 

 

function intervalFunction() {
//numberLikes++;
//console.log(numberLikes);
// get number of likes fro facebook api
// write number of likes to serial

request(‘https://graph.facebook.com/v2.11/1804701356496677/?access_token=129775407689050|78ed9db9ed017b09f4a610c26f33bbf7&fields=fan_count’, function (error, response, body)
{
console.log(“old value1”, oldLikes);
console.log(‘error:’, error); // Print the error if one occurred
console.log(‘statusCode:’, response && response.statusCode); // Print the response status code if a response was received
console.log(‘body:’, body); // Print the HTML for the Google homepage.
var parsedBody = JSON.parse(body);
console.log(‘parsed json:’, parsedBody)

console.log(“fan count!!!!!!:”, parsedBody.fan_count)

newLikes = parsedBody.fan_count;

likeTime();

//X sets the interval number – it is used to control de servo step and the moment the solenoid/led is activated
x= x +1;

console.log(“valor x”,x);
if (x<17){
servo.to(10*x);
}

 

 

});

 

oldLikes = newLikes;

}

function likeTime(){
if(oldLikes < newLikes){
led.stop();
led.off();
servo.to(0);
x=0;
}
else if
((oldLikes >= newLikes)&&(x>=17)){
led.blink(1000);

 

}
}

 

//interval of time that it will check for likes
setInterval (intervalFunction, 3000);

 

//graph.facebook.com/v2.11/364263730369745/likes HTTP/1.1
//https://graph.facebook.com/v2.11/364263730369745/likes?access_token=129775407689050|78ed9db9ed017b09f4a610c26f33bbf7
//https://graph.facebook.com/v2.11/1804701356496677/?access_token=129775407689050|78ed9db9ed017b09f4a610c26f33bbf7&fields=fan_count

 


Leave a Reply

Your email address will not be published.