Skip to content

Commit 236a5de

Browse files
committed
Initial commit
0 parents  commit 236a5de

9 files changed

Lines changed: 1610 additions & 0 deletions

File tree

README.md

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
Morse Arduino
2+
=============
3+
This library sends Morse Code via toggling a specified output pin and/or toggling a boolean member variable which indicates the key state of the output.
4+
5+
**Please feel free to use the Issues feature of GitHub if you run into problems or have suggestions for important features to implement. This is the best way to get in touch.**
6+
7+
Thanks For Your Support!
8+
------------------------
9+
If you would like to support my library development efforts, please consider a [PayPal donation](https://paypal.me/NT7S) or purchasing something from the [Etherkit Store](https://www.etherkit.com). Thank you!
10+
11+
Library Installation
12+
---------------------
13+
The best way to install the library is via the Arduino Library Manager, which is available if you are using Arduino IDE version 1.6.2 or greater. To install it this way, simply go to the menu Sketch > Include Library > Manage Libraries..., and then in the search box at the upper-right, type "Etherkit Morse". Click on the entry in the list below, then click on the provided "Install" button. By installing the library this way, you will always have notifications of future library updates, and can easily switch between library versions.
14+
15+
If you need to or would like to install the library in the old way, then you can download a copy of the library in a ZIP file. Download a ZIP file of the library from the GitHub repository by using the "Download ZIP" button at the right of the main repository page. Extract the ZIP file, then rename the unzipped folder as "Etherkit_Morse". Finally, open the Arduino IDE, select menu Sketch > Import Library... > Add Library..., and select the renamed folder that you just downloaded. Restart the IDE and you should have access to the new library.
16+
17+
Hardware Requirements and Setup
18+
-------------------------------
19+
This library has been written for the Arduino platform, to be processor agnostic. It has been successfully tested on the Arduino Uno, an Uno clone, and an Empyrean (Arduino Zero derivative). In order to be platform independent, it requires that the end user call on the class _update()_ member function one time per millisecond. The details of the implementation are left up to the user, but it is best done using a timer interrupt service routine.
20+
21+
Example
22+
-------
23+
First, install the Morse library into your instance of the Arduino IDE as described above.
24+
25+
There two simple examples named **morse_example_avr.ino** and **morse_example_samd.ino** that are placed in your examples menu under the Etherkit Morse folder. Open one corresponding to the Arduino variant on which you will be running the example.
26+
27+
In order to use the Morse library in your sketch, you must first instantiate an object of class Morse:
28+
29+
Morse morse(LED_BUILTIN, 15);
30+
31+
The class constructor takes two parameters: the desired Morse code output pin and sending speed.
32+
33+
Each example implements a method for calling the Morse class _update()_ method every one millisecond so that Morse code can be sent with the proper timing. See each sketch for details and note that these examples are only one possible way to implement the update function. As long as the _update()_ method is called reliably every one millisecond, the Morse library will function as intended.
34+
35+
Now all that one has to do to send Morse code in real-time is to use the _send()_ method with the desired message to send as a string literal or C-type string (null delimited character array).
36+
37+
morse.send("HELLO WORLD");
38+
39+
Note that this library can accept lower or uppercase letters in the message buffer. The maximum message size is 100 characters.
40+
41+
Further Details
42+
---------------
43+
If you need to check to see if the Morse library is currently sending the contents of its message buffer, check the boolean _busy_ class member. Should you call the _send()_ method before the library is done sending a current message, the old buffer will be overwritten with the new message and sending of the new message will start immediately.
44+
45+
The sending speed can be changed on-the-fly by using the _setWPM()_ method. The parameter is typed using a _float_ so that fractional words per minute can be specified. Why would you want to do this? In case you need to send Morse code using a very long integration time such as with the QRSS operating mode. For example, a setting of 0.2 WPM sets a Morse code "dit" length of 6 seconds.
46+
47+
If you don't want to have the library directly control a digital I/O pin, you may have your sketch poll the boolean _tx_ member variable and act on it accordingly within their periodic 1 ms function.
48+
49+
Startup Conditions and Constraints
50+
----------------------------------
51+
The default output pin is defined as LED_BUILTIN while the default sending speed is 25 words per minute.
52+
53+
The maximum transmit buffer size is 100 characters.
54+
55+
Public Methods
56+
--------------
57+
### Morse() [class constructor]
58+
```
59+
/*
60+
* Morse::Morse(uint8_t tx_pin, float init_wpm) : output_pin(tx_pin)
61+
*
62+
* Create an instance of the Morse class.
63+
*
64+
* tx_pin - Arduino pin used as the output by this library.
65+
* init_wpm - Sending speed in words per minute.
66+
*
67+
*/
68+
Morse::Morse(uint8_t tx_pin, float init_wpm) : output_pin(tx_pin)
69+
```
70+
### update()
71+
```
72+
/*
73+
* void Morse::update()
74+
*
75+
* State machine for the Morse library.
76+
*
77+
* This must be called by the client sketch every one millisecond in order
78+
* for the library to accurately send Morse code.
79+
*
80+
*/
81+
void Morse::update()
82+
```
83+
### setWPM()
84+
```
85+
/*
86+
* void Morse::setWPM(float new_wpm)
87+
*
88+
* Set the Morse code sending speed.
89+
*
90+
* new_wpm - Sending speed in words per minute.
91+
*
92+
*/
93+
void Morse::setWPM(float new_wpm)
94+
```
95+
### send()
96+
```
97+
/*
98+
* void Morse::send(char * message)
99+
*
100+
* Send the specified message in Morse code on the output pin.
101+
*
102+
* message - String literal or zero-delimited string to transmit.
103+
*
104+
*/
105+
void Morse::send(char * message)
106+
```
107+
108+
Public Variables
109+
----------------
110+
float wpm;
111+
bool tx;
112+
bool tx_enable;
113+
uint8_t output_pin;
114+
bool busy;
115+
116+
Valid Characters
117+
----------------
118+
The standard uppercase and lowercase letters 'A' through 'Z' and digits '0' through '9' are of course supported, along with a handful of punctuation and special characters. The following table indicates the special characters supported along with the corresponding Morse code. Other input characters are ignored.
119+
120+
| Input Character | Morse Character |
121+
|-------------------|-----------------|
122+
| - (minus sign) | ➖➖ (M) |
123+
| / (slash) | ➖••➖• |
124+
| = (equal sign) | ➖•••➖ (BT) |
125+
| ? (question mark) | ••➖➖•• |
126+
127+
Changelog
128+
---------
129+
130+
* v1.0.0
131+
132+
* Initial release
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* morse_example_avr.ino - Simple example of using the Etherkit Morse library
3+
* on an AVR-based Arduino
4+
*
5+
* Copyright (C) 2018 Jason Milldrum <milldrum@gmail.com>
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
21+
#include <SimpleTimer.h>
22+
#include <Morse.h>
23+
24+
// Class declaration
25+
Morse morse(LED_BUILTIN, 15);
26+
SimpleTimer timer;
27+
28+
// a function to be executed periodically
29+
void repeatMe()
30+
{
31+
morse.update();
32+
}
33+
34+
void setup()
35+
{
36+
timer.setInterval(1, repeatMe);
37+
38+
delay(1000);
39+
morse.send("HELLO WORLD");
40+
}
41+
42+
void loop() {
43+
timer.run();
44+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* morse_example_samd.ino - Simple example of using the Etherkit Morse library
3+
* on a SAMD-based Arduino
4+
*
5+
* Copyright (C) 2018 Jason Milldrum <milldrum@gmail.com>
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
21+
#include <Morse.h>
22+
23+
// Constant expressions
24+
constexpr uint16_t TIMER_PRESCALER_DIV = 1024;
25+
26+
// Class declaration
27+
Morse morse(LED_BUILTIN, 15);
28+
29+
void setup()
30+
{
31+
startTimer(1000); // 1 ms ISR
32+
delay(1000);
33+
morse.send("HELLO WORLD");
34+
}
35+
36+
void loop()
37+
{
38+
// Let the ISR have all the fun
39+
}
40+
41+
// Timer code derived from:
42+
// https://github.com/nebs/arduino-zero-timer-demo
43+
44+
void setTimerFrequency(int frequencyHz)
45+
{
46+
int compareValue = (VARIANT_MCK / (TIMER_PRESCALER_DIV * frequencyHz)) - 1;
47+
TcCount16* TC = (TcCount16*) TC5;
48+
// Make sure the count is in a proportional position to where it was
49+
// to prevent any jitter or disconnect when changing the compare value.
50+
TC->COUNT.reg = map(TC->COUNT.reg, 0, TC->CC[0].reg, 0, compareValue);
51+
TC->CC[0].reg = compareValue;
52+
while (TC->STATUS.bit.SYNCBUSY == 1);
53+
}
54+
55+
/*
56+
This is a slightly modified version of the timer setup found at:
57+
https://github.com/maxbader/arduino_tools
58+
*/
59+
void startTimer(int frequencyHz)
60+
{
61+
REG_GCLK_CLKCTRL = (uint16_t) (GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | GCLK_CLKCTRL_ID (GCM_TC4_TC5)) ;
62+
while ( GCLK->STATUS.bit.SYNCBUSY == 1 );
63+
64+
TcCount16* TC = (TcCount16*) TC5;
65+
66+
TC->CTRLA.reg &= ~TC_CTRLA_ENABLE;
67+
68+
// Use the 16-bit timer
69+
TC->CTRLA.reg |= TC_CTRLA_MODE_COUNT16;
70+
while (TC->STATUS.bit.SYNCBUSY == 1);
71+
72+
// Use match mode so that the timer counter resets when the count matches the compare register
73+
TC->CTRLA.reg |= TC_CTRLA_WAVEGEN_MFRQ;
74+
while (TC->STATUS.bit.SYNCBUSY == 1);
75+
76+
// Set prescaler to 1024
77+
TC->CTRLA.reg |= TC_CTRLA_PRESCALER_DIV1024;
78+
while (TC->STATUS.bit.SYNCBUSY == 1);
79+
80+
setTimerFrequency(frequencyHz);
81+
82+
// Enable the compare interrupt
83+
TC->INTENSET.reg = 0;
84+
TC->INTENSET.bit.MC0 = 1;
85+
86+
NVIC_EnableIRQ(TC5_IRQn);
87+
88+
TC->CTRLA.reg |= TC_CTRLA_ENABLE;
89+
while (TC->STATUS.bit.SYNCBUSY == 1);
90+
}
91+
92+
void TC5_Handler()
93+
{
94+
TcCount16* TC = (TcCount16*) TC5;
95+
96+
if (TC->INTFLAG.bit.MC0 == 1)
97+
{
98+
TC->INTFLAG.bit.MC0 = 1;
99+
morse.update();
100+
}
101+
}

keywords.txt

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
Morse KEYWORD1
2+
3+
init KEYWORD2
4+
reset KEYWORD2
5+
set_freq KEYWORD2
6+
set_freq_manual KEYWORD2
7+
set_pll KEYWORD2
8+
set_ms KEYWORD2
9+
output_enable KEYWORD2
10+
drive_strength KEYWORD2
11+
update_status KEYWORD2
12+
set_correction KEYWORD2
13+
set_phase KEYWORD2
14+
get_correction KEYWORD2
15+
pll_reset KEYWORD2
16+
set_ms_source KEYWORD2
17+
set_int KEYWORD2
18+
set_clock_pwr KEYWORD2
19+
set_clock_invert KEYWORD2
20+
set_clock_source KEYWORD2
21+
set_clock_disable KEYWORD2
22+
set_clock_fanout KEYWORD2
23+
set_pll_input KEYWORD2
24+
set_vcxo KEYWORD2
25+
si5351_write_bulk KEYWORD2
26+
si5351_write KEYWORD2
27+
si5351_read KEYWORD2
28+
dev_status KEYWORD2
29+
dev_int_status KEYWORD2
30+
pll_assignment KEYWORD2
31+
clk_freq KEYWORD2
32+
plla_freq KEYWORD2
33+
pllb_freq KEYWORD2
34+
xtal_freq KEYWORD2
35+
36+
SI5351_PLL_FIXED LITERAL1
37+
SI5351_FREQ_MULT LITERAL1
38+
SI5351_DEFAULT_CLK LITERAL1
39+
SI5351_CRYSTAL_LOAD_0PF LITERAL1
40+
SI5351_CRYSTAL_LOAD_6PF LITERAL1
41+
SI5351_CRYSTAL_LOAD_8PF LITERAL1
42+
SI5351_CRYSTAL_LOAD_10PF LITERAL1
43+
SI5351_CLK0 LITERAL1
44+
SI5351_CLK1 LITERAL1
45+
SI5351_CLK2 LITERAL1
46+
SI5351_CLK3 LITERAL1
47+
SI5351_CLK4 LITERAL1
48+
SI5351_CLK5 LITERAL1
49+
SI5351_CLK6 LITERAL1
50+
SI5351_CLK7 LITERAL1
51+
SI5351_PLLA LITERAL1
52+
SI5351_PLLB LITERAL1
53+
SI5351_DRIVE_2MA LITERAL1
54+
SI5351_DRIVE_4MA LITERAL1
55+
SI5351_DRIVE_6MA LITERAL1
56+
SI5351_DRIVE_8MA LITERAL1
57+
SI5351_CLK_SRC_XTAL LITERAL1
58+
SI5351_CLK_SRC_CLKIN LITERAL1
59+
SI5351_CLK_SRC_MS0 LITERAL1
60+
SI5351_CLK_SRC_MS LITERAL1
61+
SI5351_CLK_DISABLE_LOW LITERAL1
62+
SI5351_CLK_DISABLE_HIGH LITERAL1
63+
SI5351_CLK_DISABLE_HI_Z LITERAL1
64+
SI5351_CLK_DISABLE_NEVER LITERAL1
65+
SI5351_FANOUT_CLKIN LITERAL1
66+
SI5351_FANOUT_XO LITERAL1
67+
SI5351_FANOUT_MS LITERAL1
68+
SI5351_PLL_INPUT_XO LITERAL1
69+
SI5351_PLL_INPUT_CLKIN LITERAL1
70+
SYS_INIT LITERAL1
71+
LOL_B LITERAL1
72+
LOL_A LITERAL1
73+
LOS LITERAL1
74+
REVID LITERAL1
75+
SYS_INIT_STKY LITERAL1
76+
LOL_B_STKY LITERAL1
77+
LOL_A_STKY LITERAL1
78+
LOS_STKY LITERAL1

library.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=Etherkit Morse
2+
version=1.0.0
3+
author=Jason Milldrum <milldrum@gmail.com>
4+
maintainer=Jason Milldrum <milldrum@gmail.com>
5+
sentence=Generate Morse Code for transmission on an digital I/O pin.
6+
paragraph=Provide this library with a function that calls every one millisecond, and it will generate Morse code for you on the digital pin and at the sending speed that you desire.
7+
category=Data Processing
8+
url=https://github.com/etherkit/MorseArduino
9+
architectures=*

0 commit comments

Comments
 (0)