Skip to content

Commit 027433f

Browse files
authored
Merge pull request #2952 from adafruit/sparkle_arduino
sparkle mini factorytest
2 parents daa736c + 88281cf commit 027433f

File tree

4 files changed

+127
-0
lines changed

4 files changed

+127
-0
lines changed

Factory_Tests/Adafruit_Sparkle_Motion_Mini_FactoryTest/.feather_esp32_v2.test.only

Whitespace-only changes.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// SPDX-FileCopyrightText: 2025 Limor Fried for Adafruit Industries
2+
//
3+
// SPDX-License-Identifier: MIT
4+
#include <Arduino.h>
5+
#include "WiFi.h"
6+
#include <Adafruit_TestBed.h>
7+
#include "ESP_I2S.h"
8+
extern Adafruit_TestBed TB;
9+
10+
// I2S pin definitions
11+
const uint8_t I2S_SCK = 23; // BCLK
12+
const uint8_t I2S_WS = 10; // LRCLK
13+
const uint8_t I2S_DIN = 9; // DATA_IN
14+
I2SClass i2s;
15+
16+
// the setup routine runs once when you press reset:
17+
void setup() {
18+
Serial.begin(115200);
19+
pinMode(LED_BUILTIN, OUTPUT);
20+
digitalWrite(LED_BUILTIN, HIGH);
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+
// TestBed will handle the neopixel swirl for us
27+
TB.neopixelPin = PIN_NEOPIXEL;
28+
TB.neopixelNum = 1;
29+
TB.begin();
30+
31+
// Set WiFi to station mode and disconnect from an AP if it was previously connected
32+
WiFi.mode(WIFI_STA);
33+
WiFi.disconnect();
34+
}
35+
36+
// the loop routine runs over and over again forever:
37+
uint8_t wheelColor=0;
38+
void loop() {
39+
if (wheelColor == 0) {
40+
// Test I2C!
41+
Serial.print("I2C port ");
42+
TB.theWire = &Wire;
43+
TB.printI2CBusScan();
44+
45+
// Test WiFi Scan!
46+
// WiFi.scanNetworks will return the number of networks found
47+
int n = WiFi.scanNetworks();
48+
Serial.print("WiFi AP scan done...");
49+
if (n == 0) {
50+
Serial.println("no networks found");
51+
} else {
52+
Serial.print(n);
53+
Serial.println(" networks found");
54+
for (int i = 0; i < n; ++i) {
55+
// Print SSID and RSSI for each network found
56+
Serial.print(i + 1);
57+
Serial.print(": ");
58+
Serial.print(WiFi.SSID(i));
59+
Serial.print(" (");
60+
Serial.print(WiFi.RSSI(i));
61+
Serial.print(")");
62+
Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN)?" ":"*");
63+
delay(10);
64+
}
65+
}
66+
Serial.println("");
67+
for (int i=0; i < 5; i++) {
68+
int32_t sample = i2s.read();
69+
if (sample >= 0){
70+
Serial.print("Amplitude: ");
71+
Serial.println(sample);
72+
73+
// Delay to avoid printing too quickly
74+
delay(200);
75+
}
76+
}
77+
}
78+
79+
TB.setColor(TB.Wheel(wheelColor++)); // swirl NeoPixel
80+
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
81+
82+
delay(5);
83+
}

Sparkle_Motion_Mini_Examples/Arduino_I2S_SparkleMotionMini/.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 = 23; // BCLK
10+
const uint8_t I2S_WS = 10; // LRCLK
11+
const uint8_t I2S_DIN = 9; // 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)