diff --git a/Factory_Tests/Adafruit_Sparkle_Motion_Mini_FactoryTest/.feather_esp32_v2.test.only b/Factory_Tests/Adafruit_Sparkle_Motion_Mini_FactoryTest/.feather_esp32_v2.test.only new file mode 100644 index 000000000..e69de29bb diff --git a/Factory_Tests/Adafruit_Sparkle_Motion_Mini_FactoryTest/Adafruit_Sparkle_Motion_Mini_FactoryTest.ino b/Factory_Tests/Adafruit_Sparkle_Motion_Mini_FactoryTest/Adafruit_Sparkle_Motion_Mini_FactoryTest.ino new file mode 100644 index 000000000..4450f0927 --- /dev/null +++ b/Factory_Tests/Adafruit_Sparkle_Motion_Mini_FactoryTest/Adafruit_Sparkle_Motion_Mini_FactoryTest.ino @@ -0,0 +1,83 @@ +// SPDX-FileCopyrightText: 2025 Limor Fried for Adafruit Industries +// +// SPDX-License-Identifier: MIT +#include +#include "WiFi.h" +#include +#include "ESP_I2S.h" +extern Adafruit_TestBed TB; + +// I2S pin definitions +const uint8_t I2S_SCK = 23; // BCLK +const uint8_t I2S_WS = 10; // LRCLK +const uint8_t I2S_DIN = 9; // DATA_IN +I2SClass i2s; + +// the setup routine runs once when you press reset: +void setup() { + Serial.begin(115200); + pinMode(LED_BUILTIN, OUTPUT); + digitalWrite(LED_BUILTIN, HIGH); + 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; + } + // TestBed will handle the neopixel swirl for us + TB.neopixelPin = PIN_NEOPIXEL; + TB.neopixelNum = 1; + TB.begin(); + + // Set WiFi to station mode and disconnect from an AP if it was previously connected + WiFi.mode(WIFI_STA); + WiFi.disconnect(); +} + +// the loop routine runs over and over again forever: +uint8_t wheelColor=0; +void loop() { + if (wheelColor == 0) { + // Test I2C! + Serial.print("I2C port "); + TB.theWire = &Wire; + TB.printI2CBusScan(); + + // Test WiFi Scan! + // WiFi.scanNetworks will return the number of networks found + int n = WiFi.scanNetworks(); + Serial.print("WiFi AP scan done..."); + if (n == 0) { + Serial.println("no networks found"); + } else { + Serial.print(n); + Serial.println(" networks found"); + for (int i = 0; i < n; ++i) { + // Print SSID and RSSI for each network found + Serial.print(i + 1); + Serial.print(": "); + Serial.print(WiFi.SSID(i)); + Serial.print(" ("); + Serial.print(WiFi.RSSI(i)); + Serial.print(")"); + Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN)?" ":"*"); + delay(10); + } + } + Serial.println(""); + for (int i=0; i < 5; i++) { + int32_t sample = i2s.read(); + if (sample >= 0){ + Serial.print("Amplitude: "); + Serial.println(sample); + + // Delay to avoid printing too quickly + delay(200); + } + } + } + + TB.setColor(TB.Wheel(wheelColor++)); // swirl NeoPixel + digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); + + delay(5); +} diff --git a/Sparkle_Motion_Mini_Examples/Arduino_I2S_SparkleMotionMini/.feather_esp32_v2.test.only b/Sparkle_Motion_Mini_Examples/Arduino_I2S_SparkleMotionMini/.feather_esp32_v2.test.only new file mode 100644 index 000000000..e69de29bb diff --git a/Sparkle_Motion_Mini_Examples/Arduino_I2S_SparkleMotionMini/Arduino_I2S_SparkleMotionMini.ino b/Sparkle_Motion_Mini_Examples/Arduino_I2S_SparkleMotionMini/Arduino_I2S_SparkleMotionMini.ino new file mode 100644 index 000000000..43f0fb478 --- /dev/null +++ b/Sparkle_Motion_Mini_Examples/Arduino_I2S_SparkleMotionMini/Arduino_I2S_SparkleMotionMini.ino @@ -0,0 +1,44 @@ +// SPDX-FileCopyrightText: 2025 Limor Fried for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#include +#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(); + } +}