Hi, this is my first time posting so forgive me if I miss anything. I am busy with a project where I want to control a speaker with a remote over a long distance. For the remote I am using a Arduino Nano and RFM9x LoRa Radio to send an array with a length of 2 to the "Speaker" when a button press is registered. The speaker consists of an Arduino Nano, RFM9x LoRa Radio and a DFPlayer mini. The audio out of the DFPlayer is connected to an amplifier and speaker.
I have gotten it to start playing a mp3 file from the SD card in the DFPlayer Mini. I send a data packet with length 2, that tells the DFPlayer which track number to play. It received the data packet and starts playing the song I want. After the DFplayer mini starts playing and I send another data packet the DF Player resets.
Below is an image of my "Speaker" circuit diagram.
Attached find the code that I am using
#include <RHReliableDatagram.h>
#include <RH_RF95.h>
#include <SPI.h>
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
SoftwareSerial mySoftwareSerial(4,3); // TX, RX
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);
#define CLIENT_ADDRESS 1
#define SERVER_ADDRESS 2
#define RF95_FREQ 868.0
RH_RF95 driver;
// Class to manage message delivery and receipt, using the driver declared above
RHReliableDatagram manager(driver, SERVER_ADDRESS);
uint8_t volVal = 20;
uint8_t data[2]; //Array to store data that is sent to remote
uint8_t buf[2]; //Array to store data recieved from remote
uint8_t playFlag = 0; //used to determine if start() or pause() function is used for DFPlayer mini.
uint8_t mp3Flag = 0; //Value of 0 if mp3 failed and value of 1 if mp3 online
void setup()
{
mySoftwareSerial.begin(9600);
if (!myDFPlayer.begin(mySoftwareSerial)) { //Use softwareSerial to communicate with mp3.
while(true){
delay(0); // Code to compatible with ESP8266 watch dog.
}
}
mp3Flag = 1;
myDFPlayer.volume(volVal); //Set volume value. From 0 to 30
if (!manager.init()){
}
if (!driver.setFrequency(RF95_FREQ)) {
while (1);
}
driver.setTxPower(23, false);
}
void loop()
{
if (manager.available())
{ uint8_t len = sizeof(buf);
uint8_t from;
if (manager.recvfromAck(buf, &len, &from)) //Recieve message from remote and store message in "buff"
{
if (buf[0]=10)
{ uint8_t trackNum = myDFPlayer.readFileCounts(); //Reads number of tracks on SD card
data[0] = mp3Flag;
data[1] = trackNum;
// Send a reply back to the originator client
manager.sendtoWait(data, sizeof(data), from); //send mp3 status and number of tracks to remote
}
if (buf[0]=2) //If selMsg is received
{ myDFPlayer.play(buf[1]); //Play trackNum
playFlag=1;
}
if (buf[0]=1){ //If volMsg is received
if (buf[1]>volVal){
myDFPlayer.volumeUp(); //Set volume value (0~30).
}
else{
myDFPlayer.volumeDown(); //Set volume value (0~30).
}
volVal=buf[1];
}
if (buf[0]=3){ //If play_pauseMsg is received
if (playFlag==1){
myDFPlayer.pause(); //pause the mp3
playFlag=0;
}
else{
myDFPlayer.start(); //pause the mp3
playFlag=1;
}
}
}
}
}
I am in no way an expert in digital communication. From what I can tell the DFPlayer mini uses UART and the RFM9x Radio uses SPI. Could these 2 interfere with each other?
