Skip to content

Commit 81f7f21

Browse files
Add I2S input and transmit over WiFi example
Very simple example sends I2S microphone data using UDP over WiFi. Runs very well and proves the I2S receive DMA buffer management is working pretty well.
1 parent 0039dbc commit 81f7f21

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
I2S stereo microphone (input) UDP transmitter
3+
Needs a UDP listener (netcat/etc.) on port 8266 on the PC
4+
5+
Under Linux:
6+
nc -u -p 8266 -l | play -t raw -r 11025 -b 16 -c 2 -e signed-integer -
7+
8+
Released to the Public Domain by Earle F. Philhower, III
9+
*/
10+
11+
#include <ESP8266WiFi.h>
12+
#include <WiFiUdp.h>
13+
#include <i2s.h>
14+
15+
// Set your network here
16+
const char *SSID = "....";
17+
const char *PASS = "....";
18+
19+
WiFiUDP udp;
20+
// Set your listener PC's IP here:
21+
const IPAddress listener = { 192, 168, 1, 2 };
22+
const int port = 8266;
23+
24+
int16_t buffer[100][2]; // Temp staging for samples
25+
26+
void setup() {
27+
Serial.begin(115200);
28+
29+
// Connect to WiFi network
30+
Serial.println();
31+
Serial.println();
32+
Serial.print("Connecting to ");
33+
Serial.println(SSID);
34+
35+
WiFi.begin(SSID, PASS);
36+
37+
while (WiFi.status() != WL_CONNECTED) {
38+
delay(500);
39+
Serial.print(".");
40+
}
41+
Serial.println("");
42+
Serial.println("WiFi connected");
43+
Serial.print("My IP: ");
44+
Serial.println(WiFi.localIP());
45+
46+
i2s_rxtx_begin(true, false); // Enable I2S RX
47+
i2s_set_rate(11025);
48+
49+
Serial.print("\nStart the listener on ");
50+
Serial.print(listener);
51+
Serial.print(":");
52+
Serial.println(port);
53+
Serial.println("ex: nc -u -p 8266 -l | play -t raw -r 11025 -b 16 -c 2 -e signed-integer -");
54+
55+
udp.beginPacket(listener, port);
56+
udp.write("I2S Receiver\r\n");
57+
udp.endPacket();
58+
59+
}
60+
61+
void loop() {
62+
static int cnt = 0;
63+
// Each loop will send 100 raw samples (400 bytes)
64+
// UDP needs to be < TCP_MSS which can be 500 bytes in LWIP2
65+
for (int i=0; i<100; i++) {
66+
i2s_read_sample(&buffer[i][0], &buffer[i][1], true);
67+
}
68+
udp.beginPacket(listener, port);
69+
udp.write((uint8_t*)buffer, sizeof(buffer));
70+
udp.endPacket();
71+
cnt++;
72+
if ((cnt % 100) == 0) {
73+
Serial.printf("%d\n", cnt);
74+
}
75+
}

0 commit comments

Comments
 (0)