Code Monkey home page Code Monkey logo

esp-idf-vs1053's Introduction

esp-idf-vs1053

VS1053 Driver for esp-idf.
You can listen Internet radio.
I ported from here.

Software requirements

esp-idf ver4.3 or later.
Because this project uses MessageBuffer instead of RingBuffer.
MessageBuffer is 3 times faster than RingBuffer.

Hardware requirements

VS1003 or VS1053 Development Board.
The performance of VS1003 (Blue Board) and VS1053 is completely different.
VS1003 (Blue Board) is not fast.

Instalation

git clone https://github.com/nopnop2002/esp-idf-vs1053
cd esp-idf-vs1053
idf.py set-target esp32
idf.py menuconfig
idf.py flash monitor

config-main config-app

Configuration

You have to set this config value with menuconfig.

WiFi Setting

  • CONFIG_ESP_WIFI_SSID
    SSID of your wifi.
  • CONFIG_ESP_WIFI_PASSWORD
    PASSWORD of your wifi.
  • CONFIG_ESP_MAXIMUM_RETRY
    Maximum number of retries when connecting to wifi.

config-wifi

VS1053 Setting

  • CONFIG_GPIO_CS
    GPIO for XCS of VS1003.
  • CONFIG_GPIO_DCS
    GPIO for XDCS of VS1003.
  • CONFIG_GPIO_DREQ
    GPIO for XDREQ of VS1003.
  • CONFIG_GPIO_RESET
    GPIO for XRST of VS1003.Normally use the EN pin.
  • CONFIG_VOLUME
    Volume of VS1003.

config-vs1053

Radio Station Setting

  • CONFIG_SERVER_HOST
    Play this internet radio.
  • CONFIG_SERVER_PORT
  • CONFIG_SERVER_PATH
  • CONFIG_METADATA_OUTPUT
    See Display Metadata section.

config-radio-1

Infrared Setting(Optional)

See Infrared operation section.

config-ir

Wireing

for Blue board(VS1003)

VS1003 ESP32
5V -- VIN(*1)
DGND -- GND
MISO -- GPIO19
MOSI -- GPIO23
SCK -- GPIO18
DREQ -- GPIO4(*2)
XRST -- EN(*2)
XCS -- GPIO5(*2)
XDCS -- GPIO16(*2)

(*1) External power if no VIN Pin.
(*2) You can change any GPIO using menuconfig.

vs1053-1

vs1053-2

for Red board(VS1053)

VS1053 ESP32
5V -- VIN(*1)
GND -- GND
CS -- N/C(*3)
MISO -- GPIO19
SI -- GPIO23
SCK -- GPIO18
XCS -- GPIO5(*2)
XRESET -- EN(*2)
XDCS -- GPIO16(*2)
DREQ -- GPIO4(*2)

(*1) External power if no VIN Pin.
(*2) You can change any GPIO using menuconfig.
(*3) For SD card reader on the back

vs1053-1

for Green board(VS1053)

Same as Blue board.

vs1053-GREEN


Chip identification

  • VS1003
I (2135) VS1053: REG     Contents
I (2135) VS1053: ---     -----
I (2145) VS1053:   0 -   800
I (2155) VS1053:   1 -    38 ---- > 0x3X is VS1003
I (2165) VS1053:   2 -     0
I (2175) VS1053:   3 -     0
I (2185) VS1053:   4 -     0
I (2195) VS1053:   5 -  1F40
I (2205) VS1053:   6 -     0
I (2215) VS1053:   7 -     0
I (2225) VS1053:   8 -     0
I (2235) VS1053:   9 -     0
I (2245) VS1053:   A -     0
I (2255) VS1053:   B -     0
I (2265) VS1053:   C -     0
I (2275) VS1053:   D -     0
I (2285) VS1053:   E -     0
I (2295) VS1053:   F -     0

  • VS1053
I (17237) VS1053: REG    Contents
I (17237) VS1053: ---    -----
I (17247) VS1053:   0 -  4800
I (17257) VS1053:   1 -    40 ---- > 0x4X is VS1053
I (17267) VS1053:   2 -     0
I (17277) VS1053:   3 -  6000
I (17287) VS1053:   4 -     0
I (17297) VS1053:   5 -  AC44
I (17307) VS1053:   6 -     0
I (17317) VS1053:   7 -  1E06
I (17327) VS1053:   8 -     0
I (17337) VS1053:   9 -     0
I (17347) VS1053:   A -     0
I (17357) VS1053:   B -  FFFC
I (17367) VS1053:   C -     0
I (17377) VS1053:   D -     0
I (17387) VS1053:   E -     0
I (17397) VS1053:   F -     0

With the VS1003, radio stations larger than 128K bit rate cannot be played for a long time.
VS1003 and VS1053 have completely different performance.
Click here for details.


Infrared operation

You can operate using infrared remote.

Hardware requirements

  • NEC or RC5 infrared remote with two or more buttons.
  • An infrared receiver module (e.g. IRM-3638T), which integrates a demodulator and AGC circuit.
    My recommendation is a vishay product.
    http://www.vishay.com/ir-receiver-modules/

Get infrared code

Use this example to get the infrared code.
Run this example, you will see the following output log (for NEC protocol):

I (2000) example: Send command 0x20 to address 0x10
I (2070) example: Scan Code  --- addr: 0x0010 cmd: 0x0020
I (2220) example: Scan Code (repeat) --- addr: 0x0010 cmd: 0x0020
I (4240) example: Send command 0x21 to address 0x10
I (4310) example: Scan Code  --- addr: 0x0010 cmd: 0x0021
I (4460) example: Scan Code (repeat) --- addr: 0x0010 cmd: 0x0021
I (6480) example: Send command 0x22 to address 0x10
I (6550) example: Scan Code  --- addr: 0x0010 cmd: 0x0022
I (6700) example: Scan Code (repeat) --- addr: 0x0010 cmd: 0x0022
I (8720) example: Send command 0x23 to address 0x10
I (8790) example: Scan Code  --- addr: 0x0010 cmd: 0x0023
I (8940) example: Scan Code (repeat) --- addr: 0x0010 cmd: 0x0023
I (10960) example: Send command 0x24 to address 0x10
I (11030) example: Scan Code  --- addr: 0x0010 cmd: 0x0024
I (11180) example: Scan Code (repeat) --- addr: 0x0010 cmd: 0x0024

Wireing

This is typical wireing.

ESP32-IRRecv

Configure

  • Infrared Protocol
  • RMT RX GPIO
  • Remote ADDR & CMD to start PLAY
  • Remote ADDR & CMD to stop PLAY

config-ir-nec config-ir-rc5


About embedded metadata

SHOUTCast server can put a Metadata Chunk in the middle of StreamData.
The Metadata Chunk contains song titles and radio station information.

Request embedded metadata chunk

Include the following in the HTTP Request.

Icy-MetaData: 1

Metadata chunk interval

The SHOUTcast server will notify the metadata interval below.

icy-metaint:45000

This means that embedded metadata is sent from the server every 45000 bytes.

 --------------------------------------------------------------------------------
 |<---45000Byte Stream data---><Metadata><---45000Byte Stream data---><Metadata>
 --------------------------------------------------------------------------------

Metadata chunk format

Here is a detailed explanation.

The very first byte of the metadata chunk tells us how long the metadata chunk is.
However, most are 0.
0 indicates that the metadata chunk is 0 blocks(=0 byte)

 --------------------------------------------------------------------------------
 |<---45000Byte Stream data---><0><---45000Byte Stream data---><0>
 --------------------------------------------------------------------------------

Display Metadata

The detected Metadata is sent to the CONSOLE task via RingBuffer.
CONSOLE task display example:

I (3479002) CONSOLE: xRingbufferReceive item_size=112
I (3479012) CONSOLE:
StreamTitle='Maria Muldaur - Sweet Harmony';StreamUrl='http://somafm.com/logos/512/seventies512.jpg';

By changing the CONSOLE task, the received Metadata can be displayed on an external monitor.
These pages will be helpful.

Note:
If you use the SPI interface for this purpose, you need to use a VSPI_HOST(SPI3_HOST) device.
Because VS1053 occupies HSPI_HOST(SPI2_HOST) device.

My recommendation:
My recommendation is to transfer the detected metadata to another ESP on the network and view it on another ESP.
The simplest implementation is UDP Broadcast.
You can select Metadata output destination using menuconfig.
config-radio-2

If you select UDP Broadcast, you can specify the UDP port number.
config-radio-3

You can use udp_receive.py to receive Broadcast metadata.
UDP broadcast data can be received by ESP32/ESP8266.
udp-receive


About Transfer-Encoding: chunked

There is some radio station return [Transfer-Encoding: chunked].
This is one of them.

host = "icecast.radiofrance.fr";
path = "/franceculture-lofi.mp3";
Port = 80;

Even if you request [Icy-MetaData: 1], there is no [Icy-metaint] in the responce.
Chunks are padded periodically.
Details of [Transfer-Encoding: chunked] is here.

 -------------------------------------------------------------------------------------------------
 |<StreamSize><CR><LF><---Stream data---><CR><LF><StreamSize><CR><LF><---Stream data---><CR><LF>
 -------------------------------------------------------------------------------------------------

<StreamSize> is Hexadecimal string.

<1234> is 4660 bytes.

esp-idf-vs1053's People

Contributors

nopnop2002 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

esp-idf-vs1053's Issues

Consider to support audio recording (e.g. ogg format)?

Thank you for your hard work. I know VS1053 does not only support decoding and playing audio files, but also recording and encoding audio (ogg format via a proper patch). Do you consider adding audio recording functionalities in this repo? Thanks.

pin out

What about this board?
What is correspond pins?

image

Thx

Task watchdog got triggered

...
I (3070) CONSOLE: Start
I (3070) VS1053: Start
I (3070) VS1053: GPIO_DREQ=4
I (3070) gpio: GPIO[4]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 1| Intr:0 
I (3080) VS1053: GPIO_CS=5
I (3090) VS1053: GPIO_DCS=16
I (3090) VS1053: GPIO_RESET=-1
I (3100) CLIENT: Start
I (3100) MAIN: Your remote is NONE
I (3120) VS1053: 
I (3120) VS1053: REG	 Contents
I (3120) VS1053: ---	 -----
E (26550) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
E (26550) task_wdt:  - IDLE (CPU 0)
E (26550) task_wdt: Tasks currently running:
E (26550) task_wdt: CPU 0: VS1053
E (26550) task_wdt: CPU 1: IDLE
E (26550) task_wdt: Print CPU 0 (current core) backtrace

Backtrace:0x400ED5DC:0x3FFB0660 0x40081C91:0x3FFB0680 0x4008BBB8:0x3FFE2880 0x400D33F1:0x3FFE28A0 0x400D345F:0x3FFE28C0 0x400D373E:0x3FFE2910 0x400D3945:0x3FFE2940 0x400D248C:0x3FFE29D0 0x4008C45D:0x3FFE2A10 

0x400ed5dc: task_wdt_isr at /home/user/esp/esp-idf/components/esp_common/src/task_wdt.c:189
0x40081c91: _xt_lowint1 at /home/user/esp/esp-idf/components/freertos/port/xtensa/xtensa_vectors.S:1105
0x4008bbb8: _frxt_dispatch at /home/user/esp/esp-idf/components/freertos/port/xtensa/portasm.S:461
0x400d33f1: await_data_request at /home/user/esp/projects/esp-idf-vs1053/main/vs1053.c:190
0x400d345f: read_register at /home/user/esp/projects/esp-idf-vs1053/main/vs1053.c:227
0x400d373e: printDetails at /home/user/esp/projects/esp-idf-vs1053/main/vs1053.c:489
0x400d3945: spi_master_init at /home/user/esp/projects/esp-idf-vs1053/main/vs1053.c:149
0x400d248c: vs1053_task at /home/user/esp/projects/esp-idf-vs1053/main/main.c:260
0x4008c45d: vPortTaskWrapper at /home/user/esp/esp-idf/components/freertos/port/xtensa/port.c:168

ESP8266_RTOS_SDK support

Hi, I was trying to compile your project with ESP8266_RTOS_SDK and it looks ok except errors related to SPI (SPI driver looks to be very different to ESP32).

Any chance you could create another branch and support SDK for ESP8266?
Thanks

Transfer-Encoding: chunked

There is some radio station return [Transfer-Encoding: chunked].

const char *host = "icecast.radiofrance.fr";
const char *path = "/franceculture-lofi.mp3";
int httpPort = 80;

HTTP/1.1 200 OK
Content-Type: audio/mpeg
Transfer-Encoding: chunked
Connection: close
Date: Fri, 20 Mar 2020 05:44:17 GMT
icy-br: 32
ice-audio-info: channels=1;samplerate=48000;bitrate=32
icy-br: 32
icy-name: franceculture-lofi.mp3
icy-pub: 1
Server: Icecast 2.4.0-kh13
Cache-Control: no-cache, no-store
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Origin, Accept, X-Requested-With, Content-Type, Icy-MetaData
Access-Control-Allow-Methods: GET, OPTIONS, HEAD
Expires: Mon, 26 Jul 1997 05:00:00 GMT
X-Cache: Miss from cloudfront
Via: 1.1 025de06f7deee324c277661a5d0ef5fb.cloudfront.net (CloudFront)
X-Amz-Cf-Pop: NRT12-C2
X-Amz-Cf-Id: dLfbmrGSPDX7kwWnp-Xd5YG6R1JqmYNvBffs3_fcWUiOeGFmf7XYvw==

When I request [Icy-MetaData: 1] there is no [Icy-metaint]
The chunk is embedded regularly.
Not support yet.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.