Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Adabox 004 - Problem with Streaming Cutting Out (follow up)
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Adabox 004 - Problem with Streaming Cutting Out (follow up)

by connerhunihan on Fri Aug 28, 2020 8:38 pm

This is my first post, so apologies in advance if I am not 100% on the protocol. I have the same issue as Stacks had in Adabox 004 - Problem with Streaming Cutting Out, but the issue was locked, so I am posting a new thread here. Please let me know if this is incorrect.

I wanted to build the internet-streaming music box outlined in Adabox 004 - Streaming Internet Radio. I already had a HUZZAH ESP8266 Feather, so I bought the MusicMaker FeatherWing, and stacked them:
IMG_9267.JPG
IMG_9267.JPG (176.23 KiB) Viewed 67 times

IMG_9865.JPG
IMG_9865.JPG (156.97 KiB) Viewed 67 times


Note, I did not add any additional hardware (the potentiometer, power switch, etc), but rather just stacked the two boards. I followed the instructions and got somafm streams playing through an external speaker, but like Stacks, the audio cuts off about a minute in. Using a digital multimeter, I read 3.28v, regardless of whether I power with a 5V1A USB Power Supply, or my computer's USB.

I debugged a little and found that when the audio stops, the program is not entering the
Code: Select all | TOGGLE FULL SIZE
if (client.available() > 0)
loop, but is exiting through the else condition. Reading WiFi.status() in that else condition returns a "3" value, so the connection is still live.

Any thoughts as to why the audio is cutting out? Or where I can focus my debugging efforts? I have included my code below (with internet network and password obscured), for reference.

Again, please let me know if this is more appropriately posted elsewhere.

Thank you!

Code: Select all | TOGGLE FULL SIZE
// Tested: ESP8266, ESP32, M0+WINC1500
 
// include SPI, MP3 and SD libraries
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <ESP8266WiFi.h>
 
char* ssid     = "*****************";
const char* password = "*****************";
 
//  http://ice1.somafm.com/u80s-128-mp3
const char *host = "ice2.somafm.com";
const char *path = "/lush-128-mp3";
int httpPort = 80;
 
// These are the pins used
#define VS1053_RESET   -1     // VS1053 reset pin (not used!)
#define VS1053_CS      16     // VS1053 chip select pin (output)
#define VS1053_DCS     15     // VS1053 Data/command select pin (output)
#define VS1053_DREQ     0     // VS1053 Data request, ideally an Interrupt pin
 
#define VOLUME_KNOB    A0
#define ON_OFF_SWITCH  4
 
int lastvol = 30;
 
Adafruit_VS1053 musicPlayer =  Adafruit_VS1053(VS1053_RESET, VS1053_CS, VS1053_DCS, VS1053_DREQ);
 
// Use WiFiClient class to create HTTP/TCP connection
WiFiClient client;
 
void setup() {
  Serial.begin(115200);
 
  Serial.println("\n\nAdafruit VS1053 Feather WiFi Radio");
 
  /************************* INITIALIZE MP3 WING */
  if (! musicPlayer.begin()) { // initialise the music player
     Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
     while (1) delay(10);
  }
 
  Serial.println(F("VS1053 found"));
  musicPlayer.sineTest(0x44, 500);    // Make a tone to indicate VS1053 is working
 
  // Set volume for left, right channels. lower numbers == louder volume!
  musicPlayer.setVolume(lastvol, lastvol);
 
  // don't use an IRQ, we'll hand-feed
 
  pinMode(ON_OFF_SWITCH, INPUT_PULLUP);
  /************************* INITIALIZE WIFI */
  Serial.print("Connecting to SSID "); Serial.println(ssid);
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
 
  Serial.println("WiFi connected"); 
  Serial.println("IP address: ");  Serial.println(WiFi.localIP());
 
 
  /************************* INITIALIZE STREAM */
  Serial.print("connecting to ");  Serial.println(host);
 
  if (!client.connect(host, httpPort)) {
    Serial.println("Connection failed");
    return;
  }
 
  // We now create a URI for the request
  Serial.print("Requesting URL: ");
  Serial.println(path);
 
  // This will send the request to the server
  client.print(String("GET ") + path + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +
               "Connection: close\r\n\r\n");
 
}
 
// our little buffer of mp3 data
uint8_t mp3buff[32];   // vs1053 likes 32 bytes at a time
 
int loopcounter = 0;
 
void loop() {
  if (! digitalRead(ON_OFF_SWITCH)) {
    yield();
    return;
  }

  Serial.println(loopcounter);
  loopcounter++;

  // wait till mp3 wants more data
  if (musicPlayer.readyForData()) {
    Serial.print("ready ");
   
    //wants more data! check we have something available from the stream
    if (client.available() > 0) {
      Serial.print("set ");
      // yea! read up to 32 bytes
      uint8_t bytesread = client.read(mp3buff, 32);
      // push to mp3
      musicPlayer.playData(mp3buff, bytesread);
 
      Serial.println("stream!");
    }
    else {
      Serial.println("client is not available");
      Serial.println(WiFi.status());
    }
  } else {

    if (loopcounter >= 1000) {
      loopcounter = 0;
      // adjust volume!
      int vol = 0;
      vol = analogRead(VOLUME_KNOB);
      vol /= 10;
      if (abs(vol - lastvol) > 3) {
        Serial.println(vol);
        lastvol = vol;
        musicPlayer.setVolume(lastvol, lastvol);
      }
    }
  }
}

connerhunihan
 
Posts: 1
Joined: Sat Mar 03, 2018 3:07 am

Please be positive and constructive with your questions and comments.