Data transmission to an Arduino through Morse code
Dec 27, 2020 10:19 · 2235 words · 11 minute read
In this video I ’d like to demonstrate simple ways to exchange data with microcontrollers over the air.
00:14 - As little helpers, I am using several boards with an 8x8 LED matrix that I have shown in detail in previous videos.
00:22 - For the examples shown in this video, microcontrollers type ATmega328 communicate with each other, two of them on Arduino UNO boards.
00:33 - I will use acoustic signals in my examples and as a sender I am using my hand…
00:44 -… and a mini speaker,… … while microphones are used as a receivers.
00:55 - While recording the sequences for this video, I found that attaching a low-pass filter to the input voltage of the microphone module is needed to increase the sensitivity and reduce noise - more on this on my website.
01:10 - Computers, which include microcontrollers, do not communicate via spoken words, instead binary signals are commonly used.
01:18 - As a first example I will knock on the table to transmit data - in the simplest case the number of knocks corresponds to a letter in the alphabet.
01:27 - Knocking always produces a very short noise - the data to be transmitted must therefore be encoded by the pause between two knocks.
01:36 - In this example, a longer pause means that the character has been transmitted - it is then displayed on the screen.
01:44 - A disadvantage of this method is that up to 26 knocks have to be done for just one letter.
01:53 - Another problem is that every sound that exceeds the given threshold is misinterpreted as the transmission of a letter.
02:05 - Next, I use the so-called tap code to transmit data: 25 letters of the alphabet are listed in a table with 5 columns and 5 rows.
02:18 - A letter is transmitted by tapping the number of rows followed by the number of columns - there is a longer pause between the two, also after the transmission of the letter has been completed.
02:29 - After the Arduino has received the row number, a ‘+’ is displayed, indicating that the microcontroller waits for the column to be transmitted.
02:37 - After receiving the column number, the decoded letter is displayed.
02:42 - If the received number of rows or columns is too large, a transmission error is detected and the microcontroller jumps back to the previous letter.
02:54 - The same applies for a to too long a pause between the two tap signals.
03:03 - A maximum of 10 taps is required for one letter, so more data than in the first example can be transmitted per time unit.
03:14 - This procedure is somewhat more stable when it comes to misinterpretation of background noise: As long as not two tap sequences with the required pause are received, the software can recognize the transmission as faulty and jumps back to the previous state.
03:32 - However, this method is also not totally safe against interference.
03:39 - The Morse alphabet offers a way of transmitting letters with even fewer knocking signals, but this method uses more different signal states: A short and a long tone, as well as the pauses in between.
03:58 - Since a long tone cannot be produced when knocking, the distinction between “long” and “short” must be made using the pauses.
04:06 - However, following this system, for example the two letters “D”…
04:12 -… and “K”… … sound identically because the last knock cannot be identified as “short” or “long”.
04:23 - A way out of this dilemma is to add a terminating tap at the end of each letter: So the “D” becomes…
04:35 -… and the K now is… The two letters can now be distinguished, same as all other letters of the alphabet, as well as the digits and some special characters.
04:59 - As a separator between two words, either an even longer pause can be inserted, or a special character can be transmitted, which indicates that the transmission of a word has been completed.
05:10 - In computer age, the “space” is used for this, although it does not appear in Morse Code, but new times require new characters - I use long, long, long, short - and don’t forget the teminating knock at the end.
05:26 - With this modified Morse code you can transfer any text to a microcontroller quite effectively by clapping or knocking.
05:39 - What happens if two of my little helpers are present? Well, both receive the same signals, so the knocked message can be read on both target systems.
05:54 - If you want to transmit data to only one of the two microcontrollers, in addition to the standard for coding letters, another standard for addressing a special target must be created for all listening systems: One method is to assign a unique number, a so called “address”, to each of the microcontrollers.
06:12 - The digits 0 to 9 are suitable for up to 10 addresses.
06:17 - Each transmission must start by tapping the address of the target system: If the left microcontroller has the address “0” and the right one the address “1”, the transmission to the right target begins with “1”, in the Morse code with short, followed by four times long signal and of course the terminating tap.
06:36 - The right microcontroller indicates with a ‘+’ that it is waiting for more characters to be transmitted, while the left microcontroller indicates with a ‘-’ that it is ignoring these characters.
06:48 - When knocked like this, the message is finally only displayed on the right screen, while the left screen goes back to the old message.
06:59 - Another advantage of this system is that not every environmental sound is misinterpreted as a command to change the displayed message: While without an address, almost every sound exceeding a certain threshold is interpreted as a letter…
07:17 -… nothing happens as long as that sound doesn’t accidentally correspond to the appropriate address of the microcontroller.
07:37 - As already said, knocking can only produce a short sound.
07:43 - With a loudspeaker, tones can be used for data transmission, whereby the tone length can be used as an additional element for coding the characters besides to the pause length.
07:55 - We can therefore use the unmodified Morse alphabet - the terminating signal is no longer required, so data transmission is a bit faster.
08:08 - So far I have only transferred data to the microcontrollers - it is getting more interesting when all systems involved are able to communicate with each other.
08:24 - As an example, I am now asking which letter the microcontroller is currently displaying.
08:29 - Here, too, there must be a standard that says when a microcontroller should send data - for that purpose I use another special character that I define as long, short, long, short, long: The microcontroller replies with long, short, long, which corresponds to the stored letter ‘K’.
08:58 - If several microcontrollers are within range, they all answer at the same time and the resulting cacophony doesn’t allow to decode the messages.
09:11 - Here, too the standard must indicate which of the devices in range should answer, which happens by sending its address as the first code.
09:19 - Here microcontroller 3 is queried, which answers initially with its own address,…
09:29 -… and afterwards with short, long, short, which corresponds to the letter ‘R’.
09:37 - Discipline is required because I cannot start another request until the full answer has been received.
10:05 - According to this principle, the microcontrollers can exchange data with one another: I initiate the queries among the chain of microcontrollers by requesting the stored letter of the rightmost target system.
10:23 - The controller responds with its address and long, long, long, short for the saved “space”.
10:31 - This microcontroller then asks for the letter stored by the microcontroller to its left, which causes that letter to move one position to the right.
10:47 - This wandering runs through the whole chain of microcontrollers from right to left by automatically sending the corresponding commands.
11:05 - The currently active microcontroller first sends its own character to the right microcontroller by morsing this address and the stored letter.
11:20 - After that is done, the address of the microcontroller to the left is morsed,…
11:27 -… and the stored letter of this microcontroller is requested.
11:32 - If you looked closely, you will have noticed that I now soldered the low-pass filter to the microphones as mentioned at the beginning of the video.
11:40 - With that, the sensitivity of these sensors is significantly higher so that the microcontrollers in the chain receive the acoustic signals of their neigbours cleanly.
11:50 - When the process is complete, which is indicated by the fact that the leftmost microcontroller is no longer displaying anything, I can transfer the next letter to that first microcontroller in the chain.
12:06 - As already shown, several letters or words can be transmitted to a microcontroller - the message is then displayed as ticker.
12:17 - Noise can cause a transmission to run incorrectly.
12:31 - Additional commands must therefore be added to the transmission standard to ensure that communication has taken place without errors.
12:44 - To do this, I create a new code table in which all characters consist of 8 tones, with which theoretically 256 different combinations are possible.
12:55 - Since 51 combinations are sufficient to transfer text and digits as well as some special characters, I only use every fifth possible combination.
13:06 - An error in the transmission can now be detected in two ways: On the one hand, each character must consist of 8 tones, followed by a longer pause - if this is not the case, at least one tone must have been omitted or additional tones have falsely been identified due to background noise.
13:25 - If 8 tones were correctly received, but a “long” was interpreted as “short” or vice versa, there is a chance of 4 to 5 that this combination cannot be assigned to any valid character, so that the transmission is also recognized as faulty.
13:41 - A special character signals to the sender that the message must be repeated, the screen shows the number of errors found.
13:59 - The modified Morse code is very effective because it only transmits a limited number of characters.
14:04 - The screens of our small computer boards consist of 64 LEDs, which can represent 2 raised by the power of 64 different combinations - which is a huge number.
14:16 - In order to display a combination of LEDs that does not correspond to any of the stored letters, a standard must be defined that allows any graphics to be transmitted.
14:27 - This can be done by another special character indicating that the following signals must be assigned to a graphic.
14:39 - After this special character, 64 tones are transmitted, whereby a “long” corresponds to a switched on LED and a “short” to a switched off LED.
14:49 - The transmission takes much longer than sending a simple letter, the shape of which is stored in each of the microcontrollers.
14:55 - Sending graphics instead of letters is the reason why Powerpoint clowns have to transmit so much more data than people who understand to put their message into simple words and numbers.
15:07 - Even in the age of Gigabytes and Gigahertz, “keep it simple” is the mantra that coders must follow.
15:20 - The basic rules of data transmission with acoustic signals also apply to wired communication: Electromagnetic waves move along copper or fiber optic cables, in the latter in the form of light waves through the medium.
15:34 - Here, I lock the sound waves in two hoses that run from the loudspeaker of one microcontroller to the microphone of the other microcontroller.
15:43 - This means that the sounds can hardly be heard outside - the two microcontrollers now communicate via the rubber cables.
15:54 - A major advantage of wired communication is that ambient noise is largely blocked - even with the simple Morse code, the transmission succeeds without errors despite external background noise.
16:21 - Light signals can also be used for data transmission without fiber optics - here I am using an infrared interface.
16:27 - The same basic rules apply to addressing the microcontroller and to coding the information - I use the Morse alphabet once more for data transmission to the 5 target systems.
16:40 - That’s all for my introduction to the world of data transmission - as always, more information as well as the software examples used in this video can be found on my website.
16:50 - If you want to support me in my efforts to create more such learning videos that can be copied, edited and shared by anyone for free, you are welcome to click the “Donate” button on my website - many thanks to all existing backers! There’s a lot to be said, for example, on the subject of frequency detection with microcontrollers in order to be able to transfer data more efficiently.
17:16 - Thanks for watching and: “I’ll be back!”.