Today I found the time to test some audio on the Rasperry Pico 2W Microcontroller. I tried out the standard Interenet Streaming sketch from the Audio Tools examples.

Unfortunatly, I noticed that the regular WiFi login logic is quite unreliable, but using the WiFiMulti works each time.

Here is the adapted version:

#include "AudioTools.h"
#include "AudioTools/AudioCodecs/CodecMP3Helix.h"
#include <WiFiMulti.h>

const char *ssid = "ssid";
const char *pwd = "password";
WiFiMulti wifiMulti;
URLStream url;
I2SStream i2s; // final output of decoded stream
EncodedAudioStream dec(&i2s, new MP3DecoderHelix()); // Decoding stream
StreamCopy copier(dec, url); // copy url to decoder

void setup(){
  Serial.begin(115200);
  AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);  
  while(!Serial);
  Serial.println("starting...");

  // connect to Wifi
  wifiMulti.addAP(ssid, pwd);
  if ((wifiMulti.run() != WL_CONNECTED)) {
    Serial.println("Connection error");
    stop();
  }
  // mp3 radio
  url.begin("http://stream.srg-ssr.ch/m/rsj/mp3_128","audio/mp3");

  // setup i2s
  auto config = i2s.defaultConfig(TX_MODE);
  i2s.begin(config);

  // setup I2S based on sampling rate provided by decoder
  dec.begin();
}

void loop(){
  copier.copy();
}


0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *