Xbee Wireless Servo Control

Program Download:

Project Archives

Xbee Servo Transmitter

Xbee Servo Receiver

The Software
           The full project used to create the firmware hex file in included for both the transmitter and the receiver in the downloadable archive files. Let's take a quick look at snippets of code from the two programs:
    -The Data Output via Transmitter
    -The Data Input via Receiver

           The main purpose of the transmitter is to take input via the A/D converter, format the data and then send it to the transmitter via USART. The forever while loop seen below does exactly that.

Snippet of Xbee Tranmistter Code:

------------« Begin Code »------------
..
...
while(1){
   Delay10TCYx( 5 ); // Delay for 50TCY
   ConvertADC(); // Start conversion
   while( BusyADC() ); // Wait for completion
   result = (ReadADC()/20); // Read result

   Delay10KTCYx(5);
   putcUSART( result );
}
...
..
------------« End Code »------------

           The receiver's forever while loop simply inputs the data value received input the PWM generation circuit which is a series of delay statements triggering PORTD on and off. The USART data variable is updated by an interrupt that is triggered when data is received.

Two Interrupt Service Routines

------------« Begin Code »------------
..
...
while(1){
     PORTD = 0x00;
     Delay100TCYx(100);
     Delay100TCYx(100);
     Delay100TCYx(100);
     Delay100TCYx(100);
     Delay100TCYx(100);
     Delay100TCYx(100);
     Delay100TCYx(100);
     Delay100TCYx(100);
     Delay100TCYx(100);
     Delay100TCYx(100-(data));

     PORTD = 0xFF;
     Delay100TCYx(50+(data));
}
...
..
------------« End Code »------------

           The software for this article is not meant to be overly complex in anyway. The main purpose is to give you a skeleton core of code to start with and use for your own project. So take a look through the code and let's see how it works in the system.