I am sending three analog signals through the xbees to be written to analog pins on the receiving side so they can be read in Simulink. I connected both of the arduino megas to my laptop and uploaded the sketches. I have a shield and a series xbee connected to each arduino. I pulled up the serial monitor for each sketch. I connected a 1 volt DC power supply to all three analog pins. On the transmitting serial monitor I got numbers close to 200 which I believe is correct but on the receiving side I was not getting anything. I believe the problem is with the arduino. After I uploaded the code on the transmitting side the TX led was green but the RX led on the receiving side was not lit up at all. The power LED on the transmitting arduino is red but it is green on the receiving side. The ‘L’ led on the transmitting side is red on the transmitting side is read and yellow on the receiving side. On both of the xbee shield the power led’s are red and the DIO5 led blinks green. On the receiving xbee shield the DOUT LED is red and the DI LED is green. If more information is needed let me know.
Here is my configuration for the xbees: (series 1. firmware version: 10ed)
Transmitting Xbee:
PAN ID: 1234
MY:10
DL:11
Receiving Xbee:
PAN ID: 1234
MY: 11
DL: 10
Transmitting arduino program:
int val1 = 0;
int val2 = 0;
int val3 = 0;
int analogPin1 = 0; //these are you analog in pins
int analogPin2 = 1;
int analogPin3 = 2;
void setup() {
Serial.begin(9600); //start serial
}
void loop() // run over and over again
{
Serial.print("<"); // This character signifies the begining of our data cycle
val1 = analogRead(analogPin1); // read the input pin
Serial.println(val1); // output the signal
Serial.print("\t"); // Signifies end of 1st piece of data
val2 = analogRead(analogPin2); // read the input pin
Serial.println(val2); // output the signal
Serial.print("\t"); // Signifies end of 2nd piece of data
val3 = analogRead(analogPin3); // read the input pin
Serial.println(val3); // output the signal
Serial.print(">"); // This character signifies the end of our data cycle
delay(100);
}
Receiving arduino program:
#include <SoftwareSerial.h>
// software serial #1: TX = digital pin 0, RX = digital pin 1
SoftwareSerial portOne(0,1);
int Apin1 = 0; // These variables hold the current incoming value
int Apin2 = 0;
int Apin3 = 0;
int AnalogOut1 = 0; //Set our analog pins
int AnalogOut2 = 1;
int AnalogOut3 = 2;
int Digits = 0; // Helps watch for comma
int Mode = 0; // This designates which section of reading we are doing - begin = 0, Apin1 = 1, Apin2 = 2, APin3 = 3, end = 4
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
// Start each software serial port
portOne.begin(9600);
}
void loop()
{
portOne.listen();
while (portOne.available() > 0) {
// read the incoming byte:
char inByte = portOne.read();
if (isdigit(inByte) && Mode == 1) {
int temp = inByte - '0';
Apin1 = (Apin1 * 10) + temp;
Serial.print('\n'); // This is just some debugging stuff, if you plug in your programmer this will output the data to a serial monitor
Serial.print(temp);
Serial.print('\n');
Serial.print(Apin1);
Serial.print('\n');
}
if (isdigit(inByte) && Mode == 2) {
int temp = inByte - '0';
Apin2 = (Apin2 * 10) + temp;
Serial.print(temp); // This is just some debugging stuff, if you plug in your programmer this will output the data to a serial monitor
Serial.print('\n');
Serial.print(Apin2);
Serial.print('\n');
}
if (isdigit(inByte) && Mode == 3) {
int temp = inByte - '0';
Apin3 = (Apin3 * 10) + temp;
Serial.print(temp); // This is just some debugging stuff, if you plug in your programmer this will output the data to a serial monitor
Serial.print('\n');
Serial.print(Apin3);
Serial.print('\n');
}
if (inByte == ',') {
Mode++;
}
if (inByte == '<') {
Mode = 1;
}
if (inByte == '>') {
Mode = 4;
if (Apin1 > 0 && Apin2 > 0 && Apin3 > 0) {
analogWrite(AnalogOut1, Apin1);
analogWrite(AnalogOut2, Apin2);
analogWrite(AnalogOut3, Apin3);
}
Serial.print('\n'); // This is just some debugging stuff, if you plug in your programmer this will output the data to a serial monitor
Serial.print(Apin1);
Serial.print('\n');
Serial.print(Apin2);
Serial.print('\n');
Serial.print(Apin3);
Serial.print('\n');
Apin1 = 0; // These variables hold the current incoming value
Apin2 = 0;
Apin3 = 0;
}
}
}