2688Views9Replies

Author Options:

How can i send 2 potentiometer values over xbee using arduino?( I mean in code)

Hi guys!

I need help in sending 2 potentiometer values over xbee via 2 arduinos... I want to print those 2 pot values over serial monitor :)

Do anyone had an idea about this? Would you mind sharing your ideas to me? :)

Thanks,
Michael

9 Replies

maewert (author)2012-04-06

If you are going to send two numbers, you will need to distinguich between the numbers when you receive them.  You could send the numbers as ASCII text.  For example, Say the first parameter is 'A' and the second is 'B'.  You can send the text string "AXXXXXXX." when you send the first parameter and "BYYYYYYYY." when you send the second.  The first letter is the Parameter identifier, the the XXXXX's and the YYYYY's are the actual reading or the parameter value.  Finally the end is identified by the '.'  The code fragment to accomplish this is like so:

char string_to_send[40];

int A,B;

sprintf(string_to_send,"A%d.",A);
... send string_to_send via xbee
sprintf(string_to_send,"B%d.",B);
... send string_to_send via xbee


Best Wishes.

GraffikeL (author)maewert2012-04-06

Can you give me a brief idea what will the receiver code will look like?

GraffikeL (author)GraffikeL2012-04-06

And, what "A%s" mean in the code?

maewert (author)GraffikeL2012-04-09

The 'A' and the 'B' distinguish between the two values. so the A is the first value and the B the second. The '%' is part of the '%d' which is how you tell in C that you want to print a decimal number.

Here is an example: Say you are building a remote control for your window blinds and you have two pots, one controls the position of the blinds and the other controls the angle of the blinds.  Your remote reads in the position of the Pots as analog values from 0 - 1023. Lets say Pot A is the position and pot B is the angle.  Lets say the remote reads the position as 519 and the angle as 27.  The remote sends the string "A519.B27." if you used the code snippit I sent above. 

The receiver now has to listen to the characters coming in and decode them.
Best Wishes.

lemonie (author)2012-04-07

How are you reading the values?

L

GraffikeL (author)lemonie2012-04-07

via arduino's analog pins

lemonie (author)GraffikeL2012-04-07

Are you putting voltage across them?

L

GraffikeL (author)lemonie2012-04-09

Yes.

rickharris (author)2012-04-06

In general:

Read the value with ADC

Send that value via Wifi as a serial data stream (Binary number)

Receive

Convert data back to decimal and send to display.

Exactly how in terms of code will be for others to add if they like although I would say half the fun is figuring out how to o these things yourself by research - trial and error.