Program to transmit strings as Morse code using the CC1200. Useful for amateur radio projects!

Dependencies:   CC1200 SerialStream

This project contains a class (CC1200Morse) to convert text into Morse code that can be transmitted over a CC1200 radio IC, and a test program for this class. This is useful for amateur radio projects which need to broadcast their call sign in order to operate legally, and just a cool demonstration of the flexibility of the CC1200.

How It Works

First, the input string is translated into Morse code using a conversion table. Nearly all ASCII characters contained in the Morse character set are supported. For example, the string "ha" would become " ···· · −". Then, the Morse code is converted into one and zero bits according to the standard Morse timing rules. " ···· · −" then becomes 10101010 00010111 000". Finally, these bits are enqueued into the radio's packet buffer and transmitted. The CC1200 is configured into OOK (On-Off Keying) mode, so a 1 bit is modulated as full transmit power, and a 0 bit is modulated as zero transmit power. The transmission will occur at the speed (specified as the time unit, or the length of a dot) that you configure. Note that the CC1200 does the transmission in the background, so your processor can enqueue up to 128 bytes worth of Morse and then go do other things while it transmits at a human readable speed. You can't enqueue two packets at a time though.

Demo Video

Hardware Setup

This program assumes that a CC1200 radio is connected to your processor's SPI bus. The CC1200's circuit board must be configured for the 900MHz band (though you could also change the frequency in the code to match your boards).

I used a custom circuit board for my testing, but you should also be able to use an Mbed board connected to an CC1200 eval kit to run the program. Make sure to edit the #defines at the top of main.cpp to match the pins that your equipment is plugged into!

Note: License free transmission on the 900MHz band is only legal in Region 2 countries (North and South America). Make sure to follow all local regulations covering radio transmissions!

Committer:
Jamie Smith
Date:
Sat Aug 29 03:06:11 2020 -0700
Revision:
0:9e9ede3ac523
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jamie Smith 0:9e9ede3ac523 1 //
Jamie Smith 0:9e9ede3ac523 2 // Class allowing you to transmit Morse code using the CC1200 radio
Jamie Smith 0:9e9ede3ac523 3 //
Jamie Smith 0:9e9ede3ac523 4
Jamie Smith 0:9e9ede3ac523 5 #ifndef LIGHTSPEEDRANGEFINDER_CC1200MORSE_H
Jamie Smith 0:9e9ede3ac523 6 #define LIGHTSPEEDRANGEFINDER_CC1200MORSE_H
Jamie Smith 0:9e9ede3ac523 7
Jamie Smith 0:9e9ede3ac523 8 #include <CC1200.h>
Jamie Smith 0:9e9ede3ac523 9
Jamie Smith 0:9e9ede3ac523 10 class CC1200Morse
Jamie Smith 0:9e9ede3ac523 11 {
Jamie Smith 0:9e9ede3ac523 12 CC1200 & radio;
Jamie Smith 0:9e9ede3ac523 13
Jamie Smith 0:9e9ede3ac523 14 // time units at the start and end of the morse message.
Jamie Smith 0:9e9ede3ac523 15 const size_t spaceBefore = 3;
Jamie Smith 0:9e9ede3ac523 16 const size_t spaceAfter = 3;
Jamie Smith 0:9e9ede3ac523 17
Jamie Smith 0:9e9ede3ac523 18 public:
Jamie Smith 0:9e9ede3ac523 19
Jamie Smith 0:9e9ede3ac523 20 CC1200Morse(CC1200 & _radio):
Jamie Smith 0:9e9ede3ac523 21 radio(_radio){}
Jamie Smith 0:9e9ede3ac523 22
Jamie Smith 0:9e9ede3ac523 23 /**
Jamie Smith 0:9e9ede3ac523 24 * Configure the CC1200 to transmit morse code.
Jamie Smith 0:9e9ede3ac523 25 *
Jamie Smith 0:9e9ede3ac523 26 * @param band Radio band containing the frequency.
Jamie Smith 0:9e9ede3ac523 27 * @param radioFrequency Frequency to transmit on.
Jamie Smith 0:9e9ede3ac523 28 * @param morseTimePeriod Time unit in seconds to use when transmitting.
Jamie Smith 0:9e9ede3ac523 29 * @param transmitPower Power in dBm to transmit at. Must be in the CC1200 allowed range.
Jamie Smith 0:9e9ede3ac523 30 * Dots are one time unit, dashes are three.
Jamie Smith 0:9e9ede3ac523 31 * 50ms is about the fastest a human can understand, while 125ms is a more reasonable speed.
Jamie Smith 0:9e9ede3ac523 32 * Specifics are here: http://www.codebug.org.uk/learn/step/541/morse-code-timing-rules/#:~:text=The%20space%20between%20symbols%20(dots,words%20is%207%20time%20units.
Jamie Smith 0:9e9ede3ac523 33 */
Jamie Smith 0:9e9ede3ac523 34 void configure(CC1200::Band band, float radioFrequency, float morseTimePeriod, float transmitPower);
Jamie Smith 0:9e9ede3ac523 35
Jamie Smith 0:9e9ede3ac523 36 struct EncodedMorse
Jamie Smith 0:9e9ede3ac523 37 {
Jamie Smith 0:9e9ede3ac523 38 /// Whether this morse data is valid.. If false, it couldn't be encoded due to an error.
Jamie Smith 0:9e9ede3ac523 39 bool valid;
Jamie Smith 0:9e9ede3ac523 40
Jamie Smith 0:9e9ede3ac523 41 /// Buffer storing morse data. Uses memory passed to configure()
Jamie Smith 0:9e9ede3ac523 42 uint8_t const * buffer;
Jamie Smith 0:9e9ede3ac523 43
Jamie Smith 0:9e9ede3ac523 44 /// Number of complete bytes and bits used in the data
Jamie Smith 0:9e9ede3ac523 45 size_t byteLen;
Jamie Smith 0:9e9ede3ac523 46 uint8_t bitLen;
Jamie Smith 0:9e9ede3ac523 47
Jamie Smith 0:9e9ede3ac523 48 // Number of bytes in the buffer that are at least partially filled.
Jamie Smith 0:9e9ede3ac523 49 size_t totalLength;
Jamie Smith 0:9e9ede3ac523 50 };
Jamie Smith 0:9e9ede3ac523 51
Jamie Smith 0:9e9ede3ac523 52 /**
Jamie Smith 0:9e9ede3ac523 53 * Convert ASCII text into characters suitable to be sent over the radio.
Jamie Smith 0:9e9ede3ac523 54 * Some ASCII characters do not have a morse equivalent, these will be removed.
Jamie Smith 0:9e9ede3ac523 55 *
Jamie Smith 0:9e9ede3ac523 56 * @param string ASCII string to convert.
Jamie Smith 0:9e9ede3ac523 57 * @param outputBuffer Buffer to write morse into. Will be zeroed.
Jamie Smith 0:9e9ede3ac523 58 * @return Encoded morse data, if there was insufficient space valid will be false.
Jamie Smith 0:9e9ede3ac523 59 */
Jamie Smith 0:9e9ede3ac523 60 EncodedMorse convertToMorse(const char* string, uint8_t * outputBuffer, size_t bufferLen);
Jamie Smith 0:9e9ede3ac523 61
Jamie Smith 0:9e9ede3ac523 62 /**
Jamie Smith 0:9e9ede3ac523 63 * Queue this morse code to be transmitted over the radio.
Jamie Smith 0:9e9ede3ac523 64 * Packets with a total length larger than 128 bytes cannot be transmitted (though this limit
Jamie Smith 0:9e9ede3ac523 65 * could be worked around).
Jamie Smith 0:9e9ede3ac523 66 *
Jamie Smith 0:9e9ede3ac523 67 * The packet will be transmitted as soon as the radio is switched to TX state.
Jamie Smith 0:9e9ede3ac523 68 * If it's already in TX then it will be transmitted immediately.
Jamie Smith 0:9e9ede3ac523 69 * @param morse
Jamie Smith 0:9e9ede3ac523 70 */
Jamie Smith 0:9e9ede3ac523 71 void transmit(EncodedMorse const & morse);
Jamie Smith 0:9e9ede3ac523 72 };
Jamie Smith 0:9e9ede3ac523 73
Jamie Smith 0:9e9ede3ac523 74
Jamie Smith 0:9e9ede3ac523 75 #endif //LIGHTSPEEDRANGEFINDER_CC1200MORSE_H