Hardware Reference
In-Depth Information
Reading Received Signal Strength Using XBee Radios
In the previous chapter, you saw the received signal strength, but you didn't do anything
with it. The Processing code that read the solar cell's voltage output parsed the XBee
packet for the received signal strength (RSSI). Here's a simpler variation on it that just
reads the signal strength. To test it, you can use the same radio settings from Project 14,
Relaying Solar Cell Data Wirelessly. Use a USB-to-XBee serial adapter for the receiving
circuit, and see Figure 7-5 (the gas sensor circuit) or Figure 7-13 (the solar cell circuit)
for circuits that work well as transmitters.
Run this Processing sketch to
connect to the receiver radio via the
USB-to-XBee serial adapter. When you
run this program, you'll get a graphing
bar like that shown in Figure 8-7.
8
/*
XBee Signal Strength Reader
Context: Processing
Reads a packet from an XBee radio and parses it. The packet
should be 22 bytes long. It should be made up of the following:
byte 1: 0x7E, the start byte value
byte 2-3: packet size, a 2-byte value (not used here)
byte 4: API identifier value, a code that says what this response
is (not used here)
byte 5-6: Sender's address
byte 7: RSSI, Received Signal Strength Indicator (not used here)
byte 8: Broadcast options (not used here)
byte 9: Number of samples to follow
byte 10-11: Active channels indicator (not used here)
byte 12-21: 5 10-bit values, each ADC samples from the sender
*/
import processing.serial.*;
Serial XBee ; // input serial port from the XBee Radio
int[] packet = new int[22]; // with 5 samples, the XBee packet is
// 22 bytes long
int byteCounter; // keeps track of where you are in
// the packet
int rssi = 0; // received signal strength
int address = 0; // the sending XBee's address
int lastReading = 0; // value of the previous incoming byte
void setup () {
size(320, 480); // window size
// get a list of the serial ports:
println(Serial.list());
// open the serial port attached to your XBee radio:
XBee = new Serial(this, Serial.list()[0], 9600);
}
ยป
Search WWH ::




Custom Search