-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrtty-arduino-beacon-audio.ino
191 lines (164 loc) · 4.24 KB
/
rtty-arduino-beacon-audio.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
Basic RTTY Arduino audio Beacon
See README in https://github.com/lu1aat/rtty-arduino-beacon-audio for instructions.
TL;DR:
- Connect OUT_PIN to speaker "+" and speaker "-" to GND, should output RTTY audio.
- Change MESSAGE for the beacon message and SLEEP_SEC for beacon internal
*/
#define MARK 1
#define SPACE 0
// Settings
const int OUT_PIN = 13;
const int SLEEP_SEC = 60;
char MESSAGE[] = "CQ CQ CQ DE N0CALL N0CALL N0CALL";
// char MESSAGE[] = "CQ CQ CQ DE ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789";
//
// TONES, mark and space
//
const int markFreqHz = 2125;
const int shiftFreqHz = 170;
const int spaceFreqHz = markFreqHz - shiftFreqHz;
const int toneDurationMs = 22;
// Send mark/space tones to a pin
void toneSwitch(bool mark) {
if (mark) {
tone(OUT_PIN, markFreqHz);
} else {
tone(OUT_PIN, spaceFreqHz);
}
}
//
// ASCII + custom to Baudot symbols
//
// 0-9 group is ASCII 48-57 located fom 25 to 35
// A-Z group is ASCII 65-90 located from 0 to 25
int symbolTable[][5] = {
{1, 1, 0, 0, 0}, // 0 A
{1, 0, 0, 1, 1}, // 1 B
{0, 1, 1, 1, 0}, // 2 C
{1, 0, 0, 1, 0}, // 3 D
{1, 0, 0, 0, 0}, // 4 E
{1, 0, 1, 1, 0}, // 5 F
{0, 1, 0, 1, 1}, // 6 G
{0, 0, 1, 0, 1}, // 7 H
{0, 1, 1, 0, 0}, // 8 I
{1, 1, 0, 1, 0}, // 9 J
{1, 1, 1, 1, 0}, // 10 K
{0, 1, 0, 0, 1}, // 11 L
{0, 0, 1, 1, 1}, // 12 M
{0, 0, 1, 1, 0}, // 13 N
{0, 0, 0, 1, 1}, // 14 O
{0, 1, 1, 0, 1}, // 15 P
{1, 1, 1, 0, 1}, // 16 Q
{0, 1, 0, 1, 0}, // 17 R
{1, 0, 1, 0, 0}, // 18 S
{0, 0, 0, 0, 1}, // 19 T
{1, 1, 1, 0, 0}, // 20 U
{0, 1, 1, 1, 1}, // 21 V
{1, 1, 0, 0, 1}, // 22 W
{1, 0, 1, 1, 1}, // 23 X
{1, 0, 1, 0, 1}, // 24 Y
{1, 0, 0, 0, 1}, // 25 Z
{0, 1, 1, 0, 1}, // 26 0
{1, 1, 1, 0, 1}, // 27 1
{1, 1, 0, 0, 1}, // 28 2
{1, 0, 0, 0, 0}, // 29 3
{0, 1, 0, 1, 0}, // 30 4
{0, 0, 0, 0, 1}, // 31 5
{1, 0, 1, 0, 1}, // 32 6
{1, 1, 1, 0, 0}, // 33 7
{0, 1, 1, 0, 0}, // 34 8
{0, 0, 0, 1, 1}, // 35 9
{0, 0, 1, 0, 0}, // 36 SPACE
{0, 0, 0, 1, 0}, // 37 CR
{0, 1, 0, 0, 0}, // 38 LF
{1, 1, 0, 1, 1}, // 39 NUMBERS
{1, 1, 1, 1, 1} // 40 LETTERS
};
void rttyTxBits(int bits[]) {
// Start bit
rttyStartBit();
// 5 data bits
for(byte i = 0; i < 5; i++) {
int symbol = 0;
symbol = bits[i];
toneSwitch(symbol);
delay(toneDurationMs);
}
// Stop bit
rttyStopBit();
}
// Switch RTTY mode from numbers to letters, true for letters
void rttyMode(bool letters) {
if(letters) {
rttyTxBits(symbolTable[40]);
} else {
rttyTxBits(symbolTable[39]);
}
}
void rttyStartBit() {
// Start bit
toneSwitch(SPACE);
delay(toneDurationMs);
}
void rttyStopBit() {
// Stop bit
toneSwitch(MARK);
delay(toneDurationMs * 1.5);
}
void rttyTx(char message[]) {
// Set MARK for 200ms
toneSwitch(MARK);
delay(200);
// Letters of numbers mode and previous mode, letters by default
bool numbersMode = false;
bool numbersModePrev = false;
// Iter over message characters
for(byte i = 0; i < strlen(message); i++) {
// Calculate charcter position in symbol table
int symbolIndex = 0;
int symbolShift = 65;
// Numbers shift
if (message[i] < 58 && message[i] != 32) {
numbersMode = true;
symbolShift = 22;
if(!numbersModePrev) {
rttyMode(0);
}
} else {
// Letters
numbersMode = false;
if(numbersModePrev) {
rttyMode(1);
}
}
numbersModePrev = numbersMode;
symbolIndex = message[i] - symbolShift;
// Check for SPACE, DEC 32 in ASCII force to "SPACE" symbol
if(message[i] == 32) {
symbolIndex = 36;
}
// TX Character
rttyTxBits(symbolTable[symbolIndex]);
}
// End of message
rttyTxBits(symbolTable[37]); // CR
rttyTxBits(symbolTable[37]); // LF
noTone(OUT_PIN);
}
//
// Setup
//
void setup() {
// Set output PIN as OUTPUT
pinMode(OUT_PIN, OUTPUT);
}
//
// Loop
//
void loop() {
// TX
rttyTx(MESSAGE);
// Sleep
delay(SLEEP_SEC * 1000UL);
}