macsbug

Web_Radio_of_M5Stack_I2S_DAC

with 4 comments

M5Stack と I2S DAC Board で Web Radio を製作しました。 ORG : 2021.02.14
……………………… Boards Manager 1.05-rc7 による改訂:rev1 : 2021.02.20
……………………………. Boards Manager 1.05 による改訂:rev2 : 2021.03.04
……………………………. Boards Manager 1.06 による改訂:rev3 : 2021.05.01
……………………………. A Button GPIO39 不具合対策追記:rev4 : 2022.08.10
……………………………. スケッチ Rev.4, リニューアル  :rev5 : 2022.08.21

.
仕様:
1. 局 ( Station ) :150局。ボタンで選択。局の追加も可能です。
2. 再生:Stereo。
3. 音質:M5Stack内蔵スピーカーより遥かに良いです。
4. 操作:ボタンで操作します。
_  A button:Volume – 。B button:Channel up 。C button:Volume +
5. 文書発声機能:日本語、英語 等の文章を音声再生が出来ます。

構成:
1. 開発機種:MacBook Pro (16-inch, 2019) , macOS Catalina Ver 10.15.7
2. 開発環境:Arduino IDE 1.8.13
3. Library:schreibfaul1/ESP32-audioI2S
4. HARD:M5Stack
5. HARD:UDA1334A I2S DAC Module:現品は NXP1334A
_     Aliexpressで $2.8(300円)以下で購入可能。
6. HARD:Speaker Amp or Headphones:ダイソー ミニスピーカー

費用:1000円。( Without M5Stack )

No. Nomen Price
1 UDA1334A I2S DAC Module 300円
2 M-BUS PCB 100円
3 DAYSO Speaker 300円
4 Other 280円
Total 980円

.


.
🔵 追記:2022.08.21
スケッチ Rev.4, リニューアル:rev5 : 2022.08.21
.
🟢 Down Load:Web_Radio_of_M5Stack_I2S.zip
. Fileは PDF形式で DL後に Web_Radio_of_M5Stack_I2S.zip に変更し解凍します。
.
1. M5STack.h から M5Unified.h に変更。
2. I2S DAC は MAX1334A, UDA1334A, PCM5102A I2S DAC に対応。
3. 表示:
- Play LED , Reseption LED , Wave , Starion Store(保存) 追加。
- Starion Store は Play時の Stationを保存し 再起動時に そのStationから始めます。
- 起動して WiFi 接続中に B Button を押すと Station 0 になります。
- B button は ch 又は vol に切り替えます。
- A button で – , C button で + です。
4. Startionを受信しない時は 次のStationを選択します。
5. Station の見直し:廃止された局や再起動する局の削除。
6. 開発環境:
- 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 : schreibfaul1 / ESP32-audioI2S 2.0.4
.

.


.
Down Load:
. Web_Radio_of_M5Stack_I2S_DAC.zip を Down Load します。
. Fileは PDF形式で DL後に Web_Radio_of_M5Stack_I2S_DAC.zip に変更し解凍します。

. Library:ESP32-audioI2S


.
I2S DAC Board:CJMCU-1334 ( UDA1334A I2S DAC ) ( NXP1334A I2S DAC )
_ 電源:VIN は 5V です。LDO LG33 で 3.3V が作られています。
_ 参考:Adafruit I2S Stereo Decoder – UDA1334A

.


.
配線:5本 ( BCLK, DIN, WSEL, GND, VIN )

UDA1334A BCLK DIN WSEL GND VIN
M-BUS 26 22 25 GND 5V

M5Stackの改造:ノイズ対策。
理由:I2S は M5Stack の GPIO 25 を使用します。
_ GPIO 25 には アンプとSpeaker が接続されており I2Sの信号でノイズがでます。
_ 対策は M5Stack基板上の T1 端子をハンダ等でShort させます。
_ Speaker Amp の電源が遮断され ノイズが無くなります。


.
Arduino IDE 開発条件と方法:
_ 1. Additional Boards Manager URLs:ESP32 Stable version
_ 2. Boards Manager:ESP32 by Espresso Systems version 1.0.5
_ 3. Board Selection : M5Stack-Core-ESP32
_ の設定を行ないます。

条件:
1. Aduino IDE Additional Boards Manager URLs に以下のStable verを追加します。
_ 補足:released this Feb 23, 2021:Latest Stable Release and Latest Development Release

https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json

2. Arduino IDE Boards Manager 設定:
_ Boards Managerを選択し ESP32 で検索。
_ ESP32 by Espresso Systems version 1.05 にします。( released this Feb 23, 2021)
_

3. Arduino IDE 設定:
_ Board Selection : M5Stack-Core-ESP32

方法:スケッチ:宣言
1. include <M5Stack.h>
2. include <Audio.h>

補足:ESP32-audioI2S_Library ( Audio.cpp ) について。
_ Audio.cpp に以下の記述があり、上記設定外でコンパイルエラーが出る時があります。
_ Audio::Audio(const uint8_t BCLK, const uint8_t LRC, const uint8_t DOUT) {
_ clientsecure.setInsecure();
_ // if that can’t be resolved update to ESP32 Arduino version 1.0.5-rc05 or higher
_ //i2s configuration
_
.


.
Library:ESP32-audioI2S:文書発声機能について。
_ ESP32-audioI2S にある Audio.cppには 文書発声機能が内蔵されています。
_ これにより PCM5102A , UDA1334A I2S DAC から音声を出す事が出来ます。
_ 日本語、英語 等ができます。
_ 例:audio.connecttospeech(“こんにちは”, “ja”)
_ 例:audio.connecttospeech(“Hello”, “en”)
_ 例:audio.connecttospeech(“Wenn die Hunde schlafen, kann der Wolf gut Schafe stehlen.”, “de”);
.


.
課題:時々 ボタンを押さなくとも GPIO 39 に Pulseが発生し Vol – が動作する。
_ 特に Joy Radio Station , http://uk5.internet-radio.com:8174/ で多く発生する。
_ 受信の あるタイミングで GPIO 39 をアクセスする。
_ ソフト検証では、GPIO 39 に 0〜1msec 程度の Pulse が発生します。
_  24msec程度の時も1度経験しました。
対策:M5.BtnA.wasPressed() でなく、M5.BtnA.pressedFor(50) にて
_   50msec以上の場合の時に Vol – を動作する様にしました。
_   メモ:通常、人のボタンをプチッと押す時間は 200〜300msec程度です。
🔴 追記: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


.
感想:
1. 注意:ESP32-audioI2S の Audio.cpp の注意書きの対応が必要です。
_ ESP32 by Espresso Systems version 1.05 を使用します。

2. 前回の Web Radio of M5Stack (VS1053)よりも通信速度が速い事と
_ 出力が大きく音が明瞭です。
3. 費用:UDA1334A Module は 300円以下で安価にできます。
_    ただし国内やアマゾンでは高価な価格で販売されています。
4. 局数:150局。現存する Web Radio の中で最大の局数です。
5. ESP32 by Espresso System version:
_ 1.05-rc5, 1.05-rc6 は たまに M5stackの画面が白くなる現象がありました。
_ 2021.02.23 に ver 1.0.5 が公開されました。
_ ver 1.0.5-rc7 又は ver 1.05 により M5Stackの画面が白くなる現象は無くなりました。
_ 上記の開発環境は
_ ESP32-audioI2S ( Audio.cpp ) を使用する為に、
_ Espresso System version 1.05 が必要である事、
_ さらに Board Select を ESP32 Dev Module にする事。
_ M5Stack で使用するには ESP32-Chimera-Core が必要になる。
_ この為に M5.Lcd の ボタン操作命令が使用出来ないとか
_ 一部の画像表示命令が使用出来ない制限があります。
_ ver 1.05 により M5Stack.h が使用できる様になりました。
6 .課題と対策:たまに VOL- (GPIO39)が動作する課題がありました。原因不明。
_ VS1053 mp3 Board, I2S DAC UDA1334A, PCM5102A Board にて同様に VOL- が発生します。
_ 対策は VOL- に 50msec Filter を入れました。


.
スケッチ:Web Radio of M5Stack and I2S DAC : 2021.02.14 : macsbug
_ Enter your ssid and password:Wifi の ssid , pass は ご自身の値を設定してください。

//===========================================================
// Web Radio of M5Stack I2S DAC 
// UDA1334A : ORG   : 2021.02.14 : macsbug
// PCM5102A : rev 1 : 2021.02.20 : macsbug
// PCM5102A : rev 2 : 2021.03.03 : macsbug
// GPIO39   : rev 3 : 2021.05.01 : macsbug
// Github   : https://macsbug.wordpress.com/2021/04/16/web-radio-with-a-built-in-speaker-in-m5stack/
// Github   : https://macsbug.wordpress.com/2021/02/14/web_radio_of_m5stack_i2s_dac/
// Github   : https://macsbug.wordpress.com/2021/02/19/web-radio-of-m5stack-pcm5102a-i2s-dac/
// Github   : https://macsbug.wordpress.com/2021/01/08/web-radio-of-m5stack/
// Development environment : Aduino IDE ver 1.8.13
// Additional Boards Manager URLs : 
//            https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
// Boards Manager  : ESP32 by Espresso System version 1.06
// Board selection : M5Stack-Core_ESP32
// Library  : schreibfaul1/ESP32-audioI2S_Library
//            https://github.com/schreibfaul1/ESP32-audioI2S
// HardWare : M5Stack and UDA1334A I2S DAC Board
// HardWare : M5Stack and PCM5102A I2S DAC Board
// M5Stack  : Short T1 of M5stack Board(M5 Speaker Nois Cut)
// 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
//===========================================================

#pragma GCC optimize ("Ofast")
#include <M5Stack.h>
#include <M5StackUpdater.h> // SD-Upadate
#include "Free_Fonts.h"
#include <Arduino.h>
#include <WiFi.h>
#include <Audio.h>
Audio audio;
#define I2S_BCK  26 // M5Stack Node I2S pins
#define I2S_WS   25 // M5Stack Node I2S pins
#define I2S_DOUT 22 // M5Stack Node I2S pins
//        Enter your ssid and password. ------------
char ssid[] = "xxx"; // your network SSID (name) 
char pass[] = "xxx"; // your network password
int counter=0, old_counter=0, new_counter=0; 
int playflag=0, led=0, vol=5;
char URL[100], sname[100];

int Number_of_urls = 164 -1; // Change depending on the number of URLs
char *url[164] = {           // url*Station nam 
 "http://sj32.hnux.com/stream?type=http&nocache=3104*Smooth Jazz",
 "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://sj32.hnux.com/stream?type=http&nocache=1257*Smooth Lounge",
 "http://relay4.slayradio.org:8200/*SlayRadio", 
 "http://allstream.rainwave.cc:8000/all.mp3*Rainwave All",
 "http://tx.sharp-stream.com/icecast.php?i=planetrock.mp3*Planet Rock",
 "http://s1.viastreaming.net:8000*Smooth Choice",
 "http://sc6.radiocaroline.net:8040/listen.pls*Radio Caroline",
 "http://sc6.radiocaroline.net:10558/listen.pls*Radio Caroline Flashback",
 "http://listen.181fm.com/181-uktop40_128k.mp3*181 F M Top 40",
 "http://listen.181fm.com/181-90scountry_128k.mp3*181 F M Country",
 "http://listen.181fm.com/181-oldschool_128k.mp3*181 F M Old School",
 "http://listen.181fm.com/181-90sdance_128k.mp3*181 F M Nineties Dance",
 "http://listen.181fm.com/181-chilled_128k.mp3*181 F M Chilled",
 "http://listen.181fm.com/181-classical_128k.mp3*181 F M Classical", //
 "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

//============================================================
void setup() {
  // M5Stack Initialize --------------------------------------
  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
  // WiFi Connection ----------------------------------------
  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");      // Infomation
  // UDA1334A or PCM5102A I2S DAC Initialize ----------------
  audio.setPinout(I2S_BCK,I2S_WS,I2S_DOUT);// Setup I2S Pin
  audio.setVolume(vol);                    // Set Vol 0...21
  speech("こんにちは","ja");                 // Speech
  speech("Web Radio of M5Stack","en");     // Speech
  // Button Initialize --------------------------------------
  Button_(0xD6DA,0xD6DA,0xD6DA);           // ch Button off
  delay(1000);
}
//============================================================
void loop() {
  M5.update();
  audio.loop();//Executes an internal loop of the audio library
  // playflag 0 ---------------------------------------------
  if (playflag == 0){
    // Station up -------------------------------------------
    Button_(0xD6DA,0x762F,0xD6DA);       // ch Button on
    MP(0,2,0xFFFF,"Wait...");            // Infomation
    url_sname(counter);                  // station,url,sname
    speech(sname,"en");                  // speech
    audio.connecttohost(URL);            // URL connection
    playflag = 1;
    // Display update ---------------------------------------
    MP(0,3,0xFFFF,"Station:"+String(counter));// Staion NO.
    M5.Lcd.fillRect (0,110,320,80,BLUE);      // clear
    MP(0,4,0xFFFF,"Playing:"+String(sname));  // Staion name
    set_vol_btn();                       // Volume and Button
    M5.Lcd.fillRect (0,30,320,20,BLUE);  // Clear info Line
    MP(0,2,0xFFFF,"Playing");            // Infomation
  }
  // playflag 1 ----------------------------------------------
  // Play LED ------------------------------------------------
  led = led + 1;
  if (led>1){led=0;M5.Lcd.fillCircle(310,8,5,GREEN);// led on
    }else{         M5.Lcd.fillCircle(310,8,5,BLUE );// led off
  }
  // ch+ -----------------------------------------------------
  if(M5.BtnB.wasPressed()){                // B Button
    M5.Lcd.fillRect (0,110,320,88,BLUE);   // Clear Sta,sname Line
    Button_(0xD6DA,0x762F,0xD6DA);         // ch Button on
    old_counter=counter;                   // old counter set
    counter=counter+1;                     // Station UP
    if(counter>Number_of_urls){counter=0;} // url count
    new_counter=counter;                   // New Station UP
    playflag = 0;                          // Start Play
  }
  // Vol- -----------------------------------------------------
  if(M5.BtnA.wasPressed()){                // A Button
    Button_(0x762F,0xD6DA,0xD6DA);         // vol Button on
    vol=vol-1; if(vol<0){vol=0;}           // Vol -
    set_vol_btn();                         // Volume and Button
  }
  // Vol+ ------------------------------------------------------
  if(M5.BtnC.wasPressed()){                // C Button
    Button_(0xD6DA,0xD6DA,0x762F);         // vol Button on
    vol=vol+1; if(vol>21){vol=20;}         // 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 set_vol_btn(){
  audio.setVolume(vol);                    // Set Volume
  MP(0,7,0xFFFF,"Volume:");MP(100,7,0xFFFF,String(int(vol*5)));
  M5.Lcd.progressBar(150,180,160,16,vol*5);// 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 url_sname(int c){ // Separate into URL, sname
  // URL -------------------------------------------------------
  String u=String(url[c]).substring(0,String(url[c]).indexOf("*")+1); 
  u.toCharArray(URL,u.length());           // URL
  // Sname -----------------------------------------------------
  String s=String(url[c]).substring(String(url[c]).indexOf("//")+2); 
  String n=s.substring(s.indexOf("*")+1)+1;
  n.toCharArray(sname,n.length());         // sname
}
//--------------------------------------------------------------
void speech(char* speech, char* Lang){ // Increase volume by +5
  audio.setVolume(vol+5);audio.connecttospeech(speech,Lang);
  audio.setVolume(vol);
}
//--------------------------------------------------------------

.
,
M5Stack , Web Radio , UDA1334A , I2S DAC , 1334A ,

Written by macsbug

2月 14, 2021 @ 8:05 am

カテゴリー: M5STACK

4件のフィードバック

Subscribe to comments with RSS.

  1. Bボタンを押してcounterが8くらいになるとLCDが消えてしまいます。バグ?

    まさ

    2月 17, 2021 at 11:17 pm

    • まさ さん
      Arduino IDE + M5Stack + I2S DAC Board で一応の動作ができたレポートをありがとうございます。
      Board Manager:by Espresso Systems version 1.05-rc6 と Board Selection:ESP32 Dev Module ができた事が解りました。
      この方法は特殊でどこか未完成に見えます。
      不具合は どの部分かとか バグであると言う証明はできていません。

      目的:完璧な動作よりも公開する事を優先にしました。
      条件:ネット上にある ほぼ全ての Web Radio を検証した結果、今回の方法にしました。
      _ 1. Arduino IDE
      _ 2. M5Stack
      _ 3. I2S DAC
      _ 4. シンプルなスケッチで初心者にも解る事
      _ 5. 局数の多い事
      _ 6. コントロールにPC等を使用しない事 等です。

      原因:多岐(通信,HARD,スケッチ,Library等々)に渡る事が考えられます。
      現在 解決のためのヒントを模索中です。解決方やヒントになる情報を求めています。

      不明な点:
      ブログに記載してある様に 何かの切っ掛けでM5Stackの画面が白くなります。
      又、VOL- (GPIO 39) が動作する事があります。
      この時 シリアルモニターに「Brownout detector was triggered」が出る場合と出ない場合があります。
      この時 音が聞こえ受信は継続しています。これは void loop() を継続しているという事に見えます。
      何故 VOL- (GPIO 39) のみが突然動作するか不明です。
      何故 不具合発生後に void setup() が動作しないか不明です。再起動では無い事を示しています。

      レポートへの質問。
      1. 不具合発生時に音声は出力しているのでしょうか?
      2. 不具合の参考になる、シリアルモニターの出力はどの様な表示がでるでしょうか?
      3. Aボタンを押さないのに VOL- が 動作する事はありますか?
      4. by Espressif Systems version 1.05-rc7 にすると表示はどうなりますか?

      検討課題と検証:
      1. 他の Web Radio
      _ 検証:VS1053 mp3 Board + ESP8266 Library + M5Stack.h の場合は 不具合は出ません。
      2. I2S DAC Board:UDA1334A I2S DAC Bioard + ESP32-audioI2S Library + ESP32-Chimera-Core + Board:ESP32 Dev Moduleの場合に不具合が出ます。
      _ 検証:PCM5102A I2S DAC Board を使用しても同様の不具合が出る事が判明しました。
      3. 局数:(char *url[150])の宣言に於いて コンパイルエラーは出ないものの 配列数が大き過ぎないか疑問を持っています。
      _ 検証:局数を8にしても同様の不具合が起きる事を確認しています。この時「Brownout detector was triggered」は出ていません。
      4. 電源:USB電源 及び USB Cable
      _ 検証:2400mA Battery駆動でも同様の不具合が出る事が判明しました。
      5. 通信:通信の良否検証の方法が解りません。
      6. 不具合モニター:不具合の検出方法が解りません。検出できれば対策を考える事ができます。
      7, Library:他に Web Radio を使用できる 目的にあった Library が見つかりません。

      上記 検討課題と検証から考えられる原因:
      1. ESP32-Chimera-Core:不具合時に表示だけ白くなる件。
      2. ESP32-audioI2S Library ( Audio.h ):1.05-rc6 でないと動作しない件。
      3. Board selection : ESP32 Dev Module:コンパイルと書き込みはできている。
      4. Board Manager:by Espressif Systems version 1.05-rc6:Boardの設定は正しいか。
      上記4点は 私の分野では無いので対策はできません。
      上記が原因と判明した場合は 原作者へ依頼するしかありません。
      数週間モニターや検討をしています。これからも継続する予定です。
      :
      🔴 尚、お返事の日に Board Manager:by Espressif Systems version は
      _ 1.05-rc6 から 1.05-rc7 にUPされました。
      _ Ver 1.05-rc7 で試して頂けますでしょうか?
      _ 私の12時間のモニターでは 画面が白くなる事は起きなくなりました。

      🔴 この記載以降にブログ記事に設定方法とスケッチを変更致しました。
      _ 問題無く動作しています。

      macsbug

      2月 18, 2021 at 9:12 am

      • あれから色々試してみましたが、ちゃんと確認もせずバグとかすいません。
        バグと見えたのは自宅のArduiniIDEのセットアップ環境が悪かった様です。
        会社の構築環境だとrc6でも正常書込&数時間連続動作しました。
        M5stack x DACボードオンリーじゃなく、より安い構成のesp32/D1mini x VS1053でも動きました。
        ちゃんと動かないときはストレスですが、最後いい音でなったのでとても楽しい体験でした。
        これからも面白いスケッチや記事、よろしくお願いします。

        まさ

        3月 2, 2021 at 9:51 pm

      • まさ さん
        お返事ありがとうございます。
        いろいろ試していただいて助かります。
        Arduino IDEでのセットアップ環境の善し悪しは 私の方でもあり、古いマックで起きています。
        そこで記事投稿後は、新しいPC(MacBook Pro)で動かして順調になっています。

        D1 mini kit ESP32 + VS1053 で動作したとの報告をありがとうございます。
        実は 本来 D1 mini kit ESP32 で、この事を試したかったので、とても助かる情報です。
        そうすれば言われる様に最安値で製作する事ができます。

        作ったものから、音が出るようになると楽しいです。
        音楽をのんびり聴きながら、ゆっくり次の案を考えています。

        macsbug

        3月 3, 2021 at 6:29 am


コメントを残す