I'm working with an Arduino Nano board clone (CH340) on wireless control of DFPlayer Mini, transceiver sending a Struct variable with MachinePrefix (just in case), sound type (I have more folders by type of machines) and number of sounds.
The transceiver works fine, but the receiver doesn't. If I upload data into the Arduino, the DFPlayer plays the first song once (row 43 - myDFPlayer.play(1)), but after nRF24 init is not working.
After nRF24 init I'm still receiving data in valid format and range. If I comment out the nRF24 part, the DFPlayer is working, but together not. I read about working two devices on one SPI bus but I don't understand what's wrong. I think the problem is the same MOSI pin. In my opinion it should work but did not.
Any suggestions?
Here is the code of receiver:
#include
#include "RF24.h"
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
RF24 myRadio (8, 9); // CE, CS
byte addresses[][6] = {"Sx001"};
SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);
struct dataStruct {
short machinePrefix;
short soundType;
short soundNumber;
} dataReceived;
void setup() {
mySoftwareSerial.begin(9600);
Serial.begin(115200);
delay(1000);
Serial.println(F("RF24+dfplayermini-recever"));
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);
}
Serial.println(F("DFPlayer Mini online."));
myDFPlayer.setTimeOut(500);
myDFPlayer.volume(5); //Set volume value. From 0 to 30
myDFPlayer.play(1); //Play the first mp3
//----------------------------
delay(1000);
myRadio.begin(); // Start up the physical nRF24L01 Radio
myRadio.setChannel(108); // Above most Wifi Channels
// Set the PA Level low to prevent power supply related issues since this is a
// getting_started sketch, and the likelihood of close proximity of the devices. RF24_PA_MAX is default.
myRadio.setPALevel(RF24_PA_MAX);
myRadio.setDataRate(RF24_250KBPS);
// myRadio.setPALevel(RF24_PA_MAX); // Uncomment for more power
myRadio.openReadingPipe(1, addresses[0]); // Use the first entry in array 'addresses' (Only 1 right now)
myRadio.startListening();
Serial.println(F("RF24 online."));
}//--(end setup )---
void loop() { /****** LOOP ******/
if (myDFPlayer.available()) {
printDetail(myDFPlayer.readType(), myDFPlayer.read()); //Print the detail message from DFPlayer to handle different errors and states.
}
if (myRadio.available()) { // Check for incoming data from transmitter
while (myRadio.available()) { // While there is data ready
myRadio.read( &dataReceived, sizeof(dataReceived) ); // Get the data payload
}
Serial.println("loop");
myDFPlayer.loop(3);
if (dataReceived.machinePrefix == 11001) {
Serial.println("same device prefix");
int playingData = dataReceived.soundNumber;
if (myDFPlayer.available()) {
Serial.println("player available");
Serial.println(myDFPlayer.readType());
Serial.println(myDFPlayer.read());
}
myDFPlayer.play(2);
}
Serial.println(dataReceived.machinePrefix);
Serial.println(dataReceived.soundType);
Serial.println(dataReceived.soundNumber);
Serial.println("-----------------------------");
} //END Radio available
}//--(end main 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;
}
}
