Use of a 9 Volt battery (we tried 2)
was problematic. The serial monitor would work well for a few
minutes and then the blinking red light on the receiver board would
start to dim and stop communicating. Going off USB power was
reliable of course, but we need to figure out what we are going to do
on the boat if 9 V batteries deplete themselves so quickly!
The other issue we face is the lack of
a place to mount the X-Bee on the motor shield, which even covers up
the female header pins so it is hard to put wires to the breadboard.
We ordered some more female headers to solder on to the motor shield
so that may do the trick, but then the boards stack pretty high and
it is hard to fit them in the small otter cases recommended by MIT.
To test out the xbee modules (which we
got as part of the XBee Wireless Kit from Parallax) we used the
wiring diagram here:
https://sites.google.com/site/parallaxinretailstores/home/parallax-xbee-wireless-kit
With the code below it worked fine:
//
Requires remote XBee in loopback mode (DIN connected to DOUT)
#include
<SoftwareSerial.h>
#define
Rx 6 // DOUT to pin 6
#define
Tx 7 // DIN to pin 7
SoftwareSerial
Xbee (Rx, Tx);
void
setup() {
Serial.begin(9600);
// Set to No line ending;
Xbee.begin(9600);
// type a char, then hit enter
delay(500);
}
void
loop() {
if(Serial.available())
{ // Is serial data available?
char
outgoing = Serial.read(); // Read character, send to XBee
Xbee.print(outgoing);
}
if(Xbee.available())
{ // Is data available from XBee?
char
incoming = Xbee.read(); // Read character,
Serial.println(incoming);
// send to Serial Monitor
}
delay(50);
}
Now, to run the motors with the XBee we
will try this tutorial:
I download an XCTU installer .exe for
Windows XP from
http://www.digi.com/support/productdetail?pid=3352&osvid=0&type=utilities.
But I’m not sure I need XCTU since I’m using Arduino’s IDE?
(Note:
When I tried to test the hacked Sea Perch controller using the
normal 12 V battery and used the SPDT toggles they got stuck and then
ruined. They won’t work anymore. Did I damage them in the hack?)
A
decent XBee Tutorial is here:
Teaches
how to configure with X-CTU which I downloaded. I’m not pleased
that the installer uses ATI Catalyst Installer and shows lots of
games as it is installing. It appears to be installing a lot of ATI
drivers. And it want’s a reboot. I’m switching to Linux,
especially since my efforts to convert David’s mpegs of the school
still won’t allow them to be imported into Adobe Premiere 3.0 and
it took overnight forever to convert half of them!
There
is a configure xbee tutorial for ubuntu here:
It
has good advice, consistent with what I observed when using a 9 volt
battery which was inadequate to run the Xbee, saying, “Don't use
USB powered USB Hubs, since these may not be able to provide enough
power for the USB XBee Adapter. You'll need two available USB ports
if you are planning to configure and test the XBees simultaneously.”
Problem
is, this tutorial wants us to use Wine (Windows emulator) and install
X-CTU. Yick. I'm trying the advice in Tom Igoe's making things talk
instead (page 194) and seeing if I can use PuTTY in Ubuntu.
PuTTY
seems to be available in the Ubuntu Software center. Not sure whether
it is the terminal emulator I want or the client so I'm downloading
both.
I
start PuTTY (the client is the only one that installed because it
installed first and the other was redundant) and Igoe's advice was to
check “Implicit LF in every CR” in the Terminal configuration.
Now I open the program.
Using
SSH I couldn't get anything to happen (tried using the local host
127.0.0.1 but that didn't work). When I click on Serial a
window opens but it wouldn't let me type anything in. So then I read
this
Where he tells us to force local echo:
“It just means that anything that goes in or out is printed on the
screen.
So when you have the Putty screen up click on the "Terminal" option on the left, then under "Line discipline options" force the local echo on, so when you run it you can see if the xbee accepts what you have to say.”
So when you have the Putty screen up click on the "Terminal" option on the left, then under "Line discipline options" force the local echo on, so when you run it you can see if the xbee accepts what you have to say.”
I
was finally able to see what I was typing, but nothing happens.
“First
off, you need to remove the Atmega from the board, so you can
communicate directly with the XBee (if you are using the shield also
set both the jumpers to USB). Next, download Putty and open it, it
should look something like this after you choose the "Serial"
option on the start up screen under connection type (image1). Next,
make sure the correct communication speed and com are correct then
click the terminal button on the left side and under "Line
description options" force on the local echo (Image2). Next,
click the open option on the bottom and a black screen should pop up.
Now type in "+++" with the one second delay, and the
screen should display "OK" (Image3). Now, lets check the
current ID by typing "ATID" and the default ID should
pop up. Now I will change it to 420 (or whatever) by typing "ATID420"
and, again, looking for the OK. Next, check to see if it has been
changed (typing ATID again). Finally, save the changes by typing
"ATWR" and close out with "ATCN". There are other
AT commands found here
http://www.arduino.cc/en/Main/ArduinoXbeeShield”
To
find out what Serial port I'm using I use the advice from the Arduino
cookbook page 470:
No
matter where I plug the xbee in I get the same result:
Only
when I remove it does it say “no such file or directory”.
So
we are reasonably certain that ttyUSB0 is the right port.
This
procedure does not work when I have the Arduino's plugged in.
Running ls /dev/ttyUSB* yields “no such file or directory”
except when the Xbee itself is plugged in. This corresponds to what
another tutorial said about having to remove the ATMega chip from the
arduino when using the shield to configure the Xbee.
By
booting up the Arduino IDE I can see in the Tools/Serial Port what I
have plugged in. I remove the Xbee and ttyUSB0 dissapears. Now I
have only ttyACM0 and ttyS0. From the terminal I can run “ls
/dev/ttyACM*” and it returns “ttyACM0” and I can run “ls
/dev/ttyS*” and get back a whole list of “ttyS numbers ” from
ttyS0 to ttyS31. Hmm.
When
I unplug the Arduino Uno and leave the clone plugged in (using the
FTDI Chip TTL-232R-3V3 USB to TTL Serial Cable), I see that the ttyS0
is the only thing listed in the Arduino IDE Tools/Serial Port. So the
real Uno must have been the ACM0.
I
verify this by unplugging and plugging in the UNO via USB. The ACM*
command can't find a file or directory when I use ls /dev/ttyACM*
without it plugged in. But the other board, the clone, shows all the
ttyS* options regardless of being plugged in or not. And it stays
present in the Arduino serial port under tools. It seems that
/dev/ttyS0 is always there by default in Ubuntu using the Arduino
IDE.
Weirdly,
when I remove the real UNO and keep only the clone plugged in, I need
to select USB0 to do my uploading of code.
And
now when I type in “ls /dev/ttyUSB*” it returns /dev/ttyUSB0.
Hmmm.
Now
I try to run the XbeeLoopbackTest sketch and I get the “error:
'class SoftwareSerial' has no member named 'available'” Funny
because it worked on XP yesterday. I try to download NewSoftSerial
and install it according to this tutorial:
No,
that doesn't help; it is for windows.
Instead
I use $ which arduino and find that my arduino folder is
/usr/bin/arduino.
No,
that doesn't help.
libraries go into your sketchbook directory.
On my machine the sketchbook folder is in /home/wayoda/sketchbook
Create a new directory on ypour machine
/home/<your user name>/sketchbook/libraries
and install the libs into this directory
You should at least read this page herehttp://arduino.cc/en/Guide/Environment
Okay, I did what was asked and I changed the sketch for XbeeLoopbackTest to read
the following:
// Requires remote XBee in loopback mode (DIN connected to DOUT)
//#include <SoftwareSerial.h>
#include <NewSoftSerial.h>
#define Rx 6 // DOUT to pin 6
#define Tx 7 // DIN to pin 7
//SoftwareSerial Xbee (Rx, Tx);
NewSoftSerial Xbee (Rx, Tx);
void setup() {
Serial.begin(9600); // Set to No line ending;
Xbee.begin(9600); // type a char, then hit enter
delay(500);
}
void loop() {
if(Serial.available()) { // Is serial data available?
char outgoing = Serial.read(); // Read character, send to XBee
Xbee.print(outgoing);
}
if(Xbee.available()) { // Is data available from XBee?
char incoming = Xbee.read(); // Read character,
Serial.println(incoming); // send to Serial Monitor
}
delay(50);
}
It compiles, but there is no response from the Serial monitor! Ah, but that is because my loop between pins 6 and 7 on the receiving Xbee were wired wrong.
Now it is working!
Now I will work with this tutorial that says, “You should be able to get two Arduino boards with Xbee shields talking to each other without any configuration, using just the standard Arduino serial commands (described in the reference).”
http://arduino.cc/en/Guide/ArduinoXbeeShield
Perhaps
the baud rate is what is wrong?
What
if I change the 38400,38400 to 9600,9600?
No
difference.
Meanwhile,
I soldered female headers to the Motor Shield so I can experiment
with the Xbee. I soldered 2 eight pin and 2 six pin corresponding to
the usual arduino pins and then two more 6 pin female headers for the
extra 5V and ground pins on the motorshield board. I must thus bring
2 eight pin and 4 six pin female headers to Washington Prep today.