Our first assignment is to chose one word from each of these three columns, and create a physical improv project.

Actions:
* squeezing
* stroking
* tapping
* shaking
* dancing
* caressing
* breathing
* pushing

Things:
* feathers
* cup
* monkey
* playground ball
* sneakers
* lentils
* pudding

Responses:
* color
* sound
* animation
* speech
* music
* kinetic movement

I was pretty stumped about what to do for awhile…and actually still kind of am….so Tuesday I decided to start off by familiarizing myself with physical computing. It’s amazing how little you can remember about circuits once you have been away from it for awhile. Anyway, so I started off kind of big, and tried to re-do my ZIgBee radio - pcomp final project from last fall. After becoming frustrated, I back tracked ever further and redid some labs. Yes, I actually redid the Servo Motor and Analog labs. Haha. So today,(Friday) I felt confident that I could tackle wireless and actually was able to get it working. (**Rob Faludi, thanks again for all of your code, and your expertise with Zigbee!**)

So now I have my radios working, and I can actually hit a switch and have an LED light up on the other end.

Here is Rob’s tutorial I used originally


Here is my original documentation

Here are my circuits.
ProjectOne_1.jpg
ProjectOne_2.jpg

Some Close Ups:
ProjectOne_3.jpg ProjectONe4.jpg

Basically one Zigbee is sending, and one is receiving.

The Sender works like this: When the sending Zigbee flips its digital switch (pin 12) off and on, it converts the 0 and 1 values to a readable ASCII value and sends it out the serial port.

The Receiver works like this: When the receiving Zigbee gets the ASCII value (in this case its a “T”) then the Arduino turns on the LED that is connected to connected to pin 11.

****This code is lifted from Rob Faludi*****
****If you would like to use this code, absolutely feel free, but be sure to use a different PanID (Your personal area network) My is set to 9999 in this code. Once you have selected a PanID, Be sure check the Wiki, and make sure no one else is using it, and then add yours to the list so that your radios do not interfere with anyone elses.

Here is the Code!

Sender Code:

// a digital input is on port 12
int switchPin = 12;

// a status light is on port 13
int ledPin = 13;

// a byte to send out data:
char thisByte = 0;

void setup () {
// set pins to input and output appropriately
pinMode(ledPin, OUTPUT);
pinMode(switchPin, INPUT);

// start up the serial connection with 9600-8-n-1-true (non-inverted):
Serial.begin(9600);

// blink the status LED
blinkLED(ledPin, 3);

// for some reason it seems to help to send an arbitrary character first
//then pause for the guard time before requesting command mode
Serial.print(”X”);
delay(1100);
// put the XBee in command mode
Serial.print(”+++”);
delay(1100);
// wait for a response from the XBee for 2000 ms, or start
// over with setup if no valid response comes

if (returnedOK() == ‘T’) {
// if an OK was received then continue
}
else {
setup(); // otherwise go back and try setup again
}

// set the PAN (personal area network) ID number
// this example uses 0×3330, but you’ll want to choose your own
// unique hexadecimal number between 0×0 and 0xFFFE
// (note the comma at the end of the command which indicates that another command will follow)
Serial.print(”ATID9999,”);
// set the Destination High to 0×0
// to select 16 bit addressing mode. These addresses can
// be assigned and changed by sending commands from a microcontroller
Serial.print(”DH0,”);
// set the Destination Low (16 bit address)
// this example uses 0×0 for send and 0×1 for receive but you’ll
// want to choose your own hexadecimal numbers between 0×0 and 0xFFFE
Serial.print(”DL1234,”);
// exit command mode (note that we use Serial.printLN here to issue a linefeed that completes the command sequence)
Serial.println(”CN”);

// the preceeding commands can also be sent on a single line like this, using a single AT command with commas:
// Serial.println(”ATID9999,DH0,DL5678,CN”);

// the preceeding command line could also be sent as separate commands, by reissuing the AT command:
// Serial.println(”ATID3330″);
// Serial.println(”ATDH0″);
// Serial.println(”ATDL1″);
// Serial.println(”ATCN”);

// wait for a response from the XBee for 2000 ms, or start
// over with setup if no valid response comes

if (returnedOK() == ‘T’) {
// if an OK was received then continue
}
else {
setup(); // otherwise go back and try setup again
}

}

void loop () {
// read the switch:
thisByte = digitalRead(switchPin);
// convert it to a readable ASCII value, send it out the serial port:
Serial.print(thisByte, DEC);
}

void blinkLED(int targetPin, int numBlinks) {
// this function blinks the status LED light as many times as requested
for (int i=0; i digitalWrite(targetPin, HIGH); // sets the LED on
delay(250); // waits for a second
digitalWrite(targetPin, LOW); // sets the LED off
delay(250);
}
}

char returnedOK () {
// this function checks the response on the serial port to see if it was an “OK” or not
char incomingChar[3];
char okString[] = “OK”;
char result = ‘n’;
int startTime = millis();
while (millis() - startTime < 2000 && result == 'n') { // use a timeout of 10 seconds
if (Serial.available() > 1) {
// read three incoming bytes which should be “O”, “K”, and a linefeed:
for (int i=0; i<3; i++) {
incomingChar[i] = Serial.read();
}
if ( strstr(incomingChar, okString) != NULL ) { // check to see if the respose is “OK”
// if (incomingChar[0] == ‘O’ && incomingChar[1] == ‘K’) { // check to see if the first two characters are “OK”
result = ‘T’; // return T if “OK” was the response
}
else {
result = ‘F’; // otherwise return F
}
}
}
return result;
}

Receiver Code:

// an output light is on port 11
int outputPin = 11;

// a status light is on port 13
int ledPin = 13;

// a byte to receive data:
char inByte = 0;

void setup () {
// set pins to input and output appropriately
pinMode(ledPin, OUTPUT);
pinMode(outputPin, OUTPUT);

// start up the serial connection with 9600-8-n-1-true (non-inverted):
Serial.begin(9600);

// blink the status LED
blinkLED(ledPin, 3);

// for some reason it seems to help to send an arbitrary character first
//then pause for the guard time before requesting command mode
Serial.print(”X”);
delay(1100);
// put the XBee in command mode
Serial.print(”+++”);
delay(1100);
// wait for a response from the XBee for 2000 ms, or start
// over with setup if no valid response comes

if (returnedOK() == ‘T’) {
// if an OK was received then continue
}
else {
setup(); // otherwise go back and try setup again
}

// set the PAN (personal area network) ID number
// this example uses 0×3330, but you’ll want to choose your own
// unique hexadecimal number between 0×0 and 0xFFFE
// (note the comma at the end of the command which indicates that another command will follow)
Serial.print(”ATID9999,”);
// set the MY (16 bit address)
// this example uses 0×0 for send and 0×1 for receive but you’ll
// want to choose your own hexadecimal numbers between 0×0 and 0xFFFE
Serial.print(”MY5678,”);
// exit command mode (note that we use Serial.printLN here to issue a linefeed that completes the command sequence)
Serial.println(”CN”);

// the preceeding commands can also be sent on a single line like this, using a single AT command with commas:
// Serial.println(”ATID3330,MY1,CN”);

// the preceeding command line could also be sent as separate commands, by reissuing the AT command:
// Serial.println(”ATID3330″);
// Serial.println(”ATMY1″);
// Serial.println(”ATCN”);

// wait for a response from the XBee for 2000 ms, or start
// over with setup if no valid response comes

if (returnedOK() == ‘T’) {
// if an OK was received then continue
}
else {
setup(); // otherwise go back and try setup again
}

}

void loop () {
// get any incoming data:
if (Serial.available() > 1) {
// read a byte
inByte = Serial.read();
// light the LED if a 1 has been received
}
if (inByte == ‘1′) {
digitalWrite(outputPin, HIGH);
}
// douse the LED if anything else was received
else {
digitalWrite(outputPin, LOW);
}
}

void blinkLED(int targetPin, int numBlinks) {
// this function blinks the status LED light as many times as requested
for (int i=0; i digitalWrite(targetPin, HIGH); // sets the LED on
delay(250); // waits for a second
digitalWrite(targetPin, LOW); // sets the LED off
delay(250);
}
}

char returnedOK () {
// this function checks the response on the serial port to see if it was an “OK” or not
char incomingChar[3];
char okString[] = “OK”;
char result = ‘n’;
int startTime = millis();
while (millis() - startTime < 2000 && result == 'n') { // use a timeout of 10 seconds
if (Serial.available() > 1) {
// read three incoming bytes which should be “O”, “K”, and a linefeed:
for (int i=0; i<3; i++) {
incomingChar[i] = Serial.read();
}
if ( strstr(incomingChar, okString) != NULL ) { // check to see if the respose is “OK”
// if (incomingChar[0] == ‘O’ && incomingChar[1] == ‘K’) { // check to see if the first two characters are “OK”
result = ‘T’; // return T if “OK” was the response
}
else {
result = ‘F’; // otherwise return F
}
}
}
return result;
}

So now for the big question, what can I do with all of this for the assignment?? I decided to use the words, Tapping, Monkey and Color….So now when you tap a switch, a monkey’s headband will light up.

Here is the headband:

ProjectONe5.jpg


Comments are closed.