Pro Micro will not start till its reset

I was using Pro Minis and switched to the Sparkfun Pro Micro because it had the onboard USb connector. When I upload my code the board works perfect right after the upload but when I hook it up to a power supply alone only it wouldn’t work. After some playing around I found that if I did a reset on the board then the code would start working. I don’t want my users to have to hit a reset button everytime they turn on my device. I want them to just turn on the device and the board to start running its code. Am I doing something wrong? Is there a way to get these boards to just start running right away once power is applied?

Are you able to confirm this behavior with a simple sketch like “Blink”?

Yes. I can upload any sketch to the board and the code won’t execute until a reset is performed. I have 3 boards all the same thing.

OK the blink code from Nathan Seidle seems to work but my other code isn’t. This is the code I need to get working. The board is interfacing with a DFPlayer.

/***************************************************

Plastic Arms Dealer Sound and Light Board

V1.2

JUNE 9, 2019

Andrew McClary

Copyright 2018 All Rights Reserved

UPDATES:

  • Changed pin outs for Arduino Micro

****************************************************/

#include “Arduino.h”

#include “SoftwareSerial.h”

#include “DFRobotDFPlayerMini.h”

SoftwareSerial mySoftwareSerial(8,9); // RX, TX

DFRobotDFPlayerMini myDFPlayer;

void printDetail(uint8_t type, int value);

int triggerButton = 12; //the pin where we connect the button

int voiceButton = 11; //the pin where we connect the button

int lightButton = 10; //the pin where we connect the Snout light button

//int scanButton = 13; //the pin where we connect the Side Scanner button

//Output Pins to turn lights on

int LED1 = 6; //the pin we connect the Blaster LED

int LED2 = 7; //the pin we connect the Blaster LED

int LED3 = 4; //the pin we connect the Side ScannerLED

int LED4 = 5; //the pin we connect the lite Scanner LED

int fireSound = 1;

int voiceSound = 1;

int lightOn=0;

int litelightOn=0;

void setup()

{

mySoftwareSerial.begin(9600);

Serial.begin(115200);

pinMode(triggerButton, INPUT_PULLUP); //set the button pin as INPUT

pinMode(voiceButton, INPUT_PULLUP); //set the button pin as INPUT

pinMode(lightButton, INPUT_PULLUP); //set the button pin as INPUT

//pinMode(scanButton, INPUT_PULLUP); //set the button pin as INPUT

pinMode(LED1, OUTPUT); //set the LED pin as OUTPUT

pinMode(LED2, OUTPUT); //set the LED pin as OUTPUT

pinMode(LED3, OUTPUT); //set the LED pin as OUTPUT

pinMode(LED4, OUTPUT); //set the LED pin as OUTPUT

Serial.println();

Serial.println(F(“Plastic Arms Dealer Blaster Sound System beta 2.1 May 2020”));

Serial.println(F(“Initializing Sound Player … (May take 3~5 seconds)”));

//This sets up the code and connects with the MP3 player

if (!myDFPlayer.begin(mySoftwareSerial)) { //Use softwareSerial to communicate with mp3.

Serial.println(F(“Unable to begin:”));

Serial.println(F(“1.Please recheck the connection!”));

Serial.println(F(“2.Please insert the SD card!”));

while(true);

}

Serial.println(F(“Plastic Arms Dealer Blaster Sound System online.”));

Serial.println(F(“Folder 1.”));

Serial.println(myDFPlayer.readFileCountsInFolder(1)); //read fill counts in folder SD:/1

Serial.println(F(“Folder 2”));

Serial.println(myDFPlayer.readFileCountsInFolder(2)); //read fill counts in folder SD:/03

Serial.println(F(“Folder 3”));

Serial.println(myDFPlayer.readFileCountsInFolder(3)); //read fill counts in folder SD:/03

myDFPlayer.volume(30); //Set volume value. From 0 to 30

//Play startup sound

myDFPlayer.playLargeFolder(03, 1);;

}

//*** This is the main looping code that monitors the buttons ***

void loop()

{

static unsigned long timer = millis();

//This is were the button states are all read

int stateButton = digitalRead(triggerButton); //read the state of the button

int callButton = digitalRead(voiceButton); //read the state of the button

int liteButton = digitalRead(lightButton); //read the state of the button

//int scannerButton = digitalRead(scanButton); //read the state of the button

//Check for Fire button

if(stateButton == LOW) { //if is pressed

//Serial.println(F(“Fire button Pressed”));

//Play the sound file

//myDFPlayer.next(); //Play next mp3

myDFPlayer.playLargeFolder(02, fireSound);

printDetail(myDFPlayer.readType(), myDFPlayer.read());

delay(100);

//Flash the leds

digitalWrite(LED1, HIGH); //write 1 or HIGH to led pin

delay(200);

digitalWrite(LED1, LOW); //write 1 or HIGH to led pin

delay(100);

digitalWrite(LED2, HIGH); //write 1 or HIGH to led pin

delay(100);

digitalWrite(LED2, LOW); //write 1 or HIGH to led pin

delay(50);

digitalWrite(LED2, HIGH); //write 1 or HIGH to led pin

delay(200);

digitalWrite(LED2, LOW); //write 1 or HIGH to led pindigitalWrite(LED2, HIGH); //write 1 or HIGH to led pin

delay(50);

digitalWrite(LED2, HIGH); //write 1 or HIGH to led pindigitalWrite(LED2, HIGH); //write 1 or HIGH to led pin

delay(100);

digitalWrite(LED2, LOW); //write 1 or HIGH to led pin

//Change the blaster sound

fireSound++;

Serial.print("Fire Button Pressed - ");

Serial.print(fireSound);

if (fireSound >= 10){

fireSound = 1;

}

}

//Check for Voice activation button

if(callButton == LOW) { //if is pressed

//Play the voice file

myDFPlayer.playLargeFolder(01, voiceSound);

printDetail(myDFPlayer.readType(), myDFPlayer.read());

Serial.println(F("Voice button Pressed - "));

delay(3000);

voiceSound++;

Serial.print(voiceSound);

if (voiceSound >= 21){

voiceSound = 1;

}

}

//Check for light buttons

if(liteButton == LOW) { //if is pressed

Serial.println(F(“lite Scanner pressed”));

if (litelightOn==0) {

litelightOn=1;

//Flash the leds

Serial.println(F(“Chin LIGHTS on”));

digitalWrite(LED4, HIGH); //write 1 or HIGH to led pin

//digitalWrite(LED3, HIGH); //write 1 or HIGH to led pin

delay(500);

}else {

litelightOn=0;

Serial.println(F(“Chin LIGHTS off”));

digitalWrite(LED4, LOW); //write 0 or LOW to led pin

//digitalWrite(LED3, LOW); //write 0 or LOW to led pin

delay(500);

}

}

} //END Loop

void printDetail(uint8_t type, int value){

switch (type) {

case TimeOut:

Serial.println(F(“Time Out!”));

break;

case WrongStack:

Serial.println(F(“Stack Wrong!”));

break;

case DFPlayerCardInserted:

Serial.println(F(“Card Inserted!”));

break;

case DFPlayerCardRemoved:

Serial.println(F(“Card Removed!”));

break;

case DFPlayerCardOnline:

Serial.println(F(“Card Online!”));

break;

case DFPlayerPlayFinished:

Serial.print(F(“Number:”));

Serial.print(value);

Serial.println(F(" Play Finished!"));

break;

case DFPlayerError:

Serial.print(F(“DFPlayerError:”));

switch (value) {

case Busy:

Serial.println(F(“Card not found”));

break;

case Sleeping:

Serial.println(F(“Sleeping”));

break;

case SerialWrongStack:

Serial.println(F(“Get Wrong Stack”));

break;

case CheckSumNotMatch:

Serial.println(F(“Check Sum Not Match”));

break;

case FileIndexOut:

Serial.println(F(“File Index Out of Bound”));

break;

case FileMismatch:

Serial.println(F(“Cannot Find File”));

break;

case Advertise:

Serial.println(F(“In Advertise”));

break;

default:

break;

}

break;

default:

break;

}

}

Once I hit reset, then the program works perfectly. But requires a reset before it will start.

It’s your code.

Your board is waiting for a serial connection from a computer that isn’t attached and it hangs at that point.

Can you help? Where? The code establishes a serial connection on pins 8 an 9 which connect to the DFPlayer to control it. There is some code for serial output for debugging but it shouldn’t hang the board? The code works flawlessly on other boards so there is some difference her with this board.

turn the LED on (or off) right before the Serial call and toggle it after the call, then run it without the serial attached and see what the light does. If it doesn’t toggle then your call is “hanging”.

Try commenting out all your serial debugging code.