We recently moved to using Arduino Micro Pro boards in our system. These have an onboard USB serial port so that users don't need a USB to Serial adapter to program the boards. Unfortunately we discovered that the pin numbers are different even though the pins have the same footprint. Below is the updated code to run the board.
We also created a nice diagram for setting up one of our sound boards for a helmet.
Updated Arduino Code:
/***************************************************
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 = 14; //the pin where we connect the button
int voiceButton = 16; //the pin where we connect the button
int lightButton = 10; //the pin where we connect the Snout light button
int scanButton = 15; //the pin where we connect the Side Scanner button
//Output Pins to turn lights on
int LED1 = 4; //the pin we connect the Blaster LED
int LED2 = 5; //the pin we connect the Blaster LED
int LED3 = 6; //the pin we connect the Side ScannerLED
int LED4 = 7; //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 V beta 1"));
Serial.println(F("Initializing Sound Player ... (May take 3~5 seconds)"));
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);;
}
void loop()
{
static unsigned long timer = millis();
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 scanner buttons
if(scannerButton == LOW) { //if is pressed
Serial.println(F("Scanner Lights Pressed"));
if (lightOn==0) {
lightOn=1;
//Flash the leds
Serial.println(F("scanner on"));
digitalWrite(LED3, HIGH); //write 1 or HIGH to led pin
delay(200);
}else {
lightOn=0;
Serial.println(F("Scanner off"));
digitalWrite(LED3, LOW); //write 0 or LOW to led pin
delay(200);
}
}
//Check for scanner 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;
}
}