SparkFun Forums 

Where electronics enthusiasts find answers.

All things pertaining to wireless and RF links
By Renee
#169125
I need to send three analog signals wirelessly using series one xbees. I have heard the best way to do this is to use an xbee shield on both sides and send the data serially using serial streaming, where the signals will be read through the analog pins and sent serially to the receiving arduino where they will be read serially. I have also heard this programming is easy but I have never worked with arduinos so is there any samples on how to do this programming.
By waltr
#169129
There has been a few recent threads on using XBee's with Arduino in the forums here. Look/search for them (Projects, Arduino and Wireless sub-forums) as a few have the same question you have and the answers are posted.
By Renee
#169137
Here is a code I have came up with for the transmitting side..im using an Arduino mega.
if anyone notices anything I should add or take away or if its completely wrong please let me know.

int Sensor1 = 0;
int Sensor2 = 1;
int Sensor3 = 2;

void setup()
{
Serial.begin(9600);
}

void loop()
{
byte servoValue1;
byte servoValue2;
byte servoValue3;


int SensorV1 = analogRead(Sensor1);
int SensorV2 = analogRead(Sensor2);
int SensorV3 = analogRead(Sensor3);

Serial.print(SensorV1);
Serial.print(SensorV2);
Serial.print(SensorV3);


delay(100);
By stevech
#169138
can't tell since the code doesn't say that you're going to use the Arduino XBee library. Looks like no, as there are no dotted references to library class methods shown.
You probably don't want to reinvent the wheel here.

Maybe you are trying to use the XBees in the transparent serial mode (wireless UART extension)?
By hherhold
#169140
Is Series 1 transparent only? I seem to remember reading this somewhere but I could be totally flaking.

If that's the case, the code you wrote looks reasonable, at first glance. You probably want to format your output with delimiters or something otherwise your readings will all smash together - meaning, you read 125, 140, and 96 for your sensor readings. Your code would send "12514096". You probably want to add colons or slashes or something so you'd instead send
(125/140/96) or something like that, to denote the start of a group of readings and separate them.

Rob Faludi's book "Building Wireless Sensor Networks" talks about stuff like this. I'd recommend it - it's useful for Arduino newbies too.

As an aside, Megas are really useful for developing Arduino code because of all the I/O and multiple serial ports. Make sure you're using them to their best advantage - you can use Serial1 for talking to your XBee and the default Serial as a debug console, for example.
By Valen
#169146
hherhold wrote:Is Series 1 transparent only? I seem to remember reading this somewhere but I could be totally flaking.
It's transparent out-of-the-box/factory default. But can communicate with the microcontroller over serial with API-packet protocol if configured appropriately. The latter is much more structured, and the sending device adres is part of the packet. So you always know from who it came. But also adds protocol overhead.
By Renee
#169309
Okay thanks everyone! with the receiving side we are controlling servo motors using a Simulink code. The Simulink code reads from certain pins. Using the Dout pin of the xbee the signals will no longer be in these separate pins of the arduino. To solve this problem we are hoping to use an arduino uno to receive the signals with another xbee and then output them through three separate pins to the mega so that they can be used in the Simulink code. Will the code for the receiving side be similar to the one I have posted above for the transmitting side?
By Renee
#169473
I changed my code a little and used the serial monitor to check it. I had an input of 2 volts with a frequency of 1 KHz to test it and got numbers like 150 150 93 87 106 38 60 42 0 0 0 183. Just wanted to see if this is what I should be getting.

here is my code that I changed

void setup() {

Serial.begin(9600);
}
void loop() {

int sensorValue1 = analogRead(A0);
int sensorValue2 = analogRead(A1);
int sensorValue3 = analogRead(A2);

Serial.println(sensorValue1);
Serial.println(sensorValue2);
Serial.println(sensorValue3);
delay(1);
}
By Valen
#169481
How about focussing on just 1 analog input signal? Then you can check how the Arduino senses that signal. And if the numbers match your input signal. That will be tricky to tell, since we don't know the exact interval between those measurements. Also, you haven't said anything about what shape that 2 volts, 1 kHz is supposed to be. So, you may tell us if that is what you should be getting (every 3rd value)!

[EDIT]Me thinks checking with a fixed steady DC voltage would tell you more how this is working.
By Renee
#169551
I just tried sending 2 volts of DC voltage through one signal and got numbers ranging from around 930 to 1040 in the serial monitor. Im thinking this is wrong...
By Valen
#169566
Yes, I used the above program on my Arduino Uno R3. (It's so basic there can't be anything wrong with it.) I disabled the measurement (and transmission) of A1 and A2 in my program, and increased the delay to 1 second. I connected a simple voltage divider to A0 (2 resistors:, 1K from 5V pin on top of a 2.2K resistor to GND) If I consider the voltage on the Aref pin (the analog reference value which would result in 1023), then the middle point of the 2 resistors neatly results in the right ADC value.
Code: Select all
void setup() {

 Serial.begin(9600);
}
void loop() {

 int sensorValue1 = analogRead(A0);
// int sensorValue2 = analogRead(A1);
// int sensorValue3 = analogRead(A2);

 Serial.println(sensorValue1);
 //# Serial.println(sensorValue2);
 // Serial.println(sensorValue3);
 delay(1000); 
}
So I would question your voltage source, or the way it is connected. Did you also connect the minus or GND connection of the voltage source to the arduino's GND?

If I connect nothing at all to A0, then the values change alot around 330. Especially if I come near with my hand or body. Which makes sense as the input pin is floating, and my body functions as an antenna/variable capacitor.
By Valen
#169571
Sure, if the Xbee is setup to just transmit the characters as it receives them, then yes. It works just like a cable replacement. There might be a bit of lag though.

The analog inputs or other functions of the Xbee are not used. Atleast, that is what I understood from your feeback, it being undesired or unneccessary.

[edit]Ultimately you need a way to seperate the values, and add a 'begin' and 'end' marker, so that your Simulink code knows which value is the 1`st, 2nd and 3rd. And can notice when the sequence is messed up. As you can allways experience loss of data over wireless links. Don't expect it to be perfect.
By Renee
#169580
This is how my xbees are set up, the only changes I made are with the channel, pan ID, MY, and DL
transmitting xbee:
Channel:10, pan ID: 1234, MY:10, DL:11
receiving xbee:
Channel:10, pan ID:1234, MY:11, DL:10

Is this correct for sending the signals serially?
By Valen
#169581
Yes, those settings are only to make them adres each other, and be on the same channe and PAN. The other registers in the XBee are good by default I think. Provided that you do not send the data too quickly.