I'm having a bit of trouble getting audio out of my ESP32-A1S and could use your help. With ESP NOW, I'm able to send a signal from a D1 Mini to the A1S, but I cannot get the signal to activate either a wav file on the SD card or a header file with wav turned into hex. When I use Faust code, it works, which means there's no problem with the board, but there must be something I'm missing or need to implement to get the triggering to output sound through the headphone jack. Does anyone have experience with the A1S or might know a solution to this conundrum?
I'm using the Arduino IDE along with AC101. You can probably tell with some of the code that I'm trying multiple avenues of possible functionality, so sorry for it being a bit of a mess.
Code: Select all
#include <esp_now.h>
#include <WiFi.h>
#include <XT_DAC_Audio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "WM8978.h"
#include "AC101.h"
#include "Audio.h"
#include "SD.h"
#include "FS.h"
#include "ElectronicCLHH.h"
#include "ElectronicSnareClap.h"
#include "ElectronicSubKick.h"
int senderID;
//Audio audio;
XT_DAC_Audio_Class DacAudio(25,0); //pin, interrupts
XT_Wav_Class e_CLHH(electronicCLHH_wav);
XT_Wav_Class e_SC(electronicSnareClap_wav);
XT_Wav_Class e_SK(electronicSubKick_wav);
//Receive data; must match sender structure
typedef struct struct_message {
int id;
}struct_message;
struct_message myData;
//Callback for executed received data
void OnDataRecv(const uint8_t * mac_addr, const uint8_t *incomingData, int len) {
char macStr[18];
memcpy(&myData, incomingData, sizeof(myData));
Serial.print("Packet received from: ");
snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
Serial.printf("Board ID %u: %u bytes\n", myData.id, len);
Serial.println();
senderID = myData.id;
}
void setup() {
/*pinMode(SD_CS, OUTPUT);
digitalWrite(SD_CS, HIGH);
SPI.begin(SPI_SCK, SPI_MISO, SPI_MOSI);*/
//Serial Monitor
Serial.begin(115200);
/* if(!SD.begin(SD_CS)){
Serial.println("Error talking to SD Card.");
while(true);*/
//}
//WiFi Station
WiFi.mode(WIFI_STA);
//Audio Codec Configuration
/*WM8978 wm8978;
wm8978.init();
wm8978.addaCfg(1,1);
wm8978.inputCfg(1,0,0);
wm8978.outputCfg(1,0);
wm8978.micGain(0);
wm8978.auxGain(0);
wm8978.lineinGain(0);
wm8978.spkVolSet(0);
wm8978.hpVolSet(40,40);
wm8978.i2sCfg(2,0);*/
/*AC101 ac101;
ac101.begin();
ac101.I2S1_SDOUT_CTRL(2,0);
ac101.SetVolumeHeadphone(40);*/
/* e_CLHH.start();
e_SC.start();
e_SK.start();*/
//Initialize ESP-NOW
if(esp_now_init() != ESP_OK) {
Serial.println("Error initializing ESP-NOW");
return;
}
//ESP-NOW success will register for recv CB to get packer info
esp_now_register_recv_cb(OnDataRecv);
}
void loop() {
switch(senderID) {
case 1:
DacAudio.Play(&e_SK);
senderID = 0;
break;
case 2:
DacAudio.Play(&e_SK);
senderID = 1;
break;
case 3:
DacAudio.Play(&e_SK);
senderID = 2;
break;
case 4:
DacAudio.Play(&e_CLHH);
senderID = 3;
break;
default:
break;
}
}