Shop OBEX P1 Docs P2 Docs Learn Events
sending xbee data to terminal — Parallax Forums

sending xbee data to terminal

solder_fumessolder_fumes Posts: 18
edited 2015-01-12 07:30 in Propeller 1
I don't know that my problem is as much as with the xbee as with my coding, so I'm posting it here for more exposure.

My setup is two Prop activity boards, and three xbee modules. I have an xbee on each activity board, with the third connected to my PC as a traffic monitor.

On board/xbee combo is set up to transmit a floating point number. This seems to work fine, as I can see the data with the traffic monitor xbee so I know it's being transmitted.

My problem is with the receive side. I can't get the received data to print either on the LCD or the terminal. If I substitute a fixed value for the variable called "data" (line 30 of the code), then all works...I see the data on the LCD and on the terminal. However when I remove line 30 and include lines 36 to 40, I don't get any data to the LCD or terminal.

My (likely mistaken) impression is that line 38 should assign the received data from the xbee as the variable named "data", and should subsequently be printed out on the devices via lines 43 and 44.

Any help greatly appreciated!

/*
receive voltage over xbee and display on lcd and terminal
*/

#include "simpletools.h" // Include required libraries
#include "fdserial.h"
#include "serial.h"

fdserial *xbee;
serial *lcd;
serial *term;

int main() // Main function
{

const int ON = 22;
const int CLR = 12;

xbee = fdserial_open(7, 6, 0, 9600); // initialize devices
lcd = serial_open(13, 13, 0, 9600);
term = serial_open(31, 30, 0, 115200);

float data; // declare data variable as type float

writeChar(lcd, ON); // prepare LCD to receive data
writeChar(lcd, CLR);
pause(1000);


data = 11.234; //when this line is included (line 30), and lines 36 to 40 are excluded
//both the lcd and term print 11.234 as expected.
//however, when line 30 is excluded and lines 36 to 40 are included
//nothing prints to either device

/*
while(1) // loop....this is line 36
{
data = fdserial_rxChar(xbee); // receive xbee data
if(data != -1);
} // this is line 40
*/
{
writeFloatPrecision(lcd, data, 5, 3); // send received data to devices as 5 characters total, precision of 3
writeFloatPrecision(term, data, 5, 3);
}

{
pause(1000);
writeChar(term, CLR);
pause(1000);
}
}

Comments

  • banjobanjo Posts: 447
    edited 2015-01-11 11:04
    To me it seems that you are receiving one character at a time forever inside the while loop, but you are not doing anything with the data.
    while(1) // loop....this is line 36
    {
      data = fdserial_rxChar(xbee); // receive xbee data
      if(data != -1);                                ---> nothing is happening here as the while loop ends on next line
    } // this is line 40
    
  • kuronekokuroneko Posts: 3,623
    edited 2015-01-12 02:23
    On board/xbee combo is set up to transmit a floating point number. This seems to work fine, as I can see the data with the traffic monitor xbee so I know it's being transmitted.
    What does this transmit code look like (just to establish what is sent)? Also, please post code within [noparse]
    
    [/noparse] tags.                        
  • solder_fumessolder_fumes Posts: 18
    edited 2015-01-12 05:24
    Here is the transmit code...
    /*
      transmit voltage over xbee
    */
    #include "adcDCpropab.h"                            // Include adcDCpropAB
    #include "simpletools.h"                            // Include simpletools
    #include "fdserial.h"
    
    fdserial *xbee;
     
    int main()                                          // Main function
    {
      xbee = fdserial_open (7, 6, 0, 9600);
      
      
      adc_init(21, 20, 19, 18);                         // CS=21, SCL=20, DO=19, DI=18
      float volts;                                      // Voltage variable
    
     
      while(1)                                          // Loop repeats indefinitely
      {
        volts = adc_volts(0) * 2;                       // Check A/D 0 and double value          
        putChar(HOME);                                   // Cursor -> top-left "home"
        {
        print("Volts = %f\n", volts, CLREOL);            // Display voltage on terminal (if connected)
        }     
        {
          dprint (xbee, "%f\n",  volts, CLREOL);        // send votage variable to the xbee
        }
                 
      pause(1000);                                      // wait 1 second                                
     }     
    }
    

    and here is the receive code...
    /*
    receive voltage over xbee and display on lcd and terminal
    */
    
    #include "simpletools.h"                       // Include required libraries
    #include "fdserial.h"
    #include "serial.h"
    
    fdserial *xbee;
    serial *lcd;
    serial *term;
    
    int main()                                      // Main function
    {
    
    const int ON = 22;
    const int CLR = 12; 
    
    xbee = fdserial_open(7, 6, 0, 9600);           // initialize devices
    lcd = serial_open(13, 13, 0, 9600);
    term = serial_open(31, 30, 0, 115200);
    
    float data;                                    // declare data variable as type float
    
    writeChar(lcd, ON);                            // prepare LCD to receive data
    writeChar(lcd, CLR);
    pause(1000);
    
    
    while(1)                                       // loop....this is line 36
    {
    data = fdserial_rxChar(xbee);                  // receive xbee data
    if(data != -1);
    }                                              // this is line 40
      
    {
    writeFloatPrecision(lcd, data, 5, 3);          // send received data to devices as 5 characters total, precision of 3
    writeFloatPrecision(term, data, 5, 3); 
    }  
    

    As I mentioned, using a third xbee I can see that that data is being transmitted as a floating point number, so it is at least making it out of the transmitter. Thinking that the third xbee may be causing an issue, I disconnect it and try again, but it doesn't help.

    Thanks!

    John
  • banjobanjo Posts: 447
    edited 2015-01-12 06:37
    On the receiving end, shouldn't it be more like this? Do note though that rxChar is receiving one character at a time and not a floating number as you are sending.
    while(1)                                       // loop....this is line 36
    {
    data = fdserial_rxChar(xbee);                  // receive xbee data
    if(data != -1)
      {
      writeFloatPrecision(lcd, data, 5, 3);          // send received data to devices as 5 characters total, precision of 3
      writeFloatPrecision(term, data, 5, 3); 
      }
    }
    
  • solder_fumessolder_fumes Posts: 18
    edited 2015-01-12 07:30
    Thanks, that certainly makes sense about the "Char". I don't find a fdserial_rxFloat command, so there must be some other way to receive a float.

    Back to the references...

    John
Sign In or Register to comment.