Motor control is all well and good, but of course we need a way to send commands. Control is accomplished through a Pololu controller as described in Phase 1.
That controller can be commanded by a standard R/C controller, or an analog signal or, as I am doing, ttl-level serial inputs. I am using an Xbee module to send the serial inputs and read responses.
Yesterday, I got full wireless control. This was rather difficult for me, as I am new both to Xbee and to Pololu. Each of these has its own wiring requirements, as well as programming and protocol. I will post detailed specifications once I get past the bubble gum and baling wire stage, but here is a high-level set of points:
-
The Pololu motor controller wires up easily. It must be programmed with a USB cable to act the way you want it to. Currently, my settings are:
a. Serial input set. Autodetect baud rate
b. No kill or limit switch set (yet!)
c. Acceleration rate set by experimentation to something like 30mv per 30 ms. -
The Xbee is a pain to set up. I went for the most complex version because I have other aspirations for the system, but it took some figuring out.
a. Two “nodes” need to be configured to make them work. They have to be set to the same network code so they see each other, and they each have to be told where to send their information. This requires typing in some codes. Also, it may be a good thing to update the firmware in the node. All of this is readily done using a program called X-CTU and a usb cable.
b. The Xbee radio node requires 3.3 volts. Turns out, this is available on a pin of the motor controller, so it is way easy to find. Otherwise, you’ll need to spend a buck or so.
c. In addition to power and ground, the XBee needs to connect its output to the Pololu input and vice versa. So, four wires total. -
The commands must be correctly formatted for the Pololu and correctly sent to the Xbee. This was the hardest part that I could not master until I broke it down into very small parts.
a. Demonstrate that the motor controller controls the motor (done)
b. Use serial commands (rather than native USB input) to command the controller. This took a little work, as the controller has a specific format to follow. I ended up using a sample program written for the Arduino to generate the commands. This is because my PC’s output was the wrong voltage for the motor controller.
c. Once the commands are proved to manage the controller, substitute the wire for properly-configured XBee nodes operating in “transparent” mode, where anything on the input of one appears on the output of the other.
There was some sort of wiring mystery on the Xbee, that may have been due to a soldering error on my part, but it went away when I used a pre-made socket.
Next steps:
- Configure the Arduino to support normal train commands sent to the loco (Forward, reverse, brake, bell, whistle, light, laser cannon…)
- Configure the XBee network in the “API” mode, so that multiple trains can be commanded from one or more controllers.
Whew.