Welcome to the second installment in the continuing saga of a boy and his truck. In tonight’s episode, we dust off the soldering iron and get down to business building a couple circuits that will give the truck an “interface”.
Now that the Arduino is more or less capable of competently controlling the truck, the next orders of business were to devise a way of interacting with the Arduino that didn’t involved re-uploading the sketch and a method of getting feedback as to what the truck was up to at a glance. Both of these were easy to accomplish using a little bit of Google and a lot of grade 10 electronics.
I say RS232, You say TTL
Even though the Uno has a UART for handling serial communications, you can’t just connect its TX and RX pins directly to their serial port counter parts. This is because RS232 lines use -3 to -25 volts for logic high and +3 to +25 volts for low, which is much more than the TTL (+5 and 0 respectively) voltages the Arduino expects. You can build your own RS232 to TTL converter using a handful of parts, but I opted to simply use a MAX232 IC.
The ‘232 ICs are actually dirt simple to get going, but they do require a few external capacitors. After perusing some data sheets, I fired up Fritzing and made a quick schematic:
Naturally, before you build the final circuit you should build it on a breadboard and put it through its paces but, on a previous trip scouring the basement for parts, I noticed that the card reader for an old satellite emulator I had kicking around not only had a 232, but it was also pretty much a reference implementation. I grabbed the desoldering pump, took off the bits I didn’t need, hooked it up to the Arduino and we were good to go:
When it came time to build the permanent version, I didn’t want to have a bulky DB9 connector or need to track down longer serial cables, so I picked up a solder-on RJ-45 jack and wired it to match an RJ45 to DB9 connector I had kicking around. The whole thing went together smoothly and I had it spitting out serial data using the SoftwareSerial library in no time.
Note that I used SoftwareSerial because the Uno shares pins 0 and 1 with the USB interface which interferes with the board’s programming. In the final version of the hardware, serial will happen on pins 0 and 1 to take advantage of the UART hardware.
For the LOLs
A word of warning to those of you playing along at home, there are probably many other much better ways of finding out what’s going on inside your creation’s head than the route I chose, I simply took the path of greater lols. Besides, if your vehicle’s going to be driving itself around, why shouldn’t it have a Knight Rider chaser on the front?
The chaser itself is pretty easy to build: At the core, it’s a 4017 decade counter. For those of you blanking on grade 11 digital electronics, a decade counter basically counts to 10 (actually, from 0 to 9) then resets itself and counts up all over again. The first and sixth LEDs are connected to the output pins for 0 and 5, the middle 4 LEDs have two diodes attached to their anode so when the counter hits 6, the lights seem to go backwards. The diodes exist to prevent crosstalk between the 4017’s output pins.
If you look at the schematic below, you’ll notice that each LED actually has one more diode than mentioned above. This is because I wanted the ability to turn on all the lights at once. Unfortunately, this draws more power than the Arduino’s digital pins can output so it’s on hold until not-Christmas Eve when I can get a couple transistors. You also might find it easier to use 2- or 3-input OR gates rather than a sea of diodes, but I didn’t think they’d fit on the PCB I bought and, really, it’s probably just as much soldering.
The Arduino can advance the chaser by sending a high/low pulse out whichever digital pin happens to be connected to the 4017’s clock input. It will be able to light all LEDs in the near future by sending logic high along the wire connected to the extra diode on each light. They’ll remain on until a logic low is sent, although my Chaser library does cancel the light-all when it’s told to increment the counter.
We’re very rapidly reaching the point where the truck has enough hardware to do what we want and, in the next post, we’ll put down the soldering iron and have some arts and crafts time mounting the PCB we just built in the truck’s passenger compartment and the LED chaser along the front.
Here’s a quick video showing the chaser and serial chip in action:
|DIP socket (3 pack)
|RJ45 Solder-on Jack||$2.00|
|4017 Decade Counter (2 pack)||$1.50|
|6 Red 2.5mm x 5mm LEDs (2 x 3 packs)||$3.90|
|16 x IN4148 Diodes (100 pack)||$5.00|
|1k Resistor (50 pack)||$2.50|
|22uF 16v Capacitors (7 pack)||$1.05|
|Hook Wire Kit (7 colours x 5 feet)||$4.75|
|Around 2 feet of Cat-5||$0.00|
| Previous Total