Skip to content

Commit c87021a

Browse files
committed
Serial example
1 parent 2491ecc commit c87021a

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* @file example-serial-send.ino
3+
* @author Phil Schatzmann
4+
* @brief Sending and receiving audio via Serial. You need to connect the RX pin
5+
* with the TX pin!
6+
*
7+
* @version 0.1
8+
* @date 2022-03-09
9+
*
10+
* @copyright Copyright (c) 2022
11+
*/
12+
13+
#include "AudioTools.h"
14+
// #include "AudioLibs/AudioKit.h"
15+
16+
AudioInfo info(22000, 1, 16);
17+
SineWaveGenerator<int16_t> sineWave(32000);
18+
GeneratedSoundStream<int16_t> sound(sineWave);
19+
I2SStream out; // or AudioKitStream
20+
StreamCopy copierOut(Serial, sound, 256); // copies sound into i2s
21+
StreamCopy copierIn(out, Serial, 256); // copies sound into i2s
22+
23+
void setup() {
24+
Serial2.begin(115200);
25+
AudioLogger::instance().begin(Serial2, AudioLogger::Warning);
26+
27+
// Note the format for setting a serial port is as follows:
28+
// Serial2.begin(baud-rate, protocol, RX pin, TX pin);
29+
Serial.begin(1000000, SERIAL_8N1);
30+
31+
// Setup sine wave
32+
sineWave.begin(info, N_B4);
33+
34+
// start I2S
35+
Serial.println("starting I2S...");
36+
auto config = out.defaultConfig(TX_MODE);
37+
config.copyFrom(info);
38+
out.begin(config);
39+
40+
Serial.println("started...");
41+
}
42+
43+
void loop() {
44+
// copy to serial
45+
copierOut.copy();
46+
// copy from serial
47+
copierIn.copy();
48+
}

0 commit comments

Comments
 (0)