3007Views9Replies

Author Options:

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

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

Comments

The forums are retiring in 2021 and are now closed for new topics and comments.
0
maewert
maewert

9 years ago

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.

0
GraffikeL
GraffikeL

Answer 9 years ago

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

0
GraffikeL
GraffikeL

Answer 9 years ago

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

0
maewert
maewert

Answer 9 years ago

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.

0
lemonie
lemonie

9 years ago

How are you reading the values?

L

0
GraffikeL
GraffikeL

Answer 9 years ago

via arduino's analog pins

0
lemonie
lemonie

Answer 9 years ago

Are you putting voltage across them?

L

0
rickharris
rickharris

9 years ago

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.