Morsetrainer

Find it amazing how fast computers communicate via a LAN cable: 10 Mbps, 100 Mbps or even 1 Gbps. As a reminder: the M stands for mega, ie 1 million (10 high 6), the G for GIGA, ie 1 billion (10 high 9). Before becoming dizzy with these transmission speeds, I suggest that we "decelerate" together and learn to recognize around 100 characters per minute with a home-built Morsetrainer.

Information about the MorseCode

Worth knowing about Samuel Morse invention you will find u.a. at Wikipediawhere I also discovered some interesting details. The most important thing I summarize here:

At the beginning, the motivation is certainly why one should deal with the MorseCode today, because the last internationally decided change is only a few years. I myself needed it in my avian education, because the radio fires, ie transmitter in the center wave and FM area, send an identifier that leads together with the set frequency for unambiguous verification. In addition to the acoustic signals, such identifiers, e.g. of illuminated fires and buoys in the seafaring, can also be emitted as light signals. In the foreground of our efforts, therefore, the understanding of an identifier is usually two or three "guilest" letters, e.g. MNE, MNW, MSE, and MSW for the four non-directed radiopers (NDSB) around Munich.

The Morse code for each letter consists of so-called points and strokes, so short and long tones. When speaking, the "DI" or at the end "Dit" for the point, a long "DAH" for the line. So "Di Di Di Dit" corresponds to the MorseCode short-long-short-short. The letters consist of 1 to 4 characters, original idea: the more frequent the letter occurs, the shorter the Morse code. Little surprisingly so the point. For the "E". Numbers and special characters consist of five or even more characters. The most famous special character knows every child, the international emergency di-dit - Dah-Dah-Dah-di-di-dit (., - - -.,). As we will see, it has similarity with the bookstraps S-O-S, but it lacks the breaks between the letters. Save Our Souls is the first known "backronym".

Of course, how quickly the signs are "given" depends on the capabilities of the encoder (transmitters) and receiver. In our program we will define the length a "dit" as variable, which we can adjust later if necessary. This "dit" is the basic unit of time to which all other times are returned: a "DAH Has a length of 3 "dit". And the length of the pauses are 1 "dit" between two sent characters, 3 "dit" between the letters in a word and 7 dit between words.

What we need

Number Component
1 Any Raspberry Pi
alternatively Micro Controller Arduino Compatible
1 Buzzer KY-012 or Buzzer KY-006
optional Breadboard, electric wire, Additional LED


Program in Python

The first Morsetrainer I would like to introduce to them, I realized with a Raspberry Pi in the programming language Python. The problem can break down in two subtasks: First we need a table with the "translations". Thereafter, the points and strokes must be implemented in tones or light marks.

In Python there is a data type named "Dictionary", which is ideal for the purpose of translation. So we have to the table below in a "Dictionary" e.g. with the name Morse implement.

Morsecode

For this part, I use program code from the book of Michael How I learned Python, and that I still occasionally take it today.

  #----------------------------------------------------------------
 # Dateiname: morsen.py
 # Text durch Morsezeichen darstellen.
 #
 # Michael Weigend: Raspberry Pi programmieren mit Python, mitp 2013
 # 3.13.2
 # 28.10.2013
 #----------------------------------------------------------------
 
 morse = {"a":".-", "b":"-...", "c":"-.-.", "d":"-..", "e":".", "f": "..-.", "g":"--.", "h":"....",
          "i":"..", "j":".---", "k":"-.-", "l":".-..", "m":"--", "n":"-.", "o":"---", "p":".--.",
          "q":"--.-", "r":".-.", "s":"...", "t":"-","u":"..-", "v":"...-", "w":".--", "x":"-..-",
          "y":"-.--", "z":"--..", "ä":".-.-", "ö":"---.", "ü":"..--", "ß":"...--.", " ":" "}
 
 text = input("Geben Sie einen Text ein: ")
 morsetext = []
 for buchstabe in text:
     if buchstabe in morse.keys():
         morsetext.append(morse[buchstabe])
 
 for m in morsetext:
     print(m, end=" ")

The letters are used within the "Dictionary" as the key (keys). Behind the colon, the Morse code is listed as value (value) with points and dashes.

Since we only use lowercase letters in the Dictionary, the string method Lower () that creates a copy of the small letter strings to have no gaps when accidentally entered a capital letter.

In the for loop, each letter of the entered text is converted individually and attached to the initially empty list MorseText. Afterwards, the elements of the list are printed out.

For output as a sound or light signal, we connect an LED and / or a buzzer to a GPIO pin (here GPIO24) and switch to high I (LED.ON ()) or LOW (LED.FF () ). With the function Sleep () from the TIME module, we determine the duration of the signal or pause. As mentioned above, all times refer to the length of a "dit", which we define as variable dit = 0.2. As a reminder: The decimal point is in Python of the Decimal Point. And you can vary this value later if you want to hear the Morse signs faster.

 #! /usr/bin/python3
 # Morsen_LED.py
 # Programmidee und Algorithmus: Nele Marie Klipp, Enrichment-Kurs 2016/17
 # angepasst an gpiozero: Bernd Albrecht, Kursleiter
 #
 
 from time import time, sleep
 from gpiozero import LED
     
 DIT = 0.2
 led = LED(24)
 
 MORSECODE = {"a" : ".-" , "b" : "-...", "c" : "-.-.", "d" : "-.." , "e" : ".", "f" : "..-." , "g" : "--." , "h" : "...." ,
            "i" : ".." , "j" : ".---" , "k" : "-.-" , "l" : ".-.." , "m" : "--" , "n" : "-." , "o" : "---" , "p" : ".--." ,
            "q" : "--.-" , "r" : ".-." , "s" : "..." , "t" : "-", "u" : "..-" , "v" : "...-" , "w" : ".--" , "x" : "-...-",
            "y" : "-.--" , "z" : "--.." ,  "1" : ".----" , "2" : "..---" , "3" : "...--" , "4" : "....-" ,
            "5" : "....." , "6" : "-...." , "7" : "--..." , "8" : "---.." , "9" : "----." , "0" : "-----" }
 
 def morse(letter):
      print(letter,MORSECODE[letter])
      for a in MORSECODE[letter]:
          if a == ".":
             # print('drin Punkt')
             led.on()
             sleep(DIT)
             led.off()
             sleep(DIT)
          else:
             # print('drin Strich')
             led.on()
             sleep(3*DIT)
             led.off()
             sleep(DIT)
      sleep(3*DIT)
 
 def send(text):
     for letter in text:
          if letter in MORSECODE.keys():
             morse(letter)
          else:
              sleep(7*DIT)
              print(" ")
 
 print('Was soll gesendet werden?\n')
 
 Eingabe=input('Text: \n').lower()
 print(Eingabe)
 send(Eingabe)

Download source code MORSEN_LED.PY

Program in C ++

In order to realize our Morsetrainer with an Arduino-compatible Micro Controller, we have to choose another approach, because C ++ knows no dictionary as a data type. Alternatively, we will use a list of Morse signs instead, which we then access the individual letters in the MorseCode via the index.

For the sake of simplicity, I show the principle only on the basis of the letters without umlauts, numbers and special characters.

 String morseTable[] = { ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."};

Now I just have to assign the index 0 to the letter A etc. until index 25 for the letter z; So 26 letters, index from 0 to 25!

In the ASCII table, I find ASCII codes 65 to 90 for capital letters A to Z and 97 to 122 for small letters A to z. After entering the letters in the serial monitor, it is checked whether the ASCII value is between the numbers mentioned. Then the index is determined by subtraction of 65 and 97 and the Morse code from the list is removed. According to the number of Morse signs of a letter, the loop for the output of the light or sound signals is run through one to four times. I would like to mention a stumbling block: at the if - query point or stitch IF (MorseChar [i] == '.') I had first used double highly comma because the Morsecode is stored as a string in the list. But the individual characters of the "string" are, Characters', so simple highly comma to use.

Here is the code for our Arduino Morsetrainer:

/* Morse-Trainer mit Arduino
  * Buzzer und LED an Pin 13
  */
 
 int ledPin = 13;
 int dit = 200;
 int dah = 3 * dit;
 int oneChar;
 String morseChar;
 String morseTable[] = { ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."};
 
 void setup() {
   pinMode(ledPin, OUTPUT);
   digitalWrite(ledPin, HIGH);  
   delay(1000);  
   digitalWrite(ledPin, LOW);  
   Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }  
   Serial.println("\nEnter group of characters in Serial Monitor");
   Serial.println();  
 }  // end setup()
 
 void loop () {
   // get any incoming bytes:
   if (Serial.available() > 0) {
     oneChar = Serial.read();
     Serial.print(char(oneChar));
     Serial.print("   ");    
     morseCode();
  }
 }  // end loop()
 
 void morseCode() {
   if (oneChar >= 65 && oneChar <= 90) {
     morseChar=morseTable[oneChar-65]; }  
   else if (oneChar >= 97 && oneChar <= 122) {
     morseChar=morseTable[oneChar-97]; }
   else {
     morseChar=" ";}
   Serial.println(morseChar);
   outputMorse();
   Serial.println();
 }
 
 void outputMorse() {
   int len = morseChar.length();
 // Serial.print( "morseChar.length = ");
 // Serial.println(len);
   for (int i=0; i<len; i++) {
 //   Serial.print(morseChar[i]);      
     if (morseChar[i]=='.') {      //reminder: "String" with characters '.' and '-'
       digitalWrite(ledPin, HIGH);  
       delay(dit);  
       digitalWrite(ledPin, LOW);  
       delay(dit);   }
     if (morseChar[i]=='-') {      //reminder: "String" with characters '.' and '-'
       digitalWrite(ledPin, HIGH);  
       delay(dah);  
       digitalWrite(ledPin, LOW);  
       delay(dit);   }  
     else {
       delay(7*dit);}  
    }
     delay(dah);
  }

Download Source Code Morsetrainer.ino

Overview MorseCode

To recognize the Morse signs, the table shown above, which was sorted alphabetically, helps unfortunately little. Therefore here again the "reversal" of the Morse table. Tip: Start with the letters that have a maximum of three characters. Especially in the summer months, you will certainly remember the e i s fastest. Have fun.

.

E

. .

I

. . .

S

. . . .

H

. . . -

V

. . -

U

. . - .

F

. . - -

Ü

. -

A

. - .

R

. - . .

L

. - . -

Ä

. - -

W

. - - .

P

. - - -

J

-

T

- .

N

- . .

D

- . . .

B

- . . -

X

- . -

K

- . - .

C

- . - -

Y

- -

M

- - .

G

- - . .

Z

- - . -

Q

- - -

O

- - - .

Ö

- - - -

Ch

AmateurfunkFor arduinoProjects for beginnersRaspberry pi

3 comments

Alexander essreiter

Alexander essreiter

Habe früher viel gemorst werde jetzt wieder damit beginnen etwas eingerostet durch die viele arbeit

Jacobo

Jacobo

Para hacer esa traducción automática tan mala, vale más dejar el texto entero en inglés.
Por lo demás, bien.
Saludos.

Hermann Eckel

Hermann Eckel

Den richtigen Morsetrainer gibt es mit dem Morserino32
das ist Public Domain Infos bei morserino32.info

Liebe Grüße
Hermann, OE2HEM / AB3DR

Leave a comment

All comments are moderated before being published

Recommended blog posts

  1. Install ESP32 now from the board manager
  2. Lüftersteuerung Raspberry Pi
  3. Arduino IDE - Programmieren für Einsteiger - Teil 1
  4. ESP32 - das Multitalent
  5. OTA - Over the Air - ESP programming via WLAN