ESP32-S3 + PCM5102 でWeb Radio ― 2025/08/16
電子部品がアリエクで安いので、いろいろと買ってみました。
で、インターネットラジオを作ってみました。
ESP32-S3-N16R8 \560
PCM5102A DAC デコーダ GY-PCM5102 \340
ESP32-S3-N16R8
PCM5102A DAC デコーダボードの設定
●はんだブリッジ
H1L → L
H2L → L
H3L → H
H4L → L
●SCK はんだブリッジ
左上にあるパターン。GNDに落としているのでSCKをGNDにつないでもOK
配線(I2S接続)
PCM5102 → ESP32-S3(基板に書いてある番号)
VIN → 3.3V
GND → GND
LCK → 12
DIN → 11
BCK → 13
SCK → GND または、はんだブリッジしていれば OPEN
LCK,DIN,BCK は適当に好きなところにつないだだけで、ほかでもいいのかも。。
arduino ide の設定
最初、ボードの設定を気にせずいたらいろいろとエラーが出ました。
(I2Sの配線の場所が悪いのかと思い、いろいろかえたりしましたが、これが原因ではなくメモリが足りないだけでした。)
●フラッシュの容量が足りないエラー → フラッシュの容量を増やすには、ツールの Partition Scheme: を Huge APP に
●実行すると、シリアルモニタにOOM: failed to allocate xxxxx bytes エラー(バッファーアロケーションメモリ足りない)が出る → Tools->PSRAM->OPI PSRAM に設定
スケッチ
ネットにあったものを参考にしました。
SSID & Password 自宅のWifiに
とりあえず放送局は、NHK
ここから
#include <Wire.h>
#include "WiFi.h"
#include "Audio.h"
// PCM5102A
# define I2S_DOUT 11 // DIN connection
# define I2S_BCLK 13 // Bit clock
# define I2S_LRC 12 // Left Right Clock
Audio audio;
//SSID & Password
String ssid = "xxxxxxxx";
String password = "xxxxxxxx";
String stations[] ={
"https://radio-stream.nhk.jp/hls/live/2023229/nhkradiruakr1/master.m3u8", //NHK 1
"https://radio-stream.nhk.jp/hls/live/2023501/nhkradiruakr2/master.m3u8", //NHK 2
"https://radio-stream.nhk.jp/hls/live/2023507/nhkradiruakfm/master.m3u8", //NHK FM
};
uint8_t cur_station = 0; // current station No.
uint8_t num_elements = sizeof(stations) / sizeof(stations[0]);
void setup() {
//setup serial
Serial.begin(115200);
//setup Wifi
WiFi.disconnect();
WiFi.mode(WIFI_STA);
WiFi.begin(ssid.c_str(), password.c_str());
while (WiFi.status() != WL_CONNECTED) delay(1500);
Serial.println("WiFi start");
//setup audio
audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
audio.setVolume(12); // 0...21
Serial.println("audio start");
//set Radio Station
audio.connecttohost(stations[cur_station].c_str());
Serial.println(stations[cur_station].c_str());
}
void loop() {
vTaskDelay(1);
audio.loop();
}
ここまで
最近のコメント