Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Nick Koumaris
Published © CC BY-NC-SA

Internet Radio Using an ESP32

Today we are going to build an Internet radio device with a large 3.5” display using an inexpensive ESP32 board.

IntermediateFull instructions provided1 hour15,536
Internet Radio Using an ESP32

Things used in this project

Story

Read more

Code

Code snippet #2

Plain text
void setup () {   Serial.begin(9600);
   delay(500);
   SPI.begin();   pinMode(previousButton, INPUT_PULLUP);
   pinMode(nextButton, INPUT_PULLUP);   attachInterrupt(digitalPinToInterrupt(previousButton), previousButtonInterrupt, FALLING);
   attachInterrupt(digitalPinToInterrupt(nextButton), nextButtonInterrupt, FALLING);   initMP3Decoder();   connectToWIFI();}

Code snippet #3

Plain text
void loop() {     
      if(radioStation!=previousRadioStation)
      {
           station_connect(radioStation);
           previousRadioStation = radioStation; 
      }
      
      if (client.available() > 0)
      {
        uint8_t bytesread = client.read(mp3buff, 32);
        player.playChunk(mp3buff, bytesread);
      }
}

Code snippet #4

Plain text
void IRAM_ATTR previousButtonInterrupt() {  static unsigned long last_interrupt_time = 0;
  unsigned long interrupt_time = millis();
 
 if (interrupt_time - last_interrupt_time > 200) 
 {
   if(radioStation>0)
    radioStation--;
    else
    radioStation = 3;
 }
 last_interrupt_time = interrupt_time;
}

Code snippet #5

Plain text
void drawRadioStationName(int id){
  String command;
  switch (id)  
  {
    case 0:  command = "p1.pic=2"; Serial.print(command); endNextionCommand(); break; //1940 UK Radio
    case 1:  command = "p1.pic=3"; Serial.print(command); endNextionCommand(); break; //KOSMOS     GREEK
    case 2:  command = "p1.pic=4"; Serial.print(command); endNextionCommand(); break; //REAL FM    GREEK
    case 3:  command = "p1.pic=5"; Serial.print(command); endNextionCommand(); break; //SKAI 100.3 GREEK
  }
}

Credits

Nick Koumaris

Nick Koumaris

13 projects • 311 followers
My name is Nick Koumaris and I am a software engineer from Sparta, Greece. I love building projects and share them with the world!

Comments