Tuesday, November 30, 2010

First Robot

After some time, I've built a first completely wireless robot.
It uses a wireless XBee connection to send the commands.
It will move for 4 seconds and then stop for 4 seconds before moving 4 seconds and so on.

Here is a video:

The code is very basic, it uses the UART example provided with the XMOS development environment.

This is the code that receives the data sent by an Arduino with XBee module on top.

void rxByte (in port RXD, chanend c){
 unsigned byte;
 unsigned time;
 char val;

 // Wait for start bit
 RXD when pinseq (0) :> void @ time;
 time += BIT_TIME / 2;

 // Input data bits
 for (int i = 0; i < 8; i++) {
  time += BIT_TIME;
  RXD @ time :> >> byte;
 }

 // Input stop bit
 time += BIT_TIME;
 RXD @ time :> void;

 // Send received character to listener to perform associated action
 c <: val;
}
This is the code that sends the data.   
void setup()
{
  Serial.begin(9600);
}

void loop()
{
  Serial.print('H');
  delay(1000);
  Serial.print('L');
  delay(1000);
}

No comments:

Post a Comment