Kickstarter Alert! The Airhorn Project

Kickstarter Alert! The Airhorn Project


Arduberry Raspberry Pi for Arduino

We recently launched the Arduberry on Kickstarter which brings a seamless experience to Raspberry Pi by providing a very simple yet powerful way to interface the Arduino sensors and shields with the Raspberry Pi.

One of the things with a Kickstarter project, especially if it’s yours, is that it keeps you hooked. There’s always a tab in the browser open with the Kickstarter page that you’ll keep on obsessively checking every 10 minutes.

We found a solution this addiction that involves air horns, the Arduberry, and web-scraping. What better way to demonstrates the power, flexibility and the ease of use the Arduberry than to make a glorified Kickstarter Backer Alert?

We have sitting in our lab right now an Air horn.  Actually 5 air horns controlled by an Arduberry, which plays the theme song from the Dukes of Hazard whenever we have a new backer . We also have a small OLED which displays the live stats too.

Hardware Required

  1. Air horns (get the biggest and the baddest one’s you can find, should easily make someone jump out of their chairs)
  2. Arduberry
  3. Raspberry Pi
  4. WiFi adapter for the Raspberry Pi
  5. Grove Base Shield
  6. Grove OLED – to display live stats
  7. Grove Relay – to control the air horns
  8. 12V battery or power supply for the Air horns
  9. 5V battery or power supply for the Raspberry Pi and Arduberry

Arduberry Raspberry Pi for Arduino

Step 1- Connecting the Airhorns

Connect the air horns to the 12V power supply and leave the switch unconnected for the Grove relay.  We used a Tetrix 12V battery.  These horns are generally meant for cars, so a large car battery will work too.

Be careful when powering the air horns: they often need a power source capable of supplying 20 Amps at 12V.  Luckily we had some rechargeable NiMH batteries lying around which were rated at 20 Amps.  Cutting and soldering the connections on the air horn with a 14AWG wire was a challenge in itself.

Step 2- Connecting the Arduberry and the Grove modules

The beauty of the Grove system is that all the sensors use the same 4 wire connector, so there’s no headache when connecting different modules and no unreliable wiring. Just connect the sensors to the base shield and you are up and running. We had a couple of Grove sensors lying around which were ideal for our project.

Arduberry Raspberry Pi for Arduino

Connect the Grove Relay to Port D7 and the OLED shield to any I2C port and slide it on the Arduberry. Now slide the Arduberry on the Raspberry Pi and power it on.

Step 3- Connecting the Air horn to the Arduberry

Connect the wires in the air horn circuit which were meant for the switch, to the two terminals on the Grove Relay.

Step 4- Getting data from Kickstarter

Kickstarter does not have a public API and we wanted to get live stats of our project. The solution is to set up a web crawler to get data from Kickstarter periodically and extract the data. We have some experience with crawlers but we usually try to avoid the pain of setting up a web crawler and it would have been an overkill for a small project like this.

Enter Kimono. This is an awesome product (still in beta) from Kimonolabs  that converts any website into API’s directly from the browser without writing a single line of code. The only bottleneck is the 1000 free API calls provided for real time data. It might not suit a large project, but was just the thing we needed for our project. Within minutes the API was streaming data to our python client on the Raspberry Pi.

A huge shout out for the guys at Kimonolabs for making our lives easier!

The python client code is in our Arduberry Github Repository. Here’s a quick preview of the code.

import serial
import json
import urllib
import time
backer_count=0
alert=' '
while True:
try:
alert=''
#Get data from kickstarter using Kimono's API
results = json.load(urllib.urlopen("http://www.kimonolabs.com/api/cprwyx20?apikey=api_key"))
#Parse the data
data= results['results']['collection3']
comments= results['results']['collection2'][0]['number']
total= results['results']['collection1'][0]['total']
backers= results['results']['collection1'][0]['backers']
#Print on terminal
print "Comments:",comments,"Total:",total,"Backers:",backers
goals=["$1:","$5:","$23:","$23P:","$37:","$84:","$185:","$900:"]
backer_count=str(backer_count)
backers=str(backers)
for i in range(len(backer_count)):
if backer_count[i] is backers[i]: #if backer_count has not changed do nothing
print " "
else:
print"New backer " #if backer_count has changed, mark the alert flag for the horn
alert='?'
backer_count=backers
break
#Send data to arduberry
ser = serial.Serial('/dev/ttyAMA0', 9600) # open first serial port
#Since the OLED shield does not new lines
#'`'- parsed as a new line by Arduberry when printing on the OLED
#'~'- parsed as clear screen on OLED by Arduberry
#If first character on a message is '?' Arduberry blows the Air horn
mesg="~"+str(alert)+"ARDUBERRY`"+total+'`'+"Backers:"+backers+'`'
ser.write(mesg) #Send the message to arduberry
for i in range(len(data)):
ser.write(goals[i]+data[i]['count'][:-7]+'`') #Send individual backer count
print goals[i]+data[i]['count'][:-7]
ser.close()
time.sleep(240) #Run every 4 minutes(240 s)
except:
print "Error"
view raw dixie.py hosted with ❤ by GitHub

Step 5- Setting up the Arduberry

We need the Grove OLED library for the OLED shield. Take a look at Installing a library tutorial if you don’t know how to use the library with Arduberry.

The sketch which goes on the Arduberry is in the Arduberry Github Repository.

#include <Wire.h>
#include <SeeedGrayOLED.h>
#include <avr/pgmspace.h>
int horn=7;
void setup()
{
Serial.begin(9600);
Wire.begin();
pinMode(horn, OUTPUT);
SeeedGrayOled.init(); //initialize SEEED OLED display
SeeedGrayOled.clearDisplay(); //Clear Display.
SeeedGrayOled.setNormalDisplay(); //Set Normal Display Mode
SeeedGrayOled.setVerticalMode(); // Set to vertical mode for displaying text
}
int data;
int x=0, y=0, erase =0, sound=0;
void loop()
{
sound=0; //Turn of the Air horns
if(Serial.available()>0)
{
if(erase==1) //Clear the screen when a new message comes
{
erase=0;
SeeedGrayOled.init(); //initialize SEEED OLED display
SeeedGrayOled.clearDisplay(); //Clear Display.
SeeedGrayOled.setNormalDisplay(); //Set Normal Display Mode
SeeedGrayOled.setVerticalMode(); //Set to vertical mode for displaying text
x=0;y=0; //Set x,y pointers back to origin
}
data=Serial.read();
Serial.print((char)data);
if((char)data=='?') //If '?' was received, then we had a new backer
{
sound=1;
}
else if((char)data=='`') //If '`' received, then print a newline
{
y++;
x=0;
}
else if((char)data=='~') //If '~' received, then set the flag to clear the screen
{
erase=1;
}
else //Otherwise, just print the message
{
SeeedGrayOled.setTextXY(y,x);
SeeedGrayOled.putChar(data);
Serial.print((char)data);
x++;
}
}
if(sound==1) //Sound the Air horns if someone backed us
{
digitalWrite(horn,HIGH);
delay(1000);
digitalWrite(horn,LOW);
}
}
view raw dixie.ino hosted with ❤ by GitHub

The messages sent to the Arduberry from the python program uses Serial interface. The serial buffer on the Arduberry is by default set at 64 bytes. It needs to be increased to 128 bytes to accommodate the bigger messages. Here’s a quick tutorial on how to increase the serial buffer.

Step 6 – Putting it all together

Arduberry Raspberry Pi for Arduino

Upload the code on the Arduberry (here’s how). Power on the Air horns and run the python code and wait for the Air horns to come to life.  This is sure to raise the liveliness of the office!

Our inspiration: Dwight Schrute: