Thank you for your help, Raspiaudio!
I can compile it now, problem solved
What Iāve done so far (MacOs):
-
(was not required) Uninstalled Arduino + removed /Users/aleksey/Documents/Arduino (sketches and libraries) + removed /Users/aleksey/Library
-
(was not required) Downloaded and installed the latest version of Arduino
- Installed Esp32 board version 1.05 (<<< that was important)
- Copied muse_lib to /Users/aleksey/Library/
- Copied sketch from here https://raw.githubusercontent.com/RASPIAUDIO/Simple_Bluetooth_Speaker_ESP32/master/speaker/speaker.ino
- Verify
I had:
In file included from /Users/aleksey/Documents/Arduino/muse_test/muse_test.ino:20:0:
/Users/aleksey/Documents/Arduino/libraries/muse_lib/src/Audio.h:15:10: fatal error: FS.h: No such file or directory
#include āFS.hā
^~~~~~
compilation terminated.
- I forget to select the board (āESP32 Wrover Moduleā),
Now it compiles!
I still have some trouble with playing files from SD. Iāve built a sketch that can only work with .wav and 44100 kHz but it looks far from optimal.
Could you provide the simplest sketch for reading a file by name from SD card and playing it?
Could you provide supported SD card capacities and expected file system format? I have a 32Gb microSD card with FAT32, will it work?
Here is my sketch:
#include "Arduino.h"
#include "SD.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "esp_log.h"
#include <driver/i2s.h>
#include "SPIFFS.h"
#define I2SR (i2s_port_t)0
#define VM GPIO_NUM_0 // button
#define ONled 0
#define PW GPIO_NUM_21 // Amp power ON
#define GAIN GPIO_NUM_23 //
#define BLOCK_SIZE 128
#define SD_CS 13
bool testOK;
static bool mp3ON;
const i2s_config_t i2s_configR = {
.mode = i2s_mode_t(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_TX ), // Receive, transfer
.sample_rate = 44100, //
.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT, //
.channel_format = I2S_CHANNEL_FMT_ONLY_RIGHT, // although the SEL config should be left, it seems to transmit on right
.communication_format = i2s_comm_format_t(I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB),
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, // Interrupt level 1
.dma_buf_count = 4, // number of buffers
.dma_buf_len = BLOCK_SIZE // samples per buffer
};
i2s_pin_config_t pin_configR =
{
.bck_io_num = 5 , // BCKL
.ws_io_num = 25 , // LRCL
.data_out_num = 26, // DOUT
.data_in_num = 35 // DIN
};
static void playAudio(void)
{
int16_t s0, s1;
static int8_t c[44100];
int l;
size_t t;
uint16_t s16[64];
int a = 0;
i2s_set_clk(I2SR, 44100, I2S_BITS_PER_SAMPLE_16BIT, I2S_CHANNEL_MONO);
File f = SD.open("/500hz44100Mono.wav", FILE_READ);
// File f = SPIFFS.open("/bluetooth.wav", FILE_READ);
if (f == NULL) printf("err opening file\n");
// header read
f.read((uint8_t*)c, 44);
do
{
// data read
l = (int)f.read((uint8_t*)c, 44100);
if (l < 0) printf("Erreur \n");
// i2s_zero_dma_buffer(I2SR);
for (int i = 0; i < l; i++)
{
// sample value 8bits -> 16
s0 = (((int16_t)(c[i] & 0xFF)) - 128) << 8 ;
// attenuation a
s0 = s0 >> a;
// buffering -> s16
s16[i % 64] = (uint16_t)s0;
if (((i + 1) % 64) == 0)
{
int n = 0;
//sending
while (n == 0) n = i2s_write_bytes(I2SR, (const char*)s16, 128, portMAX_DELAY);
}
}
}while(l > 0);
// muting after playing
for (int i = 0; i < 64; i++)s16[i] = 0;
int n = 0;
while (n == 0) n = i2s_write_bytes(I2SR, (const char*)s16, 128, portMAX_DELAY);
i2s_zero_dma_buffer(I2SR);
f.close();
printf ("Play End\n");
}
#define SPI_MOSI 15
#define SPI_MISO 2
#define SPI_SCK 14
void setup()
{
Serial.begin(115200);
esp_err_t err;
if (!SPIFFS.begin(true))Serial.println("Erreur SPIFFS");
SPI.begin(SPI_SCK, SPI_MISO, SPI_MOSI);
if(!SD.begin(SD_CS))
{
Serial.printf("SD initialization failed!\n");
} else {
Serial.printf("SD initialization successfully\n");
}
//Init buton
gpio_reset_pin(VM);
gpio_set_direction(VM, GPIO_MODE_INPUT);
gpio_set_pull_mode(VM, GPIO_PULLDOWN_ONLY);
// Amp power enable
gpio_reset_pin(PW);
gpio_set_direction(PW, GPIO_MODE_OUTPUT);
gpio_set_level(PW, 1);
gpio_reset_pin(GAIN);
gpio_set_direction(GAIN, GPIO_MODE_OUTPUT);
gpio_set_pull_mode(GAIN, GPIO_PULLDOWN_ONLY); // 15dB
i2s_driver_install(I2SR, &i2s_configR, 0, NULL);
i2s_set_pin(I2SR, &pin_configR);
i2s_stop(I2SR);
}
void loop() {
if (gpio_get_level(VM) == 0)
{
//playing
printf("Playing\n");
i2s_start(I2SR);
playAudio();
delay(100);
i2s_stop(I2SR);
}
}