Hallo zusammen,
da mir letztens in diesem Forum so toll weitergeholfen wurde, versuche ich es nun noch einmal mit einem anderen Anliegen
Ich habe aus Teilen, die ich sowieso noch übrig hatte, ein kleines Webradio gebastelt. Und zwar im Prinzip nach dieser Vorlage: ESP32 Internet Radio - educ8s.tv - Watch Learn Build
Allerdings ohne den Verstärker, einem anderen Display (SSD1306) und statt den Knöpfen möchte ich touch-Sensoren der touch-pins des esp32 nutzen. (Für nächster Sender - letzter Sender, also vor - zurück)
Das funktioniert auch schon PRINZIPIELL.
Also es gibt da zwei Probleme.
1.) Wenn ich ein am Touch Pin befestigtes Kabel berühre, wird das offenbar detektiert, das Display spring einen Sender weiter. Aber meist (oder immer?!) muss ich ihn mehrfach berühren, damit auch der Sender wechselt.
2.) Das Teil stürzt mir regelmäßig ab beim Berühren der Touch Pins. Nicht immer, aber oft. Vielleicht muss das irgendwas softwaretechnisch "entprellt" werden oder so? Ich kenne mich leider nicht so gut aus.
Im Anhang ist die Fehlermeldung beim Absturz und die ino-Datei.
#include <VS1053.h> //https://github.com/baldram/ESP_VS1053_Library
#include <WiFi.h>
#include <esp_wifi.h>
#include <EEPROM.h>
#include <SPI.h>
#include <Wire.h>
#include <U8g2lib.h>
// pin definitions vs-player
#define VS1053_CS 32
#define VS1053_DCS 33
#define VS1053_DREQ 34
#define VOLUME 85 // volume level 0-100
#define EEPROM_SIZE 2
long interval = 1000;
int SECONDS_TO_AUTOSAVE = 30;
long seconds = 0;
long previousMillis = 0;
int radioStation = 0;
int previousRadioStation = -1;
const int previousButton = 36;
const int nextButton = 39;
char ssid[] = "meinessid"; // your network SSID (name)
char pass[] = "meinpasswort"; // your network password
U8G2_SSD1306_128X64_NONAME_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 22, /* data=*/ 21, /* cs=*/ 5, /* dc=*/ 17, /* reset=*/ 16);
// Few Radio Stations
char *stationname[4] = {"UK 1940s Radio","Kosmos Radio","realfm.live24", "secure1.live24"};
char *host[4] = {"149.255.59.162","radiostreaming.ert.gr","realfm.live24.gr", "secure1.live24.gr"};
char *path[4] = {"/1","/ert-kosmos","/realfm","/skai1003"};
int port[4] = {8062,80,80,80};
int status = WL_IDLE_STATUS;
WiFiClient client;
uint8_t mp3buff[32]; // vs1053 likes 32 bytes at a time
VS1053 player(VS1053_CS, VS1053_DCS, VS1053_DREQ);
void IRAM_ATTR previousButtonInterrupt() {
if(radioStation>0)
radioStation--;
else
radioStation = 3;
}
void IRAM_ATTR nextButtonInterrupt() {
if(radioStation<4)
radioStation++;
else
radioStation = 0;
}
void setup () {
Serial.begin(9600);
delay(1000); // give me time to bring up serial monitor
// touchAttachInterrupt(T2, gotTouch, threshold);
// touchAttachInterrupt(T3, gotTouch1, threshold);
SPI.begin();
delay(500);
EEPROM.begin(EEPROM_SIZE);
pinMode(previousButton, INPUT_PULLUP);
pinMode(nextButton, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(previousButton), previousButtonInterrupt, CHANGE); //war auf falling
attachInterrupt(digitalPinToInterrupt(nextButton), nextButtonInterrupt, CHANGE); //war auf falling
Serial.println("decoder initialisieren");
initMP3Decoder();
Serial.println("decoder initialisiert");
Serial.println("wlan initialisieren");
connectToWIFI();
Serial.println("wlan initialisiert");
}
void loop() {
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval)
{
if(radioStation!=previousRadioStation)
{
station_connect(radioStation);
previousRadioStation = radioStation;
seconds = 0;
}else
{
seconds++;
if(seconds == SECONDS_TO_AUTOSAVE)
{
int readStation = readStationFromEEPROM();
if(readStation!=radioStation)
{
Serial.println("loop(): Saving new station to EEPROM");
writeStationToEEPROM(&radioStation);
}
}
}
previousMillis = currentMillis;
Serial.println("loop(): "+String(seconds) +" "+String(radioStation));
Serial.print(VOLUME);
}
if (client.available() > 0)
{
uint8_t bytesread = client.read(mp3buff, 32);
player.playChunk(mp3buff, bytesread);
}
}
void station_connect (int station_no ) {
if (client.connect(host[station_no],port[station_no]) ) Serial.println("Connected now to");
Serial.println (stationname[station_no]);
client.print(String("GET ") + path[station_no] + " HTTP/1.1\r\n" +
"Host: " + host[station_no] + "\r\n" +
"Connection: close\r\n\r\n");
Serial.println("OLED begin");
u8g2.begin();
u8g2.setFont(u8g2_font_ncenB10_tr);
u8g2.firstPage();
do {
u8g2.setCursor(0, 10);
u8g2.print(F("es spielt:"));
u8g2.setCursor(0, 40);
u8g2.print(stationname[station_no]);
u8g2.setCursor(0, 60);
u8g2.print("Lautstaerke: ");
u8g2.println(VOLUME);
} while ( u8g2.nextPage() );
Serial.println("OLED end");
}
void connectToWIFI()
{
WiFi.begin(ssid, pass);
delay(1000);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("WiFi connected");
}
void initMP3Decoder()
{
player.begin();
player.switchToMp3Mode(); // optional, some boards require this
player.setVolume(VOLUME);
}
int readStationFromEEPROM()
{
int station;
byte ByteArray[2];
for(int x = 0; x < 2; x++)
{
ByteArray[x] = EEPROM.read(x);
}
memcpy(&station, ByteArray, 2);
Serial.println("readFrequencyFromEEPROM(): "+String(station));
return station;
}
void writeStationToEEPROM(int *freq)
{
byte ByteArray[2];
memcpy(ByteArray, freq, 2);
for(int x = 0; x < 2; x++)
{
EEPROM.write(x, ByteArray[x]);
}
EEPROM.commit();
Serial.println("writeFrequencyFromEEPROM(): "+String(radioStation));
}
void IRAM_ATTR resetModule(){
// ets_printf("reboot\n");
//esp_restart();
}
Vielen Dank allen, die sich die Zeit nehmen es auch nur anzuschauen.
Danke!
ESP32_Web_Radio_v3_forum.ino (5.02 KB)