3
3
and sample rate. Then outputs the data using the I2S interface to a
4
4
MAX08357 I2S Amp Breakout board.
5
5
6
- Circuit:
6
+ I2S Circuit:
7
7
* Arduino/Genuino Zero, MKR family and Nano 33 IoT
8
8
* MAX08357:
9
9
* GND connected GND
12
12
* BCLK connected to pin 1 (Zero) or 2 (MKR), A3 (Nano) or 5 (ESP32)
13
13
* DIN connected to pin 9 (Zero) or A6 (MKR), 4 (Nano) or 26 (ESP32)
14
14
15
+ DAC Circuit:
16
+ * ESP32 or ESP32-S2
17
+ * Audio amplifier
18
+ - Note:
19
+ - ESP32 has DAC on GPIO pins 25 and 26.
20
+ - ESP32-S2 has DAC on GPIO pins 17 and 18.
21
+ - Connect speaker(s) or headphones.
22
+
15
23
created 17 November 2016
16
24
by Sandeep Mistry
25
+ For ESP extended by
26
+ Tomas Pilny
27
+ 2nd September 2021
17
28
*/
18
29
19
30
#include < I2S.h>
@@ -27,12 +38,16 @@ const int halfWavelength = (sampleRate / frequency); // half wavelength of squar
27
38
short sample = amplitude; // current sample value
28
39
int count = 0 ;
29
40
41
+ // i2s_mode_t mode = I2S_PHILIPS_MODE;
42
+ i2s_mode_t mode = I2S_ADC_DAC;
43
+
44
+
30
45
void setup () {
31
46
Serial.begin (115200 );
32
47
Serial.println (" I2S simple tone" );
33
48
34
49
// start I2S at the sample rate with 16-bits per sample
35
- if (!I2S.begin (I2S_PHILIPS_MODE , sampleRate, bps)) {
50
+ if (!I2S.begin (mode , sampleRate, bps)) {
36
51
Serial.println (" Failed to initialize I2S!" );
37
52
while (1 ); // do nothing
38
53
}
@@ -45,9 +60,11 @@ void loop() {
45
60
sample = -1 * sample;
46
61
}
47
62
48
- // write the same sample twice, once for left and once for the right channel
49
- I2S.write (sample);
50
63
I2S.write (sample);
64
+ // write the same sample twice, once for left and once for the right channel
65
+ if (mode == I2S_PHILIPS_MODE){
66
+ I2S.write (sample);
67
+ }
51
68
52
69
// increment the counter for the next sample
53
70
count++;
0 commit comments