Repost: Arduino Morse code sender

Arduino projects on the go
Post Reply
Martin
Posts: 745
Joined: 16 Feb 2018, 14:11
Location: Warwickshire

Repost: Arduino Morse code sender

Post by Martin »

Postby ceptimus » Tue May 09, 2017 6:13 pm

I know some of you use Morse code. There are doubtless already loads of Arduino sketches out there that do it, but here's my effort for anyone that's interested.

I wanted to keep it as simple as possible from the main sketch point of view, so you just include a class, call the initializer to set the output pin and Morse speed and then call MorseCode::loop() from within your main sketch loop.

The simplest possible sketch looks like this:

Code: Select all

#include "MorseCode.h"

void setup() {
  MorseCode::initialize(13, 12.0); // use pin 13 and a speed of twelve words per minute
  MorseCode::transmit("HELLO THERE!"); // start transmitting a message
}

void loop() {
  MorseCode::loop(); // make sure to call MorseCode::loop() from your main sketch loop()
}
Of course you wouldn't normally want to only transmit from the setup() method, but if you're transmitting from inside loop() you need to make sure that you don't try to transmit messages faster than they can be sent out.
To allow the main loop() to know when any existing message has finished being sent, there is an idle flag, so a slightly more complicated example that keeps sending 'HELLO ' looks like this.

Code: Select all

#include "MorseCode.h"

void setup() {
  MorseCode::initialize(13, 12.0); // use pin 13 and a speed of twelve words per minute
}

void loop() {
  MorseCode::loop(); // make sure to call MorseCode::loop() from your main sketch loop()

  if (MorseCode::idle) { // once any existing message has completed
    MorseCode::transmit("HELLO... "); // start transmitting another one
  }
}
Unfortunately I cant recover Martin's 'Morse' sketch - did anyone download it please?
Edit by Martin: Thanks Phil. I've attached it now. Included in the zip is the Excel file (.xlsx) where I worked out the Morse code packing - you don't need that file for the sketch to work so you can safely delete it. I included it just in case anyone wishes to figure out how the sketch works, or maybe add some extra characters to the Morse alphabet.


Re: Arduino Morse code sender
Postby Sunbird » Thu May 11, 2017 11:37 am

Thanks for sharing your sketch Martin.
I think I understand how you have done it..good work.
Looking on the internet I see there are also a few Morse decoders for Arduino using a microphone for pickup. Also interesting code.

One of my work colleagues from years back is a Ham and I think he still uses CW. I would imagine Morse is used less and less now that it is no longer part of the license requirement. As a scout we were introduced to Morse for some reason but cant remember why. Most of us were quite proficient with semaphore however.

Cheers
Ian
Attachments
MorseCode.zip
(12.03 KiB) Downloaded 128 times
Post Reply