-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathTeensyFMTransmitter.ino
118 lines (95 loc) · 3.51 KB
/
TeensyFMTransmitter.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
/*
Output FM for Teensy 4
Compatible to Audio Library
Legal note
TeensyFMTransmitter is an experimental program, designed only for experimentation.
It is in no way intended to become a personal media center or a tool to operate a radio station,
or even broadcast sound to one's own stereo system.
In most countries, transmitting radio waves without a state-issued licence specific
to the transmission modalities (frequency, power, bandwidth, etc.) is illegal.
Therefore, always connect a shielded transmission line from the Teensy directly to a radio receiver,
so as not to emit radio waves. Never use an antenna.
Even if you are a licensed amateur radio operator, using TeensyFMTransmitter to transmit
radio waves on ham frequencies without any filtering between the Teensy and an antenna is most probably illegal
because the square-wave carrier is very rich in harmonics, so the bandwidth requirements are likely not met.
I could not be held liable for any misuse of your own Teensy.
Any experiment is made under your own responsibility.
Data files to put on your SD card can be downloaded here:
http://www.pjrc.com/teensy/td_libs_AudioDataFiles.html
2021, Frank B
*/
#include <Audio.h>
#include <SD.h>
#include "output_fm.h"
AudioPlaySdWav playWav1;
//AudioOutputFM fm(33, 91.0, PREEMPHASIS_75); //Pin (23= I2S1, 30= I2S3, 33= I2S2) , Frequency in MHz, preemphasis
AudioOutputFM fm(33, 107, PREEMPHASIS_50); //Pin (23= I2S1, 30= I2S3, 33= I2S2) , Frequency in MHz, preemphasis
AudioConnection patchCord1(playWav1, 0, fm, 0);
AudioConnection patchCord2(playWav1, 1, fm, 1);
#define MAXRUNTIME (10 * 60 * 1000) // 10 Minutes
unsigned long starttime = millis();
void setup()
{
AudioMemory(8);
if (!(SD.begin(BUILTIN_SDCARD))) {
while (1) {
Serial.println("Unable to access the SD card");
delay(500);
}
}
#if FM_STEREO_RDS
//optional:
fm.setPI(42); //Program Identification-Nr
fm.setPTY(1); //News
fm.setTA(0); //No Traffic Announcements
fm.setTP(0); //No Traffic Program
fm.setPS("Teensy"); //max 8 chars
#endif
}
//optional:
void textStateMachine(const char *filename)
{
#if FM_STEREO_RDS
static int state = 0;
if (!fm.transmitted()) return;
// '\n' is "clear screen" in RDS protocol.
// the fm object filters "\r\n" -> it becomes "\r"
// But: '\r' "Carriage Return" does not work on all receivers.
// IF it works, it should be displayed as a new line.
switch (state++)
{
case 0 : fm.printf("%s Diag: Audio %2.2f%% FM: %2.2f%% ", filename, (double)(AudioProcessorUsage()), (double)((fm.time_us() / 2902.0f) * 100.0f) ); break;
// case 1 : fm.println("Peter Piper picked mixed pickles"); break;
default : state = 0; break;
}
#endif
}
void playFile(const char *filename)
{
Serial.print("Playing file: ");
Serial.println(filename);
playWav1.play(filename);
delay(25);
while (playWav1.isPlaying())
{
delay(1500);
if ( fm.enabled() ) {
Serial.printf("Diagnostics AudioLib:%0.2f%% FM:%dus\n", (double)AudioProcessorUsage(), fm.time_us() );
textStateMachine(filename);
unsigned runtime = millis() - starttime;
if (runtime > MAXRUNTIME) fm.enable(false); //disable transmitter
} else
Serial.println("Transmitter disabled");
}
}
void loop()
{
playFile("SDTEST2.WAV"); // filenames are always uppercase 8.3 format
delay(500);
playFile("SDTEST3.WAV");
delay(500);
playFile("SDTEST4.WAV");
delay(500);
playFile("SDTEST1.WAV");
delay(500);
}