QC

DIY Arduino Morse Code Decoder and Trainer

This device is especially useful for HAM radio beginners, as well as SW listeners who can monitor CW communications without knowing Morse code.

Devices and components

Arduino-Nano

10k resistance

128x64 LCD with ST7565 driver

Diode 1N4148

Grove - Button (P)

capacitors

Materials and tools

Soldering kit

Software and tools

Arduino IDE

Project description

1/*
2 * Morse code receiver
3 */
4
5#include <U8g2lib.h>
6#include <TimerOne.h>
7
8U8G2_ST7565_ERC12864_1_4W_SW_SPI u8g2 ( U8G2_R0, /* scl=*/ 13 , /* si=*/ 11 , /* cs=*/ 10 , /* rs=*/ 9 , /* rse=*/ 8 ) ;
9
10byte inPin1 = 0; //analog input to telegraph key or radio output
11byte P1, P2; //button states
12int readPin1; //telegraph key or radio output variableradia
13int k, i; //iloop index
14int kropka; //dot length
15int z, s; //character pulses
16int p, r; //break pulses
17int wpm; //word per minute
18String znak_M;
19String litera_M;
20char S_str[6];
21char P_str[6];
22char wpm_str[2];
23char* znak;
24char* wiersz[12]; //char workline*
25char* wiersz1[12]; //top line char*
26
27
28const byte index_key = 48; //number of characters in the array 48
29const char* Z_char[index_key] = {
30"a","b","c","d","e","f","g","h","i","j","k","l","m",
31"n","o","p","q","r","s","t","u","v","w","x","y","z",
32"0","1","2","3","4","5","6","7","8","9",
33"!","(",")","+",",","-",".","/","=","?","_"};
34
35const String Morse[index_key] = { //Morse code
36".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--",
37"-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--..",
38"-----",".----","..---","...--","....-",".....","-....","--...","---..","----.",
39"-.-.--","-.--.","-.--.-",".-.-.","--..--","-....-",".-.-.-","-..-.","-...-","..--..","..--.-"};
40/*
41' (single apostrophe) • — — — — •
42" (quote) • — • • — •
43: (colon) — — — • • •
44; (semicolon) — • — • — •
45@ (monkey or at) • — — • — •
46*/
47
48void setup() {
49
50 Serial.begin(9600);
51 u8g2.begin();
52 u8g2.setContrast(210);
53 Timer1.initialize(1000);
54 Timer1.attachInterrupt(Zliczaj);
55}
56
57void loop() {
58 //Serial.println(s);
59 //delay(100);
60 Display();
61}
62
63void Display() {
64 //sprintf(S_str,"%d", s);
65 //sprintf(P_str,"%d", r);
66 u8g2.setFontMode(1);
67 u8g2.setFont(u8g2_font_10x20_tr);
68 u8g2.firstPage();
69 do {
70 u8g2.drawStr(0, 15, "Morse");
71 u8g2.drawStr(75, 15, wpm_str);
72 u8g2.drawStr(98, 15, "w/m");
73 //u8g2.drawStr(75, 30, S_str);
74 //u8g2.drawStr(105, 30, P_str);
75 for (k = 0; k < 12; k++){
76 u8g2.drawStr(k*10, 40, wiersz1[k] ); //top line
77 u8g2.drawStr(k*10, 60, wiersz[k] ); //workline
78 }
79 } while ( u8g2.nextPage() );
80 delay(10);
81}
82
83void Zliczaj(){
84 readPin1 = analogRead(inPin1);
85 if (readPin1 > 10 ) { //key is pressed
86 z++;
87 if (z == 1){
88 r = p;
89 //Display(); //Displays the length of the last pause
90 //delay(5);
91 p = 0;
92 }
93 }
94 if (readPin1 <= 10) { //key released
95 p++;
96 if (p == 1) {
97 s = z;
98 if ( kropka == 0){
99 kropka = s ;
100 //wpm = 1200/s;
101 //sprintf(wpm_str,"%d", wpm);
102 }
103 if ( z > 5 && z < 1.5 * kropka){ znak_M = "."; kropka = z ;}
104 if ( z > 2 * kropka ){ znak_M = "-";}
105 if ( r < 2 * kropka){ litera_M += znak_M;}
106 if ( litera_M.length() == 0 ) {litera_M = znak_M;}
107 z = 0;
108 }
109 if (p == 2 * kropka) {
110 wpm = 1200/kropka;
111 if (wpm > 90) {wpm = 0 ; z = 0;}
112 sprintf(wpm_str,"%d", wpm);
113 if ( litera_M.length() > 0 ) {
114 ZnajdzZnak();
115 i++;
116 wiersz[i-1] = znak;
117 if (i > 11) {
118 for (int k = 0; k < 12; k++) {
119 wiersz1[k] = " "; //delete the top line
120 wiersz1[k] = wiersz[k]; //rewriting characters from the working line to the top line
121 wiersz[k] = " "; //delete work line
122 }
123 i = 0;
124 }
125 }
126 Display(); //displays the read characters
127 }
128 if (p == 100 * kropka && i > 0) {
129 for (int k = 0; k < 12; k++) {
130 wiersz1[k] = " "; //rewriting characters from the working line to the top line
131 wiersz1[k] = wiersz[k]; //rewriting characters from the working line to the top line
132 wiersz[k] = " "; //delete work line
133 }
134 i = 0;
135 Display(); //Displays the characters read
136 }
137 }
138}
139
140void ZnajdzZnak(){
141 znak = "";
142 for (k = 0; k <= index_key; k++){
143 if (Morse[k] == litera_M) {
144 znak = Z_char[k]; //converting the key code to a letter
145 break;
146 }
147 }
148 k = 0;
149 litera_M = "";
150}

Downloadable files

schematic

Schema.png




Note: Content and images are from: https://projecthub.arduino.cc/, with some modifications.
If you want it removed due to copyright reasons, please leave a comment. Thank you.
I want to share this article more widely so that everyone knows about Arduino and your project.

Arduino Tutorial: Mini Piano

In this video I show you how to make a mini piano with Arduino. Devices and components Arduino Uno Rev3 Jumper wires (generic) Buzzer Breadb...