ESP32-audioI2S-master library #939
Unanswered
billglass38
asked this question in
Q&A
Replies: 1 comment 3 replies
-
You could use a ticker for toggle: #include <Arduino.h>
#include "SD_MMC.h"
#include "Audio.h"
#include "Ticker.h"
#define I2S_LRC 26
#define I2S_DOUT 25
#define I2S_BCLK 27
#define I2S_MCLK 0
#define SD_MMC_D0 2
#define SD_MMC_CLK 14
#define SD_MMC_CMD 15
String ssid = "*****";
String password = "*****";
Audio audio;
Ticker ticker;
int8_t toggle = 0;
bool start = false;
void t10s(){
toggle++;
start = true;
if(toggle == 3) toggle = 0;
}
void setup(void) {
Serial.begin(115200);
WiFi.begin(ssid.c_str(), password.c_str());
while (WiFi.status() != WL_CONNECTED){
delay(1500);
}
pinMode(SD_MMC_D0, INPUT_PULLUP);
if(!SD_MMC.begin("/sdmmc", true)){
Serial.println("Card Mount Failed");
return;
}
audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT, -1);
audio.setVolume(21); // 0...21
ticker.attach(10, t10s); // every 10 seconds
audio.connecttohost("http://mp3.ffh.de/radioffh/hqlivestream.mp3");
}
void loop(){
audio.loop();
vTaskDelay(1);
if(start == true){
start = false;
if(toggle == 1) audio.connecttoFS(SD_MMC, "A17A1203615.mp3");
if(toggle == 2) audio.connecttohost("http://mp3.ffh.de/radioffh/hqlivestream.mp3");
}
}
void audio_info(const char *info){
Serial.print("info: "); Serial.println(info);
} |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello
I am using the ESP32-audioI2S-master library, SPI library for an SD card reader, a pcm5102
i2s DAC, and a headphone.
I want to switch (on-the-fly) from internet radio to SD card, and back to internet radio.
I can sequentially switch from internet server1, to server2, then to the SD card with no
problem. But when I try to switch back to server1, there is no more audio unless I reboot.
Below is my code. Does anyone have an idea on what is happening? Thank you!
``
#include "Arduino.h"
#include "WiFi.h"
#include "Audio.h"
#include "SD.h"
#include "FS.h"
#define I2S_DOUT 22
#define I2S_BCLK 26
#define I2S_LRC 25
/*
PCM5102_XMT<---
ESP32_Gnd------------------->PCM5102_FMT |
ESP32_25-------------------->PCM5102_LCK |
ESP32_22-------------------->PCM5102_DIN |
ESP32_26-------------------->PCM5102_BCK |
ESP32_Gnd------------------->PCM5102_SCL |
ESP32_Gnd------------------->PCM5102_DMP |
ESP32_Gnd------------------->PCM5102_FLT |
ESP32_Gnd------------------->PCM5102_GND |
ESP32_Vin------------------->PCM5102_Vcc |
PCM5102_3.3V---
*/
#define SD_CS 5
#define SPI_MOSI 23
#define SPI_MISO 19
#define SPI_SCK 18
Audio audio;
String ssid = "xxxxxxxxxx";
String password = "xxxxxxxxxx";
int toggle=0;
unsigned long changeChannels=millis();
void setup()
{
Serial.begin(115200);
WiFi.disconnect();
WiFi.mode(WIFI_STA);
WiFi.begin(ssid.c_str(), password.c_str());
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.println("");
audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
pinMode(SD_CS, OUTPUT);
digitalWrite(SD_CS, HIGH);
SPI.begin(SPI_SCK, SPI_MISO, SPI_MOSI);
if(!SD.begin(SD_CS))
{
Serial.println("Error accessing microSD card!");
while(true);
}
audio.setVolume(21);
audio.connecttohost("0n-80s.radionetz.de:8000/0n-70s.mp3");
//audio.connecttohost("http://icecast.radiofrance.fr/francemusiquelajazz-midfi.mp3");
//audio.connecttoFS(SD,"/AfricanMist.mp3");
}
void loop()
{
if (millis()-changeChannels>10000UL) //change channel every 10sec
{
Serial.println("change channels");
changeChannels=millis();
if (toggle==0)
{
toggle=1;
audio.connecttohost("http://icecast.radiofrance.fr/francemusiquelajazz-midfi.mp3");
}
else if (toggle==1)
{
toggle=2;
audio.connecttoFS(SD,"/AfricanMist.mp3");
}
else if (toggle==2)
{
toggle=0;
audio.connecttohost("0n-80s.radionetz.de:8000/0n-70s.mp3");
}
}
audio.loop();
}
void audio_info(const char *info) {
Serial.print("info "); Serial.println(info);
}
void audio_id3data(const char *info) { //id3 metadata
Serial.print("id3data "); Serial.println(info);
}
void audio_eof_mp3(const char *info) { //end of file
Serial.print("eof_mp3 "); Serial.println(info);
}
void audio_showstation(const char *info) {
Serial.print("station "); Serial.println(info);
}
void audio_showstreaminfo(const char *info) {
Serial.print("streaminfo "); Serial.println(info);
}
void audio_showstreamtitle(const char *info) {
Serial.print("streamtitle "); Serial.println(info);
}
void audio_bitrate(const char *info) {
Serial.print("bitrate "); Serial.println(info);
}
void audio_commercial(const char *info) { //duration in sec
Serial.print("commercial "); Serial.println(info);
}
void audio_icyurl(const char *info) { //homepage
Serial.print("icyurl "); Serial.println(info);
}
void audio_lasthost(const char *info) { //stream URL played
Serial.print("lasthost "); Serial.println(info);
}
void audio_eof_speech(const char *info) {
Serial.print("eof_speech "); Serial.println(info);
}
``
Beta Was this translation helpful? Give feedback.
All reactions