Help in sending 2 pot values over wireless communication(xbee)

Hi There!

Can anyone help me in my project? Here's the setup:
Btw, my project is a mobot with robotic arm. :slight_smile:

  1. The sender arduino have 2 pots and a xbee(let's name this xbee1).
  2. The receiver arduino also have a xbee(xbee2).
    3.I want the sender arduino to send the 2 pot values.
  3. I want the receiver arduino to receive those 2 values from the 2 pots
    and print them in the serial monitor or map their values for the servos..

Please help me in the code :slight_smile: Thanks for the HELP! :)))

What have you written so far?

So far, i've written this code for the sender:

int potPin = 0;

void setup()
{

Serial.begin(115200);
}

void loop()
{
int potVal = analogRead(potPin);
byte servoVal = map(potVal, 0, 1023, 0, 180);

Serial.write(servoVal);

delay(10);

}

and for the receiving arduino:

#include <Servo.h>

int servopin = 11;
Servo myservo;

void setup(){
Serial.begin(115200);
myservo.attach(servopin);
}

void loop(){
if (Serial.available()){
byte servoAng = Serial.read();
myservo.write(servoAng);

So far this code works but i don't have an idea on how will i attach another pot and separate the 2 values of the pots

Search the forum for 'PaulS started ended'. Paul regularly posts code for sending and receiving packets of data.

I can't understand PaulS codes..... Is there something more basic than that? :slight_smile: Sorry i'm noob :frowning:

It depends on whether it matters if your data gets out of sequence. If it's not important, then just write the values one after the other, and read the two values in your receiving code. If it does matter then you need something like Paul's code.

dxw00d:
It depends on whether it matters if your data gets out of sequence. If it's not important, then just write the values one after the other, and read the two values in your receiving code. If it does matter then you need something like Paul's code.

can you help me extract paul's code in his post:
http://arduino.cc/forum/index.php/topic,98248.0.html

the code from far below his post is okay but i don't know what to extract from it to accompany my problem.

For your case sending single bytes you can devise an even simpler protocol. Send a byte that you won't send as a servo position first, say 200. Then send pos byte for servo1, then servo2.

On the reader, read and ignore until you get 200. The next byte you read is servo1, the next is servo2. Don't forget to use Serial.available to check that there is something there before every read.

wildbill:
For your case sending single bytes you can devise an even simpler protocol. Send a byte that you won't send as a servo position first, say 200. Then send pos byte for servo1, then servo2.

On the reader, read and ignore until you get 200. The next byte you read is servo1, the next is servo2. Don't forget to use Serial.available to check that there is something there before every read.

can you give me a sample code? :slight_smile: for me to have an idea what will i do..

If you're looking for dead simple, take a look at: http://www.billporter.info/easytransfer-arduino-library/

There are lots of examples in the GitHub repository if you dig through: GitHub - madsci1016/Arduino-EasyTransfer: An Easy way to Transfer data between Arduinos

Chagrin:
If you're looking for dead simple, take a look at: EasyTransfer Arduino Library « The Mind of Bill Porter

There are lots of examples in the GitHub repository if you dig through: GitHub - madsci1016/Arduino-EasyTransfer: An Easy way to Transfer data between Arduinos

I've tried this before but nothing works... :frowning: Can you inspect my code for error?

Sender arduino:
#include <EasyTransfer.h>
EasyTransfer ETout;

int potpin1 = 0;
int potpin2 = 1;

struct SEND_DATA_STRUCTURE{
int servo1val;
int servo2val;
};

SEND_DATA_STRUCTURE txdata;

void setup(){
Serial.begin(115200);
ETout.begin(details(txdata), &Serial);
pinMode(potpin1, INPUT);
pinMode(potpin2, INPUT);

}

void loop(){
txdata.servo1val = analogRead(potpin1);
txdata.servo2val = analogRead(potpin2);

ETout.sendData();
}

receiver arduino:

#include <Servo.h>

#include <EasyTransfer.h>
EasyTransfer ET, ETin;

Servo myservo1;
Servo myservo2;

struct RECEIVE_DATA_STRUCTURE{
int servo1val;
int servo2val;
};

RECEIVE_DATA_STRUCTURE txdata;

void setup(){
Serial.begin(115200);
ETin.begin(details(txdata), &Serial);
myservo1.attach(9);
myservo2.attach(10);
}

void loop(){
if(ET.receiveData()){

myservo1.write(map(txdata.servo1val, 0, 1023, 0, 179));
myservo2.write(map(txdata.servo2val, 0, 1023, 0, 179));
delay(10);
}
}

Is there an error? but in compiling it is ok.

In your receiver you have ET and ETin. You ETin.begin with the serial port but later try to ET.receiveData when ET was never "begun".

Chagrin:
In your receiver you have ET and ETin. You ETin.begin with the serial port but later try to ET.receiveData when ET was never "begun".

I can't get your point...

Did you mean like this:

ETin.begin then later i should write ET.receiveData?

Correct me if i'm wrong :slight_smile: