June 21, 2011

Morse-code trainer

My kids are learning Morse code this summer, so I threw together this little circuit to help them learn. And to make it more fun...
It uses an ATtiny85 ($2.26 at digikey.com) to drive a piezo beeper (≈ $3.50 at Radio Shack.) The ATtiny85 takes 5.5V max, so I built the circuit on a piece of strip-board so as to fit onto the back of a 3-AA-cell ($3 or so at Radio Shack) battery pack.
To program it, I used MIT's "High-Low Tech" ATtiny85 core using an Arduino as an ISP programmer. I actually built a 6-pin ISP header into the board, so I don't have to pull the chip out to reprogram it as you would with MIT's instructions, but that's neither here nor there. Using an Arduino core allows me to  use all the Arduino tools I'm familiar with, but I don't have to spend $20 or more on a full Arduino when all I really need is one output pin and a couple kb of program space. The ATtiny85 is perfect for this: plenty of memory and dirt cheap. (Actually, an ATtiny25 would work with the amount of memory this program takes, but ATtiny85s are so cheap you don't save much buying the ATtiny25.)

Here's the code. When the device is powered up, it waits 3 seconds then puts out the message at the desired speed. The message repeats until power is removed. Currently the message is "SOS the moon rover has broken down and I am stuck in the trash can in the garden shed." Once the kids decode it, they'll find a small Lego moon rover there as a prize.

Changing the speed of the Morse output is easy: just increase or decrease the definition of DOTLENGTH and everything adjusts proportionally. Changing the message is equally simple: just change the value of message[] in the source code. As written, it can handle up to 255 characters in the message. The program can handle upper/lower case, numbers, and some punctuation.

The program will also work with an Arduino, of course. You can even change the value of OUTLINE to 13 and the Arduino will use the built-in LED. (No circuit required, just a bare Arduino!)

I know Morse code is pretty much obsolete now. You don't even need it for a ham license any more... but all the more reason to learn it! 

.... .- ...- .  ..-. ..- -.  .-- .. - ....  .. -  .- -. -..  . -- .- .. .-..  -- .  .. ..-.  -.-- --- ..-  ..- ... .  .. - .-.-.-

5 comments:

  1. It is good.
    very simple code

    ReplyDelete
  2. Great project! Have the kids found their prize yet?

    ReplyDelete
  3. - .... .. ... .. ... .- .-- . ... --- -- . --. .-. . .- - .--- --- -...

    ReplyDelete
  4. Great little project dude... haven't fiddled with my Arduino in months now. Will give it a go:)
    One thing though: In the wordBreak function, your comment says that you want 4 breaks but the actual code will end up outputting 7? or am i missing something??:D

    ReplyDelete
  5. @peteZa: A Morse word break is seven dots. The way the code is written, there is always a dot-length break at the end of a dot or dash (1) and there are two more dot-lengths at the end of a character (+2) so in response to a space, the code needs to add only enough to make seven dots. You can't get to a space without having just ended a dot or dash and just ended a character, so you only need to add 4 to make the necessary 7.

    @Anonymous: Yeah, they got it. The current message now reads "The magic word is spink. Say spink to Dad and he will wash your dishes." One kid has it, the other hasn't yet and can't figure out why the one is laughing.

    ReplyDelete