Help please to get the rssi from the pulseIn method

I have this code in the coordinator xbee :

int digitalPin = 10;
int myPins ;
pinMode(digitalPin, INPUT);
if(zbRx.getData(0) == 0xA4 || zbRx.getData(1) == 0x76){
Serial.println(“Read data from router 1”);
for(int i=0;i<5;i++){
myPins = pulseIn(digitalPin, HIGH, 200); //get one reading from the source node
}

and i am send from the router xbee 2 payload : 0xA4 and 0x76

the result in the serial monitor is :
the result of the pulseIn change when moving the coordinator xbee so it’s a good result
But the problem is that i can’t determine the rssi value from the pulseIn result !!!
In the xbee datasheet there is a method :

The RSSI PWM runs at 12MHz and has 2400 total counts (200us period).
RSSI (in dBm) is converted to PWM counts using the following equation:
PWM counts = (41 * RSSI_Unsigned) - 5928

i didn’t understand this method !!! if anyone can help me to explain it !!

I have some idea that are not clear :

duty cycle = myPins/200; // 200 is the period and myPins is the value that i get from the pulseIn method
and so what is the relation with the formula : PWM counts = (41 * RSSI_Unsigned) - 5928 in the xbee datasheet

Thank you all for your assistance

Your timeout value might be too low. If the cycle time is 200 microseconds you may catch the end of one cycle and not have enough time left for the entirety of the next cycle. I would try 400 or 500 microsecond timeout.

Since the result of pulseIn() is a time in microseconds you should multiply by 12 to get PWM counts.

unsigned long counts = pulseIn(10, HIGH, 500) * 12; RSSI = counts + 5928) / 41;

Thank you Mr. John for your support

After using this method the rssi unsigned value varies from 144 to 210 and this value is RSSI_Unsigned (decimal) !!!

Can you tell me please how to obtain the rssi value in dB (range between -40dB and -100dB) and if there is a formula between the RSSI_Unsigned and the rssi in dB /color]

because i don’t understand the motivation from the rssi unsigned value.

Thank you in advance for your help.

From the documentation it looks like they are just treating the signed RSSI value in dBm as an unsigned value. Declare it as 'signed char' or 'int8' and you should get the negative value back.

144 -> -112 dBm 210 -> -46 dBm

I have another question concerning : unsigned long counts = pulseIn(10, HIGH, 500) What is the theoretical effect of replacing HIGH by unsigned long counts = pulseIn(10, LOW, 500) ????

I know that if value is HIGH, pulseIn() waits for the pin to go HIGH, starts timing, then waits for the pin to go LOW and stops timing. or if if value is LOW, pulseIn() waits for the pin to go LOW, starts timing, then waits for the pin to go HIGH and stops timing. But what is the correct one concerning the rssi value and why ???

Thank you a lot

If you get the LOW time and subtract that from 200 microseconds (the cycle time) you should end up with the same answer.

Thank you so much for your help but i have a problem that the pulseIn :

unsigned long counts = pulseIn(10, HIGH, 500)

the result of "counts" is 0 when i don't move the xbee and it's a big problem for me do you have any help for this !??? So when i move the xbee the value of "counts" changed and if xbee is then fixed the value of "counts" return to 0

I think a result of 0 means a timeout occurred. The RSSI is only updated when a packet arrives and there is a timer that determines how long the PWM output is active after the last packet. The manual says that the default timer is 40 seconds but it might have been set lower. Have you tried putting an LED one the PWM output so you can see it change brightness as RSSI changes?

Thank you M. john for your assistance Concerning the RP (PWM timer) it's equal to 40 in my case; the problem is that the value returned by pulseIn is 0 when not moving xbee although this value fluctuate when moving xbee. And about the led I want to test it soon.

[u]I have another serious problem:[/u] When adding another xbee router to my network, so I have one coordinator and two router void loop(){

if(zbRx.getData(0) == 0xA4){ //0xA4 is a HEX value sent by router 1 Serial.println("Read data from router 1"); pulseIn_function();//call for a function that return a value of the pulseIn method }

if(zbRx.getData(0) == 0xAA){ //0xAA is a HEX value sent by router 2 Serial.println("Read data from router 2"); pulseIn_function(); } }

The problem is that the value returned by the function for router one is the same for the second router although the distance from router 1 to coordinator is different (above 5 meters) from router 2 to that coordinator

I think that the pwm signal is not adapted to differentiate the packet coming from router 1 or router2. In another way when getting data from router 1 this code:

if(zbRx.getData(0) == 0xA4){ //0xA4 is a HEX value sent by router 1 Serial.println("Read data from router 1"); pulseIn_function();//call for a function that return a value of the pulseIn method } This code call the function pulseIn_function(); and at this time maybe a packet arrive from router 2 and the result returned for router 1 is updated to a packet giving from router2. I think that this is the problem, there is not a synchronization between receiving data by the coordinator from router1 and router2

Can you help me to resolve this issues please?