As you will soon see, I am quite new at this and probably in over my head.
I am trying to send sensor data (flex sensor in a voltage divider) wirelessly to my computer running Max/MSP. I think I finally have my XBees programmed right, but data is not coming through in Max/MSP. I have one Xbee on a sparkfun explorer board, which I also used to program the XBees. The other XBee is on an XBee shield. The arduino is programmed with the very basic SMS patch, see below. it appears as though there is a connection between remote arduino/XBee and the Xbee that is attached to the computer. That is, I get some LED activity on DOUT on the shield and a blink of TX on the explorer when I make a query in Max/MSP, but data is not coming through as expected. Can someone help me understand if I'm missing something? How does the SMS patch below need to change in order to accommodate data sent via XBee?
Thanks for any feedback...
/*
---- SimpleMessageSystem Example 1 ----
Control Arduino board functions with the following messages:
r a -> read analog pins
r d -> read digital pins
w d [pin] [value] -> write digital pin
w a [pin] [value] -> write analog pin
Base: Thomas Ouellet Fredericks
Additions: Alexandre Quessy
*/
// Include de SimpleMessageSystem library
// REMOVE THE FOLLOWING LINE IF USING WIRING
#include <SimpleMessageSystem.h>
void setup()
{
// The following command initiates the serial port at 9600 baud. Please note this is VERY SLOW!!!!!!
// I suggest you use higher speeds in your own code. You can go up to 115200 with the USB version, that's 12x faster
Serial.begin(9600); //Baud set at 9600 for compatibility, CHANGE!
}
void loop()
{
if (messageBuild() > 0) { // Checks to see if the message is complete and erases any previous messages
switch (messageGetChar()) { // Gets the first word as a character
case 'r': // Read pins (analog or digital)
readpins(); // Call the readpins function
break; // Break from the switch
case 'w': // Write pin
writepin(); // Call the writepin function
}
}
}
void readpins(){ // Read pins (analog or digital)
switch (messageGetChar()) { // Gets the next word as a character
case 'd': // READ digital pins
messageSendChar('d'); // Echo what is being read
for (char i=2;i<14;i++) {
messageSendInt(digitalRead(i)); // Read pins 2 to 13
}
messageEnd(); // Terminate the message being sent
break; // Break from the switch
case 'a': // READ analog pins
messageSendChar('a'); // Echo what is being read
for (char i=0;i<6;i++) {
messageSendInt(analogRead(i)); // Read pins 0 to 5
}
messageEnd(); // Terminate the message being sent
}
}
void writepin() { // Write pin
int pin;
int state;
switch (messageGetChar()) { // Gets the next word as a character
case 'a' : // WRITE an analog pin
pin = messageGetInt(); // Gets the next word as an integer
state = messageGetInt(); // Gets the next word as an integer
pinMode(pin, OUTPUT); //Sets the state of the pin to an output
analogWrite(pin, state); //Sets the PWM of the pin
break; // Break from the switch
// WRITE a digital pin
case 'd' :
pin = messageGetInt(); // Gets the next word as an integer
state = messageGetInt(); // Gets the next word as an integer
pinMode(pin,OUTPUT); //Sets the state of the pin to an output
digitalWrite(pin,state); //Sets the state of the pin HIGH (1) or LOW (0)
}
}
Moderator edit: [code] ... [/code] tags added. (Nick Gammon)