Thursday, March 19, 2009

Using the ButtonShield to make an Open Source BlackBerry

Last week Mike threw up a video of the ButtonShield prototype he made, I added it to the Open Source Hardware bank and Justin added it to the liquidware store. Incidentally, this project uses most of the exact same components as the Open Source GamePack (from my Open Source Gameboy project) Actually, it technically uses 2 new parts too, so it uses 60% of the old plus 40% new parts :-)

In the meantime, I figured I’d use one of the prototypes that Mike built to actually show off what it could do, and so I decided to see if I could hack together an Open Source version of the Blackberry – and I even made the 2.5 hour road trip to CT to meet Mike in person at Dunkin Donuts. The result? I guess you could call this the “OpenBerry” project. I also kept a stop watch next to me to measure how long it took to make everything (assembly and coding, that is), and start to finish it took a little under 3 hours. Anyway, here goes:

The OpenBerry "Open Source Blackberry" is a 26-key ASCII alphabetical keyboard ButtonShield module wired to an Arduino, which polls the buttons, and writes a small message that gets displayed simultaneously on the OLED TouchShield. When the message is written, it gets kicked out over the XBee Shield from Libelium (I picked it up at Sparkfun). In the meantime, it polls over the XBee serial connection to see if the XBee base station on the laptop has any new emails to send, and if so, it pipes it over the serial wireless connection to the OpenBerry. It's obviously still a work in progress, since the GUI isn't complete, but the hard part is done!

Here are some pictures I took of it:

And here’s a little step-by-step tutorial of how I put it together, including the base source code in case anyone else wanted to make one too. I’ve already done the hardest part by getting the modules and code integrated…


Step 0: Assemble Modules and Sketch Design

Here’s everything I used to build the Open Source BlackBerry… and just so I could be like MacGuyver, I made sure to find a use for Duct Tape and a paperclip, both of which (of course) are integral, life-saving elements of the finished design… :-)


Step 1: Pre-program the XBee Wireless Shields

I started with Mike’s tutorial over here which basically involved grabbing this program here.

The Libelium XBee shields I had were actually XBee 802.15.4 protocol, so I just had to select that properly in the pull-down menu, and otherwise I was ok. These are pretty neat little shields, and I definitely recommend them!


Step 2: Program the Arduino Transceiver Base Station

The next step is to place the XBee Shield on the Arduino that will serve as the base station module, and leave that sitting on the desk, connected via USB to the computer that will act as the email relay gateway.

Here’s the very simple source code I used in the early stages to get it up and running:

//code for the base station xbee transmitter

#include

#define rxPin 2

#define txPin 3

SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);

void setup ( void) {

pinMode(rxPin, INPUT);

pinMode(txPin, OUTPUT);

mySerial.begin(9600);

Serial.begin(9600);

}

char x;

void loop ( void) {

//x = mySerial.read();

//Serial.print(x);

mySerial.print("x");

//Serial.print("a");

delay(500);

}


Step 3: Assemble the OpenBerry Gadget

This wasn’t too bad, actually, since each of the shields are easily intercompatible.

This involved snapping the TouchShield Slide and ButtonShield on the top of the DoubleWide ExtenderShield, and snapping the Arduino and Lithium Backpack to the underside. Phew, that was a lot of links to look up! I set the ButtonShield to Mode B, so it wouldn’t clobber the pins the TouchShield Slide needed to communicate with.

The tricky part was wiring up the other XBee Shield, since there wasn’t enough space for it on the top or front. That wasn’t too hard, though, I just took the sticky tape off the back of a black Mini Protoboard and snapped the Arduino XBee Shield into the protospace holes. Then, I used 4 wires to connect the shield to +5V, Ground (underneath the TouchShield Slide), and to serial Rx, and serial Tx on pins 4 and 5 on the ExtenderShield.


Step 4: Program the OpenBerry

This was pretty easy to figure out, I just plugged the device into the USB port of my computer, and used the Arduino IDE to program the following code:

//code for blackberry

#include

#define rxPin 4

#define txPin 5

SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);

unsigned int val;

unsigned int valold;

void setup ( void) {

//set up xbeeshield

pinMode(rxPin, INPUT);

pinMode(txPin, OUTPUT);

mySerial.begin(9600);

Serial.begin(9600);

//set up button shield

digitalWrite(8, LOW); pinMode(8, INPUT);//bit 0

digitalWrite(9, LOW); pinMode(9, INPUT);// bit 1

digitalWrite(10, LOW); pinMode(10, INPUT);// bit 2

digitalWrite(16, LOW); pinMode(16, INPUT);//bit 3

digitalWrite(17, LOW); pinMode(17, INPUT);//bit 4

pinMode(11,OUTPUT);//led in mode b

digitalWrite(11,LOW);//led in mode b

}

char x;

void loop ( void) {

//x = mySerial.read();

//Serial.print(x);

if (x == 'x') {

mySerial.print("a");

delay(10);

mySerial.print("a");

delay(10);

mySerial.print("a");

delay(10);

}

val = ((digitalRead(17)<<4)|>

(digitalRead(16)<<3)|

(digitalRead(10)<<2)|

(digitalRead(9)<<1)|

(digitalRead(8)<<0));

if (val != valold) //test to see if val changed

{

Serial.println(val,BIN); // write the array reference at val to the serial port

valold = val; //document the previous vale

mySerial.print(val);

delay(100);

}

/*

digitalWrite(11,LOW); //led blink

delay(200);

digitalWrite(11,HIGH); //led blink

delay(200);

*/

//Serial.print("a");

delay(10);

}

This let me test all of the configuration settings, and then I was able to tack on a few lines to send information back and forth with the TouchShield Slide to display incoming messages, using the same code snippets from the InputShield forwarder (ironically, since the packet formats were just right) – thanks, Chris! http://antipastohw.blogspot.com/2009/02/gamepack-with-inputshieldellipses.html

Which led to the finished device!


And here's a video of me showing it in action ... I would probably have retaken the video to edit the corny comment about having a bigger screen... too bad I don't know how to use video editing software... oh well :)

Of course, all the code is GNU Open Source, and I’ve uploaded some pictures to Flickr, and Justin helped me put everything together as a kit on the liquidware shop for the ButtonShield and other modules…

7 comments:

Matt said...

ok, it is officially waaaay too late to be up doing this... it's 4am, and i have to go to work tomorrow. oh well.

anyway, thanks a lot for lending me the prototype, mike!

Maxium said...

do you need any help with the graphics of the gui interface you are making? this project seems really cool and i would love to lend a hand

Matt said...

yaaaay! http://www.engadget.com/2009/03/20/openberry-diy-messenger-heavy-on-style-wont-replace-your-smart/#continued

:-)

@maximum - i could definitely use some help with the gui, ... maybe i could send you my c code sketch template?

Chris said...

I would also love to help with this project; what other software help are you looking for?

Maxium said...

Ok, just send it over and ill come up with something for it. :)

Unknown said...

A "blackberry" project sounds like fun! I suggest using github (http://github.com/liquidware) so we all can contribute on the software.

AubidadedBallad said...

Great tutorial! Very informative in how well worded and descriptive you were! You know they say that if one knows how to describe what they want really well, then life is just as good as how you describe it :)
Its great for people who feel like time is running against them and then land on your blog and feel like a whole burden was just lifted off of their shoulder.. I admire and respect people who take
time to make it easier for others.. Thanks a bunch! :)
Compaq Laptop Parts