SparkFun Forums 

Where electronics enthusiasts find answers.

All things pertaining to wireless and RF links
By mdb67
#168670
Hello everyone,

Working with 2 Arduino Fio v3's as well as 2 Xbee S1's. I will be having 2 pot values coming in to Fio1 which will be sent to Fio2 to power a pair of servo's.

I can send over values just fine one at a time but if i lose the signal it messes up on me. I have just been playing with a basic code to change the led's on Fio2. I have spent a few hours looking around but i cant figure out how everyone is using delimited code and strings and all sorts of other fancy bytes.

The best way i can think of is to send over AxxxByyy from the TX and receive that on RX and break it apart and use xxx as pot value 1 and yyy as pot value 2. But i cant seem to send over AxxxByyy because its text and the only thing ive been able to send over so far is single characters and numerical values.

OR is there a way i can break apart a number by how many digits it is? and would that be a good way? so i would send over xxxyyy and break that 6 digit number into its 2 parts?

Any and all help is greatly appreciated as i'm lost again

So far for the TX i have:

int led = 13;

void setup() {
Serial1.begin(57600);
Serial.begin(57600);
pinMode(led,OUTPUT);
}
void loop() {
int high= 200;
int low = 100;
Serial1.write(high);
delay(1000);
Serial1.write(low);
delay(1000);
}

and for the RX

int led = 13;

void setup() {
Serial1.begin(57600);
Serial.begin(57600);
pinMode(led,OUTPUT);
}
void loop() {
while(Serial1.available() > 0) {
int power = Serial1.read();
analogWrite(13,power);

delay(50);
}
}
By mdb67
#168818
one idea i just came up with would be to take A value and multiply it by 1000 to get xxx000 and then add it to the B value of YYY to get XXXYYY.

then on the other arduino i could reverse the math . this way i could send over 1 full line of code with both values. only issue is that it would be required to do math. im not sure if that would slow the system down or if these very basic calculations wouldnt cause it to stall
By waltr
#168827
Why have an Ardiuno just to read the ADC value of the pots? The XBee has a few ADC's that can do the job without the Ardiuno between the pots and the XBee.

Now on the receive side you will still need to parse the data from the XBee to extract the values. This kind of coding is a bit tough for a beginner but if you persist you'll get it. The best way is to write out the sequence of what needs to be done on paper in English (or your native language). Then work on coding it.
There should be a number of examples on parsing XBee data for an Ardiuno on the web, so do some searchs.
There is also lots of code for parsing GPS NEMA sequences that would be good to study to learn techniques.
By stevech
#168830
The receiving XBee, as I recall, can convert the incoming digital reports of analog level (from potentiometer), and the Xbee can output a pulse width modulated (PWM) proportional to the analog level. That PWM signal could go to an LED whose brightness would the be proportional. No microprocessor on either hend.

Or you could have a microprocessor on the receiving end, as waltr notes.
By mdb67
#168881
the TX needs to have an arduino because i will be mapping the pot values as well as doing some math with them. also powering RBG leds.

the RX would not need an arduino however i feel that its a very simple code and since i already have it , might as well use it
By Valen
#168923
Maybe the high baudrate is messing up your datastream. Second there is an AT command for the Xbees that makes it wait a certain number of new character periods before it starts to send it's buffer over the RF link. Default should probably work, but I do not know what your earlier coding attempts were.

You can't disect the number of bits. Atleast not at the serial level, those are mostly fixed. But the String class should have ample function to disect your "AxxxBxxx" code into "A","xxx","B","yyy" and convert "xxx" and "yyy" back into a variable. See the functions on the left of this page:
http://arduino.cc/en/Reference/StringOb ... w914j5quvQ

Or else, please explain what you are receiving on the endpoint when you did attempt to send the desired code over. Since the 2 arduino's are not synchronised in receiving you have to receive and process 1 byte at a time. (But sending can be done in 1 go. Wait for when it starts with "A". Start storing the specific number of characters in variable xxx (string type of sufficient length) or until you received "B". After that you put whatever number you receive in string variable yyy. Perhaps you should consider ending with a packet-trailing symbol. Or send the numbers with preceding zeros with a fixed total length ("0123") Afterwards, if the contents of the packet makes sense then you start converting it in integer values.

Just some ideas.
By mdb67
#169310
while(Serial1.available() >0) { //only when serial active
while(lookforheader == 1) { // without this, header didnt pick up
int header = Serial1.read(); // header gets 1st byte
if(header == 22) { // if header is 22, bytes 1 and 2 are next two serial reads
byte1 = Serial1.read();
byte2 = Serial1.read();
}//close if header

final code i went with fyi for anyone else looking