Measuring XBee signal strength from the RSSI pin
In my thesis I wanted to read the signal strength of incoming packets and store it in a variable on a microcontroller without using the XBee’s API Mode (In API Mode, you construct packets to command the XBees explicitly, as opposed to just sending serial data in AT or “Transparent Mode”). XBee modules have an RSSI (Received Signal Strength Indicator) pin that outputs a PWM signal representing this value. But how do you turn that PWM duty cycle into a useable integer on your microcontroller? Luckily Arduino has a function made for just this application: pulseIn.
- Connect the RSSI pin (pin 6) to a digital pin on your microcontroller.
- Use this line of code in your Arduino loop:
rssiDur = pulseIn(digitalPin, LOW, 200);
pulseIn returns the duration of a pulse (specified HIGH or LOW) in microseconds (µs). The 200 is a timeout value in µs—it waits this long to see if there’s going to be a pulse. Since the XBee’s RSSI PWM period is 200µs, we want to wait at most that long to see if there’s a pulse at all.
Since this function gives you a duration, it’s up to you to map that to a value relevant to your program. Since the maximum duration of the pulse would be 200µs, you could map that to your logical maximum.
Keep in mind that if you were planning on using API Mode anyway, every API Mode packet has the latest RSSI within it.