MKRZERO project works on computer USB; not a wall USB

I'm creating the simple audio player from the Arduino site:

It runs well when connected to the computer's USB, but not when connected to a USB wall plug as there is no sound. This will be used remotely for 2 months so I do not want to use a battery.

I've checked the voltages the VCC pin shows 3.24V for either connector, and the DAC0 shows 0.40V for the computer USB and 0.10V for the wall USB.

I've pushed the reset button twice quickly, and it flashes continuously for the wall usb, and doesn't otherwise correct any problems.

Any insights are appreciated! thanks

{
#include <SD.h>
#include <SPI.h>
#include <AudioZero.h>

const int chipSelect = SDCARD_SS_PIN;
int iCount = 0;
bool bPlayed=false;
Sd2Card card;
SdVolume volume;
SdFile root;

void setup() {
  delay(5000);
  Serial.println("Starting Setup");

  // debug output at 9600 baud
  Serial.begin(9600);
  // setup SD-card
  while (!Serial) {
    ;
  }
  Serial.println("Initializing SD card...");
  //
  if (!SD.begin(chipSelect)) {
    Serial.println("1 failed!");
    while (true);
  }
  AudioZero.begin(44100);
}

void loop() {
  Serial.println("loop starts");
  if (!bPlayed)
  {
    playFile("thunder.wav");
  //playFile("geese2.wav");
  //playFile("coyote2.wav");
  //playFile("bison1.wav");
  //playFile("bison2.wav");
  }
}

void playFile(char fileName[]) 
{
 
  long lExists = SD.exists(fileName);
  Serial.print("file exists: ");
  Serial.println(lExists);
  File soundFile = SD.open(fileName);
  Serial.print("SoundFile check: ");
  Serial.println(soundFile);
  if (!soundFile) 
  {
    // if the file didn't open, print an error and stop
    Serial.print("error opening ");
    Serial.println(fileName);
    while (true);
  } 
  else
  {
    Serial.print("Playing ");
    Serial.print(fileName);
    AudioZero.play(soundFile);
    Serial.println("End of file. Thank you for listening!");
    Serial.println("Count");
    Serial.println(iCount);
    AudioZero.end();
    iCount = iCount + 1;  
  } 
}

Hi @JimWeaver

This code will make your program stay in an infinite loop until the serial port is opened in the Arduino IDE Serial Monitor (or some equivalent application). The reason that is useful is because on native USB boards like yours, the board is not reset when you open Serial Monitor. That means any serial output printed between the time the program starts running and when you get Serial Monitor open will be lost.

In applications where missing that serial output would be a problem, it's useful to add this code to the sketch in order to make the program wait for the Serial Monitor before running.

However, if you are wanting to run your program when the board is not connected to Serial Monitor, you must remove that while loop to allow the rest of the sketch to run.

Thanks @ptillisch. Omitting the While Loop solved the problem. Thanks very much.

The solution raises the question of where the Serial.print() output goes when the serial monitor is not connected. Evidently it doesn't prevent the code from running.

It goes to Bill Gates' hotmail.

1 Like

You are welcome. I'm glad it is working now.

I don't know enough about the MKR Zero USB CDC stack to provide an answer to that. Maybe one of the other forum members can explain it.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.