Skip to main content
Chemistry LibreTexts

2: Serial and Morse Code

  • Page ID
    433829
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)

    ( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\id}{\mathrm{id}}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\kernel}{\mathrm{null}\,}\)

    \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\)

    \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\)

    \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    \( \newcommand{\vectorA}[1]{\vec{#1}}      % arrow\)

    \( \newcommand{\vectorAt}[1]{\vec{\text{#1}}}      % arrow\)

    \( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vectorC}[1]{\textbf{#1}} \)

    \( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)

    \( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)

    \( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)

    \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    The earliest forms of serial communication were probably drumbeats and smoke signals. An early alphabetical system would be the Semaphore flag signaling system or optical telegraph that allowed ships to communicate. In the 1830's Samuel Morse and others invented the telegraph, which transmitted electrical signals over a wire, coding information in the forms of dots and dashes (short and long signals). Today information is coded in bits and we have already looked at multiple binary digital data representations like strings, integers and float. Although electronics have evolved since the days of the Morse Code, there is still a common binary component to digital information representation and communication across devices. In this activity we will develop a Morse Code based system as an introduction to digital communication.

    clipboard_e04af0a0595f5e17bc22ce24cff605935.pngFigure \(\PageIndex{1}\): Copper Telegraph Machine 1837-1843. (Public Domain, Metropolitan Museum of Art, NY)

     

    Series 

    Most of the devices we will work in this class transmit data through a variety of series communication protocols, and this class will cover several of this. But first, there are a few terms you need to understand with respect to the description of data transfer across devices.  Devices hooked in series have either one wire, or two.  When there are two wires each is unidirectional, with one sending data from device A to device B, while the other goes in the opposite direction and sends data from device B to device A.

    Modes of Operation

    There are three basic modes of operation for data transmission along a wire

    • Simplex
      • data only goes in one direction
      • Would be use for something like controlling an array of LEDs, they do not send data, only receive it
    • Half-Duplex
      • data transmission goes in both directions, but is not simultaneous.  
    • Full-Duplex
      • simultaneous data transmission in both directions.

    Baud (Bd) Rate

    Baud rate is a measure of how quick data can be transferred along a line and is named after  Émile Baudot for the Baudot code in early telegraphy. The baud rate is the number of symbols (or pulses) per second and the gross baud rate is the number of bits per second.  If there are exactly two symbols (0 and 1) then the baud rate equals the bit rate. What is important is that the transmitting device is operating at the same baud rate as the receiving and you may need to check this in your code. Standard baud rates range from 110Bd to 256kBd.

    Communication Protocols

    It is through protocols that electronic devices can communicate data. The data is transmitted as bits. There are two ways bit can be identified, either as high or low values, or the time a value is high (or low).

    Some common serial communications protocols that are germane to IOT are:

    Morse Code

    Morse code represents the alphabet by using two characters, dashes and dots, as given in table \(\PageIndex{1}\). Note, there is actually a third entity in the code, which is the space between the dashes and the dots. In Morse code (unlike many digital systems) the number of characters varies from letter to letter, with commonly used letters having few characters and infrequently used letters (or symbols) having more characters ("E" is a dot, "T" is a dash, but a hyphen is dash-dot-dot-dot-dot-dash. Because this is being detected and transmitted by a human the amount of time to send information is very long, but in principle, this is a form of serial communication.

    A • – K – • – U • • – 0 – – – – –
    B – • • • L • – • • V • • • – 1 • – – – –
    C – • – • M – – W • – – 2 • • – – –
    D – • • N – • X – • • – 3 • • • – –
    E O – – – Y – • – – 4 • • • • –
    F • • – • P • – – • Z – – • • 5 • • • • •
    G – – • Q – – • – Period • – • – • – 6 – • • • •
    H • • • • R • – • Comma – – • • – – 7 – – • • •
    I • • S • • • Hyphen – • • • • – 8 – – – • •
    J • – – – T Colon – – – • • • 9 – – – – •
    Table \(\PageIndex{1}\): Morse Code 

    In order to construct a sentence and transmit that information you need to not only identify each character in a letter, but when you are separating letters from letters in the same word, and between different words. For example six dots (\( \cdot \cdot \cdot \cdot \cdot  \cdot  \)) could be HI or EEEEEE or 5E or E5 or SS or EESE or ESSE or.... you get the problem. So you need to develop a set of protocols to indicate the difference between the dashes, the dots and the time delay between them. Here is a protocol adapted from Bob LeSeyer and FeAtHEr-Cm

    Morse Code Translator

    The following code comes from GeeksforGeeks.  In a future activity you will make an LED Morse code transmitter and some of this code will be useful.

    # Python program to implement Morse Code Translator
     
    '''
    VARIABLE KEY
    'cipher' -> 'stores the morse translated form of the english string'
    'decipher' -> 'stores the english translated form of the morse string'
    'citext' -> 'stores morse code of a single character'
    'i' -> 'keeps count of the spaces between morse characters'
    'message' -> 'stores the string to be encoded or decoded'
    '''
     
    # Dictionary representing the morse code chart
    MORSE_CODE_DICT = { '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':'-----', ', ':'--..--', '.':'.-.-.-',
                        '?':'..--..', '/':'-..-.', '-':'-....-',
                        '(':'-.--.', ')':'-.--.-'}
     
    # Function to encrypt the string
    # according to the morse code chart
    def encrypt(message):
        cipher = ''
        for letter in message:
            if letter != ' ':
     
                # Looks up the dictionary and adds the
                # corresponding morse code
                # along with a space to separate
                # morse codes for different characters
                cipher += MORSE_CODE_DICT[letter] + ' '
            else:
                # 1 space indicates different characters
                # and 2 indicates different words
                cipher += ' '
     
        return cipher
     
    # Function to decrypt the string
    # from morse to english
    def decrypt(message):
     
        # extra space added at the end to access the
        # last morse code
        message += ' '
     
        decipher = ''
        citext = ''
        for letter in message:
     
            # checks for space
            if (letter != ' '):
     
                # counter to keep track of space
                i = 0
     
                # storing morse code of a single character
                citext += letter
     
            # in case of space
            else:
                # if i = 1 that indicates a new character
                i += 1
     
                # if i = 2 that indicates a new word
                if i == 2 :
     
                     # adding space to separate words
                    decipher += ' '
                else:
     
                    # accessing the keys using their values (reverse of encryption)
                    decipher += list(MORSE_CODE_DICT.keys())[list(MORSE_CODE_DICT
                    .values()).index(citext)]
                    citext = ''
     
        return decipher
     
    # Hard-coded driver function to run the program
    def English2Morse():
        message = input("Enter English message you want transmitted to morse code. ")
        result = encrypt(message.upper())
        print (result)
    
    def Morse2English():
        message = input("Enter Morse code message you want transmitted to English code. ")
        result = decrypt(message)
        print (result)
    
    action=input("Enter e2m if you want to convert English to Morse and m2e if you want to convert Morse to English")
    # Executes the main function
    if action == 'e2m':
        English2Morse()
    elif action == 'm2e':
        Morse2English()
    else:
        print("you did not make a valid request")
        
    
    Hello world!

     

     

    Resources and References


    This page titled 2: Serial and Morse Code is shared under a not declared license and was authored, remixed, and/or curated by Robert Belford.

    • Was this article helpful?