-
Notifications
You must be signed in to change notification settings - Fork 778
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b3ddb74
commit 88281cf
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
44 changes: 44 additions & 0 deletions
44
Sparkle_Motion_Mini_Examples/Arduino_I2S_SparkleMotionMini/Arduino_I2S_SparkleMotionMini.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// SPDX-FileCopyrightText: 2025 Limor Fried for Adafruit Industries | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
#include <Arduino.h> | ||
#include "ESP_I2S.h" | ||
|
||
// I2S pin definitions for Sparklemotion | ||
const uint8_t I2S_SCK = 23; // BCLK | ||
const uint8_t I2S_WS = 10; // LRCLK | ||
const uint8_t I2S_DIN = 9; // DATA_IN | ||
|
||
// Create I2S instance | ||
I2SClass i2s; | ||
|
||
void setup() { | ||
// Fast serial for plotting | ||
Serial.begin(500000); | ||
|
||
// Initialize I2S | ||
i2s.setPins(I2S_SCK, I2S_WS, -1, I2S_DIN); | ||
if (!i2s.begin(I2S_MODE_STD, 44100, I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_MONO, I2S_STD_SLOT_LEFT)) { | ||
Serial.println("Failed to initialize I2S bus!"); | ||
return; | ||
} | ||
|
||
Serial.println("I2S Mic Plotter Ready"); | ||
} | ||
|
||
void loop() { | ||
static uint32_t lastPlot = 0; | ||
|
||
// Get a sample | ||
int32_t sample = i2s.read(); | ||
|
||
// Only plot every 1ms (1000 samples/sec is plenty for visualization) | ||
if (millis() - lastPlot >= 1) { | ||
if (sample >= 0) { // Valid sample | ||
// Plot both raw and absolute values | ||
Serial.printf("%d,%d\n", (int16_t)sample, abs((int16_t)sample)); | ||
} | ||
lastPlot = millis(); | ||
} | ||
} |