::::::::::::::::   Anne Hong    
::::::::::::::::   NYU | Tisch School | ITP  
::::::::::::::::   MPS Candidate-2007  
::::::::::::::::   studio@annehong.com  
::::::::::::::::   Networked Objects
     

Josh Cheng
Anne Hong
Kazuhiro Nozaki
Max Weng

         
       

Arduino Code

Send/Request Function (in Processing)

#define bit9600Delay 84
#define halfBit9600Delay 42
#define bit4800Delay 188
#define halfBit4800Delay 94

byte rx = 6;
byte tx = 7;
byte SWval;

char inByte;
char serialString[20];
int idx=0;

void setup() {

//
// setup hardware serial, used to communicate with RFID reader
//
Serial.begin(9600);

//
// setup software serial to talk to XPort
//
pinMode(rx,INPUT);
pinMode(tx,OUTPUT);
pinMode(8,OUTPUT);
digitalWrite(8,HIGH);
digitalWrite(tx,HIGH);
digitalWrite(13,HIGH); //turn on debugging LED

//
// clear the serialString
//
for( int i=0; i<20; i++ )
serialString[i]=0;

//
// test
//
prStr("Hello world\n");

//
// reset the Xport
//
digitalWrite(8,LOW);
delay(500);
digitalWrite(8,HIGH);
delay(2000);

//
// send command to RFID reader
//
Serial.print("\r0B1401\r");

}

void loop()
{

if( Serial.available() > 0 ) {

inByte = Serial.read();
//Serial.print( inByte );
//SWprint(inByte);

if (inByte == 13) {
// send out the request
idx=0;
sendRequest();
}
else if(inByte == 10 ) {
// skip the '\r' character
;
}
else { // cache the input bytes
serialString[idx] = inByte;
idx ++;
}

}

//Serial.print('h');
//delay(50);

}

void sendRequest()
{
prStr("C208.97.190.158/80\n");
delay(50);
prStr("GET /test.php?test=");
prStr(serialString);
prStr(" HTTP/1.1\n");
prStr("Connection: Close\n");
prStr("Host:www.wengmin.com\n");
prStr("User-Agent: Mozilla/5.0\n\n");
delay(10);
}

//
// print the string, return how many char printed
//
int prStr(char * str)
{
int i=0;
while(str[i]) {
SWprint(str[i]); i++;
}

return i;
}

///////////////////////////////////////////////////////
//
// software serial functions
//

void SWprint(int data)
{
byte mask;
//startbit
digitalWrite(tx,LOW);
delayMicroseconds(bit4800Delay);
for (mask = 0x01; mask>0; mask <<= 1) {
if (data & mask){ // choose bit
digitalWrite(tx,HIGH); // send 1
}
else{
digitalWrite(tx,LOW); // send 0
}
delayMicroseconds(bit4800Delay);
}
//stop bit
digitalWrite(tx, HIGH);
delayMicroseconds(bit4800Delay);
}

int SWread()
{
byte val = 0;
while (digitalRead(rx));
//wait for start bit
if (digitalRead(rx) == LOW) {
delayMicroseconds(halfBit9600Delay);
for (int offset = 0; offset < 8; offset++) {
delayMicroseconds(bit9600Delay);
val |= digitalRead(rx) << offset;
}
//wait for stop bit + extra
delayMicroseconds(bit9600Delay);
delayMicroseconds(bit9600Delay);
return val;
}
}