Shop OBEX P1 Docs P2 Docs Learn Events
Send ADC Voltage values from one propeller activity board to another w/ XBee — Parallax Forums

Send ADC Voltage values from one propeller activity board to another w/ XBee

arlandiantoarlandianto Posts: 8
edited 2015-01-30 15:47 in Accessories
Hi,

I'm wondering if someone can help me with this one.
I would like to send voltage value taken using ADC and send it to another propeller activity board.
I have written some coding, but I can't seem quite figure out how to receive that value at the receiver side... That value will be used as integer value for pulse_out function. I know it seems weird but it will be helpful for my robotic project..

At transmitter side:
#include "simpletools.h" // Include simple tools
#include "fdserial.h"
#include "adcDCpropab.h"
fdserial *xbee;
int main()
{
[indent]xbee = fdserial_open(9,8,0,9600 ); //open the serial connection [/indent]
[indent]adc_init(21,20,19,18 ); [/indent]
[indent]float volt1; [/indent]
[indent]while (1)[/indent]
[indent]{[/indent]
[indent][indent]volt1 = adc_volts(2); //ADC conversion from channel 2[/indent][/indent]
[indent][indent]dprint(xbee, "%f\n", volt1, CLREOL); [/indent][/indent]
[indent][indent]pause(100);  [/indent][/indent]
[indent]}[/indent]
}


Now at the receiver side:
#include "simpletools.h" // Include simple tools
#include "fdserial.h"

fdserial *xbee;
int main() // Main function
{
[indent]xbee = fdserial_open( 9, 8, 0, 9600 );[/indent]
[indent]float data;[/indent]

[indent]while(1)[/indent]
[indent]{[/indent]
[indent][indent]data = fdserial_rxChar( xbee );[/indent][/indent]
[indent][indent]pulse_out(3, data); //pulse_out function at P3 [/indent][/indent]
[indent]}[/indent]
}


Am I on the right track?
Any help will be appreciated. Thank you

Comments

  • DomanikDomanik Posts: 233
    edited 2015-01-28 18:08
    At the end of your code what is the purpose of "pulse_out(3, data);"? Seems like if your data is zero you might have an 11 second pulse and if data is 100 it would be a 100 ms/micro sec pulse. Is it an indication you're receiving data?

    void pulse_out ( int pin, int time )

    Transmit a pulse with an I/O pin.

    Default time increments are specified in 1 microsecond units. Unit size can be changed with a call to set_io_dt function. The pulse will be positive if the I/O pin is transmitting a low signal before the call. The pulse will be negative if it transmits a high signal before the call. When the pulse is done, the pin returns to whatever state it was in before the pulse. If the pin was an input, it will be changed to output and use whatever value was in the output register bit for the pin. This defaults to low on start-up, but you can pre-set it while leaving the pin set to input with the set_output function (or check it with get_output).

    Parameters
    pin I/O pin number.
    time Amount of time the pulse lasts.


    Also you will make happy faces on this forum if you use the [ code] your program goes here [ /code] format for your program code.
    Link to HTML mark up page

    #include "simpletools.h" // Include simple tools
    #include "fdserial.h"
    #include "adcDCpropab.h"
    fdserial *xbee;
    int main()
    {
    xbee = fdserial_open( 9, 8, 0, 9600 ); //open the serial connection
    adc_init( 21, 20, 19, 18 );
    float volt1;
    while ( 1 )
    {
    volt1 = adc_volts( 2 );
    putChar(HOME);
    dprint(xbee, "%f\n", volt1, CLREOL);
    pause(50);
    }
    }
    
    #include "simpletools.h" // Include simple tools
    #include "fdserial.h"
    
    fdserial *xbee;
    int main() // Main function
    {
    
    xbee = fdserial_open( 9, 8, 0, 9600 );
    int data;
    
    
    while(1)
    {
    data = fdserial_rxChar( xbee );
    pulse_out(3, data);
    }
    }
    

    If you do a "Reply With Quote" you'll see the HTML mark up in this reply.
  • arlandiantoarlandianto Posts: 8
    edited 2015-01-28 19:40
    Domanik wrote: »
    At the end of your code what is the purpose of "pulse_out(3, data);"? Seems like if your data is zero you might have an 11 second pulse and if data is 100 it would be a 100 ms/micro sec pulse. Is it an indication you're receiving data?

    void pulse_out ( int pin, int time )

    Transmit a pulse with an I/O pin.

    Default time increments are specified in 1 microsecond units. Unit size can be changed with a call to set_io_dt function. The pulse will be positive if the I/O pin is transmitting a low signal before the call. The pulse will be negative if it transmits a high signal before the call. When the pulse is done, the pin returns to whatever state it was in before the pulse. If the pin was an input, it will be changed to output and use whatever value was in the output register bit for the pin. This defaults to low on start-up, but you can pre-set it while leaving the pin set to input with the set_output function (or check it with get_output).

    Parameters
    pin I/O pin number.
    time Amount of time the pulse lasts.


    Also you will make happy faces on this forum if you use the [ code] your program goes here [ /code] format for your program code.
    Link to HTML mark up page

    #include "simpletools.h" // Include simple tools
    #include "fdserial.h"
    #include "adcDCpropab.h"
    fdserial *xbee;
    int main()
    {
    xbee = fdserial_open( 9, 8, 0, 9600 ); //open the serial connection
    adc_init( 21, 20, 19, 18 );
    float volt1;
    while ( 1 )
    {
    volt1 = adc_volts( 2 );
    putChar(HOME);
    dprint(xbee, "%f\n", volt1, CLREOL);
    pause(50);
    }
    }
    
    #include "simpletools.h" // Include simple tools
    #include "fdserial.h"
    
    fdserial *xbee;
    int main() // Main function
    {
    
    xbee = fdserial_open( 9, 8, 0, 9600 );
    int data;
    
    
    while(1)
    {
    data = fdserial_rxChar( xbee );
    pulse_out(3, data);
    }
    }
    

    If you do a "Reply With Quote" you'll see the HTML mark up in this reply.




    Hi Domanik, thank you for your reply.
    Maybe I am not making myself clear enough. So basically I would like to send volt1 value to another propeller board. That volt1 value will be used for something else, and in this case as my amount of time for pulse_out function.
    I'm quite new to xbee actually, so.. Is this the right way to send and receive the value?

    Transmitter:
    #include "simpletools.h" // Include simple tools
    #include "fdserial.h"
    #include "adcDCpropab.h"
    fdserial *xbee;
    int main()
    {
    xbee = fdserial_open( 9, 8, 0, 9600 ); //open the serial connection
    adc_init( 21, 20, 19, 18 );
    float volt1;
    while ( 1 )
    {
    volt1 = adc_volts(2);
    putChar(HOME);
    dprint(xbee, "%f\n", volt1, CLREOL);
    pause(50);
    }
    } 
    

    Receiver:
    #include "simpletools.h" // Include simple tools
    #include "fdserial.h"
    
    fdserial *xbee;
    int main() // Main function
    {
    
    xbee = fdserial_open( 9, 8, 0, 9600 );
    float data;
    
    
    while(1)
    {
    data = fdserial_rxChar( xbee );
    pulse_out(3, data);
    }
    }
    

    Or maybe any simple example on how to transmit and receiving values using xbee?
    Thank you :)
  • DomanikDomanik Posts: 233
    edited 2015-01-28 21:09
    Okay, got it with the pulse out.

    Sorry, haven't done anything with xbee. BUT, you might want to go thru this tutorial.

    Click on this Link

    More Examples


    Let us know if you get it to work.
  • PublisonPublison Posts: 12,366
    edited 2015-01-29 08:54
    I have removed the posting in the Learn forum. It is against forum rules to post the same question in different forums. Plus it confuses people as to which posting to respond to.

    http://forums.parallax.com/showthread.php/134682-Forum-Guidelines
  • Courtney JacobsCourtney Jacobs Posts: 903
    edited 2015-01-29 08:59
    arlandianto,

    Check out Vale T's project for a Joystick-Controlled ActivityBot. He transmits joystick data from a controller to his robot using XBee; it might help.

    http://learn.parallax.com/project/joystick-controlled-activitybot
  • twm47099twm47099 Posts: 867
    edited 2015-01-29 11:29
    arlandianto,

    I'm not sure why you are sending a float value, but then receiving it as a character (but into a float variable). If I read the receiving loop correctly you are continuously receiving a character (8 bit byte part of a float) and then using data to control the pulse.

    I would recommend collecting the adc value with the sending board and processing it there. For example convert it into a character whose ascii value is proportional to the voltage (keep the ascii value in the range of printable characters such as A,B,C, etc). Then send that character to the receiving board. On the receiving board decode the ascii value into they value you want to use in the pulse function.

    Tom
  • DomanikDomanik Posts: 233
    edited 2015-01-30 14:03
    Started learning XBee today, went through the tutorial, then your program. Used an AB (com5) and the USB to XBee board (com8). The com8 acts as a terminal to display what ever is sent to its XBee. It looks like the first half of your program will transmit a fixed value of 65 in several formats. I think the dprint sends ASCII even if the number is a float or integer. On the receive side you might need to deal with an incoming string and convert the string to an int for your pulse out. Can you try opening two terminal windows, one to each board, and print interim values to isolate the problems?

    attachment.php?attachmentid=113004
    attachment.php?attachmentid=113006

    I wanted to hookup to a Quick Start to verify the second part of your program but didn't have the adapter board for the pin spacing. Also, changing baud rates (other than 9600) didn't work. I changed bauds to 4800-19200 in the program and terminal widow without luck. Got some gobbly-gook like the timing rate is off between the boards. The tutorial indicated you could do this. Maybe someone else has run into this problem.

    Figured it out: Used Andy's tutorial code plus Dig XBee user manual, and command "ATBD7,WR, CN", changed FDSerial to 115200. Now both XBees run at 115200 baud. Also used Andy's code to look at version and build dates.
    1017 x 566 - 71K
  • DomanikDomanik Posts: 233
    edited 2015-01-30 15:47
    For the second half of your program, the following should work. It uses a com8 terminal window to enter virtual voltages, then send "data" via its XBee. The AB XBee receives the "data", echos back and prints to the AB terminal. To make your program work "data" was changed from float to int. Only one character at a time is handled; I assume it's 8/7 bit ASCII, perhaps as a result of the terminal emulation. You might want to look at Andy's tutorial near the end for an example of how to create a character buffer then convert to number.

    I'm using the XBP9B-DMST-002, 900MHz and hope to see it make the 9mile range spec.
    #include "simpletools.h" // Include simple tools
    #include "fdserial.h"
    
    fdserial *xbee;
    int data;
    
    main()
    {
      xbee = fdserial_open(9,8,0,9600 );
      
      while (1)
      {
        if(fdserial_rxReady(xbee) != -1)
        {
          data = fdserial_rxChar(xbee);
          dprint(xbee, "%d  %c  %3.2f \n", data, data, (float)data);
          print("%d  %c  %3.2f \n", data, data, (float)data);
        }
      }
    }
    
Sign In or Register to comment.