Hello,
I am new to Arduino and just started a new Project trying to connect an Arduino with an NXT brick over a wireless communication using Xbee. I am actually trying to replicate this project: Connect LEGO Mindstorms and the Arduino
The setup I have going on:
- An Arduino Uno board + Arduino Wireless Proto Shield + Xbee Series 2 (Coordinator)
- An NXT brick + NXTBee + Xbee Series 2 (End Point)
Using X-CTU, I have updated the firmwares of both Xbee as follows:
- The Coordinator -> ZNET 2.5 COORDINATOR AT (v. 1047) with (PAN ID = 1AAA) ; (SC = 13) ; (DH = High Address of End point) ; (DL = Low Address of End point)
- The End Point -> ZNET 2.5 ROUTER/END POINT AT (v. 1247) with (PAN ID = 1AAA) , (SC = 13) ; (DIO7 = RS-485 ENABLED HIGH for communication with the NXT Brick)
I have the following RobotC code running on the NXT. It's an example program by dexter industries that just reads every byte received by the end point Xbee and displays it on the screen.
/**********************************************\
|* This program will continuously read in *|
|* bytes over the XBee connection, flushing *|
|* and displaying them to the LCD one at a *|
|* time as long as there are bytes to read. *|
\**********************************************/
task main()
{
nxtEnableHSPort(); //Enable High Speed Port #4
nxtSetHSBaudRate(9600); //Xbee Default Speed
nxtHS_Mode = hsRawMode; //Set to Raw Mode (vs. Master/Slave Mode)
//short bytesRead;
ubyte incomingData;
eraseDisplay();
bNxtLCDStatusDisplay = true; // Enable top status line display
wait1Msec(25);
while(true)
{
if(nxtGetAvailHSBytes()) //Check to see if we have any data coming in
{
if(nxtReadRawHS(&incomingData, 1)) //Ask for the data, save to "incomingDate".
{
//If we actually got data, display it to the LCD
nxtDisplayTextLine(1, "Receive: %c, %i", (char)incomingData, (int)incomingData);
}
}
else //No Data, Wait a little before trying again
{
wait1Msec(25); //Wait 25ms before checking again.
}
}
nxtDisableHSPort(); //Disable HS Port #4
}
I have the following code running on the Arduino board. It is the exact same code taken from the example project given above via the link.
#include <SoftwareSerial.h>
int inByte = 0; // Data coming in from computer to ARduino
byte power = 0; // Initializing power, steering, direction.
byte steer = 0;
byte direc = 0;
#define rxPin 2
#define txPin 3
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);
void setup() {
Serial.begin(9600);
// set the data rate for the NewSoftSerial port
mySerial.begin(9600);
}
void loop() {
if (Serial.available() > 0) { // Take steering information in
// get incoming byte:
// w – forward
// a – left
// d – right
// z – reverse
inByte = Serial.read();
Serial.println((char)inByte);
if (inByte == 'w') {
power = 10;
direc = 1;
}
if (inByte == 'a') steer = -70; // Turn left
if (inByte == 'd') steer = 70; // Turn right
if (inByte == 'z') { // Reverse
power = 10;
direc = 0;
}
if (inByte == 's') power = 0; // Stop
if (inByte == 'q') { // Go straigh
steer = 0;
}
}
//char data[] = {NULL, 100, 50, 30};
//mySerial.print(data[0]);
mySerial.print('/');
// RobotC now knows the next two transmissions will be power and steering respectively.
mySerial.print(power); // Send Power
mySerial.print(steer); // Send steering info.
mySerial.print(direc);
delay(25);
}
When I run both programs, the XBee seem to discover each other which is awesome. However, the only data the end point is receiving is what I enter in the Serial Monitor. So for example, when I enter 'w' in the Serial Monitor and press send I would expect the COORDINATOR to send the char '/' followed by the values of power, steer and direction. But the COORDINATOR actually just send the char 'w' which I entered in the monitor and thus on the NXT brick display I get "Received: w, 119".
Thus, it seems that the program on the Arduino board is ignored and the Serial Monitor immediately sends to the Xbee module which transmits whatever was received from the monitor. The wireless shield is put in usb mode otherwise I cannot talk with it using the Serial Monitor.
Any suggestions as to how I can fix this?
Cheers