Digital Ribbon

I was asked to originate and pitch a creative  idea for the Launch of the Blue Room- a new facility in BBC North for demonstrating the latest in consumer media technology.I came up with a IoT ribbon cutting moment.

It involved:

  1. the user cutting a ribbon,
  2. sensed by an Arduino programmed to output key commands to VLC to trigger a video
  3.  also fed to a python script that tweeted a Hello world! type message on behalf of the Blue Room.

I pitched the idea successfully, and made a prototype out of string and Meccano to illustrate to stakeholders the feasibility.

I designed and built the posts using Inkscape (an opensource Illustrator) and operated a CNC machine to cut them out of 12mm plywood.

I designed and lasercut the triggering mechanisms and soak tested them to ensure that they would work 100% of the time.

I designed electronics to give visual feedback on the two stages of the program successfully working.

The system was to be entertaining, look the part and most of all work first time…which it did (phew!).

Here's the Python code:

######################################################################################## simpleTweet_01_python.py
# visit my instructables for more information
# http://www.instructables.com/member/pdxnat/
# SPEN CODE MADE FROM tweepy_hello.py AUGUST 2014
print 'running... simpleTweet_01_python'# import libraries
import twitter
import serial
import time

# connect to arduino via serial port **CHECK HERE**
arduino = serial.Serial('/dev/tty.usbmodem471fp', 9600, timeout=1)

# establish OAuth id with twitter
# this is the oauth for machine_o_grace
#api = twitter.Api(consumer_key='#consumer key goes here',
#                  consumer_secret='#consumer secret goes here',
#                   access_token_key='#access key here',
#                  access_token_secret='#access token here- get these from #dev.twitter.com')

# listen to arduino
def listenToArduino():
msg=arduino.readline()
if msg > '':
print 'arduino msg: '+msg.strip()
compareMsg(msg.strip())

# avoid duplicate posts
def compareMsg(newMsg):
# compare the first word from new and old
status = api.GetUserTimeline('tweetyribbon')
prevMsg = [s.text for s in status]
pM = ""+prevMsg[0]+""
pM = pM.split()
nM = newMsg.split()
print "prevMsg: "+pM[0]
print "newMsg: "+nM[0]
if pM[0] != nM[0]:
print "positive feedback"
postMsg(newMsg)

# post new message to twitter
def postMsg(newMsg):
localtime = time.asctime(time.localtime(time.time()))
tweet = api.PostUpdate(newMsg+", "+localtime)
print "tweeted: "+tweet.text

while 1:
listenToArduino()

#######################################################################################

and here's the arduino code:

 

/* **************************************************************************************************
// to combine keyboard message and simple tweet
//for use with simpleTweet_01_python.py
// for use with Tweety_Ribbon
Debounce
Each time the input pin goes from LOW to HIGH (e.g. because of a push-button
press), the output pin is toggled from LOW to HIGH or HIGH to LOW.  There's
a minimum delay between toggles to debounce the circuit (i.e. to ignore
noise).

created 21 November 2006
by David A. Mellis
modified 30 Aug 2011
by Limor Fried
modified 28 Dec 2012
by Mike Walters
modified 9 Sep 2014 
by Spencer Mardsen

This example code is in the public domain.

http://www.arduino.cc/en/Tutorial/Debounce

*/

// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 4;    // the number of the pushbutton pin
const int ledPin = 13;      // the number of the LED pin
const int twitled = 3;
const int VLCled = 2;
const int fx1led = 5;
const int fx2led = 6;
// Variables will change:
int ledState = HIGH;         // the current state of the output pin
int buttonState;             // the current reading from the input pin
int lastButtonState = LOW;   // the previous reading from the input pin

// the following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long lastDebounceTime = 0;  // the last time the output pin was toggled
long debounceDelay = 50;    // the debounce time; increase if the output flickers

void setup() {
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(twitled, OUTPUT);
pinMode(VLCled, OUTPUT);
pinMode(fx1led, OUTPUT);
pinMode(fx2led, OUTPUT);
digitalWrite(twitled, LOW);
digitalWrite(VLCled, LOW);
digitalWrite(fx1led, LOW);
digitalWrite(fx2led, LOW);
Serial.begin(9600);
// set initial LED state
digitalWrite(ledPin, ledState);
}

void loop() {
// read the state of the switch into a local variable:
int reading = digitalRead(buttonPin);

// check to see if you just pressed the button
// (i.e. the input went from LOW to HIGH),  and you've waited
// long enough since the last press to ignore any noise:

// If the switch changed, due to noise or pressing:
if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();
//Serial.println(lastButtonState);
}

if ((millis() - lastDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:

// if the button state has changed:
if (reading != buttonState) {
buttonState = reading;

// only toggle the LED if the new button state is HIGH
if (buttonState == HIGH) {
Serial.println("Last few chances to say @spencermarsden #testing");
delay(100);
digitalWrite(twitled, HIGH);
digitalWrite(VLCled, LOW);
digitalWrite(fx1led, HIGH);
digitalWrite(fx2led, HIGH);
Keyboard.begin(); //this makes use of the keyboard library that you need a leonardo for
Keyboard.print("f");
//makes VLC go full screen
delay(100);

Keyboard.print("p");
//makes vlc play
Keyboard.end();
ledState = !ledState;
}
}
}
digitalWrite(twitled, ledState);
// set the LED:
digitalWrite(ledPin, ledState);
digitalWrite(twitled, LOW);
digitalWrite(VLCled, HIGH);
// save the reading.  Next time through the loop,
// it'll be the lastButtonState:
lastButtonState = reading;
}