Arduino Iambic Keyer 2016 – Part 1: Hardware
In a Chicago winter it’s way too cold in the garage for woodworking, so I turn to coding to pass the time. In 2014 I built an ATTINY85 Morse Code keyer in an Altoids Small box and in 2015 I expanded that with an Arduino Pro Mini based keyer in a regular Altoids tin. It was a lot of fun and consumed pretty much the whole winter. I’ve written down a few ideas for enhancements and in this year’s model some of those are implemented. The hardware wish list (so far):
- Battery power, enabling stand alone operation > 24 hours
- LCD display 16×2 minimum
- Real Time Clock, Local and GMT
- More memories (7 or 8 buttons)
Batteries and LCD won’t fit in an Altoids tin. I found a metal Crayola box at Tuesday Morning. It was made by the Tin Box Company, who produce many designs that would make interesting project enclosures. It is 3″ x 5″ x 1.5″, about three times the volume of an Altoids box, the metal is slightly sturdier than Altoids but still flimsy enough to be difficult to work without distortion. I found the inside surface was coated with a thin layer of something which repelled solder unless sanded a bit first. I don’t see this particular box available any more but there is a slightly larger version. My experience indicates that the time to complete a project is inversely proportional to the size of the enclosure (maybe to the fourth power).
These days “Arduinos” come in many shapes and varieties. The latest official 1.6.7 IDE is almost 100 megabytes, expanded to accommodate different versions. I wanted to try processors other than the standard ATMEGA328, so last summer bought a Teensy2.0 (32u4) and a TeensyLC (ARM Cortex M0) made by PJRC. Both promise built in USB client support. The PJ in PJRC is Paul Stoffregan, who has contributed a great deal to the Arduino community. There’s an IDE add-on “Teensyduino” that must be downloaded from the PJRC site to use Teensy boards. Teensyduino installation is dead simple and includes Teensy versions of most familiar Arduino libraries plus a few useful additions from Paul.
Last summer I worked with the Teensy2.0 a bit, wanted to see if the DDS sine wave generation function I used in the 2015 design would work. The port was successful, the 32u4 required only a few minor tweaks, and I even got Fast PWM working as described in Atmel’s documentation. PJRC has a forum where you can brag about your accomplishments so I wrote something on the 32u4 DDS sketch thinking it might be useful to others. Paul Stoffregan replied suggesting I consider a Teensy3.2 as it has an integrated Digital-Analog Converter which would produce a cleaner waveform. I fired up the similar TeensyLC and used Paul’s suggested method. DDS on the TeensyLC was also successful so I built a breadboard version of last years keyer using the LC. Everything worked with PJRC’s libraries including DDS side tone, the PS2 keyboard, and lcd.prints added for the display.
The small module at the upper left of the breadboard is an Adafruit PAM8302 audio amplifier. Last year I struggled with a 1 transistor class A amp for the speaker, gave up on that and built an LM386 design. The PAM8302 amp at only four bucks is clearly a winning choice. The only problem I had was later on I discovered the Output side did not like being grounded and I had to insulate the external speaker jack.
TeensyLC has one serious limitation for my application. Because the ARM chip handles flash differently than the MEGA328, TeensyLC has only 128 bytes of emulated EEPROM. That meant limiting stored button memory to four messages only 30 characters each. At that time I was thinking about adding a Real Time Clock so looked at getting Adafruit’s FRAM breakout and their DS1307 RTC. But for less money than these two modules plus a TeensyLC I could get a Teensy3.2 module with a Cortex-M4, lots of memory, built in RTC, and 5 volt tolerant inputs. I sent off an order to Adafruit (10% off if you watch “Ask An Engineer”).
Teensys have lots of I/O pins, same spacing as the LCD modules, so I elected to mount the Teensy board directly on the LCD. One 3 pin header and one four pin header is needed. In the next photo you can see the headers with two short gray spacers to separate the PC boards. I had to flatten one of the LCD bezel mounting tabs for clearance but the mount is very compact and rigid. Note to self: make sure you don’t need any more connections to the bottom of the board before soldering down the headers.
I had the idea to use a software driven flashing LCD back light to indicate a flat battery. ARM I/O pins are limited to 9 milliamps each, not enough for an LCD back light so a 2n2222 transistor was glued in to act as back light current switch. The trim pot on the right is for adjusting LCD contrast. It is across the back light LED pads, did not work out well, as later in development I am PWMing the 2n2222 to get adjustable back lighting. So the trim pot has been moved up on the LCD board, epoxied in place, and hard wired to ground and +3.3 volts.
The two wires leading off the right end of the Teensy go to a CR2032 backup battery for the Real Time Clock, and you can just see the Adafruit 32KHz crystal added on the bottom of the Teensy. With this minimal configuration I was able to test and experiment with the built in RTC using the example program furnished with the PJRC Time library, modified with LCD prints. Initially setting the clock was a problem, you need to send a “T” followed by Unix time (seconds since 1970) into the serial port. I worked out this Linux incantation to get the proper format for Central Standard Time:
echo T$[`date +%s` – 6 * 3600]
Then copy “T1453151560” and paste into the Arduino serial window. Once the clock has been set it takes care of itself though I’m not sure how. I believe it reads and sets time from code uploaded from the compiler. The Time library is more than a little obscure.
Of course many wires have to be added to interface Teensy with the rest of the keyer. It’s not so neat looking now, I’m using nearly every I/O pin plus power from the built in 3.3 volt regulator. I use mostly 24 gauge wire, solid if connecting to other points on the lid, stranded if routing to points below. I have an old Ungar fine tipped soldering iron plugged into a Variac set to about 70 percent.
There are three auxiliary perf boards in the design, One mounts seven memory switches, another holds volume control, transmit LED, and the Function button, the third has clock battery and an optoisolator for transmitter keying. These boards were carefully laid out on paper, then cut out and marked up so mounting holes could be located. Working with a hinged lid box you have to be careful to leave extra clearance for the lid to close. I did have to file a bit off the button board and the speaker.
The box needs a couple dozen holes to mount parts. Blue tape was applied to all surfaces, a layout drawn on the tape, then all holes center punched. I start with my smallest drill bit in a drill press then enlarge 1/64 at a time to final size. A few holes required fine tuning with a tapered reamer. I made a rectangular cutout for the LCD bezel by using a wooden template screwed to the lid, then cutting with a 3/16 carbide router bit surrounded by a 1/4″ collar. Mounting hardware is mostly 2-56 with a few 4-40 spacers.
I had a pair of paralleled 18650 cells taken from a cell phone charging pack. These are fastened in the box by a strip of tin can metal soldered in, and restrained by an angle bracket soldered at one end. The small speaker was taken from a defunct IPod dock. In the next photo, most of the lid components are mounted. The small audio amp board goes on the two screws at right center of the lid, mounted mezzanine style.
Next is a close up of the batteries with 2 amp fuses soldered in both plus and ground leads. Also see three stereo jacks at the right side for Key/Audio Out, External Speaker, and Paddles In. You can see in the bottom three long #2 screws for mounting the third perf board and Adafruit boost/charger. Most board mounting screws have three nuts; one to secure the screw, one to support the bottom of the board at the proper height, and a third to secure the board against the second. Thank heaven I still have a Heathkit nut starter.
At the right side of the box there is a power switch, PS2 jack, and a micro USB jack breakout. The power switch does not actually switch power, it grounds the Enable pin on the charger board which turns off the boost converter. That allows charging to continue while the rest of the unit is off. Later in debugging the hardware, I added bypass capacitors to that switch and a separate wire to the Enable pin on the audio amplifier which suppresses a weird sequence of sounds from the speaker on powering off. The PS2 jack leads wouldn’t reach the processor board so they route to the third perf board and get jumpered there to stranded wire headed for the Teensy. It’s getting hard to find a real PS2 keyboard but the software works fine with a USB keyboard plugged into a USB/PS2 adaptor.
This is a good place to register a complaint. I bought the Adafruit PowerBoost 500 board to manage the battery. It charges from 5 volt USB in and boosts from the 3 volt battery, seamlessly switching sources when you pull the USB connection. It does NOT however pass through or even break out the two USB data pins from the micro USB input jack. The only way to actually use USB while charging the battery is to wire out the D+ and D- leads outside the board. Adafruit support suggested doing this by cutting up a USB cable. I was able to route the micro USB breakout data leads (Green in the next photo) to the processor and the incoming positive and negative supply leads to the PowerBoost using a plug from an Adafruit micro USB connector (red and black in the photo). An extra $2.50 in parts that wouldn’t have been needed if Adafruit had only provided pads on the PowerBoost for D+ and D- or better, added two traces to route the data signals from the input connector to the output connector.
One more issue with the PowerBoost. It has a nice pair of status LEDs (where it says CHRG) yellow when charging and green when fully charged. These operate from a single pin on the charger chip but that pin is not broken out and you can’t of course, see the LEDs when the box is closed. I added a wire (gray, leading off to the right in the photo) to the common side of the LED dropping resistors so I could have the Teensy display charging status on the LCD. Not difficult but would have been nice to have official access to that chip pin.
The keyer has four monitoring leads between the PowerBoost and the processor. Besides the status signal mentioned above, I wired up the LowBattery pin and USB (power). USB activates the Status signal which is only valid when USB is plugged in and receiving power from the host. LB goes low when the battery is REALLY flat (3.25 volts I think). I also wired the BAT pin to the Teensy A10 analog input through a 10k calibration pot so software can read and display the battery voltage. You can see the calibration pot at the bottom of the board in this photo.
The next photo shows how I insulated the External Speaker jack by opening up the mounting hole and screwing a small piece of Lexan to the box. The plastic had to be counterbored so the jack mounting nuts would fit.
Here is a close up of the box lid interior. You can see the LCD contrast pot which is glued to the LCD, perfboard for the LED, volume control, and Function button. Two screws and a couple of spacers mount the PAM8302 audio amp on top of the LED board.
Here is the completed keyer opened up. Clockwise from top left, I/O stereo jacks, 18650 batteries, memory button board, Teensy3.2 processor on top of 16×2 LCD display, LED board, speaker, on/off switch, PS2 keyboard jack, USB input jack, PowerBoost charger/boost converter, and the transmit interface board.
An Eagle schematic diagram of this project can be downloaded from:
February 25, 2016 MemoryKeyerTeensy3.2_V1.0 Initial sketch
March 9, 2016 MemoryKeyerTeensy3.2_V1.1.0 Rework battery alarm logic, bug fixes.
March 16, 2016 MemoryKeyerTeensy3.2 V1.1.1 Workaround fix LCD does not have backslash in its font.