Replies: 2 comments 12 replies
-
Be careful: for AudioKitEs8388V1 Wire is used with the pins 32 and 33 to communicate with the codec! class PinsAudioKitEs8388v1Class : public DriverPins {
public:
PinsAudioKitEs8388v1Class() {
// sd pins
addSPI(ESP32PinsSD);
// add i2c codec pins: scl, sda, port, frequency
addI2C(PinFunction::CODEC, 32, 33);
// add i2s pins: mclk, bck, ws,data_out, data_in ,(port)
addI2S(PinFunction::CODEC, 0, 27, 25, 26, 35);
// add other pins
addPin(PinFunction::KEY, 36, PinLogic::InputActiveLow, 1);
addPin(PinFunction::KEY, 13, PinLogic::InputActiveLow, 2);
addPin(PinFunction::KEY, 19, PinLogic::InputActiveLow, 3);
addPin(PinFunction::KEY, 23, PinLogic::InputActiveLow, 4);
addPin(PinFunction::KEY, 18, PinLogic::InputActiveLow, 5);
addPin(PinFunction::KEY, 5, PinLogic::InputActiveLow, 6);
addPin(PinFunction::AUXIN_DETECT, 12, PinLogic::InputActiveLow);
addPin(PinFunction::HEADPHONE_DETECT, 39, PinLogic::InputActiveLow);
addPin(PinFunction::PA, 21, PinLogic::Output);
addPin(PinFunction::LED, 22, PinLogic::Output);
}
};
|
Beta Was this translation helpful? Give feedback.
4 replies
-
Did you try to separate the I2S from the I2C processing in separate tasks ? |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I want to send ranom values between 1 and 5 via I2C to my ESP32 Audiokit. Then I want to play a Audiofile, depending on which number arrives. The I2C communication works as long as i only want to print them on the serial monitor. As soon as I want to put in the code for the audio output it doesn't work anymore. The code for the audio output is the example "streams-sdmmc_wav-audiokit" in the arduino-audiotools-library. I think somhow i block the I2C used for the audio processing, when initializing the I2C between the two ESP.
I hope you can help me.
Thank you in advance
Errors that accured where for example:
ES8388 not found on I2C address 10, check wiring,
AudioBoard::driver::begin failed,
setConfig has failed,
AudioDriver init failed
The code for the audiokit I use is:
#include <Wire.h>
#include "FS.h"
#include "SD_MMC.h"
#include "AudioTools.h"
#include "AudioTools/AudioLibs/AudioBoardStream.h"
#define I2C_SLAVE_ADDR 0x08 // I²C-Adresse des Slave
volatile uint8_t sensor = 0; // Zahl von 1 bis 5
volatile uint16_t distance = 0; // Zahl von 0 bis 400
AudioBoardStream i2s(AudioKitEs8388V1);
WAVDecoder wav;
EncodedAudioStream encoded(&i2s, &wav);
File audioFile;
StreamCopy copier(encoded, audioFile);
void setup() {
Serial.begin(115200);
Serial.println("I²C Master bereit");
Wire1.begin(21, 22);
auto config = i2s.defaultConfig(TX_MODE);
config.sd_active = false;
i2s.begin(config);
i2s.setVolume(0.25);
if (!SD_MMC.begin("/sdcard", false)) {
Serial.println("SD_MMC Fehler");
while (true);
}
}
void playAudioFile(uint8_t sensorValue) {
String filename = "/sinus" + String(sensorValue) + ".wav";
Serial.print("Spiele Datei: ");
Serial.println(filename);
if (audioFile) {
audioFile.close();
}
audioFile = SD_MMC.open(filename.c_str());
if (!audioFile) {
Serial.println("Datei nicht gefunden");
return;
}
encoded.begin();
bool bPlaying = true;
while (bPlaying) {
if (copier.copy() != 0) {
bPlaying = false;
}
}
Serial.println("Abspielen beendet");
}
void loop() {
uint8_t bytesReceived = Wire.requestFrom(I2C_SLAVE_ADDR, 3);
if (bytesReceived == 3) {
uint8_t buffer[3];
for (int i = 0; i < bytesReceived; i++) {
buffer[i] = Wire.read();
}
} else {
Serial.println("Fehler beim Empfangen der Daten");
}
delay(1000);
}
This is the o for the ESP32 I use:
#include <Wire.h>
#define I2C_SLAVE_ADDR 0x08
uint8_t sensor = 1;
uint16_t distance = 0;
void setup() {
Wire.begin(I2C_SLAVE_ADDR);
Wire.onRequest(requestEvent);
Serial.begin(115200);
Serial.println("I2C Slave bereit");
}
void loop() {
delay(1000);
}
void requestEvent() {
Serial.println("Master fordert Daten an!");
sensor = (sensor % 5) + 1;
distance = (distance + 20) % 401;
uint8_t data[3];
data[0] = sensor; // Zahl von 1 bis 5
data[1] = distance & 0xFF; // (LSB)
data[2] = (distance >> 8) & 0xFF; // (MSB)
Wire.write(data, 3);
Serial.print("Gesendete Daten: Sensor = ");
Serial.print(sensor);
Serial.print(", Distance = ");
Serial.println(distance);
}
This is the code for the Auiokit whih works but only with serial monitor output of the values
// Master Aktorik
#include <Wire.h>
#include "FS.h"
#include "SD_MMC.h"
#include "AudioTools.h"
#include "AudioTools/AudioLibs/AudioBoardStream.h"
#define I2C_SLAVE_ADDR 0x08
volatile uint8_t sensor = 0;
volatile uint16_t distance = 0;
void setup() {
Wire.begin();
Serial.begin(115200);
Serial.println("I2C Master bereit");
}
void loop() {
uint8_t bytesReceived = Wire.requestFrom(I2C_SLAVE_ADDR, 3);
Serial.print("Bytes empfangen: ");
Serial.println(bytesReceived);
if (bytesReceived == 3) {
uint8_t buffer[3];
for (int i = 0; i < bytesReceived; i++) {
buffer[i] = Wire.read();
}
} else {
Serial.println("Fehler beim Empfangen der Daten");
}
delay(1000);
}
Beta Was this translation helpful? Give feedback.
All reactions