Hello,
I've been coming to this forum for a long time, and this is my first time posting.
I have a node, that has a DFPLAYER (mp3) and it works with the stock arduino (nano) bootloader. When I burn MYSBootloader 1.3.0, the node continuously restarts every 20 seconds. It stops at "Enable to begin" and restarts.
The library I use for the DFplayer is "SoftwareSerial". The problem would not come from there?
#define MY_DEBUG
#define MY_NODE_ID 19
#define MY_REPEATER_FEATURE
#define NODE_NAME "Door Bell"
#define NODE_VERSION "1.0"
#define MY_RADIO_RF24
#include <MySensors.h>
#include <Wire.h>
#include "SparkFunHTU21D.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
//For DFPlayer
#define RX_PIN 8
#define TX_PIN 7
// Id of the sensor child
#define TEMP_ID 1
#define HUM_ID 2
#define BELL_ID 3
#define SOUND_ID 4
#define VOLUME_ID 5
#define EQ_ID 6
unsigned long delay_wait = 300000; //5mn
float lastTemp = 0.0;
byte lastHum = 0;
bool boot = 1;
String eq = "Pop";
byte volume = 2; //Set volume value. From 0 to 30
int count = 0;
//Create an instance of the object
HTU21D myHumidity;
SoftwareSerial mySoftwareSerial(RX_PIN, TX_PIN); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);
// Initialize general message
MyMessage msgT(TEMP_ID, V_TEMP);
MyMessage msgH(HUM_ID, V_HUM);
MyMessage msgB(BELL_ID, V_ARMED);
MyMessage msgS(SOUND_ID, V_VAR1);
MyMessage msgV(VOLUME_ID, V_VAR2);
MyMessage msgEQ(EQ_ID, V_VAR3);
void before()
{
// Optional method - for initialisations that needs to take place before MySensors transport has been setup (eg: SPI devices).
}
void setup()
{
myHumidity.begin();
mySoftwareSerial.begin(9600);
Serial.println(F("Initializing DFPlayer ... (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) {
delay(0); // Code to compatible with ESP8266 watch dog.
}
}
Serial.println(F("DFPlayer Mini online."));
//read and send EQ setting
myDFPlayer.EQ(DFPLAYER_EQ_POP);
send(msgEQ.set(eq.c_str())); //read and send EQ setting
wait(250);
//read and send current volume
myDFPlayer.volume(volume);
byte vol = round(volume / 0.3);
send(msgV.set(vol));
wait(250);
myDFPlayer.playMp3Folder(1); //play specific mp3 in SD:/MP3/0001.mp3; File Name(0~65535)
}
void presentation()
{
// Send the sketch version information to the gateway and controller
sendSketchInfo(NODE_NAME, NODE_VERSION);
// Register all sensors to gw (they will be created as child devices)
present(TEMP_ID, S_TEMP);
present(HUM_ID, S_HUM);
present(BELL_ID, S_CUSTOM);
present(SOUND_ID, S_CUSTOM);
present(VOLUME_ID, S_CUSTOM);
present(EQ_ID, S_CUSTOM);
}
void loop()
{
static unsigned long timer = millis();
if (millis() - timer > delay_wait) {
float humd = myHumidity.readHumidity();
float temp = myHumidity.readTemperature();
Serial.print(" Temperature:");
Serial.print(temp, 1);
Serial.print("C");
Serial.print(" Humidity:");
Serial.print(humd, 1);
Serial.println("%");
if (lastTemp != temp) {
send(msgT.set(temp, 1));
lastTemp = temp;
}
byte H = round(humd);
if (lastHum != H) {
send(msgH.set(H));
lastHum = H;
}
timer = millis();
}
if (myDFPlayer.available()) {
printDetail(myDFPlayer.readType(), myDFPlayer.read()); //Print the detail message from DFPlayer to handle different errors and states.
}
}
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 DFPlayerUSBInserted:
Serial.println("USB Inserted!");
break;
case DFPlayerUSBRemoved:
Serial.println("USB Removed!");
break;
case DFPlayerPlayFinished:
Serial.print(F("Number:"));
Serial.print(value);
Serial.println(F(" Play Finished!"));
send(msgB.set(false));
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;
}
}
void receive(const MyMessage &message)
{
// We only expect one type of message from controller. But we better check anyway.
if (message.type == V_VAR1) {
int num = message.getInt();
myDFPlayer.playMp3Folder(num); //play specific mp3 in SD:/MP3/0001.mp3; File Name(0~65535)
send(msgB.set(true));
}
if (message.type == V_VAR2) {
byte vol = round(message.getByte() * 0.3); // 0~100% to 0~30
myDFPlayer.volume(vol); //Set volume value (0~30)
Serial.print("Set volume : ");
Serial.println(vol);
}
if (message.type == V_VAR3) {
byte req = message.getByte();
Serial.print("Equalizer : ");
switch (req) {
case 1:
myDFPlayer.EQ(DFPLAYER_EQ_NORMAL);
Serial.println("Normal");
eq = "Normal";
break;
case 2:
myDFPlayer.EQ(DFPLAYER_EQ_POP);
Serial.println("Pop");
eq = "Pop";
break;
case 3:
myDFPlayer.EQ(DFPLAYER_EQ_ROCK);
Serial.println("Rock");
eq = "Rock";
break;
case 4:
myDFPlayer.EQ(DFPLAYER_EQ_JAZZ);
Serial.println("Jazz");
eq = "Jazz";
break;
case 5:
myDFPlayer.EQ(DFPLAYER_EQ_CLASSIC);
Serial.println("Classic");
eq = "Classic";
break;
case 6:
myDFPlayer.EQ(DFPLAYER_EQ_BASS);
Serial.println("Bass");
eq = "Bass";
break;
default:
break;
}
send(msgEQ.set(eq.c_str()));
}
}
Thanks Google for the translation