2008년 10월 23일 목요일

Xbee Configuration and 커뮤니케이션


For the communication between two xbees without Arduino, configuration is needed.
So, ATMY, ATDL, ATID, ATDH, ATIA, ATD0, ATD1, ATP0, ATP1 are all configured.
especially, IA command is inevitably needed for output.(It means who is listening)

IA (I/O Input Address) Command
The IA com-
mand is used to bind a module output to a spe-
cific address. Outputs will only change if received
from this address. The IA command can be used
to set/read both 16 and 64-bit addresses.

더 정교하거나 커뮤니케이션을 잘 하기 위해서는 코드 필요.




코드없이 xbe
e끼리 시리얼 통신하기

2008년 7월 2일 수요일

Dueling Skirt( The final Project of Sociable Objects)

Garments usually have been used for the way of expressing people's character and their status. However, even though fashion industry makes their own brand images of 'specialty', people still have possibilities can run into the other same outfits. Therefore, as matching these needs and letting people find their own identity, Armanda and I came up the idea as our final project called 'Dueling Skirt'. This project is about people who wear the same clothes never be in the same place.

- System Diagram -
To measure the distance, we use RSSI which is the strength of the signal of XBee.



Dueling Skirt for presentation

Here is my test for pattern changing. This is one of the ways of shift.

About Software Serial

From the Arduino site:
The Arduino hardware has built-in support for serial communication on pins 0 and 1( which also goes to the computer via the USB connection). The native serial support happens via a piece of hardware(built into the chip) called a UART. This hardware allows the Atmega chip to receive serial communication even while working on other tasks, as long as there room in the 64 byte serial buffer.

Limitations
  • Only speeds up to 9600 baud work
  • Serial.available() doesn't work
  • Serial.read() will wait until data arrives
  • Only data received while Serial.read() is being called will be received. Data received at other times be lost, since the chip is not "listening".

SoftwareSerialExample

Rock, Paper, Scissors GAME


circuit with XBee


Eduardo Lytton and I made Rock, Scissor, and Paper game. The game we made will be triggered by start switch. Once, push the start switch, each side generates a random number for rock, scissor, and paper. It will be sent to the other side as a data and the data will be compared with their own data. Depending on the real rock scissor and paper game, the one who wins the game get the light with 'you win' LED.






'ZTerm' and Arduino code represent procedure when game has started.

-code-

/*
Rock Paper Scissors Game using XBee, Arduino, and usb to serial adaptor
*/

#include

#define txLed 2
#define rxLed 3
#define rocPin_0 6
#define sciPin_1 7
#define papPin_2 8
#define youWin 4
#define switchPin 5
#define blinkPin 13
#define resetPin 9
#define txPin 12
#define rxPin 11

int myNumber = 0;

int inByte = -1;
int inValue[2];
int inValuePos;
int inMyValue;
byte getPartNum;

int stringPos = 0;

int switchState = 0;
int resetSwitchState = 0;

boolean gameStart = false;
boolean firstDataGet = false;
boolean dataIn = false;

SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);


//___________________________________________________________________setup
void setup(){
Serial.begin(9600);
pinMode(txLed, OUTPUT);
pinMode(rxLed, OUTPUT);
pinMode(rocPin_0, OUTPUT);
pinMode(sciPin_1, OUTPUT);
pinMode(papPin_2, OUTPUT);
pinMode(switchPin, INPUT);
pinMode(resetPin, INPUT);
pinMode(youWin, OUTPUT);
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);


mySerial.begin(9600);
mySerial.println("start...");
setDestination();
blink(3);
Serial.flush(); // clear the serial buffer so it's empty
}// setup



void setDestination(){ //set PanID, myID, destination ID
Serial.print("+++");
char thisByte = 0;
while(thisByte != '\r'){
if( Serial.available() > 0){
thisByte = Serial.read();
}
}
Serial.print("ATRE\r");
Serial.print("ATDH0, DL1234\r");
Serial.print("ATMY5678\r");
//Serial.print("ATID1111\r");
Serial.print("ATIDE00E\r");
Serial.print("ATCN\r");
}

void blink(int howManyTimes){ // function to make sure that Arduino is functioning properly
for(int i = 0; i 0){
dataIn = true;
// Serial.print("######");
mySerial.println("true");
digitalWrite(rxLed, HIGH); // light LED to indicate reciving information on Xbee
handleSerial(); // function for what to do with this information received
compareWhoWin(getPartNum, myNumber);
}
else{
digitalWrite(rxLed, LOW); // if no information received, LED is off
}



//send the ranNumvalue to the partner
if(myNumber > 0){ // if have a number generated from random
digitalWrite(txLed, HIGH); // light the LED on Xbee to indicate sending information

mySerial.println(myNumber);
Serial.print(myNumber, DEC); // send this value serial as DEC
Serial.print("\r"); // print a carriage return in ASCII
digitalWrite(txLed, LOW); // turn off LED on Xbee to indicate not sending information
}

}//loop
//----------------------------------------------------------------------------------------------------loop


//-------------------------------------------------------------------function for handleing serial
//function for serial communication between the xbees
void handleSerial(){

inByte = Serial.read(); // a variable for each byte taken from serial read function
mySerial.print("inByte: ");
mySerial.println(inByte, BYTE);

if(inByte != '\r'){ // the first byte is not carrige return, put the first byte into inMyValue
inMyValue = inByte;
}
if(inByte == '\r'){ // if you get a carriage return
// int getPartNum = atoi(inString); // change the ASCII value in the string to integer to make getPartNum - partner's number
getPartNum = inMyValue -48 ;
// char get"Part = inByte;
mySerial.print("Partner Number: ");
mySerial.println(getPartNum);

inMyValue = 0; // make inMyValue zero
}
}

//------------------------------------------------------------------ function for getting random Number
int getRandomNum(){ // function to get random number
randomSeed(millis()*analogRead(0)); // for real random combine millis and analogRead
int ranNumber;
ranNumber = random(1,4); // get a random value from 1 to 3


return ranNumber;
}//getRandomNum


//------------------------------------------------------------------ function for comparing who win
void compareWhoWin(int partnerNum, int myNumberAgain){ // function to compare partner and your numbers to see who wins: rock, paper, or scissors
mySerial.print("myData : ");
mySerial.println(myNumberAgain);
mySerial.print("partnerData: ");
mySerial.println(partnerNum);

if(partnerNum == myNumberAgain){ // if a tie ( numbers the same)
digitalWrite(youWin, HIGH); // light both youWin LEDS
mySerial.println("&&&&&&&&&&&&&&&&&&");
mySerial.println(" TIE ");
delay(50);
} if(partnerNum == 1 && myNumberAgain == 2 ){ // if pN rock vs mN scissors
digitalWrite(youWin,LOW); // mN youWin LED is not lit (LOSE)
mySerial.println("&&&&&&&");
mySerial.println(" You Lose");
delay(50);
} if(partnerNum ==1 && myNumberAgain == 3 ){ // if pN rock vs mN paper
digitalWrite(youWin,HIGH); // mN youWin LED is lit (WIN)
mySerial.println("&&&&&&&&&");
mySerial.println(" you Win");
delay(50);
} if(partnerNum == 2 && myNumberAgain == 1 ){ // if pN scissors vs mN rock
digitalWrite(youWin,HIGH); // mN youWin LED is lit (WIN)
mySerial.println("&&&&&&&&&");
mySerial.println(" you Win");
delay(50);
} if(partnerNum == 2 && myNumberAgain == 3 ){ // if pN scissors vs mN paper
digitalWrite(youWin,LOW); // mN youWin LED is not lit (LOSE)
mySerial.println("&&&&&&&");
mySerial.println(" You Lose");
delay(50);
} if(partnerNum == 3 && myNumberAgain == 1 ){ // if pN paper vs mN rock
digitalWrite(youWin,LOW); // mN youWin LED is not lit (LOSE)
mySerial.println("&&&&&&&");
mySerial.println(" You Lose");
delay(50);
} if(partnerNum == 3 && myNumberAgain == 2 ){ // if pN paper vs mN scissors
digitalWrite(youWin,HIGH); // mN youWin LED is lit (WIN)
mySerial.println("&&&&&&&&&");
mySerial.println(" you Win");
delay(50);
}

}//compareWhoWin



//-------------------------------------------------------------------------------function for reset a game
void resetGame() { // function to reset LEDs after the counter counts time

gameStart = false;
firstDataGet = false;
dataIn = false;

digitalWrite(youWin,LOW);
digitalWrite(rocPin_0,LOW);
digitalWrite(sciPin_1,LOW);
digitalWrite(papPin_2,LOW);
digitalWrite(switchPin, LOW);

myNumber = 0;
resetSwitchState = 0;
Serial.flush();
}


2008년 5월 31일 토요일

Glow LED






To glow two leds and communicate with two XBee wirelessly, Vikram and I , as a pair, made two circuits with two Arduinos. For circuit, XBee needs 3.3V power. We used the code that Rob posted on the class site. code is HERE.
We used the code and made it works by changing address in the code for each one.

2008년 5월 27일 화요일

Find & Fix

As a Find & Fix project, I made an indicator. I found the problem that sometimes there is no water and no person to change an empty bottle of water in the right hall at ITP because all bottles of water are in man's room. Therefore, this is the prototype.
Actually, It is supposed to be drained little by little away but because I couldn't make a water cooler, I will pour some water into a cup to measure how much water left in a bottle.

Led is supposed to be blinked when there is no water in a cup to indicate no water and to encourage to change a bottle.


For more pressure, I put a this kind of shape of wood block on a pressure sensor.


To measure how much water left in a bottle, I used a seven segment. From 4 to 0 the number of sign will be shown.