Skip to content

Commit e503ce1

Browse files
authored
Merge pull request #3039 from FoamyGuy/sparklemotion_stick_arduino_i2smic
sparkle motion stick arduino i2s mic example
2 parents f3b7555 + 185cad9 commit e503ce1

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

Sparkle_Motion_Stick_Examples/Arduino_I2S_SparkleMotionStick/.feather_esp32_v2.test.only

Whitespace-only changes.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// SPDX-FileCopyrightText: 2025 Limor Fried for Adafruit Industries
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
#include <Arduino.h>
6+
#include "ESP_I2S.h"
7+
8+
// I2S pin definitions for Sparklemotion
9+
const uint8_t I2S_SCK = 14; // BCLK
10+
const uint8_t I2S_WS = 12; // LRCLK
11+
const uint8_t I2S_DIN = 13; // DATA_IN
12+
13+
// Create I2S instance
14+
I2SClass i2s;
15+
16+
void setup() {
17+
// Fast serial for plotting
18+
Serial.begin(500000);
19+
20+
// Initialize I2S
21+
i2s.setPins(I2S_SCK, I2S_WS, -1, I2S_DIN);
22+
if (!i2s.begin(I2S_MODE_STD, 44100, I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_MONO, I2S_STD_SLOT_LEFT)) {
23+
Serial.println("Failed to initialize I2S bus!");
24+
return;
25+
}
26+
27+
Serial.println("I2S Mic Plotter Ready");
28+
}
29+
30+
void loop() {
31+
static uint32_t lastPlot = 0;
32+
33+
// Get a sample
34+
int32_t sample = i2s.read();
35+
36+
// Only plot every 1ms (1000 samples/sec is plenty for visualization)
37+
if (millis() - lastPlot >= 1) {
38+
if (sample >= 0) { // Valid sample
39+
// Plot both raw and absolute values
40+
Serial.printf("%d,%d\n", (int16_t)sample, abs((int16_t)sample));
41+
}
42+
lastPlot = millis();
43+
}
44+
}

0 commit comments

Comments
 (0)