macsbug

Web Radio of M5Stack

with 11 comments

M5Stack と VS1053 Board で Web Radio を製作しました。  2021.01.08
…………………………………………. Station数の追加:rev.1: 2021.03.06
……………………………………………………. GPIO39:rev.2: 2021.05.01
……………………………………………………. GPIO39:rev.3: 2022.08.10
……………………………スケッチ Rev.4, リニューアル:rev.4: 2022.08.22

VS1053B Board:Expansion接続。

VS1003 Board:Stack接続。


.
仕様:
1. 局 ( Station ) :150局。ボタンで選択。局の追加も可能です。
2. 再生:Stereo。
3. 音質:M5Stack内蔵スピーカーより遥かに良いです。
4. 操作:ボタンで操作します。
_  A button:Volume – 。B button:Channel up 。C button:Volume +

構成:
1. 開発環境:Arduino IDE
2. Library:baldram/ESP_VS1053_Library
3. HARD:M5Stack
4. HARD:VS1053B Board:Aliexpressで 5$ ( 520円 ) 以下で購入出来ます。
_      Amazonや国内では 一桁上の高価な販売店があります。
_      基板には VS1003/VS1053 と記載。 TIP の 型番は VS1053B。
_      基板は M5Stack に見事にピッタリ入る大きさです。
5. HARD:Speaker Amp or Headphones:ダイソー ミニスピーカー
6. HARD:Expansion board

費用:1200円。( Without M5Stack )

No. Nomen Price
1 VS1053 Board 520円
2 M-BUS PCB 100円
3 DAYSO Speaker 300円
4 280円
Total 1200円

.

謝辞:Somnath Bera氏に感謝。
_ ESP32 Internet Radio
_ Somnath Bera氏の基本は Arduino IDE で作成できる事と 短いスケッチです。
_ スケッチは ESP32 Internet Radio の simple_esp32_radio_mod3 を基本に
_ M5Stackに移植致しました。

参照:Expansion Board:必要な時に接続し、不要な時に簡単に外せます。
1. M5Stack Extension Module
2. MakerBot Thingiverse:M5Stack Extension Module by macsbug
3. MakerBot Thingiverse:M5Stack Joystick by macsbug


.
🔵 rev 4:2022.08.22
スケッチ Rev.4, リニューアル:rev4 : 2022.08.22
.
Down Load:DL後 pdf(_1.pdf)を削除しzipを解凍します。
🟢 Down Load:Web_Radio_of_M5Stack_VS1053.zip
.
1. M5Stack.h から M5Unified.h に変更。
2. 表示:
- Play LED , Wave , Starion Store(保存) 追加。
- Starion Store は Play時の Stationを保存し 再起動時に そのStationから始めます。
- 起動時に B Button を押すと Station 0 になります。
- B button は ch 又は vol に切り替えます。
- A button で – , C button で + です。
3. Startionを受信しない時は 次のStationを選択します。
4. Station の見直し:廃止された局と受信しない局の削除。
5. 開発環境:
- HARD : M5Stack
- HARD : VS1053 MP3 Module
- Dev environment : Arduino IDE 1.8.19
- Board Manager : arduino-esp32 2.0.3-RC1
- Board : “M5Stack-Core-ESP32”
- Partition Scheme : “No OTA (Large APP)”
- Pord : “dev/cu.wchusbserial52D40039901”
- Library : M5Unified
- Library : baldram/ESP_VS1053_Library
. 
.
以下は 2022.08.22 改訂前です。
Down Load:ESP_VS1053_Library を含んだ File です。
. Web_Radio_of_M5Stack.zip を DLします。
. Fileは PDF形式で DL後に Web_Radio_of_M5Stack_.zip に変更し解凍します。


.
VS1053B Board.
Hard Ware:

.
仕様 ( Specifications ):
_ Separate analog, digital, and IO power supply
_ Serial data and control interface (SPI)
_ 1 headphone and audio output interface
_ 1 microphone for recording, support audio encoding format
_ 1 line input interface; supports MP3 and WAV stream
_ On-board 3.3 V and 2.5 V LDO chip AMS-1117, maximum current of 800 mA
_ Single Power Supply: +5 VDC, capacitor filter
_ 12.288 MHz crystal
_ 電源:5Vdc
_ VS1053 5V は U3 AMS1117-2.5(2.5V) から VS1053 CVDD へ供給。
_ VS1053 5V は U2 AMS1117-2.85(2.85V) から VS1053 IOVDD, AVDD へ供給。
_ VS1053 Board:Schematic
.
Soft Ware:
コード:短いコードで出来ています。
受信バッファー:32 Bytes 。player.playChunk で Play しています。
再生:固定ポートでストリーミングサイトに接続し、一度に32バイトの
_ 正確なチャンクでストリーミングデータを受信し、ボードはデータを
_ 処理し続け、ストリームは再生を続けます。

uint8_t mp3buff[32]; // VS1053 likes 32 bytes at a time

// Play -----------------------------------------
  if (client.available() > 0) {
    uint8_t bytesread = client.read(mp3buff, 32);
    player.playChunk(mp3buff, bytesread);
}
  

 
配線:
1. VS1053 Board は MBUS Board のサイズとほぼ同じです。
2. VS1053 Board を MBUS Board の以下の位置にコネクターをハンダ付けします。
3. VS1053 の GND は MBUS BAT と競合する為、BAT LIne(赤X)を Cut します。
4. VS1053 の MISO は MBUS 5V と競合する為、 5V LIne(赤X)を Cut します。
5. VS1053 の MISO,GND が MBUS 5V,BAT と非接続である事をテスターで確認します。
6. VS1053 と MBUS Pin を 以下の様に 9本配線します。

VS1053B 5V MISO SCK XRST XDCS 5V GND MOSI DREQ XCS
M-BUS 5V 19 18 EN 16 5V GND 23 17 5

.
VS1053接続: GPIO 定義

#define VS1053_CS     5 // Wiring of VS1053
#define VS1053_DCS   16 // Wiring of VS1053
#define VS1053_DREQ  17 // Wiring of VS1053
#define SPI_MOSI     23 // Wiring of VS1053
#define SPI_MISO     19 // Wiring of VS1053
#define SPI_SCK      18 // Wiring of VS1053

VS1053 CS,DCS,DREQ 接続

VS1053 player(VS1053_CS, VS1053_DCS, VS1053_DREQ);

VS1053 SPI接続:
VSPI – SCK,MISO,MOSI,SS = 18,19,23

SPI.begin();  // initialize VS1053 SPI

VS1053 SPI接続:他のGPIOを使用する場合。
HSPI – SCK,MISO,MOSI = 14,12,13

SPI.begin(SCK, MISO, MOSI);

.


 
VS1053:mp3 Mode
此のBoardは 起動時にMIDI mode になります。
そこで 音が出ないという記事が多くあります。
音を出すには mp3 mode にする必要があります。
これには 2つの方法があります。
1. HARD:33,34 Pinをshort(Yellow)すると mp3 mode になります。
2. SOFT :player.switchToMp3Mode(); を station_connectの後に記述。

player.softReset();
rx=true;
station_connect(new_counter);
player.switchToMp3Mode();  // mp3 mode
preferences.putUInt("counter",new_counter);


.
局 ( Station ) の保存:NVM Memory
_ 局を選択すると Station no (0,1,2..)を NVM Memory へ保存し 次回から
_ 保存した局 ( Station no ) から動作します。
_ 今回は 保存局を使用せず 毎回 初期の局(Station 0)から始まります。
_ 初期の局(Station 0)は setup(); の中で記述しています。
_ 保存された局を使用する場合:下記の記述をコメントアウトします。

// Comment out the following three when using NVM Memory
preferences.clear(); // namespace : NVM Clear
preferences.remove("counter"); // namespace : NVM counter Erase
preferences.end(); // preference Close

局を保存する:以下、loop(); 内に記述されています。

station_connect(new_counter); // new station connect
preferences.putUInt("counter",new_counter); // NVM Memory

局とURL:
_ 局を追加するには http://www.internet-radio.com に多数あります。
_ を Clickし URLを入手します。
_ PCでは受かるが 今回のスケッチでは 受信しない局があります。
_ 例:http://retroserver.streamr.ru:8043/retro128
_ スケッチのURLは 以下の様に変更します。( port :8043 を削除 )
_ 変更後:http://retroserver.streamr.ru/retro128 ( host + path )
_ 局によって最初の受信に時間がかかる局があります。
_ 時期や条件により 登録した局が全部受信出来るとは限りません。


 
VS1003 Board ( with phone and Line in Connector ) .
AliExpress:Aideepen Direct Store:VS1003 MP3 Board:$4.93 ( 512円)。
_      基板には VS1003/VS1053 と記載。 TIP の 型番は VS1003。
_      左上は Phone OUT。左下は LIne in Connector。
_      基板とPhone Connector は M5Stack に見事にピッタリ入る大きさです。


 
配線:

VS1003 XDCS XCS DREQ SCLK MOSI MISO XRST GND 5V
M-BUS 16 5 17 18 23 19 EN GND 5V



.
他の WEB RADIO:

m5WebRadio:Arduino IDEで直ぐ動作するスケッチ。
_ tommyho氏作成のM5StickC版「m5WebRadio」は Arduino IDEを使用。
_ 解説は丁寧で解りやすく模範となる記述内容です。
_ 出力方法は 3種類(buzzer,SPK-Hat,external speaker)があります。
_ M5Stackに移植し動作しています。

Radio Garden:地球というラジオ局をPCやiPadで聞けます。
_ 地球儀をグリグリ回して世界中のラジオ局をリアルタイムで聴けます。

iOS APP:Radio Garden Live
_ ✈️ Explore:Selected Stationで航空機の RJTT Tokyo Int – Twr/TCA,
_ App/Dep, Controlも聞けます。

Internet Radio :22,420 radio stations を PCやiPadで聞けます。


 
追記:2022.08.10
M5Stack の ButtonA が 勝手に動作する 原因と対策。
原因は ESP32チップのバグです。
対策:( 回避策 )
_ Arduino IDE:Setup() , WiFi.begin(); の直後に
_ WiFi.setSleep(false); を記載します。

void setup(){
  WiFi.begin();
  WiFi.setSleep(false);
}

参考:
ButtonA on M5Stack does not work properly


 
参考:
VLSI:VS1053b DataSheet
VS1053 Board Schematic:VS1053 Board 配線図。
VS1053 U2:AMS1117-2.85:VS1053 2.85 Regulator。
VS1053 U3:AMS1117-2.5
ESP32 Internet Radio:By Somnath Bera May 11,2018
放課後の電子工作:VS1053b 日本語データシート私家版
robo8080:M5Stack + VS1003 mp3 CodeでInternet Radioを作ったりしてみた。
_ :外部コントローラー(PC等)が必要。
Naked Ninja:M5Stack Stereo Web Radio
_ 外部コントローラー(PC等)が必要。4733行の長文。
AliExpress YX Electronic Components Store:VS1053 MP3 Board:$4.98 (518円)


 
感想:
Web Radio を経験したいが 開発環境が Arduino IDEでなかったり
あっても 行数が多く M5Stackへの移植が難しい。
YouTube には 幾つかの Web Radio があるが ソースが公開されていない。
幾つか 移植してみましたが 難解でやめました。
スケッチはシンプルさが重要だと感じました。
画像で綺麗に作ろうかと思いましたがシンプルに文字程度にしました。

ESP8266 Audio Library:この中の Sample「WebRadio」は 440行 で
_ 即 動作しない事や コントロールをPCで行い M5Stack単独ではできません。
_ コントロールをPCで行なう Web Radio は多いです。
_ PCを使用するなら PC単独でWeb Radioが出来るので意味が無いかと思います。

Web Radio は Radio Garden があり 電子工作で作るまでもありません。
電子工作ではソフトで いろいろなアイデアやアレンジが出来る効能があります。


 
スケッチ:Web Radio of M5Stack : 2021.01.08 : macsbug

//=========================================================
// Web Radio of M5Stack
// UDA1334A : ORG   : 2021.01.08 : macsbug
// Station  : Rev 1 : 2021.03.06 : macsbug
// GPIO39   : Rev 2 : 2021.05.01 : macsbug
// Github   : https://macsbug.wordpress.com/2021/01/08/web-radio-of-m5stack/
// Development environment : Aduino IDE
// Library  : baldram/ESP_VS1053_Library
//            https://github.com/baldram/ESP_VS1053_Library
// HardWare : M5Stack and VS1053 Board
// M5.BtnA.wasPressed() conflicts with WiFi? #52
//            https://github.com/m5stack/M5Stack/issues/52 
// After 1.0.6 update WiFi won't connect to other network // connection time increased #4980
//            https://github.com/espressif/arduino-esp32/issues/4980
//===========================================================
// https://www.electronicsforu.com/electronics-projects/prototypes/esp32-internet-radio
// https://forum.arduino.cc/index.php?topic=582644.0
// https://www.hackster.io/mircemk/simple-esp32-internet-radio-with-oled-display-83e49d
// https://www.elektormagazine.com/labs/esp32-internet-radio
//===========================================================

#pragma GCC optimize ("Ofast")
#include <M5Stack.h>
#include "M5StackUpdater.h"
#include "VS1053.h"      // This ESP_VS1053_Library
#include <Preferences.h> // For reading and writing into the NVM memory
Preferences preferences;
#include <WiFi.h>
#include <HTTPClient.h>
#include "ConsoleLogger.h" 
#include "helloMp3.h"
#include "Free_Fonts.h"
//        Enter your ssid and password. ------------
char ssid[] = "your network SSID";
char pass[] = "your network password"; 

int Number_of_urls = 150 -1; // Change depending on the number of URLs
char *url[150] = {           // url*Station nam
 "http://sj32.hnux.com/stream?type=http&nocache=3104*Smooth Jazz",
 "http://sj32.hnux.com/stream?type=http&nocache=1257*Smooth Lounge",
 "http://listen.181fm.com/181-beatles_128k.mp3*181-beatles_128k",
 "http://us2.internet-radio.com:8023/*Love Radio 93.9",
 "http://us5.internet-radio.com:8096/*I Love Smooth Jazz",
 "http://us5.internet-radio.com:8201/*Keith Jarrett - Over The Rainbow",
 "http://us3.internet-radio.com:8639/*Smooth Jazz Planet",
 "http://us5.internet-radio.com:8022/*Smooth Jazz DC",
 "http://us2.internet-radio.com:8046/*Matt Johnson Radio",
 "http://uk2.internet-radio.com:8236/*Funky Jazz/Soul 101 Radio",
 "http://us4.internet-radio.com:8171/*Smooth Jazz - Tampa Bay",
 "http://uk5.internet-radio.com:8174/*Joy Radio",
 "http://us3.internet-radio.com:8485/*Smooth Jazz CD 101.9 New York",
 "http://us1.internet-radio.com:8212/*KHIH-DB Colorado Smooth Jazz",
 "http://us2.internet-radio.com:8443/*MEGATON CAFE RADIO",
 "http://us4.internet-radio.com:8193/*RADIO ESTILO LEBLON",
 "http://us3.internet-radio.com:8297/*The Ranch - Classic Country",
 "http://uk7.internet-radio.com:8000/*MoveDaHouse",
 "http://uk1.internet-radio.com:8004/*Pink Noise Radio",
 "http://us5.internet-radio.com:8267/*CLASSIC ROCK RADIO HD",
 "http://us4.internet-radio.com:8258/*Classic Rock Florida HD",
 "http://us4.internet-radio.com:8266/*Smooth Jazz Florida",
 "http://us3.internet-radio.com:8297/*The Ranch - Classic Country",
 "http://uk6.internet-radio.com:8120/*Radio West Middlesex",
 "http://us3.internet-radio.com:8232/*Bach - C Major Prelude",
 "http://uk6.internet-radio.com:8144/*Radio Cherwell - Hospital Radio in Oxford",
 "http://uk5.internet-radio.com:8237/*Stoke Mandeville Hospital Radio",
 "http://us2.internet-radio.com:8075/*Classic Hits Global HD",
 "http://uk7.internet-radio.com:8226/*Box UK Radio danceradiouk",
 "http://us4.internet-radio.com:8193/*RADIO ESTILO LEBLON",
 "http://us4.internet-radio.com:8258/*Classic Rock Florida HD",
 "http://us4.internet-radio.com:8197/*EZ Hits South Florida",
 "http://uk7.internet-radio.com:8040/*Ava Max - Sweet But Psycho",
 "http://us5.internet-radio.com:8021/*Bill Evans",
 "http://uk2.internet-radio.com:31491/*A Heavenly World of Sound",
 "http://ice2.somafm.com/christmas-128-mp3*SomaFM Xmas",
 "http://www.internet-radio.com/station/sanfranciscos70shits/*San Franciscos 70s Hits",
 "http://5.152.208.98:8058/*Ancient FM",
 "http://streamer.radio.co/s06b196587/listen*KPop Way Radio",
 "http://jenny.torontocast.com:8134/stream*Mega Shuffle",
 "http://wbgo.streamguys.net/wbgo96*WBGO FM 96",
 "http://wbgo.streamguys.net/thejazzstream*jazzstream",
 "http://stream.srg-ssr.ch/thejazzstream*mp3_128",
 "http://icecast.omroep.nl/3fm-sb-mp3*3fm-sb-mp3",
 "http://media-ice.musicradio.com:80/ClassicFMMP3*Classic FM",
 "http://113fm-edge2.cdnstream.com/5185_48*BigR - 80s Lite",
 "http://streaming307.radionomy.com/WOKEmemories_64.aac*WOKEmemories ",
 "http://streaming316.radionomy.com/W1RS-blues--Rock-s-Radio*W1RSblues&Rock'sRadio",
 "http://streaming307.radionomy.com/bleudream-80_64.aac*bleudream-8",
 "http://streaming211.radionomy.com/ClassicRock-HardRock_64.aac*ClassicRock&HardRock",
 "http://streaming211.radionomy.com/kingdom-rap-radio*KingdomRapRadio",
 "http://streaming211.radionomy.com/radio-delight-kwitonta*Delight Kwitonta FM",
 "http://streaming308.radionomy.com/ViejitasPeroBonitasRadio*Viejitas Pero Bonitas Radio",
 "http://streaming307.radionomy.com/mmabathofm-live*Mmabatho FM LIVE",
 "http://streaming211.radionomy.com/sjl-radio*SjlRadio",
 "http://188.138.9.183/lounge-austria-mobile.mp3*Unspecified name",
 "http://ais-edge24-nyc06.cdnstream.com/2316_128.mp3*Foster Care Warrior Radio",
 "http://play.global.audio/bgradio128*RADIO BGRADIO",
 "http://webradio.antennevorarlberg.at/live*ANTENNE VORARLBERG HD",
 "http://s2.cdnradio.ru/ru-mp3-128*RUSSIAN SONGS",
 "http://live.coolradio.rs/cool128*COOL radio | Serbia",
 "http://streaming315.radionomy.com/foxnews*FOX News Radio",
 "http://ais-edge16-jbmedia-nyc04.cdnstream.com/hot108*HOT 108 JAMZ",
 "http://streams.iloveradio.de/iloveradio1.mp3*I Love Radio",
 "http://live.antenne.at/as*Antenne Steiermark",
 "http://webstream.schlagerparadies.de/schlagerparadies128k.mp3*SCHLAGERPARADIES",
 "http://streaming211.radionomy.com/rtl-1025*RTL 102.5",
 "http://retesport.newradio.it/1*RETE SPORT",
 "http://icy.unitedradio.it/VirginRogerWaters.mp3*PinkFloyd",
 "http://live.m2stream.fr/m280-128.mp3*M2 80's",
 "http://live.m2stream.fr/m2hit-128.mp3*M2 Hit's",
 "http://live.m2stream.fr/m2club-128.mp3*M2 Club",
 "http://live.m2stream.fr/m2love-128.mp3*M2 Love",
 "http://live.m2stream.fr/m2rock-128.mp3*M2 Rock",
 "http://live.m2stream.fr/m2sunshine-128.mp3*M2 Sunshine",
 "http://100radio-90.ice.infomaniak.ch/100radio-90-64.aac*100  0",
 "http://100radio-80.ice.infomaniak.ch/100radio-80-64.aac*1000",
 "http://100radio-hit.ice.infomaniak.ch/100radio-hit-64.aac*100",
 "http://icecast.vgtrk.cdnvideo.ru/vestifm_aac_32kbps*FM News",
 "http://nashe1.hostingradio.ru/nashe20-128.mp3*Our Radio",
 "http://mp3.ffh.de/radioffh/hqlivestream.aac*hqlivestream",
 "http://radiostreaming.ert.gr/ert-kosmos*ert-kosmos",
 "http://ic6.101.ru:8000/a161*Italo Disco",
 "http://cmr-hosting.com/*8050**CLUB MUSIC RADIO - ITALO DISCO",
 "http://den.101.ru:4000/ar_66_03*101.ru - AutoRadio Ekaterinburg",
 "http://ic7.101.ru:8000/a79*101.ru - Cyber Space",
 "http://ic7.101.ru:8000/a161*101.ru - Italo Disco",
 "http://ic7.101.ru:8000/a175*ENIGMA",
 "http://vladfm.com:8000/vfm*Radio Vladivostok FM",
 "http://jfm1.hostingradio.ru:14536/rcstream.mp3*Radio Classic",
 "http://retroserver.streamr.ru:8043/retro128*Radio Retro FM",
 "http://retro70.hostingradio.ru:8025/retro70-128.mp3*Radio Retro FM 70e",
 "http://91.211.56.218:8080/piramida/nazarovo*Radio Piramida FM",
 "http://sea.1tvcrimea.ru:9003/stream_sea.mp3*Radio More",
 "http://kommersant77.hostingradio.ru:8016/kommersant128.mp3*Radio Kommersant FM",
 "http://bfmstream.bfm.ru:8004/fm64*Business FM Moscow 87.5",
 "http://ep128server.streamr.ru:8030/ep128*Europe plus",
 "http://212.26.146.50:8000/rusrock.mp3*Russian rock music",
 "http://listen2.myradio24.com:9000/8144*Radio Magic",
 "http://media2.brg.ua:8000/shanson_l*Radio Chanson",
 "http://online1.gkvr.ru:8000/radiola_eka_128.mp3*Radio Radiola",
 "http://online.radiorecord.ru:8102/sd90_128*Disco 90х",
 "http://online.radiorecord.ru:8102/sd90_128*Superdisco 90х",
 "http://airspectrum.cdnstream1.com:8000/1261_192*Magic Oldies Florida",
 "http://37.187.79.93:8368/stream2*stream2",
 "http://tropicalisima.net:8020/stream/1/*stream",
 "http://192.173.28.222:3690/KRSHFMAAC_SC*The Krush - Wine Country Radio",
 "http://ice.creacast.com/myzen-aac-64*MyZen Radio",
 "http://cms.stream.publicradio.org/cms.aac*Classical 24",
 "http://ais-sa3.cdnstream1.com/2440_128.aac*Oregon Public Broadcasting",
 "http://nis.stream.publicradio.org/nis.aac*MPR News - Minnesota Public Radio",
 "http://current.stream.publicradio.org/current.mp3*The Current",
 "http://stm29.conectastm.com:18860/stream*Nativa FM",
 "http://stream.haarlem105.nl:8000/haarlem105low.mp3*Haarlem 10",
 "http://rockthecradle.stream.publicradio.org/radioheartland.mp3*Radio Heartland - MPR",
 "http://studioone-stream.iowapublicradio.org/StudioOne.mp3*Iowa Public Radio News and Studio One",
 "http://opera-stream.wqxr.org/wnycam-app*WNYC-AM - New York Public Radio",
 "http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio4fm_mf_p*BBC Radio 4",
 "http://bbcwssc.ic.llnwd.net/stream/bbcwssc_mp1_ws-einws*BBC World Service",
 "http://sc8.radiocaroline.net/;*Radio Caroline",
 "http://108.61.154.147:6978/*The Nemesis Radio",
 "http://198.50.156.92:8439/*Power 945 ~Your Anime & Gaming Connection~",
 "http://198.50.158.92:8803/*Japannext Radio",
 "http://62.75.215.7:8016/*Blue Heron Radio",
 "http://23.29.71.154:8062/*Friends Forever",
 "http://184.75.223.178:8011/*J-Idols Project Radio - Global Edition",
 "http://radio.kahoku.net:8000/*FMkahoku",
 "http://51.81.46.118:3350/*J-Club Powerplay HipHop",
 "http://51.81.46.118:3340/*J-Rock PowerPlay",
 "http://184.75.223.178:8083/*J-Pop Project Radio - Global Edition",
 "http://uk5.internet-radio.com:8306/*Moon Mission Recordings, Tokyo Deep and Electronic",
 "http://sj32.hnux.com/stream?type=http&nocache=3104*Smooth Jazz",
 "http://uk7.internet-radio.com:8226/*Box UK Radio danceradiouk",
 "http://uk6.internet-radio.com:8230/*Brassbandradio Radio",
 "http://uk1.internet-radio.com:8355/*The Zone - Dublin",
 "http://uk5.internet-radio.com:8011/*Top 80 radio",
 "http://uk7.internet-radio.com:8281/*SWEET ONE RADIO (FRENCH RADIO)",
 "http://uk2.internet-radio.com:8288/*Lymm Community Radio",
 "http://us3.internet-radio.com:8496/*RaveRocksRadio",
 "http://uk3.internet-radio.com:8288/*Relaxing Music",
 "http://us3.internet-radio.com:8157/*Amaghana Radio",
 "http://uk1.internet-radio.com:8465/*Great relaxing music, a nice journey away of the daily problems",
 "http://us3.internet-radio.com:8157/*Amaghana Radio",
 "http://uk1.internet-radio.com:8235/*Hospital Radio",
 "http://us5.internet-radio.com:8026/*Ukiss Radio",
 "http://uk6.internet-radio.com:8224/*Breaking Barriers Bulgaria",
 "http://us2.internet-radio.com:8075/*Classic Hits Global HD",
 "http://uk7.internet-radio.com:8168/*242 RADIO stream",
 "http://uk3.internet-radio.com:8405/*Majestic Jukebox Radio #HIGH QUALITY SOUND",
 "http://us2.internet-radio.com:8443/*MEGATON CAFE RADIO"
};
// http://icecast.omroep.nl
// http://github.com/pilnikov/KaRadio32_fork/blob/master/playlist/WebStations.txt
// http://fmstream.org
// http://www.internet-radio.com
// http://icecast.omroep.nl
// http://github.com/pilnikov/KaRadio32_fork/blob/master/playlist/WebStations.txt
// http://fmstream.org
// http://www.internet-radio.com

int  counter = 0, old_counter = 0, new_counter = 0;
char host[100], path[100], sname[100]; 
int  port;
char rx=true;
WiFiClient client;
uint8_t mp3buff[32];    // VS1053 likes 32 bytes at a time
#define VS1053_CS     5 // Wiring of VS1053
#define VS1053_DCS   16 // Wiring of VS1053
#define VS1053_DREQ  17 // Wiring of VS1053
#define SPI_MOSI     23 // Wiring of VS1053
#define SPI_MISO     19 // Wiring of VS1053
#define SPI_SCK      18 // Wiring of VS1053
int led = 0;
int vol = 80;           // volume level 0-100
VS1053 player(VS1053_CS,VS1053_DCS,VS1053_DREQ); // VS1053 init

//============================================================
void setup () {
  M5.begin();
  Wire.begin();if(digitalRead(BUTTON_A_PIN)==0){updateFromFS(SD);ESP.restart();}
  M5.Lcd.setRotation(1);
  M5.Lcd.fillScreen  (BLUE);              // 0x657F
  M5.Lcd.setFreeFont (FMB12);             // font
  MP(0,1,0xFFFF," Web Radio of M5Stack"); // x,yLine,WHITE
  // VS1053 --------------------------------------------------
  SPI.begin();              // initialize VS1053 SPI
  player.begin();           // initialize VS1053 player
  player.switchToMp3Mode(); // VS1053 board : mp3 mode
  player.setVolume(vol);    // VS1053 board : set volume
  // WiFi ----------------------------------------------------
  WiFi.disconnect();
  WiFi.begin(ssid,pass);    // Set ssid,pass
  WiFi.setSleep(false);     // Prevent GPIO39 Pulse
  M5.Lcd.setTextColor(WHITE);M5.Lcd.setCursor(0,44);
  while(WiFi.status()!=WL_CONNECTED){delay(50);M5.Lcd.print(".");}
  MP(0,2,0xFFFF,"Connected to Wifi");
  // VS1053 --------------------------------------------------
  preferences.begin("my-app",false);// Start namespace called my-app
  // https://qiita.com/T-YOSH/items/f388b4d7cbc829829aae
  // Comment out the following three when using NVM Memory
  preferences.clear();          // namespace : NVM Clear
  preferences.remove("counter");// namespace : NVM counter Erase
  preferences.end();            // preference Close
  station_connect(counter);     // station connect,host,path,sname
  counter=preferences.getUInt("counter",counter);// NVM Memory
  // Display -------------------------------------------------
  MP(0,3,0xFFFF,"Station:"+String(counter));// Staion NO.
  MP(0,4,0xFFFF,"Playing:"+String(sname));  // Staion name
  set_vol_btn();                          // Volume and Button 
  player.playChunk(hello2,sizeof(hello2));//VS1053 is wake up & running
  delay(2000);
}
//============================================================
void loop() {
  M5.update();
  // Play ----------------------------------------------------
  if (client.available() > 0) {                    // Rx
    uint8_t bytesread = client.read(mp3buff,32);   // Rx buff
    player.playChunk(mp3buff, bytesread);          // play
  }
  // Play LED ------------------------------------------------
  led = led + 1;
  if(led>1){M5.Lcd.fillCircle(310,8,5,GREEN);led=0;// led on
   }else{   M5.Lcd.fillCircle(310,8,5,BLUE );      // led off
  }
  // ch+ -----------------------------------------------------
  if(M5.BtnB.wasPressed() and rx==true){
    rx=false;
    Button_(0xD6DA,0x762F,0xD6DA);  // ch Button on
    old_counter=counter;            // old counter
    counter=counter+1;              // counter up
    if(counter>Number_of_urls){counter=0;} // url count
    preferences.putUInt("counter",counter-1);delay(500);//NVM Memory
    new_counter=counter;            // new counter
    // Station UP ---------------------------------------------
    if(old_counter != new_counter){ // new counter, new station
      rx=true;
      player.softReset();
      player.switchToMp3Mode();     // VS1053 board : mp3 mode
      station_connect(new_counter); // new station connect,host,path,sname
      preferences.putUInt("counter",new_counter);delay(500);//NVM Memory
      // Display update ---------------------------------------
      MP(0,3,0xFFFF,"Station:"+String(counter));// Station NO.
      M5.Lcd.fillRect (0,110,320,80,BLUE);      // clear
      MP(0,4,0xFFFF,"Playing:"+String(sname));  // Station Name
      set_vol_btn();                // Volume and Button
      MP(0,2,0xFFFF,"Playing");     // Infomation
    }
  }
  // Vol- -----------------------------------------------------
  if(M5.BtnA.wasPressed()){         // ButtonA
    Button_(0x762F,0xD6DA,0xD6DA);  // vol- Button on
    vol=vol-5;if(vol<=0){vol=0;}    // vol-
    set_vol_btn();                  // Volume and Button
  }
  // Vol+ ------------------------------------------------------
  if(M5.BtnC.wasPressed()){         // ButtonC
    Button_(0xD6DA,0xD6DA,0x762F);  // vol+ Button on
    vol=vol+5;if(vol>=100){vol=100;}// vol+
    set_vol_btn();                  // Volume and Button
  }
} // End of loop
//==============================================================
void MP(int xpos, int yLine, int16_t color, String str){
  M5.Lcd.fillRect (xpos,30*yLine-30,320,20,BLUE); // clear
  M5.Lcd.setCursor(xpos,30*yLine-16);             // yLine:0-8
  M5.Lcd.setTextColor(color);M5.Lcd.println(str); // Display
// https://github.com/m5stack/m5-docs/blob/master/docs/ja/api/lcd.md
}
// -------------------------------------------------------------
void station_connect(int cnt){      // Station Connect
  host_path_sname(cnt);             // host,path,port,sname
  if(client.connect(host,port)){MP(0,2,0xFFFF,"Wait...");}
  client.print(String("GET ") + path + " HTTP/1.1\r\n" +
   "Host: " + host + "\r\n" + "Connection: close\r\n\r\n");
  delay(1000);
}
//--------------------------------------------------------------
void set_vol_btn(){
  player.setVolume(vol);                   // Set Volume
  MP(0,7,0xFFFF,"Volume:");MP(100,7,0xFFFF,String(vol));
  M5.Lcd.progressBar(150,180,160,16,vol);  // ProgressBar
  delay(250);Button_(0xD6DA,0xD6DA,0xD6DA);// vol Button off
}
//--------------------------------------------------------------
void Button_(long BA,long BB,long BC){     // Button display
  // https://trolsoft.ru/en/articles/rgb565-color-picker
  M5.Lcd.setTextColor(BLACK);              // BLACK
  M5.Lcd.fillRoundRect( 37,210,60,30,5,BA);
  M5.Lcd.setCursor( 40,230);M5.Lcd.println("vol-");
  M5.Lcd.fillRoundRect(133,210,60,30,5,BB);
  M5.Lcd.setCursor(149,230);M5.Lcd.println("ch");
  M5.Lcd.fillRoundRect(226,210,60,30,5,BC);
  M5.Lcd.setCursor(229,230);M5.Lcd.println("vol+");
}
//--------------------------------------------------------------
void host_path_sname(int c){// Separate into host,path,port,sname
  // host ------------------------------------------------------
  String s=String(url[c]).substring(String(url[c]).indexOf("//")+2);
  String h=s.substring(0,s.indexOf("/")+1); // witout port
  h.toCharArray(host,h.length()); 
  if(s.indexOf(":") >= 0 ){                 // with   port
    h=s.substring(0,s.indexOf(":")+1);
    h.toCharArray(host,h.length());         // host
  }
  // path ------------------------------------------------------
  String p=s.substring(s.indexOf("/"),s.indexOf("*")+1);
  p.toCharArray(path,p.length());           // path
  // port ------------------------------------------------------
  String t=String(url[c]).substring(String(url[c]).indexOf("//")+2);
  port = 80;                                // port
  if(t.indexOf(":") > 0){ 
    String pt=t.substring(t.indexOf(':')+1,t.indexOf("*")+1);
    port=pt.toInt();                        // port
  }
  // Sname -----------------------------------------------------
  String n=s.substring(s.indexOf("*")+1)+1;
  n.toCharArray(sname,n.length());          // sname
}
//--------------------------------------------------------------

 
 
 
M5Stack , VS1053 , Web Radio , mp3 , MIDI , Radio Garden , m5WebRadio ,

Written by macsbug

1月 8, 2021 @ 3:37 pm

カテゴリー: M5STACK

11件のフィードバック

Subscribe to comments with RSS.

  1. こんにちは。
    これとても興味あります。
    なぜか https://macsbug.files.wordpress.com/2021/01/web_radio_of_m5stack.zip_.pdf
    エラーでDLできません。

    エラー
    PDF ドキュメントを読み込めませんでした。 

    なかよし

    1月 9, 2021 at 9:33 am

    • ブログ訪問をありがとうございます。
      iMac を使用し BLOG からの DL は出来ています。
      ブラウザーで https://macsbug.files.wordpress.com/2021/01/web_radio_of_m5stack.zip_.pdf
      を直接入力すると 画面がでて ↓ で DL 出来ています。

      macsbug

      1月 9, 2021 at 9:44 am

      • こんにちは。
        当方win10 chrome browser , IEでやってもだめでした。androidスマホでやってもだめです。なぜでしょうかね。。

        なかよし

        1月 9, 2021 at 9:52 am

      • なかよしさん
        お断りもなく メールで zip file をお送り致しました。

        macsbug

        1月 9, 2021 at 9:59 am

      • ありがとうございました。

        なかよし

        1月 9, 2021 at 10:07 am

  2. 初めまして。

    VS1053で無事再生確認できましたが、ボリューム操作が効きません。(画面上では反映されているが、実際の音量に反映されない。)

    33,34 Pinをshort(Yellow)するハードの mp3 modeは行っていません。
    M5StackはBasicではなくGrayです。

    どのような原因が考えられるでしょうか。
    よろしくお願いいたします。

    aka

    3月 19, 2021 at 4:33 pm

    • お騒がせしました。
      回路を確認した結果、XCSとGNDがショートしていたため音量が最大で固定になっていたようです。
      (組みあがったVS1053B Board単体では問題なかったが、M5Stack GrayとStackした際にショートしてしまった。)

      aka

      3月 19, 2021 at 5:17 pm

      • akaさん
        原因が見つかってよかったですね。
        貴重な情報をありがとうございます。
        XCSがGNDにSHORTすると その現象が起きる情報は大変参考になりました。
        単体としては問題無く STACKした時に発生したとの事から 解決手順は素晴らしいですね。

        macsbug

        3月 19, 2021 at 6:11 pm

    • akaさん、訪問をありがとうございます。
      ヒントは音量が反映されないのですね。

      macsbug

      3月 19, 2021 at 6:11 pm

  3. satton 70台の爺さんです M5スタックも2台 あります
    以前 Web radio キット(表示がなくて 使いずらい)Volumio も 作りましたが
    Aruduino raspberry の コピペ ばかりです
    今回 PDFファイル エラーで ダウンロード できません
    ご面倒ですが ファイル 送って ください

    satton

    12月 22, 2021 at 1:47 pm

    • satton 様
      サイトの訪問をありがとうございます。
      メールで zip と Folder で送らさせて頂きました。
      上手くいく事を願っています。
      お手数ですができない場合は連絡ください。

      macsbug

      12月 22, 2021 at 6:20 pm


コメントを残す