Hardware Reference
In-Depth Information
If your shield has a jumper or switch to select whether or not the XBee is
connected to the UART, you can use that while programming. (Check the
documentation for your particular shield if you're unsure.)
The sketch that reads the pot and transmits it to the computer is repeated
in Listing 11-1 for your reference.
Listing 11-1: Arduino Code to send Data to the Computer—pot_to_processing/arduino_
read_pot
//Sending POT value to the computer
const int POT=0; //Pot on analog pin 0
int val; //For holding mapped pot value
void setup()
{
Serial.begin(9600); //Start serial
}
void loop()
{
val = map(analogRead(POT), 0, 1023, 0, 255); //Read and map POT
Serial.println(val); //Send value
delay(50); //Delay so we don't
//flood the computer
}
2. Unplug the Arduino from your computer and install the XBee shield along
with the XBee. Connect a potentiometer to analog input 0 as shown in the
wiring diagram in Figure 11-16.
3. Power this Arduino using one of the methods described in the previous
section. I chose to use a USB cable with a wall power adapter, but any of
the methods described would work fine.
4. Connect your XBee USB Explorer with the other programmed XBee
radio to your computer with a USB cable. (Alternatively, you can use
another Arduino board connected to an XBee Shield with the ATMega
chip removed.) If the radios are configured correctly, you should see the
RX light on the USB XBee Explorer flashing rapidly as it receives data.
Search WWH ::




Custom Search