CORE2 as Web radio, without extra hardware ?
-
Can we use CORE2 as Web radio without any extra hardware ?
If yes does anyone have Arduino code to share ?
I just need simple code to play one station .
Thx in advance for your support. -
-
Hi @felmue
Thanks, using your link, I mange to find an untestet example using the library here
https://www.hackster.io/tommyho/arduino-web-radio-player-c4cb23but first when I added code to enable the I2S Speaker (using code from the example 'speak.ino' I manage to get something out of the speaker on CORE2, but the quality make it useless - it might get better turning the code, so will try do some test on that.
-
@agreedk
Hi, were you able to play stream or mp3 on Core2?
The only program I can make the sound is the Core2 example speak.ino. I'm trying to combine the example with the web ratio program that you mentioned. It gives me error due to decode problem.
Then I turned to another tutorial that plays mp3 on SD card. But it doesn't output the sound either. I don't know what the problem is. So I hope you did successfully and can shed some light on this issue.Thank you,
-
@raychmond I did get it to work, but the quality is very bad - had not have time to work more on it , but I have manage to get better sound out with a M5 StickC & Speaker HAT, so next step for me will be to try move that code to core2.
-
@agreedk
Thank you!
I did the same thing. The code works on M5StickC, but not on Cores2. The author did post the Core2 code, but he said it’s not tested. The fact is it’s not working.
I hope you can move to Core2 soon.
Thank you! -
I have worked on the webRadio for the Core2, I have it working for me but I'm sure there are issues to iron out. If there is allowed space here, I'll Post the code modified from the same M5WebRadio Project you are talking about.
// March 23, 2021 // Made changes to the Example Core2 Web Radio Player from: // https://www.hackster.io/tommyho/arduino-web-radio-player-c4cb23 // Wish List: (NOT DONE YET) // Nicer Fonts // Use 2nd CPU Core to handle GUI and button's so we keep it responsive // Add bluetooth output to Bluetooth speakers / headest // Get more information from the stream, Album art, etc. // Get track length and have a progress bar for the track // Have an interface to select WiFi network and enter password // -- Store password in EEPROM // Better mehod of selecting stations // ? Maybe web interface for setting up station lists? // // m5StreamTest Version 2020.12b (Source/Buffer Tester) // Board: M5StackCore2 (esp32) // Author: tommyho510@gmail.com // Required: Arduino library ESP8266Audio 1.60 // #include <M5Core2.h> #include <driver/i2s.h> #include <WiFi.h> #include <AudioFileSourceICYStream.h> #include <AudioFileSource.h> #include <AudioFileSourceBuffer.h> #include <AudioFileSourceSPIRAMBuffer.h> #include <AudioGeneratorMP3.h> #include <AudioOutputI2S.h> #include <spiram-fast.h> // Enter your WiFi, Station, button settings here: const char *SSID = "ENTER_SSID_HERE"; const char *PASSWORD = "ENTER_WIFI_PASSWORD_HERE"; const int bufferSize = 128 * 1024; // buffer size in byte // http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd // Charlie FM in Portland Oregon //http://24083.live.streamtheworld.com:80/KYCHFM_SC // //Removed these from the list: // {"Mega Shuffle", "http://jenny.torontocast.com:8134/stream"}, // {"Way Up Radio", "http://188.165.212.154:8478/stream"}, // {"Asia Dream", "https://igor.torontocast.com:1025/;.-mp3"}, // {"KPop Way Radio", "http://streamer.radio.co/s06b196587/listen"}, // {"SomaFM", "http://ice2.somafm.com/christmas-128-mp3"} //"http://icecast.thisisdax.com/CapitalEdinburghMP3", //"https://prod-34-82-94-246.wostreaming.net/ppm-jazz24mp3-ibc1", //"http://sj32.hnux.com/stream?type=http&nocache=3104", //"http://sl32.hnux.com/stream?type=http&nocache=1257", //"http://media-ice.musicradio.com:80/ClassicFMMP3", //"http://naxos.cdnstream.com:80/1255_128", //"https://v7player.wostreaming.net/854" const int stations = 7;// Change Number here if you add feeds! char * stationList[stations][3] = { {"Charlie_FM", "http://24083.live.streamtheworld.com:80/KYCHFM_SC", "good"}, {"MAXXED Out", "http://149.56.195.94:8015/steam", "good"}, {"Orig. Top 40", "http://ais-edge09-live365-dal02.cdnstream.com/a25710", "good"}, {"Smooth Jazz", "http://sj32.hnux.com/stream?type=http&nocache=3104", "good"}, {"Smooth Lounge", "http://sl32.hnux.com/stream?type=http&nocache=1257", "good"}, {"Classic FM", "http://media-ice.musicradio.com:80/ClassicFMMP3", "good"}, {"Lite Favorites", "http://naxos.cdnstream.com:80/1255_128", "good"} }; float audioGain = 1.0; float gainfactor = 0.08; int currentStationNumber = 0; unsigned long disUpdate = millis(); AudioGeneratorMP3 *mp3; AudioFileSourceICYStream *filemp3; AudioFileSourceBuffer *buffmp3; AudioOutputI2S *out, *outmp3; void displayWiFiInformation() { M5.Lcd.setCursor(0, 172, 2); M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK); M5.Lcd.setTextSize(1); M5.Lcd.println("WiFi Network: " + String(SSID)); M5.Lcd.print( "IP Address : "); M5.Lcd.println(WiFi.localIP()); } void initwifi() { WiFi.disconnect(); WiFi.softAPdisconnect(true); WiFi.mode(WIFI_STA); WiFi.begin(SSID, PASSWORD); // Try forever int i = 0; while (WiFi.status() != WL_CONNECTED) { Serial.print("STATUS(Connecting to WiFi) "); delay(1000); i = i + 1; if (i > 10) { ESP.restart(); } } Serial.println("\nWiFi Connected!\n"); } String getValue(String data, char separator, int index){ int found = 0; int strIndex[] = {0,-1}; int maxIndex = data.length() -1; for (int i = 0; i <= maxIndex && found <= index; i++){ if (data.charAt(i) == separator || i == maxIndex){ found++; strIndex[0] = strIndex[1] + 1; strIndex[1] = (i == maxIndex) ? i+1 : i; } } return found > index ? data.substring(strIndex[0], strIndex[1]) : ""; } // Calculate Battery Usable range (3.2 to 4.0 Volts) void displayBattery() { int maxVolts = 400; // Battery Max volts * 100 int minVolts = 320; // Battery Min Volts * 100 M5.Lcd.setCursor(0, 155, 2); M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK); M5.Lcd.setTextSize(1); M5.Lcd.printf("Battery: %.2f ", M5.Axp.GetBatVoltage()); int batt = map(M5.Axp.GetBatVoltage()*100, minVolts, maxVolts, 0 , 10000) / 100.0; // Draw Battery bar(s) on the right side of the screen uint16_t clr = GREEN; for(int x = 9; x >= 0; x--){ if (x < 6) clr = YELLOW; if (x < 3) clr = RED; M5.Lcd.fillRoundRect(315, (216-(x*24)), 5, 21, 2, (batt>(x*10))?clr:BLACK); } M5.Lcd.setCursor(180, 172, 2); M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK); M5.Lcd.setTextSize(1); M5.Lcd.print("WiFi Signal: "); M5.Lcd.print(WiFi.RSSI()); } // Remove the Track information (While changing stations) void clearTrack() { M5.Lcd.fillRect(0,63,310,40, BLACK); // Clear the area of old data M5.Lcd.drawRect(0,64,310,37, BLUE); // Draw a box around the Track Information } // Called when a metadata event occurs (i.e. an ID3 tag, an ICY block, etc. void MDCallback(void *cbData, const char *type, bool isUnicode, const char *string) { const char *ptr = reinterpret_cast<const char *>(cbData); (void) isUnicode; // Punt this ball for now // Note that the type and string may be in PROGMEM, so copy them to RAM for printf char s1[32], s2[64]; strncpy_P(s1, type, sizeof(s1)); s1[sizeof(s1) - 1] = 0; strncpy_P(s2, string, sizeof(s2)); s2[sizeof(s2) - 1] = 0; String band = getValue(s2, '-', 0); band.trim(); String track = getValue(s2, '-', 1); track.trim(); Serial.printf("Band: %s Track: %s \n", band.c_str(), track.c_str()); Serial.printf("METADATA(%s) '%s' = '%s'\n", ptr, s1, s2); M5.Lcd.setTextSize(1); M5.Lcd.setCursor(5, 65, 2); clearTrack(); M5.Lcd.print(band); M5.Lcd.setCursor(5, 82, 2); M5.Lcd.print(track); Serial.flush(); displayBattery(); // Make sure the new song information does not overwrite the battery } // Called when there's a warning or error (like a buffer underflow or decode hiccup) void StatusCallback(void *cbData, int code, const char *string) { const char *ptr = reinterpret_cast<const char *>(cbData); // Note that the string may be in PROGMEM, so copy it to RAM for printf char s1[64]; strncpy_P(s1, string, sizeof(s1)); s1[sizeof(s1) - 1] = 0; Serial.printf("STATUS(%s) '%d' = '%s'\n", ptr, code, s1); Serial.flush(); } void stopPlaying() { Serial.printf("Stopping MP3...\n"); if (mp3) { mp3->stop(); delete mp3; mp3 = NULL; } Serial.printf("MP3 Stopped, Stopping Buffer...\n"); if (buffmp3) { buffmp3->close(); delete buffmp3; buffmp3 = NULL; } Serial.printf("Buffer stopped... Stopping File ...\n"); if (filemp3) { filemp3->close(); delete filemp3; filemp3 = NULL; } if (outmp3) { // filemp3->close(); delete outmp3; outmp3 = NULL; } Serial.printf("STATUS(Stopped)\n"); Serial.flush(); } // Update the Station Label void updateStation(String message) { M5.Lcd.fillRect(0,30,315,30,BLACK); // Clear out other information on the line M5.Lcd.setCursor(0, 30, 2); M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK); M5.Lcd.setTextSize(2); M5.Lcd.println(message); } // Identify buttons at the bottom of screen void drawButtons() { M5.Lcd.setCursor(5, 210, 2); M5.Lcd.setTextColor(TFT_BLACK, TFT_YELLOW); M5.Lcd.setTextSize(2); M5.Lcd.println(" Vol Station Mute"); M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK); M5.Lcd.setTextSize(1); } // Change to the next station void changeStation() { updateStation("Changing..Wait.."); currentStationNumber++; if ( stationList[currentStationNumber][2] == "bad") currentStationNumber++; // Skip feeds marked as bad if (currentStationNumber >= stations) currentStationNumber = 0; Serial.printf("\n******** Changing to channel number: %i\n", currentStationNumber); } // Change the volume level void changeVolume() { audioGain += 1.0; if (audioGain > 10.0) { audioGain = 1.0; } if (audioGain < 0.0) { audioGain = 0.0; } int xtPos = 260; // X Position for the Volume indication outmp3->SetGain(audioGain * gainfactor); M5.Lcd.fillRect(xtPos, 0, 320-xtPos-5, 21, BLACK); uint16_t clr = GREEN; if (audioGain > 9) clr = RED; else if (audioGain > 6) clr = BLUE; M5.Lcd.fillTriangle(xtPos, 20, xtPos + (5 * audioGain), 20, xtPos + (5 * audioGain), 20 - (2 * audioGain), clr); } void playMP3() { outmp3 = new AudioOutputI2S(0, 0); // Output to builtInDAC outmp3->SetPinout(12, 0, 2); outmp3->SetOutputModeMono(true); outmp3->SetGain(audioGain * gainfactor); filemp3 = new AudioFileSourceICYStream(stationList[currentStationNumber][1]); filemp3->RegisterMetadataCB(MDCallback, (void*)"ICY"); buffmp3 = new AudioFileSourceBuffer(filemp3, bufferSize); buffmp3->RegisterStatusCB(StatusCallback, (void*)"buffer"); mp3 = new AudioGeneratorMP3(); mp3->RegisterStatusCB(StatusCallback, (void*)"mp3"); mp3->begin(buffmp3, outmp3); Serial.printf("STATUS(URL) %s %s\n", stationList[currentStationNumber][0], stationList[currentStationNumber][1]); Serial.flush(); updateStation(String(stationList[currentStationNumber][0])); } void loopMP3() { if (mp3 != NULL) { // To avoid crash while changing stations if (mp3->isRunning()) { if (!mp3->loop()) mp3->stop(); } else { Serial.printf("Status(Stream) Stopped \n"); stationList[currentStationNumber][2] = "bad"; // Mark feed as bad if it won't play clearTrack(); changeStation(); // stopPlaying(); delay(1000); playMP3(); } } } void setup() { Serial.begin(115200); M5.begin(); M5.Axp.SetSpkEnable(true); // M5.Lcd.setRotation(3); M5.Lcd.fillScreen(BLACK); M5.Lcd.setTextSize(2); // M5.Lcd.setFreeFont(TT1); // M5.Lcd.setFreeFont(FF33); M5.Lcd.setTextColor(TFT_GREEN, TFT_BLACK); M5.Lcd.println("Core2 Web Radio"); M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK); M5.Lcd.setTextWrap(false); initwifi(); delay(500); drawButtons(); playMP3(); changeVolume(); // To update Volume setting and graphic displayWiFiInformation(); // Serial.printf("Battery Voltage: %f \n", M5.Axp.GetBatVoltage()); } void loop() { loopMP3(); M5.update(); if (m5.BtnA.wasPressed()) { //Change Volume(Button A) changeVolume(); } if (m5.BtnB.wasPressed()) { //Change Station(Button B) clearTrack(); changeStation(); stopPlaying(); playMP3(); } if (m5.BtnC.wasPressed()) { //Mute (Button C) audioGain = -1.0; changeVolume(); } if (disUpdate + 1000 < millis()) { // Update the battery voltage disUpdate = millis(); displayBattery(); } }
-
@homeuser33 said in CORE2 as Web radio, without extra hardware ?:
// March 23, 2021
// Made changes to the Example Core2 Web Radio Player from:
// https://www.hackster.io/tommyho/arduino-web-radio-player-c4cb23// Wish List: (NOT DONE YET)
// Nicer Fonts
// Use 2nd CPU Core to handle GUI and button's so we keep it responsive
// Add bluetooth output to Bluetooth speakers / headest
// Get more information from the stream, Album art, etc.
// Get track length and have a progress bar for the track
// Have an interface to select WiFi network and enter password
// -- Store password in EEPROM
// Better mehod of selecting stations
// ? Maybe web interface for setting up station lists?
//
// m5StreamTest Version 2020.12b (Source/Buffer Tester)
// Board: M5StackCore2 (esp32)
// Author: tommyho510@gmail.com
// Required: Arduino library ESP8266Audio 1.60
//#include <M5Core2.h>
#include <driver/i2s.h>
#include <WiFi.h>
#include <AudioFileSourceICYStream.h>
#include <AudioFileSource.h>
#include <AudioFileSourceBuffer.h>
#include <AudioFileSourceSPIRAMBuffer.h>
#include <AudioGeneratorMP3.h>
#include <AudioOutputI2S.h>
#include <spiram-fast.h>// Enter your WiFi, Station, button settings here:
const char *SSID = "ENTER_SSID_HERE";
const char *PASSWORD = "ENTER_WIFI_PASSWORD_HERE";const int bufferSize = 128 * 1024; // buffer size in byte
// http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd
// Charlie FM in Portland Oregon
//http://24083.live.streamtheworld.com:80/KYCHFM_SC
//
//Removed these from the list:
// {"Mega Shuffle", "http://jenny.torontocast.com:8134/stream"},
// {"Way Up Radio", "http://188.165.212.154:8478/stream"},
// {"Asia Dream", "https://igor.torontocast.com:1025/;.-mp3"},
// {"KPop Way Radio", "http://streamer.radio.co/s06b196587/listen"},
// {"SomaFM", "http://ice2.somafm.com/christmas-128-mp3"}
//"http://icecast.thisisdax.com/CapitalEdinburghMP3",
//"https://prod-34-82-94-246.wostreaming.net/ppm-jazz24mp3-ibc1",
//"http://sj32.hnux.com/stream?type=http&nocache=3104",
//"http://sl32.hnux.com/stream?type=http&nocache=1257",
//"http://media-ice.musicradio.com:80/ClassicFMMP3",
//"http://naxos.cdnstream.com:80/1255_128",
//"https://v7player.wostreaming.net/854"const int stations = 7;// Change Number here if you add feeds!
char * stationList[stations][3] = {
{"Charlie_FM", "http://24083.live.streamtheworld.com:80/KYCHFM_SC", "good"},
{"MAXXED Out", "http://149.56.195.94:8015/steam", "good"},
{"Orig. Top 40", "http://ais-edge09-live365-dal02.cdnstream.com/a25710", "good"},
{"Smooth Jazz", "http://sj32.hnux.com/stream?type=http&nocache=3104", "good"},
{"Smooth Lounge", "http://sl32.hnux.com/stream?type=http&nocache=1257", "good"},
{"Classic FM", "http://media-ice.musicradio.com:80/ClassicFMMP3", "good"},
{"Lite Favorites", "http://naxos.cdnstream.com:80/1255_128", "good"}
};float audioGain = 1.0;
float gainfactor = 0.08;
int currentStationNumber = 0;
unsigned long disUpdate = millis();AudioGeneratorMP3 *mp3;
AudioFileSourceICYStream *filemp3;
AudioFileSourceBuffer *buffmp3;
AudioOutputI2S *out, *outmp3;void displayWiFiInformation() {
M5.Lcd.setCursor(0, 172, 2);
M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK);
M5.Lcd.setTextSize(1);
M5.Lcd.println("WiFi Network: " + String(SSID));
M5.Lcd.print( "IP Address : ");
M5.Lcd.println(WiFi.localIP());
}void initwifi() {
WiFi.disconnect();
WiFi.softAPdisconnect(true);
WiFi.mode(WIFI_STA);
WiFi.begin(SSID, PASSWORD);
// Try forever
int i = 0;
while (WiFi.status() != WL_CONNECTED) {
Serial.print("STATUS(Connecting to WiFi) ");
delay(1000);
i = i + 1;
if (i > 10) {
ESP.restart();
}
}
Serial.println("\nWiFi Connected!\n");
}String getValue(String data, char separator, int index){
int found = 0;
int strIndex[] = {0,-1};
int maxIndex = data.length() -1;for (int i = 0; i <= maxIndex && found <= index; i++){
if (data.charAt(i) == separator || i == maxIndex){
found++;
strIndex[0] = strIndex[1] + 1;
strIndex[1] = (i == maxIndex) ? i+1 : i;
}
}
return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}// Calculate Battery Usable range (3.2 to 4.0 Volts)
void displayBattery() {
int maxVolts = 400; // Battery Max volts * 100
int minVolts = 320; // Battery Min Volts * 100
M5.Lcd.setCursor(0, 155, 2);
M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK);
M5.Lcd.setTextSize(1);
M5.Lcd.printf("Battery: %.2f ", M5.Axp.GetBatVoltage());
int batt = map(M5.Axp.GetBatVoltage()*100, minVolts, maxVolts, 0 , 10000) / 100.0;// Draw Battery bar(s) on the right side of the screen
uint16_t clr = GREEN;
for(int x = 9; x >= 0; x--){
if (x < 6) clr = YELLOW;
if (x < 3) clr = RED;
M5.Lcd.fillRoundRect(315, (216-(x24)), 5, 21, 2, (batt>(x10))?clr:BLACK);
}
M5.Lcd.setCursor(180, 172, 2);
M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK);
M5.Lcd.setTextSize(1);
M5.Lcd.print("WiFi Signal: ");
M5.Lcd.print(WiFi.RSSI());
}// Remove the Track information (While changing stations)
void clearTrack() {
M5.Lcd.fillRect(0,63,310,40, BLACK); // Clear the area of old data
M5.Lcd.drawRect(0,64,310,37, BLUE); // Draw a box around the Track Information
}// Called when a metadata event occurs (i.e. an ID3 tag, an ICY block, etc.
void MDCallback(void *cbData, const char *type, bool isUnicode, const char *string) {
const char *ptr = reinterpret_cast<const char *>(cbData);
(void) isUnicode; // Punt this ball for now
// Note that the type and string may be in PROGMEM, so copy them to RAM for printf
char s1[32], s2[64];
strncpy_P(s1, type, sizeof(s1));
s1[sizeof(s1) - 1] = 0;
strncpy_P(s2, string, sizeof(s2));
s2[sizeof(s2) - 1] = 0;String band = getValue(s2, '-', 0);
band.trim();
String track = getValue(s2, '-', 1);
track.trim();Serial.printf("Band: %s Track: %s \n", band.c_str(), track.c_str());
Serial.printf("METADATA(%s) '%s' = '%s'\n", ptr, s1, s2);
M5.Lcd.setTextSize(1);
M5.Lcd.setCursor(5, 65, 2);
clearTrack();
M5.Lcd.print(band);
M5.Lcd.setCursor(5, 82, 2);
M5.Lcd.print(track);
Serial.flush();
displayBattery(); // Make sure the new song information does not overwrite the battery
}// Called when there's a warning or error (like a buffer underflow or decode hiccup)
void StatusCallback(void *cbData, int code, const char *string) {
const char *ptr = reinterpret_cast<const char *>(cbData);
// Note that the string may be in PROGMEM, so copy it to RAM for printf
char s1[64];
strncpy_P(s1, string, sizeof(s1));
s1[sizeof(s1) - 1] = 0;
Serial.printf("STATUS(%s) '%d' = '%s'\n", ptr, code, s1);
Serial.flush();
}void stopPlaying() {
Serial.printf("Stopping MP3...\n");
if (mp3) {
mp3->stop();
delete mp3;
mp3 = NULL;
}
Serial.printf("MP3 Stopped, Stopping Buffer...\n");
if (buffmp3) {
buffmp3->close();
delete buffmp3;
buffmp3 = NULL;
}
Serial.printf("Buffer stopped... Stopping File ...\n");
if (filemp3) {
filemp3->close();
delete filemp3;
filemp3 = NULL;
}
if (outmp3) {
// filemp3->close();
delete outmp3;
outmp3 = NULL;
}Serial.printf("STATUS(Stopped)\n");
Serial.flush();
}// Update the Station Label
void updateStation(String message) {
M5.Lcd.fillRect(0,30,315,30,BLACK); // Clear out other information on the line
M5.Lcd.setCursor(0, 30, 2);
M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK);
M5.Lcd.setTextSize(2);
M5.Lcd.println(message);
}// Identify buttons at the bottom of screen
void drawButtons() {
M5.Lcd.setCursor(5, 210, 2);
M5.Lcd.setTextColor(TFT_BLACK, TFT_YELLOW);
M5.Lcd.setTextSize(2);
M5.Lcd.println(" Vol Station Mute");
M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK);
M5.Lcd.setTextSize(1);
}// Change to the next station
void changeStation() {
updateStation("Changing..Wait..");
currentStationNumber++;
if ( stationList[currentStationNumber][2] == "bad") currentStationNumber++; // Skip feeds marked as bad
if (currentStationNumber >= stations) currentStationNumber = 0;
Serial.printf("\n******** Changing to channel number: %i\n", currentStationNumber);
}// Change the volume level
void changeVolume() {
audioGain += 1.0;
if (audioGain > 10.0) {
audioGain = 1.0;
}
if (audioGain < 0.0) {
audioGain = 0.0;
}
int xtPos = 260; // X Position for the Volume indication
outmp3->SetGain(audioGain * gainfactor);
M5.Lcd.fillRect(xtPos, 0, 320-xtPos-5, 21, BLACK);
uint16_t clr = GREEN;
if (audioGain > 9) clr = RED;
else if (audioGain > 6) clr = BLUE;
M5.Lcd.fillTriangle(xtPos, 20, xtPos + (5 * audioGain), 20, xtPos + (5 * audioGain), 20 - (2 * audioGain), clr);
}void playMP3() {
outmp3 = new AudioOutputI2S(0, 0); // Output to builtInDAC
outmp3->SetPinout(12, 0, 2);
outmp3->SetOutputModeMono(true);
outmp3->SetGain(audioGain * gainfactor);
filemp3 = new AudioFileSourceICYStream(stationList[currentStationNumber][1]);
filemp3->RegisterMetadataCB(MDCallback, (void*)"ICY");
buffmp3 = new AudioFileSourceBuffer(filemp3, bufferSize);
buffmp3->RegisterStatusCB(StatusCallback, (void*)"buffer");
mp3 = new AudioGeneratorMP3();
mp3->RegisterStatusCB(StatusCallback, (void*)"mp3");
mp3->begin(buffmp3, outmp3);
Serial.printf("STATUS(URL) %s %s\n", stationList[currentStationNumber][0], stationList[currentStationNumber][1]);
Serial.flush();
updateStation(String(stationList[currentStationNumber][0]));
}void loopMP3() {
if (mp3 != NULL) { // To avoid crash while changing stations
if (mp3->isRunning()) {
if (!mp3->loop()) mp3->stop();
} else {
Serial.printf("Status(Stream) Stopped \n");
stationList[currentStationNumber][2] = "bad"; // Mark feed as bad if it won't play
clearTrack();
changeStation();
// stopPlaying();
delay(1000);
playMP3();
}
}
}void setup() {
Serial.begin(115200);M5.begin();
M5.Axp.SetSpkEnable(true);
// M5.Lcd.setRotation(3);
M5.Lcd.fillScreen(BLACK);
M5.Lcd.setTextSize(2);
// M5.Lcd.setFreeFont(TT1);
// M5.Lcd.setFreeFont(FF33);
M5.Lcd.setTextColor(TFT_GREEN, TFT_BLACK);
M5.Lcd.println("Core2 Web Radio");
M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK);
M5.Lcd.setTextWrap(false);initwifi();
delay(500);
drawButtons();
playMP3();
changeVolume(); // To update Volume setting and graphic
displayWiFiInformation();
// Serial.printf("Battery Voltage: %f \n", M5.Axp.GetBatVoltage());
}void loop() {
loopMP3();
M5.update();if (m5.BtnA.wasPressed()) { //Change Volume(Button A)
changeVolume();
}if (m5.BtnB.wasPressed()) { //Change Station(Button B)
clearTrack();
changeStation();
stopPlaying();
playMP3();
}if (m5.BtnC.wasPressed()) { //Mute (Button C)
audioGain = -1.0;
changeVolume();
}if (disUpdate + 1000 < millis()) { // Update the battery voltage
disUpdate = millis();
displayBattery();
}
}Thx, will give it a try later ;-)
-
@homeuser33
Thank you! I just tried your code. It works like a charm. The sound quality on CORE2 is awesome, which is much better than it's on FIRE and StickC. -
Happy to help, but all credit goes to :
https://www.hackster.io/tommyho/arduino-web-radio-player-c4cb23
// m5StreamTest Version 2020.12b (Source/Buffer Tester)
// Board: M5StackCore2 (esp32)
// Author: tommyho510@gmail.com
// Required: Arduino library ESP8266Audio 1.60
//All I did was to work through his examples, and a few other online examples to find the right audio settings for the Core2.
Then add a few items to the GUI for battery and track information.
Hopefully I'll add some of my wish list items as time permits but it seems like a fun project.
-
Sorry, I obviously don't know what I'm doing the the 'Reply' option and I guess I made another topic. I put new code here instead of a reply to this thread.
(oops).
https://forum.m5stack.com/topic/3128/updated-version-working-core2-web-radio-player-m5stack -
Thanks a million, works as a charm on my Core2!