Send ADC Voltage values from one propeller activity board to another w/ XBee
arlandianto
Posts: 8
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:
Now at the receiver side:
Am I on the right track?
Any help will be appreciated. Thank you
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
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
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:
Receiver:
Or maybe any simple example on how to transmit and receiving values using xbee?
Thank you
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.
http://forums.parallax.com/showthread.php/134682-Forum-Guidelines
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
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
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.
I'm using the XBP9B-DMST-002, 900MHz and hope to see it make the 9mile range spec.