mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-16 00:43:00 +03:00
I2s input API and examples (#4539)
Enables I2S stereo input via DMA using new API calls: . i2s_rxtx_begin(bool rx, rool tx); . i2s_read_sample(uint32_t *l, uint32_t *r); Original API calls will only enable TX, so this is backwards compatible. Add simple I2S input example code using Arduino serial plotter. Add UDP transmit of I2S microphone data to a PC (remote microphone). Clean up and reorganize code to share RX and TX logic as much as possible. Fix a potential WDT error while in blocking sample read and write.
This commit is contained in:
committed by
GitHub
parent
7ae8f98e57
commit
8ae553d99e
55
libraries/esp8266/examples/I2SInput/I2SInput.ino
Normal file
55
libraries/esp8266/examples/I2SInput/I2SInput.ino
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
I2S stereo microphone (input) example
|
||||
Run using the Arduion Serial Plotter to see waveform.
|
||||
Released to the Public Domain by Earle F. Philhower, III
|
||||
|
||||
For the Google AIY Voice Hat Microphone daughterboard, part
|
||||
of the Raspberry Pi AIY cardboard box, the I2S stereo pinout
|
||||
looking at the board top with the RPI logo on the left hand
|
||||
side:
|
||||
+-- ------------------------------------ --+
|
||||
left RPI | (1) GND (2) DIN (3) BCLK (4) LRCLK (5) 3.3V | AIY right
|
||||
+---------------------------------------------+
|
||||
|
||||
The I2S pins are on different pins depending on your board.
|
||||
The *internal GPIO number* which is NOT NECESSARIALY the
|
||||
same as the pin numbers, are as follows:
|
||||
I2SI_DATA = GPIO12
|
||||
IS2I_BCK = GPIO13
|
||||
I2SI_WS/LRCLK = GPIO14
|
||||
|
||||
On the D1 mini the I2SI pins map to the following D pins:
|
||||
I2SI_DATA = GPIO12 = D6
|
||||
IS2I_BCK = GPIO13 = D7
|
||||
I2SI_WS/LRCLK = GPIO14 = D5
|
||||
|
||||
Expect different D pins on different ESP8266 boards, and of
|
||||
course be sure to wire up VCC(3.3V) and GND.
|
||||
*/
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <i2s.h>
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
WiFi.forceSleepBegin();
|
||||
delay(500);
|
||||
|
||||
i2s_rxtx_begin(true, false); // Enable I2S RX
|
||||
i2s_set_rate(11025);
|
||||
|
||||
delay(1000);
|
||||
|
||||
while (1) {
|
||||
int16_t l, r;
|
||||
i2s_read_sample(&l, &r, true);
|
||||
char withScale[256];
|
||||
sprintf(withScale, "%d %d", l, r);
|
||||
Serial.println(withScale);
|
||||
yield();
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
/* Nothing here */
|
||||
}
|
Reference in New Issue
Block a user