I have a simple code reading an i2s microphone on an esp32 written with Arduino. The code runs fine when I build with framework=arduino only.
As soon as I build with famework=arduino,esp-idf the i2s output is only zeros.
I have no issues with my code otherwise. Any ideas?
Have you made sure to update your platforms (
CLI
→
pio platform update
) to have “Espressif32 version 2.1.0”? Is the bug still present in the there-used ESP-IDF 4.1?
I have the same problem! I am using esp-idf framework. When I used framework versions under 2.0, I2s works fine, but when I update framework to version 2.1, it doesn’t. I use i2s to read from adc, I tried to read both, left and right channels but doesn’t work.
Did you found what the problem is?
@michikite
In case M5Atom Echo, If I read M5Atom.h first and read driver/i2s later, I succeed compile.
That mean, Type A is NG, Type B is good.
Type A
#include
<driver/i2s.h>
#include
<M5Atom.h>
Type B
#include
<M5Atom.h>
#include
<driver/i2s.h>
Maybe, we must update first.
image
953×120 6.64 KB
I’ve seen a few things in your code that are a bit unsettling:
First, you’ve configured the I2S to use 32-bit samples, but then declared a buffer of bytes (uint8_t) to store the input data. This could result in loss of information for negative values.To fix this, you should declare the i2sData buffer as an array of 32-bit integers (int32_t) instead of bytes.
Additionally, the conversion from uint8_t to int32_t in the line “int32_t *samples = (int32_t *)i2sData;” can be confusing. This line is a typecasting of the pointer, which tells the compiler to treat the pointer to i2sData as a pointer to an array of 32-bit integers. This is done to access the data as 32-bit samples instead of individual bytes. However, this conversion can be dangerous if the pointer doesn’t point to data that is actually 32 bits. In this case, as mentioned earlier, it should be safe to do so if i2sData is declared as an array of 32-bit integers instead of bytes.
Finally, your code doesn’t have a way to stop reading data from the I2S, which could lead to an infinite loop if there’s no data available. To prevent this, you could add a condition to check if bytes_read is greater than zero before processing the data