Project tutorial
ESP8266 Digital Radio

ESP8266 Digital Radio © GPL3+

Digital Radio made just from an ESP8266 and a speaker

  • 9,961 views
  • 5 comments
  • 7 respects

Components and supplies

Apps and online services

About this project

I wanted a simple, easy to make wifi radio with only an ESP8266 and a speaker. The Code is not mine, but I want to show others how to make it running, because it is realy interresting to see the possibilitys the ESP8266 actualy has.

Code

Installing the ESP8266 Board Library + sketch with example stationsArduino
You need to install the Board Library, to upload the sketch. Go to FILE, then to Preferences and paste the following link into Additional Boards Manager URLs:http://arduino.esp8266.com/stable/package_esp8266com_index.json
Now to the code you could use. It is in the examples of the library to, but I entert two German Radio Stations for Testing(you can replace these of course). When uploading you should set the CPU Frequency to 160 MHZ.
#include <Arduino.h>

#ifdef ESP32
    #include <WiFi.h>
#else
    #include <ESP8266WiFi.h>
#endif
#include "AudioFileSourceICYStream.h"
#include "AudioFileSourceBuffer.h"
#include "AudioGeneratorMP3.h"
#include "AudioOutputI2SNoDAC.h"

// To run, set your ESP8266 build to 160MHz, update the SSID info, and upload.

// Enter your WiFi setup here:
const char *SSID = "ssid";
const char *PASSWORD = "password";

const char *URL="http://mms.hoerradar.de:8000/rst128k";//Radio RST(German)
//const char *URL="http://ndr-edge-206c.fra-lg.cdn.addradio.net/ndr/njoy/live/mp3/128/stream.mp3";//NJOY (German)

AudioGeneratorMP3 *mp3;
AudioFileSourceICYStream *file;
AudioFileSourceBuffer *buff;
AudioOutputI2SNoDAC *out;

// 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;
  Serial.printf("METADATA(%s) '%s' = '%s'\n", ptr, s1, s2);
  Serial.flush();
}

// 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 setup()
{
  Serial.begin(115200);
  delay(1000);
  Serial.println("Connecting to WiFi");

  WiFi.disconnect();
  WiFi.softAPdisconnect(true);
  WiFi.mode(WIFI_STA);
  
  WiFi.begin(SSID, PASSWORD);

  // Try forever
  while (WiFi.status() != WL_CONNECTED) {
    Serial.println("...Connecting to WiFi");
    delay(1000);
  }
  Serial.println("Connected");

  audioLogger = &Serial;
  file = new AudioFileSourceICYStream(URL);
  file->RegisterMetadataCB(MDCallback, (void*)"ICY");
  buff = new AudioFileSourceBuffer(file, 2048);
  buff->RegisterStatusCB(StatusCallback, (void*)"buffer");
  out = new AudioOutputI2SNoDAC();
  mp3 = new AudioGeneratorMP3();
  mp3->RegisterStatusCB(StatusCallback, (void*)"mp3");
  mp3->begin(buff, out);
}


void loop()
{
  static int lastms = 0;

  if (mp3->isRunning()) {
    if (millis()-lastms > 1000) {
      lastms = millis();
      Serial.printf("Running for %d ms...\n", lastms);
      Serial.flush();
     }
    if (!mp3->loop()) mp3->stop();
  } else {
    Serial.printf("MP3 done\n");
    delay(1000);
  }
}
ESP8266Audio Library by earlephilhower
This is the library we will use. It has some great examples you could use to. just click Download .zip below and install it in the IDE under Sketch, then Include Library, and then choose it after clicking on Add .ZIP Library...

Schematics

Wirering Diagramm
This is how you need to wire the esp with the speaker. You connect the speakers positive to RX of the ESP and Ground to Ground. You can put a 50 µF capacitor in series, to improve sound quality by filtering noise
Esp8266 digital radio g3awh01s3n

Comments

Created by

earlephilhower

Are you earlephilhower ? Claim this project and add it to your profile.

This is mine

Posted by

Henry2106
Henry2106
  • 0 projects
  • 1 follower

Additional contributors

Published on

April 13, 2020

Members who respect this project

7c08dda2 d9b7 4c1c 9426 762a81f02574Dougalplummer

and 5 others

See similar projects
you might like

Similar projects you might like

ESP8266 ESP-01 Webserver

by Robin Kanattu Thomas

  • 157,616 views
  • 25 comments
  • 181 respects

Mozilla IoT WoT Gateway and ESP8266

Project tutorial by Giovanni Gentile

  • 7,163 views
  • 1 comment
  • 9 respects

Control Arduino Uno Using ESP8266 WiFi Module and Blynk App

Project tutorial by Adithya TG

  • 102,432 views
  • 19 comments
  • 68 respects

Art Deco FM Radio Project Using Arduino

Project tutorial by Nick Koumaris

  • 13,114 views
  • 2 comments
  • 27 respects

WiFi ESP8266 and DHT22 Sensor

Project tutorial by hbolanos2001

  • 38,814 views
  • 7 comments
  • 32 respects

Digital Logic Board

Project tutorial by saifalikabi

  • 22,128 views
  • 8 comments
  • 72 respects
Add projectSign up / Login