Beacon Pendants: Code

Posted in Uncategorized on July 2nd, 2008

//Beacon Locator Thing V 1.0  A slamming together of Rob Faludi’s RSSI Reader, and Tom Igoes Analog Duplex Sender Code
//by Chris Cerrito

//FOR XBEE2
//******************************************************************************int
int RSSI = 0; // holds the Recieved Signal Strength Value, the value used to range find the Xbees
int address = 0; //holds the 16 bit address of the incoming signal
int lastSender = 0; // last address we received an API packet from

//******************************************************************************#define

#define txLed 2 //indicates outgoing data
#define rxLed 3 //indicates incoming data
#define RedChannel 11 //red pwm pin
#define GreenChannel 9 //green pwm pin
#define BlueChannel 10 //blue pwm pin

int RedChanVal = 0;
int GreenChanVal = 0;
int BlueChanVal = 0;

unsigned long RedTimeOut = 0;
unsigned long GreenTimeOut = 0;
unsigned long StartTime = 0;

//*********************************************************************************

void setup() {
Serial.begin(9600); //Lets talk.
pinMode(txLed, OUTPUT);
pinMode(rxLed, OUTPUT);
pinMode(RedChannel, OUTPUT);
pinMode(GreenChannel, OUTPUT);
pinMode(BlueChannel, OUTPUT);
setDestination();
}

//***********************************************************************************WORKS?

void setDestination(){
blink(2);               //blink to indicate that the destination code is about to run
delay(1200);
Serial.print(”+++”); //throw Xbee into command mode
delay(500);
char thisByte = 0;
while (thisByte != ‘\r’) {           //Xbee will reply with an OK/r…wait for the ?r before printing
if (Serial.available() > 0) {      //if theres something in the serial, read it.
thisByte = Serial.read();
}
}
Serial.print(”ATDH0, DLFFFF\r”); //sets the address. Puts in the Xbee in Broadcast Mode—Anyone can listen
delay(10);
Serial.print(”ATMY0001\r”); //gives the Xbee an Address of 1. Use single digit addresses. CHANGE TO A DIFFERENT address fr each UNIT.
delay(10);
Serial.print(”ATID1124\r”); //set the PAN ID
delay(10);
Serial.print(”ATAP1\r”); //put the Xbee into API mode
delay(10);
Serial.print(”ATCN\r”); //take the Xbee out of command mode.
delay(1200);
blink(2);

}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++works

void blink(int howManyTimes) {
for (int i=0; i< howManyTimes; i++) {
digitalWrite(txLed, HIGH);
delay(200);
digitalWrite(txLed, LOW);
delay(1200);
}
}

//********************************************//Reads an API string

void APIread() {
if (Serial.available() > 13) {   //checks to make sure that we have received at least one frame worth of bytes
int inByte = Serial.read();    //reads the incoming API string
if (inByte == 0×7E) {          // (first byte)looks for tilda (ox7E) place holder…marks the beginning of the string
for (int i=0;i<4;i++) {
int junk = Serial.read();  // (next four bytes)  reads and discards the next four bytes that we’re not going to use
}

address = Serial.read();       // the sixth byte is the low part of the address (ONLY USE ONE BYTE ADDRESSES!)
RSSI = Serial.read();          // the seventh byte is the RSSI value

for (int i=0;i<7;i++) {
int junk = Serial.read();     //reads and discards the last six bytes of the API string. We dont need them. Whats in them? beats the crap outta me.
}

AssignValues();                 //if there are values to assign from a successful serial read, assign them.
}
}

}

//*******************************************//

void AssignValues() {

if (address == 0003) {                              //if Xbee 3 is detected, give the red channel a value
GreenChanVal=(100-RSSI)*2;
GreenTimeOut=  millis();
}

if (address == 0002) {                         //if Xbee2 is detected, give the green channel a value
RedChanVal=(100-RSSI)*2;
RedTimeOut = millis();
}

if (address > 0) {                         //if an address is recieved (Showing that the Xbee has
digitalWrite(rxLed, HIGH);               //received and processed info.
}
else
{digitalWrite(rxLed, LOW);
}
}
//********************************************

void Lightup() {
analogWrite(GreenChannel, GreenChanVal);
analogWrite(RedChannel, RedChanVal);
}

//**********************************************

void Timeout() {

if ((millis() - GreenTimeOut) > 1000) {
GreenChanVal=0;
}

if ((millis() - RedTimeOut) > 1000) {
RedChanVal=0;
}
}

//*********************************************

void Sendjunk() {
digitalWrite(txLed, HIGH);
sendData(”X”,0xFFFF);    //SETS ADDRESS IS REDUNDANT
delay(50);
digitalWrite(txLed, LOW);
}

//*******************************************

void loop () {
StartTime = millis();
APIread();
Lightup();
Sendjunk();
Timeout();
Serial.print(”GreenChanVal”);
Serial.print(GreenChanVal);
Serial.print(”RedChanVal”);
Serial.print(RedChanVal);
}

The Beacon Pendants

Posted in sociable objects, Uncategorized on July 2nd, 2008

Beacon Pendants

For my sociable objects final I decided to work on a project thats been the in back of my mind for quite some time. I’ve always wanted to make “social” jewelry; small wearable objects that have the ability to know if there are others of their kind in the area. For instance, say you were wearing, oh, i dunno, a pendant, and your friend had on a similar piece. Perhaps each pendant would glow, the closer the two of you are together, the brighter the response, the further apart, the dimmer. Say maybe there were three pendants, and each pendant had a specific color assigned to it; You were wearing the blue necklace, your friend the green, and your other friend the red. When the three of you were together, the pendants would flash brightly between all three colors, indicating social cohesion among the group. If one friend left early, the color show would be reduced to just two tones, and finally, when everyone parts ways, you would be left with a necklace dimly glowing it’s assigned color.

Another interesting idea: say the pendants were somewhat directional…Remember rabbit ears? Back in the day of braodcast TV (a world I’m afraid I still live in) you would have to adjust your antennae in order to pick up a station clearly. Say you were wearing one of these objects, and you suddenly noticed a flash of red, indicating that your friend was somewhere in the crowd. Using the pendant like a divining rod of sorts, you maneuver through the crowd, watching the light grow dimmer or stronger based the relative locations of both parties. Maybe you would be able to find one another?

And, finally, what if you were, say, at a huge party in the middle of the desert wearing a big furry coat, a space helmet, and stuck on sensory overload. A little help finding your way back to your camp would surely be a good thing. Perhaps there could be a beacon of sorts, broadcasting a much stronger signal then the pendants themselves, but in their range of hearing. Maybe, just maybe, you could navigate your way home using a somewhat directional antennae….

So, in a nutshell, thats pretty much what I tried to accomplish. I haven’t gotten all the way there yet, but I do feel as though I’ve made significant progress. I’m using Xbees broadcasting API packets, and giving each unit the ability to parse those packets out, seeing who they’re from, and the signal strength of each unit in the system. Right now I have three breadboarded circuits, the “pendants” themselves, up and running. Theres a ton more to do, including shrinking these things down to a wearable size, but I think it’s all doable.

Below is a video of each circuit in action. Though they’re not mobile (i was so shocked that things actually worked that I didn’t want to ruin it by moving), each unit can see wach other, as indicated by the flashing tricolor RGB LEDS.

The diagram above is basically how I envision the system working.

Take a look below:


Trash Talk

Posted in Living Art, Physical Computing, Personal, Uncategorized on July 2nd, 2008

Trash Talk is in Conflux this year….

MRS. DESI LIVES!!!!

I’ll be posting info about the rebuild as it happens. Should be pretty damn good.

Rock Paper Scissors

Posted in sociable objects on June 30th, 2008

Rock Paper Scissors
Or
What a Pain in the Ass.

So, building and coding a wireless rock-paper-scissors game proved to be way, way harder then I would have ever expected. Dave Spector and I started off using a slightly different approach then most everyone else seemed to take, using the Duplex Sender code as a foundation. Our idea seemed incredibly simple:

1) Use a 10k pot to select rock, paper, or scissors
2) Send the pot value via the Analog Duplex Sender code.
3) Insert that value into a RPS game.

And of course in the end, nothing worked.

After  struggling, changing our code, swearing, and a lot of Robs help, we managed to get something together that allowed use to play 1 or 2 games of RPS, and then crashed completely. I still have no idea why this happened, and would like to take another look at all the code when I have a bit more time.

I still really don’t understand why our original approach failed so miserably.

Pics:

Code:

/*
XBee Analog Duplex sender
Language: Wiring/Arduino

This sketch configures an XBee radio via the serial port,
sends the value of an analog sensor out, and listens for
input from the radio, using it to set the value of
a PWM output.

Thanks to Robert Faludi for the critique and improvements
*/
#define sensorPin 0         // input sensor
#define txLed 2             // LED to indicate outgoing data
#define rxLed 3             // LED to indicate incoming data
#define analogLed 9         // LED that will change brightness with incoming value
#define threshold 10        // how much change you need to see on
// the sensor before sending

int gameState = 1; // 1 = choice, 2 = tx/rx, 3 = winner mode
int brightness = 0;
int sensorValue = 0;
int x = 0;
int y = 0;

int ledScissors = 7;
int ledRock = 5;
int ledPaper = 6;
int ledWinner = 4;
int ledLoser = 8;
int attackSwitchPin = 12;    // Analog input pin that the switch is attached to
int attackSwitchValue = 0; //value read from attackSwitch

int lastSensorReading = 0;  // previous state of the switch

int inByte= -1;             // incoming byte from serial RX
char inString[6];           // string for incoming serial data
int stringPos = 0;          // string index counter

void setup() {
// configure serial communications:
Serial.begin(9600);

// configure output pins:
pinMode(txLed, OUTPUT);
pinMode(rxLed, OUTPUT);
pinMode (analogLed, OUTPUT);

pinMode(ledRock, OUTPUT);
pinMode(ledScissors, OUTPUT);
pinMode(ledPaper, OUTPUT);
pinMode(ledWinner, OUTPUT);
pinMode(ledLoser, OUTPUT);

digitalWrite(ledRock, LOW);  //turn off led
digitalWrite(ledPaper, LOW);  //turn off led
digitalWrite(ledScissors, LOW);   //turn off led
digitalWrite(ledWinner, LOW);   //turn off led
digitalWrite(ledLoser, LOW);   //turn off led

// set XBee’s destination address:
setDestination();
// blink the TX LED indicating that the main program’s about to start:
blink(3);
}
void setDestination() {
// put the radio in command mode:
Serial.print(”+++”);
// wait for the radio to respond with “OK\r”
char thisByte = 0;
while (thisByte != ‘\r’) {
if (Serial.available() > 0) {
thisByte = Serial.read();
}
}

// set the destination address, using 16-bit addressing.
// if you’re using two radios, one radio’s destination
// should be the other radio’s MY address, and vice versa:
Serial.print(”ATDH0, DL5678\r”);  //sofia switch this to 1234
// set my address using 16-bit addressing:
Serial.print(”ATMY1234\r”);    ///sofia switch to 5678
// set the PAN ID. If you’re working in a place where many people
// are using XBees, you should set your own PAN ID distinct
// from other projects.
Serial.print(”ATID1124\r”);
// put the radio in data mode:
Serial.print(”ATCN\r”);
}
// Blink the tx LED:
void blink(int howManyTimes) {
for (int i=0; i< howManyTimes; i++) {
digitalWrite(txLed, HIGH);
delay(200);
digitalWrite(txLed, LOW);
delay(200);
}
}

void loop() {

while (gameState == 1) {
getInput();
if (digitalRead(attackSwitchPin) == HIGH) {
gameState = 2;
}
}

while (gameState == 2) {
// send my choice and listen for opponent’s choice

// listen for incoming serial data:
if (Serial.available() > 0) {
// turn on the RX LED whenever you’re reading data:
digitalWrite(rxLed, HIGH);
handleSerial();
}
else {
// turn off the receive LED when there’s no incoming data:
digitalWrite(rxLed, LOW);
}

// if there’s something to send, send it:
if (sensorValue >= 0) {

//light the tx LED to say you’re sending:
digitalWrite(txLed, HIGH);

Serial.print(sensorValue, DEC );
Serial.print(”\r”);
delay(50);
// turn off the tx LED:
digitalWrite(txLed, LOW);
}

if (brightness < 5 && brightness>0){
y = 1;
}

if (brightness >= 5 && brightness<= 250){
y = 2;
}

if (brightness > 250){
y=3;
}

if (y > 0) {
Serial.print(sensorValue, DEC );
delay(50);
Serial.print(”\r”);
delay(50);

gameState = 3;
}

while (gameState == 3) {
// calculate who won and show the output on happy LEDs

if (x == 1 ){
digitalWrite(ledRock, HIGH); //turn on led
}

if (x == 2 ){
digitalWrite(ledPaper, HIGH);  //turn on led
}

if (x == 3 ){
digitalWrite(ledScissors, HIGH);   //turn on led
}

if (y == 1 ){
digitalWrite(ledRock, HIGH); //turn on led
//Serial.println (”Player 2 Chose ROCK!”);
}

if (y == 2 ){
// Serial.println (”Player 2 Chose PAPER!”);
digitalWrite(ledPaper, HIGH);  //turn on led
}

if (y == 3 ){
// Serial.println (”Player 2 Chose SCISSORS!”);
digitalWrite(ledScissors, HIGH);   //turn on led
}

if (x == y) {
//Serial.println(”It’s a draw!”);
digitalWrite(ledWinner, HIGH);   //turn on led
digitalWrite(ledLoser, HIGH);   //turn on led
}
if (x == 1 && y == 2) {
//Serial.println(”Paper covers Rock!  PLAYER 2 WINS!”);
digitalWrite(ledLoser, HIGH);   //turn off led
}
if (y == 1 && x == 2) {
//Serial.println(”Paper covers Rock!  PLAYER 1 WINS!”);
digitalWrite(ledWinner, HIGH);   //turn on led
}

if (x == 1 && y == 3) {
//Serial.println(”Rock smashes Scissors!  PLAYER 1 WINS!”);
digitalWrite(ledWinner, HIGH);   //turn on led
}
if (y == 1 && x == 3) {
//Serial.println(”Rock smashes Scissors!  PLAYER 2 WINS!”);
digitalWrite(ledLoser, HIGH);   //turn off led
}
if (x == 2 && y == 3) {
//Serial.println(”Scissors cuts Paper!  PLAYER 2 WINS!”);
digitalWrite(ledLoser, HIGH);   //turn off led
}
if (y == 2 && x == 3) {
//Serial.println(”Scissors cuts Paper!  PLAYER 1 WINS!”);
digitalWrite(ledWinner, HIGH);   //turn on led
}

if (digitalRead(attackSwitchPin) == HIGH) {
digitalWrite(ledRock, LOW);  //turn off led
digitalWrite(ledPaper, LOW);  //turn off led
digitalWrite(ledScissors, LOW);   //turn off led
digitalWrite(ledWinner, LOW);   //turn off led
digitalWrite(ledLoser, LOW);   //turn off led
delay(3000);
y = 0;
brightness = 0;
Serial.flush();
gameState = 1;

}
//    delay (3000);
//    y = 0;

}

}
}

void getInput() {
// listen to the potentiometer:
sensorValue = analogRead(sensorPin)/4;

if (sensorValue > 0) { // if we got a real value from the readSensor() function
if (sensorValue < 5) {
digitalWrite(ledRock, HIGH);
digitalWrite(ledPaper, LOW);
digitalWrite(ledScissors, LOW);
x = 1;
}

if (sensorValue > 4 && sensorValue <  251) {
digitalWrite(ledRock, LOW);
digitalWrite(ledPaper, HIGH);
digitalWrite(ledScissors, LOW);
x = 2;
}
if (sensorValue > 250) {
digitalWrite(ledRock, LOW);
digitalWrite(ledPaper, LOW);
digitalWrite(ledScissors, HIGH);
x = 3;
}
}
}

void handleSerial() {
inByte = Serial.read();
// save only ASCII numeric characters (ASCII 0 - 9):
if ((inByte >= ‘0′) && (inByte <= ‘9′)){
inString[stringPos] = inByte;
stringPos++;
}
// if you get an ASCII carriage return:

if (inByte == ‘\r’) {
// convert the string to a number:
brightness = atoi(inString);
// set the analog output LED:
//analogWrite(analogLed, brightness);

// put zeroes in the array
for (int c = 0; c < stringPos; c++) {
inString[c] = 0;
}
// reset the string pointer:
stringPos = 0;
}
}

Analog Duplex Sender

Posted in sociable objects on June 30th, 2008

Analog Duplex Sender Lab

(Take a look at it all in action at: http://silverapple.blip.tv/#1006798)

This lab was fairly straightforward, yet still took quite a bit of time. I had an issue setting up my Xbees, but realized it all stemmed from the fact that they had been used before and needed to be reset.

Another issue was a loose pin on the breakout board, due to the fact that I did a pretty rushed soldering job.

All in All, after a bunch of obnoxious p-comp issues, eddie and were up and running.

Basically, what was going is that we were wirelessly using two potentiometers to control the brightness of two LEDS. Values were being read by the Arduinos, with the Xbees sending values back and forth.

The code is straight out of Making Things Talk by Tom Igoe. If you want to know more about it, pick a copy up, it’s well worth it.

/*
XBee Analog Duplex sender
Language: Wiring/Arduino

This sketch configures an XBee radio via the serial port,
sends the value of an analog sensor out, and listens for input
from the radio, using it to set the value of a PWM output.
Thanks to Robert Faludi for the critique and improvements.
*/

#define sensorPin 0         // input sensor
#define txLed 2             // LED to indicate outgoing data
#define rxLed 3             // LED to indicate incoming data
#define analogLed 9         // LED that changes brightness with incoming value
#define threshold 10        // how much change you need to see on
// the sensor before sending

int lastSensorReading = 0;  // previous state of the switch

int inByte= -1;             // incoming byte from serial RX
char inString[6];           // string for incoming serial data
int stringPos = 0;          // string index counter

void setup() {
// configure serial communications:
Serial.begin(9600);

// configure output pins:
pinMode(txLed, OUTPUT);
pinMode(rxLed, OUTPUT);
pinMode (analogLed, OUTPUT);

// set XBee’s destination address:
setDestination();
// blink the TX LED indicating that the main program’s about to start:
blink(3);
}
void setDestination() {
// put the radio in command mode:
Serial.print(”+++”);
// wait for the radio to respond with “OK\r”
char thisByte = 0;
while (thisByte != ‘\r’) {
if (Serial.available() > 0) {
thisByte = Serial.read();
}
}

// set the destination address, using 16-bit addressing.
// if you’re using two radios, one radio’s destination
// should be the other radio’s MY address, and vice versa:
Serial.print(”ATDH0, DL5678\r”);
// set my address using 16-bit addressing:
Serial.print(”ATMY1234\r”);
// set the PAN ID. If you’re working in a place where many people
// are using XBees, you should set your own PAN ID distinct
// from other projects.
Serial.print(”ATID1124\r”);
// put the radio in data mode:
Serial.print(”ATCN\r”);
}
// Blink the tx LED:
void blink(int howManyTimes) {
for (int i=0; i< howManyTimes; i++) {
digitalWrite(txLed, HIGH);
delay(200);
digitalWrite(txLed, LOW);
delay(200);
}
}

void loop() {
// listen for incoming serial data:
if (Serial.available() > 0) {
// turn on the RX LED whenever you’re reading data:
digitalWrite(rxLed, HIGH);
handleSerial();
}
else {
// turn off the receive LED when there’s no incoming data:
digitalWrite(rxLed, LOW);
}

// listen to the potentiometer:
char sensorValue = readSensor();

// if there’s something to send, send it:
if (sensorValue > 0) {
//light the tx LED to say you’re sending:
digitalWrite(txLed, HIGH);

Serial.print(sensorValue, DEC );
Serial.print(”\r”);

// turn off the tx LED:
digitalWrite(txLed, LOW);
}
}
void handleSerial() {
inByte = Serial.read();
// save only ASCII numeric characters (ASCII 0 - 9):
if ((inByte >= ‘0′) && (inByte <= ‘9′)){
inString[stringPos] = inByte;
stringPos++;
}
// if you get an ASCII carriage return:

if (inByte == ‘\r’) {
// convert the string to a number:
int brightness = atoi(inString);
// set the analog output LED:
analogWrite(analogLed, brightness);

// put zeroes in the array
for (int c = 0; c < stringPos; c++) {
inString[c] = 0;
}
// reset the string pointer:
stringPos = 0;
}
}

char readSensor() {
char message = 0;
// read the sensor:
int sensorReading = analogRead(sensorPin);

// look for a change from the last reading
// that’s greater than the threshold:
if (abs(sensorReading - lastSensorReading) > threshold) {
message = sensorReading/4;
lastSensorReading = sensorReading;
}
return message;
}

The Nod-Off Hat

Posted in sociable objects on June 30th, 2008

Ah…retroactive blogging.

Our first assignment for sociable objects was to address a problem on the ITP floor. I decided to tackle one near and dear to my heart: The problem of nodding off while trying to get work done. On more then one occasion over the past year, I’ve woken up with keyboard tread marks on my cheek and IC’s in my hair.

I once even tried to use an Arduino for a pillow…Turns out that drool and micro controllers don’t mix.

Anyway, in order to make a nod-off alarm, I decided to attach an accelerometer to my hat. The accelerometer would act as a sophisticated tilt sensor…If my head tilts too far forward, or too far to the side, an annoying piezo buzzer sounds, waking me up.

This all worked out pretty well. I can’t help but think of this also as some sort of Posture-o-meter or something. Maybe I’ll trying messing around with the Y-axis value in the future.

This project was pretty simple and straightforward, but also represents the frist time that I’ve written code in MONTHS. It took me a little while to get back in the swing of things, but it felt good to be coding (the main reason I’m taking this class).

Anyway, here’s the code, again, simple for most:

(photos of the board coming soon)

int analog0 = 0; // select the input pin for the potentiometer
int XaxisVal0 = 0; // variable to store the value coming from the sensor
int squirtPin = 13; // on/off for the squirtgun

void setup() {
Serial.begin(9600); // use the serial port to send the values back to the computer
pinMode(squirtPin, OUTPUT); //declare squirtPin an output
}

void loop() {
XaxisVal0 = analogRead(analog0); // read the value from the sensor
if(XaxisVal0 > 150 || XaxisVal0 < 87){digitalWrite(squirtPin, HIGH);
}
else
{digitalWrite(squirtPin, LOW);
}

Serial.println(”XaxisVal0″); // print the value to the serial port
Serial.println(XaxisVal0); // print the value to the serial port
}

The BLT

Posted in Uncategorized on June 16th, 2008

blt-schematic001.jpg

Posted in Uncategorized on June 16th, 2008

file:///Users/christiancerrito/Desktop/BLT%20schematic.001.jpg

STEPPERS!

Posted in Toy Design on May 1st, 2008

take a gander: http://beatsteppers.com  

The Draw Synth

Posted in Living Art on March 26th, 2008

I’m trying to make a simple electronic instrument that uses drawing as an input. Graphite, when spread on paper, can conduct electricity, and produces electrical resistence. If I can read that resistence, and input it to an oscillator, I should be able to make something relatively funky and straightforward. Once again, I have avoided using an arduino this semester. Shame on me….It’s interesting though, I haven’t needed one yet. I’m going to be the rustiest programmer in the world. More to follow on this.