Archive for February, 2015

Arduino Based Iambic Keyer(s)

Version 1.0 – ATTiny85 Port

Richard Chapman KC4IFB published an article in the Sep/Oct 2009 QEX magazine (subscription required) for constructing an Iambic Keyer on the Arduino platform. I downloaded his code from the QEX web site (ARRL membership required) and found it worked well.  I have not been active in Ham Radio for years and my morse code is seriously rusty, so I decided to build a keyer for practice purposes and maybe to use on a real radio some day when I figure out how to get an antenna up on this small lot.  I have a WB4VVF Accu-Keyer I used with my homemade paddles long ago.  I bought the PC board from WB4VVF himself at the Dayton Hamvention.  Chapman’s keyer implementation on the Arduino Uno felt exactly the same and I had no problem getting used to it.

I wanted to see if this code would run on an ATtiny85 chip. These are beautiful little microcontrollers in an 8 pin DIP package. They have 8K of internal flash memory and with a minor bit of library downloading, are programmable via the Arduino IDE.  There is a catch though, tiny85 does not normally have bootloader code like a formal Arduino does so you need additional circuitry to burn your sketch onto the little chip. In July 2013 Jim Williams from Workshop 88 in Glen Ellyn conducted a class in tiny85 programming which I attended. At the end of the class we all had our own Arduino ISP adapter board and could burn a tiny85 by using an Arduino UNO as an intermediary.

I amped up my ISP adapter by adding a ZIF socket. It also can program the ATMega328 chips by moving five jumpers.

ISP programmer for ATtiny85 and ATMEGA328 microcontrollers

ISP programmer for ATtiny85 and ATMEGA328 microcontrollers

With the ISP programmer working, I was ready to work on the tiny85 port.  I found Chapman’s code worked but there was no side tone generated.  After a few hours debugging I noticed Chapman’s code was turning the tone on in every iteration of loop(). The tiny85 did not like that. I just added a flag so tone was turned on once, then left on, and the tiny85 port was working 100%. In the end, a very minor change.

I wanted SMALL so I added code to eliminate the speed potentiometer. In my version, you hold both paddles closed for 5 seconds and it goes into speed set mode. Dots increase the speed and dashes decrease.  Another five second Iambic squeeze and it goes back to normal mode.  Also I added a Straight Key mode. If a two conductor instead of a three conductor plug is inserted in the paddle jack it will just beep out what it sees on the dot paddle.  Good for code practice with my J38 if I can remember where I put it.

Source code for the ATtiny85 port is here. This is the finished Keyer in the mandatory Altoids enclosure (but note SMALL Altoids):

Atmel ATtiny85 based Iambic Keyer

It was a challenge to get everything in there and still have the lid close.  The speaker is from a defunct greeting card but rest of the parts were purchased from Jameco. In the end, the most expensive single component was the Altoids mints from the drug store.  The ATtiny85 chips are less than a dollar if you buy ten.

There are these few parts required:

  • speaker and 22 ohm resistor
  • 2032 battery and holder
  • two 3.5 mm jacks, one output, one paddles
  • three bypass capacitors
  • Dropping resistor and LED
  • Power switch
  • ATtiny85 chip and 8 pin socket
Interior of ATtiny85 Iambic Keyer.

Interior of ATtiny85 Iambic Keyer.

There is a short video of the keyer in action here.  So now if I spend a few minutes every day practicing I might get back to the 13 WPM I had to do to get my current license.

Version 2.0 – ATMega328 with Memories

Richard’s QEX article suggested several possible enhancements. I thought adding memories would make the device much more useful so began another journey into Arduino programming. Yes, I know there are already Arduino keyers out there. The K3NG implementation has a ridiculous number of options, but I wanted to do my own based on Chapman’s sketch in the most efficient manner possible. A schematic drawing of my completed keyer is available, and I have written a description of the functions. Source code for the sketch is here.

The PS2 keyboard requires +5 volts so I designed around a five volt Sparkfun Pro Mini board. Only ten bucks! Available here or here. The Pro Mini has an on board 150 milliamp capacity 5 volt regulator if you use a 7-12 volt power supply.

Features in the keyer sketch now include:

  1. Memory or keyboard characters are buffered in an asynchronous circular queue so memory buttons or keyboard characters can be “typed ahead”.
  2. PS2 and serial terminal keyboards supported.
  3. Paddle generated morse is interpreted and printed as ASCII letters on the serial terminal.
  4. Four programmable memories with 50 character capacity each.
  5. Memories programmable from the keyboards or from the paddles.
  6. Random code practice modes, letters, letters and numbers, letters, numbers, and punctuation.
  7. Sending speed settable 10 to 45 WPM. Limits can be changed by recompiling.
  8. Sidetone frequency settable 100 to 1500 hz. Limits easily changed by recompiling.
  9. Commonly changed default settings are in a separate header file (Canned.h).
  10. Message strings, sending speed, and sidetone frequency are stored in EEPROM and easily reset to defaults.

The sketch requires five I/O connectors:

  1. A 3 conductor jack for the paddle or straight key. Connect dot paddle to tip, dash paddle to ring. Use a 2 conductor plug for a straight key in the same jack.
  2. A 3 conductor jack for transmitter keying. A 2N2222 open collector output is on the tip. Line level sidetone is connected through a 5k resistor to the ring so you can connect an external amplifier if you need louder audio.
  3. A power jack for either a 5 volt or 7 -12 volt wall wart supply. Consult the Sparkfun documentation for which Pro Mini pin to use for power.
  4. A six conductor mini DIN connector for the PS2 keyboard. See Canned.h for information on the four leads needed.
  5. A connection for programming, and TTL serial terminal through an FTDI adapter. This can also power the unit instead of the wall wart.

There are six push button switches and a volume control needed:

  1. A reset button for the Arduino.
  2. A Function button.
  3. Four push buttons to activate individual memories.
  4. The volume control feeds a one transistor buffer for the internal speaker. It does not affect the level on the line output connection.

Operation:

Pressing reset momentarily has different effects depending on what other switches are closed. A processor reset normally takes a few seconds, when finished three mid tone beeps will be heard.

  • Press the reset button alone to restart the Arduino. This is also the only way to exit code practice mode.
  • Press the reset button while holding the function button down until three low tone beeps sound will restore the four message memories and code speed to defaults. Default messages, speed, and sidetone frequency are set at compile time from the file canned.h. You must do this action when loading the sketch for the first time into a new Arduino to initialize the EEPROM.
  • Press the reset button with a 2 conductor straight key plug inserted and the keyer enters straight key mode where the sketch generates tone and output simply follows the key closures.
  • Press the reset button while holding down one of the memory buttons starts random code practice. Characters will be generated in five character groups and echoed on the serial port.
  1. Memory 1: letters only
  2. Memory 2: letters and numbers
  3. Memory 3: letters and numbers
  • Pressing reset while holding Memory 4 enters sidetone frequency set mode. The dot paddle increases frequency, dash paddle decreases. Press M4 again to exit set mode.

The function button has three duties:

  • Reset to default messages as mentioned above. You must hold the function button down until you hear 3 low tone beeps.
  • Holding function alone down triggers speed change mode. While function is held, the dot paddle increases speed, dash paddle decreases speed.
  • Holding function down and then momentarily pressing a memory button allows programming that memory. After programming, press function again to return to normal.

New memory messages may be entered from the PS2 keyboard, the serial port keyboard, or from the paddles.

Pressing a memory button by itself transmits the programmed message.

Serial or PS2 keyboards have a command mode, entered by typing a back slash followed by a single character. Commands implemented are:

  1. \+ increase sending speed one Word Per Minute
  2. \- decrease sending speed one Word Per Minute
  3. \u increase sidetone frequency by 5%
  4. \d decrease sidetone frequency by 5%
  5. \w save current sidetone frequency and WPM to EEPROM memory
  6. \1, \2, \3, \4 send a message as though a memory button was pressed.

The keyboard translation table (AtoM.h) includes all the characters shown in the Wikipedia article on Morse Code except the underscore and the dollar sign. Typing an unsupported character echos “x” on the serial port and will be ignored by the morse interpreter.

Version 2.0 Hardware Implementation

Here is a photo of my 2.0 construction. There are three jacks on the left for power, paddles and transmitter keying. PS2 keyboard jack on the right, small volume control and send monitor LED on the front. Not visible is the six pin serial connector on the rear.

On the lid of the S.A.E. you can see a small speaker through the holes around the center. Round holes were made with a heavy duty paper punch. For buttons, I used 6 mm square through hole PCB mount switches with four pins, the kind everybody uses on their solderless breadboard. I bent the pins on one side back so they could be soldered directly to the Altoids lid. Quarter inch square holes for the buttons were punched with a hollow chisel mortiser bit which worked quite well.  I made labels by placing the lid in a scanner, adding text to the scan in GIMP, then printing a 1:1 image of the labeled lid on photo paper. I cut the letters out and glued them to the Altoids lid. This technique produces text labels with the original Altoids artwork underneath. I coated each label with clear nail polish for protection.

Arduino Memory Keyer Exterior

Arduino Memory Keyer Exterior

With the box opened you can see the small Sparkfun Pro Mini board. It is mounted by a pair of L shaped wires cut from a paper clip. These are soldered in the Mini’s two ground pins and then soldered to the Altoids tin. A rectangular hole in the back of the tin provides access to the six pin serial connector. All the in use Arduino inputs have 9.8 k pull up resistors added, and are bypassed at the switch with a small capacitor. The outer end of the pullup resistors are soldered to a narrow bit of PC material wired to Vcc.

Three jacks on the left are epoxyed in place. The PS2 jack on the right, which was salvaged from a defunct USB-PS2 adaptor, is held by a narrow copper strap soldered to the jack and to the Altoids tin. A small perf board at the front holds most of the ancillary components for keying and the audio control. I mounted the perf board using more stiff wire cut from the paper clip.

There is a strip of thin PC material laid across the button switches to add more physical support. The two switch pins not soldered to the Altoids lid are bent over the strip and soldered. Notches filed in strategic places across the copper isolate each switch, and I added the necessary 0.1 uFd capacitors at this point.  The speaker is tucked under one of the PC strips and epoxyed in a couple of places. A short piece of flexible solder wick bonds the box lid to the bottom.

Arduino Memory Keyer Interior

Arduino Memory Keyer Interior

Future Enhancements

Add a FTDI USB to Serial adapter inside the box. It would allow a more graceful connection to a host computer running a serial communication program. Or build another unit with a USB integrated chip.

Add a 16×2 LCD display. Code would be trivial, but will probably have to find a bigger box.

Expand to six or eight memories. My sketch is compiling in about 13 k of flash, and has over 1500 bytes of ram free plus the Pro Mini has eight analog inputs so easily done. But how many memory messages can the average ham keep track of? I think four is a good number and I love the Altoids tin paradigm.

Credits

Many thanks to Richard Chapman KC4IFB whose February 2009 QEX article provided the inspiration and base for this sketch. His iambic keyer sketch feels exactly like my original WB4VVF Accukeyer. A version of his sketch with instrumentation added so you can see the state changes is here. Also see Rarons Blog  for a discussion of the tree method for decoding and encoding morse characters. Would you believe 300 WPM full duplex?  I did not use his library but his work was very helpful in building efficient translation tables. The circular queue was implemented with help from examples from the Embedded Systems Journal.

Revision History

V2.0.0 Initial coding to implement fully asynchronous event loop.
All delay() and spin waits removed from the main loop path.
Remove numbers only practice. Change eeprom order. Add change sidetone.
https://dl.dropboxusercontent.com/u/40929640/ArduinoMorseCode/MemoryKeyerV2.0.zip

V2.0.1 Minor tuning space generation in doIambic.
https://dl.dropboxusercontent.com/u/40929640/ArduinoMorseCode/MemoryKeyerV2.0.1.zip

V2.0.2 Converted sidetone generation to DDS/PWM sine wave with help from
http://ko7m.blogspot.com/2014/08/direct-digital-synthesis-dds.html

https://dl.dropboxusercontent.com/u/40929640/ArduinoMorseCode/MemoryKeyerV2.0.2.zip

Quarter Wave Symmetry

Quarter Wave Symmetry
1000 Hz 256 Step Table

V2.0.3 Changed sine table to half step offset. Saves one byte.
https://dl.dropboxusercontent.com/u/40929640/ArduinoMorseCode/MemoryKeyerV2.0.3.zip

V2.0.4 Added sidetone envelope shaping. Required several other changes.
https://dl.dropboxusercontent.com/u/40929640/ArduinoMorseCode/MemoryKeyerV2.0.4.zip

Shaped Dits at 45 WPM

Shaped Dits at 45 WPM

V2.0.4.1 Bug fix was dropping dits on a long string of upper case “H”s. Disable interrupt while changing sine tables.
https://dl.dropboxusercontent.com/u/40929640/ArduinoMorseCode/MemoryKeyerV2.0.4.1.zip

V2.0.5  Changed AtoM table from prog_uint16_t to char to save memory, which created bug where setup does gratuitous write to A6 and A7. Fixed problems when compiling under Arduino IDE 1.6.1, did not accept typedefs in pgmspace.h. Fixed bug in initByte, 1.6.1 did not like  aaByte = aByte -= 0x20;  Compiled size is 2k smaller in 1.6.1 and no more bogus compiler warnings!
https://dl.dropboxusercontent.com/u/40929640/ArduinoMorseCode/MemoryKeyerV2.0.5.zip

April 30 – Have not changed the V2.0.5 sketch but did redo the audio section of the Altoids keyer. I found the single transistor audio buffer was not satisfactory, distorting badly when driven by a sine wave. Also it was drawing 50 milliamps at idle. I removed the transistor and connected an LM386 amplifier – much better sound and very little current draw when idle. A revised schematic is at:
https://dl.dropboxusercontent.com/u/40929640/ArduinoMorseCode/MemoryKeyerV2.0.5Schematics.zip

Notes

20 March 2015  —  The keyer sketch was developed with Arduino 1.0.6. Recently I downloaded the latest Arduino IDE 1.6.1 and discovered the keyer sketch will not compile. It appears the newer version of GCC will not accept the typedefs used in the pgmspace.h library. I will upload a 1.6.1 release as soon as I figure out what’s going on. FIXED see V2.0.5 above.

24 March 2015  — Was shopping in Frys and bought an inexpensive (< $3) adaptor, is USB A female to PS2 male, is about the same size as the two connectors placed end to end.  It was made by Shaxon Industries in guess where. To my complete surprise it works. Using the adaptor I can connect any USB keyboard to the keyer which is good news, as PS2 keyboards especially compact ones, are getting hard to find. I measured power supply current with the adaptor, it does not add significant drain over the 25 Ma the keyer itself draws. The small USB keyboard I tried added only about 3 milliamps when not typing. I did find the transistor I used to buffer the speaker draws 25 milliamps itself, will have to find a more efficient amplifier.