SP4THK CwKeyer

SP4THK CwKeyer: a CW keyer on ESP32

Why a separate keyer?

Many radios, top models included, have a single USB chip inside that handles both radio control (CAT) and keying (the DTR/RTS lines of a virtual COM port). When some program asks the radio for frequency or SWR during a transmission (a logbook, OmniRig, WSJT-X), switching the key waits until the radio answers. The keying goes “drunk”.

I measured it: an SDR receiver recorded every transmission, and I compared every dot and dash with what the computer keyed.

  • Nobody asks the radio during the transmission: 0 bad elements out of several hundred dots and dashes.
  • A program asks the radio over CAT: 2 to almost 10 % of dots and dashes distorted. The key switch comes 50-90 ms late, while a dot at 20 WPM lasts 60 ms. A dot turns into a dash and a letter into another one (here a “4” went out as “3”).
  • Keying with the radio’s built-in keyer (via Hamlib) is better but not perfect: 0.7-2.4 % of elements are off by more than 25 ms. Also, the radio does not tell the program what it has already sent, and not every radio can do it.

Programs running in the background cannot be switched off: OmniRig keeps polling the radio on its own.

In the chart: the program released the key on time (blue), but the COM port line switched 64 ms later (orange), because it waited for the radio’s SWR reply. The gap shrank from 67 to 8 ms, and on air (green) two elements merged into one.

The solution

The timing of dots and dashes has to come from a separate device, not from the computer together with the radio. The computer only sends text, and the keyer sends it with an even rhythm on its own. CAT queries, Windows and the radio’s USB no longer matter. That is how a WinKeyer works, and that is how CwKeyer works.

What it is

CwKeyer is a small CW keyer you build yourself: an ESP32 D1 mini board, two optical relays and a few small parts, about 12 USD in total. It connects to the computer with a USB cable and to the radio with two wires: KEY and, if needed, PTT. The radio is optically isolated from the computer, so the grounds are not connected and there is no hum.

Programs see it as a WinKeyer, so it works with CW Decoder and with other programs that can transmit through a WinKeyer. In CW Decoder: Settings, Transmit, “WinKeyer (USB)”, choose the keyer’s port and tick “SP4THK version”.

Schematic

  • Two signals leave the ESP32 board: KEY (pin IO27) and PTT (pin IO4). Each drives an optical relay (PhotoMOS AQY212), which closes the line in the radio. It works with either keying polarity, up to about 60 V.
  • The computer ground and the radio ground are not connected: only the light inside the relays links them.
  • TVS diodes and capacitors at the terminals protect against RF spikes while transmitting.
  • Two LEDs show KEY and PTT. Two capacitors add filtering to the module’s supply.
  • Radio terminals: 1 KEY, 2 PTT, 3 and 4 radio ground. You make the cable (jack, RCA, ACC socket) for your own radio.

The board

The board is 84.5 × 37 mm with M3 screw holes in the corners. It is single-sided (all copper on the bottom, wide tracks, large pads), so the same design can be ordered or made at home:

  • From a PCB factory (e.g. JLCPCB): upload the file board/gerber_for_JLCPCB.zip from the package as it is, without unpacking, and choose 1 layer.
  • At home, with a marker or an iron: the package has ready 1:1 prints (copper drawing and drilling template). Print at 100 % scale and check the 84.5 mm width with a ruler.

The parts list is in the package and on the schematic. The most expensive parts are the two PhotoMOS relays (about 2.5 USD each).

Keyer program

A small program is uploaded once to the ESP32 board; it turns text from the computer into dots and dashes. You do it with the free Arduino IDE:

  1. In the Arduino IDE add ESP32 board support (Boards Manager, “esp32 by Espressif Systems”).
  2. Choose the board “WEMOS D1 MINI ESP32”, upload speed 115200 and the port where the board appeared.
  3. Open CwKeyer.ino from the package and click “Upload”.

A tip: buy an ESP32 board with the CP2104 USB chip. New Windows simply blocks cheap boards with a counterfeit CH340 chip, and the port will not open.

The keyer has safety limits: it never holds the key down longer than 10 s or PTT longer than 120 s, and closing the program releases everything at once. Do the first tests without a radio (a meter or an LED on the terminals), then into a dummy load at low power.

Extra: “hand” sending

A normal keyer sends perfectly even, like a machine. CwKeyer can also send like a person: every dot, dash and gap is a little different, and the speed drifts slightly. You set how uneven with a slider in CW Decoder.

The values are not guesses. I measured them on real on-air recordings: electronic keyers and computers differ from a perfect rhythm by 2-5 % of a dot length, hand keys and bugs by 7-18 %. An original WinKeyer cannot do this.

How to turn it on:

  • In CW Decoder: Settings, Transmit. Keying method “WinKeyer (USB)”, tick “SP4THK version (ESP32 keyer)”, then turn on ““Hand” style” and set the spread with the slider (e.g. 8 %). The program checks that it really is this keyer and only then turns the “hand” on.
  • In your own program: after opening the keyer (WinKeyer command 00 02) send 5 bytes 00 40 r k d: r = spread in % of a dot length (0-30, 0 = off), k = dash/dot ratio times 10 (30 = 3.0), d = slow speed drift in % (0-10). Example: 00 40 08 1E 03 turns on an 8 % “hand”, to turn it off: 00 40 00 1E 00. To check that it is this keyer, send 00 41: it answers with the text CWK1. Do not send these commands to an original WinKeyer.
  • After a power cycle or reopening the keyer (00 02) it always returns to even sending, without the “hand”. The setting has to be sent again; CW Decoder does this itself before every transmission.

Download

CwKeyer_SP4THK.zip contains:

  • the keyer program to upload with the Arduino IDE;
  • the file for ordering the board from a factory;
  • 1:1 prints for making the board at home;
  • the board project for KiCad;
  • the schematic and licenses.

Credits and license

  • WinKeyer is the idea and device of Steve Elliott, K1EL (k1elsystems.com). CwKeyer does not copy his software: it only understands the same publicly described way of talking to the computer, which is why programs see it as a WinKeyer. The WinKeyer name belongs to K1EL Systems. If you want a ready, proven device, buy the original.
  • The ESP32 D1 mini board is a common module in the WEMOS D1 mini size, made by many manufacturers.
  • The ESP32 module footprint in the board project comes from the ESP32 mini KiCad Library by r0oland, Apache-2.0 license (license text in the package).
  • Keyer program, schematic, board, 3D model of the module and descriptions: Tomasz Fronczek SP4THK.

Licenses of my parts:

  • Keyer program: MIT license. You may use, change and share it, keeping the author notice.
  • Board, schematic and descriptions: CC BY 4.0 license. You may copy, change and build them, also for sale, as long as you credit the author: Tomasz Fronczek SP4THK.

No warranty: the keyer controls a transmitter, so build and use it at your own risk.

73, Tom SP4THK