first arduino project: morse code keyboard

A couple of weeks ago, I stumbled across Arduino on the web and it sparked my old passion for hw + sw tinkering. Last week I received my first Arduino Duemilanove and I’ve had very little sleep and a lot of fun since then 🙂

I was really into ham radio when I was a kid and I always loved morse code. One of my first hw + sw projects was to use my TRS-80 Color Computer as a morse keyboard for my HW-8 QRP transceiver. So I figured a morse keyboard would be a good starter project for my Arduino adventure.

It turns out that the hardest part of this project was interfacing with a PC (AT or PS/2) keyboard. The protocol (described really nicely at Beyond Logic), is pretty bizarre. I searched around and, to my surprise, couldn’t find an efficient, reliable method for using one of these keyboards with Arduino. The solutions I found online ranged from polling the keyboard’s data and clock lines to using a seperate, dedicated microcontroller to translate the keypresses into standard serial that Arduino can easily understand.

I decided to have the keyboard clock line drive an interrupt in which I could reliably read the data line. Since the processor wouldn’t be polling, there’d be plenty of time to do other things. This worked like a charm. At some point I hope to post a cleaned up version of the keyboard code alone so that it’ll be easier for others to use.

My arduino morse keyboard in action.  Exciting, eh?

My arduino morse keyboard in action. Exciting, eh?

It’s not much to look at, but it was a lot of fun, and if I had some ham radio gear, it’d be very useful as well.  For now I’ll have to settle with morse code beeping from a piezo speaker that I ripped from an old wireless phone. I also send morse out on pin 13 which just flashes an LED on my board, but you could easily use it with a transistor to key a transmitter.

The keyboard is fully functional, supporting speeds from 5 to 40 wpm, different weights, and even volume (if you’re using a non-filtered little speaker like I am).

Here are some handy features:

  • F1 – set speed in wpm.  Valid values are integers between 5 and 40.  Press enter after the number.  Default value is 20.
  • F2 – set “volume”.  The way I’m using this, it only works if the speaker is hooked up directly to the pwm output pin of the arduino.  If you use a low pass filter then this volume method won’t work.  Valid values are integers between 0 and 9.  Press enter after the number.  Default value is 2.
  • F3 – set “weight”.  I’m not sure what the technically accurate way to set weight is.  My version just varies the length of dahs while leaving dits unaltered.  Valid values are between 1 and 5.  Deafult value is 3.
  • F5 – play back a recorded message.
  • Shift-F5 – record a message.  Max message length is 100 characters.  If you add more RAM then you can bump up the message length and/or add more messages on F6, F7, F8…

There are also a bunch of pro signs available on the keyboard.  I can’t remember all of them, but they’re commented in the source.  ‘+’ is AR,  ENTER is BT,  ‘!’ is error, etc.

The sketch is posted here.

Let me know if you find this post useful.  Enjoy!

Advertisements

7 comments

  1. I am definitely impressed. Think I’m gonna buy my arduino very soon!
    😀

  2. It works! — except for F1, F2, and F3. The *duino just locks up.
    Might be my keyboard but the memory works fine with F5 and Shift F5.
    I’ll try a different keyboard, then look at the sketch. I’m using an
    Iduino with ceramic resonator instead of a crystal clock. That
    should be OK since all the other keys work perfectly.

    This is a great Arduino application.

    73,

    K9AC

    1. Regarding F1, F2 and F3 keys not working:

      The problem appears to be related to the Serial.print error messages
      for invalid speed volume and weight. At this point, I’ve shortened the
      “Invalid weight!” message to “Wt bad” and everything works. If I
      lengthen the invalid weight message, F1, F2 and F3 lock up and require
      a reset.

      There is no need to Serial.print anything. The Arduino will not be
      connected to a computer while keying a transmitter. If a computer
      is available, there are better things for it to do than provide 5 volts to an
      Arduino and wait for an error message.

      I will comment out or just delete the error checking and reporting. Then
      the programmed ATmega168 can be put on a barebones PC board
      inside the keyboard case for dedicated use.

      Its easy to add or change key definitions. I’ve added the double dash,
      apostrophe and close parenthesis. A few non-volatile short messages
      would be good. CQ and callsign, for instance.

      Parts of this sketch can be put to other uses. The AT keyboard can
      serve as a set of 104 buttons that input data as numbers and letters to
      the Arduino. The keying routines could be used to read data out of
      the Arduino as morse code. Seems to me there is potential here for
      inclusion in the official Arduino examples.

      73,

      K9AC

  3. Thanks for the comments.

    I have a better version of this project that runs on a little attiny84. The code is in better shape now, too. I plan to clean this all up and post it here as a standalone keyer project (for keyboard and paddles).

    1. G. Travis Whitehead · · Reply

      I was thinking about expanding this to a Morse reader ( audio input ) as well. Do you have the latest code ready to post?

      73’s WA2JJF

  4. I’ll upload some of my latest code. Unfortunately, I don’t have time to write up any good documentation. I hope it’ll be useful anyway.

  5. […] Satellite Doppler Effect Rig Tuner – http://youtu.be/TP_fq_frqKw Morse Code Keyboard – http://gorsat.wordpress.com/2009/03/17/first-arduino-project-morse-code-keyboard/ More Morse Code with Arduino – http://kb3vcq.posterous.com/arduino-morse Microcontrolled Ham […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: