Hi all. The project I'm working on uses xbee radios to bi-directionally send data and commands between a remote station and a base station. I'm pretty sure I've got the transmitting code figured out. I just have to print each of my sensor values, or commands, to the serial port (xbee) with some sort of start character, an end character and a delimiter (,). My understanding stops right about there.
I'm not sure how to decode the string at this point. I also haven't decided if it's best to send the data in ASCII or something else. I don't plan on getting anywhere the limits of the xbee or the arduino so bandwidth and processing time are not a concern. It seems logical to let the base station drive the exchange and have it send it's commands, then wait for the remote to reply with data. This should avoid collisions and I'm not very worried about the update rate of the data at this point. Here's the mish mash I have currently (it's terrible, I know, I'm new to programming). I had to trim it down some, so lots of things are left out that hopefully aren't relevant to this.
//setup stuff here
void loop () {
if (Serial.available() > 0) { // listen for incoming serial data:
handleSerial();
}
//do lots of other stuff in here
}
void handleSerial() {
inbyte = Serial.read();
// save only ASCII numeric characters (ASCII 0 - 9):
if ((inbyte >= '0') && (inbyte <= '9')){
inbuf[stringPos] = inbyte;
stringPos++;
}
if (stringPos == 0) {
inbuf[0] = pulseWidth;
}
if (stringPos == 1) {
inbuf[1] = vecAngle;
}
// if you get an ASCII carriage return and linefee:
if (inbyte == '\r\n') {
// put zeroes in the array
for (int c = 0; c < stringPos; c++) {
inbuf[c] = 0;
}
// reset the string pointer:
stringPos = 0;
}
}
I'd sure appreciate help with this dilemma and any other programming tips you think might help. Thanks!
Most of my code is borrowed and from so many places I can't remember them all, so thanks everybody!