setup:
- rp2040 connect
- using GPIO pins and multicore feature (compiling with Arduino-Pico)
- 8 neopixel strips with each 20 pixels
test goal:
- use mic level to control amount of leds that light up
issue:
works fine when using less than 8 strips, more or equal to 8 NeoPixels declared and the board starts behaving abnormally.
my hypothesis:
memory problem but I have no way to prove it! Variables seem to only take 25% of available memory.
code:
#include <Adafruit_NeoPixel.h>
#define NUM_LED 20
#include <PDM.h>
Adafruit_NeoPixel grid[] = {
Adafruit_NeoPixel(NUM_LED, 15, NEO_GRB + NEO_KHZ800),
Adafruit_NeoPixel(NUM_LED, 16, NEO_GRB + NEO_KHZ800),
Adafruit_NeoPixel(NUM_LED, 17, NEO_GRB + NEO_KHZ800),
Adafruit_NeoPixel(NUM_LED, 18, NEO_GRB + NEO_KHZ800),
Adafruit_NeoPixel(NUM_LED, 19, NEO_GRB + NEO_KHZ800),
Adafruit_NeoPixel(NUM_LED, 20, NEO_GRB + NEO_KHZ800),
Adafruit_NeoPixel(NUM_LED, 21, NEO_GRB + NEO_KHZ800),
Adafruit_NeoPixel(NUM_LED, 28, NEO_GRB + NEO_KHZ800),
};
#define NUMSTRIPS (sizeof(grid)/sizeof(grid[0]))
static const char channels = 1;
static const int frequency = 16000;
short sampleBuffer[64];
volatile int samplesRead;
int devider =900;
void setup() {
PDM.onReceive(onPDMdata);
if (!PDM.begin(channels, frequency)) {
while (1);
}
}
void setup1() {
for(int i=0; i<NUMSTRIPS; i++)
{
grid[i].begin();
grid[i].show();
}
}
uint32_t lumens=0;
void loop() {
if (samplesRead) {
for (int i = 0; i < samplesRead; i++) {
lumens = abs(sampleBuffer[i]/(2*devider));
rp2040.fifo.push(lumens);
}
samplesRead = 0;
}
}
uint32_t in_lumens = 0;
bool no_freeze = false;
void loop1() {
no_freeze = rp2040.fifo.pop_nb(&in_lumens);
if (no_freeze) {
for(int i=0; i<NUMSTRIPS; i++)
{
grid[i].clear();
grid[i].fill( grid[0].Color(12, 6, 10),0,1+ in_lumens);
grid[i].show();
}
}
else {
while (1) {
// if we're here it's not a good sign
for(int i=0; i<NUMSTRIPS; i++) {grid[i].clear();grid[i].show();}
delay(1000);
for(int i=0; i<NUMSTRIPS; i++) {grid[i].fill( grid[0].Color(12, 1, 1),0,20);grid[i].show();}
delay(1000);
no_freeze = rp2040.fifo.pop_nb(&in_lumens);
if (no_freeze) break;
}
}
}
void onPDMdata() {
int bytesAvailable = PDM.available();
PDM.read(sampleBuffer, bytesAvailable);
samplesRead = bytesAvailable / 2;
}