Sorry if this is the wrong place to ask this, not really sure where they go for help.
I am working on our project where with a button is pressed and held, track 2 plays, and when release track 1 immediately plays. Code is posted below.
When using an Arduino Uno with pins 10 and 11 as the Rx and Tx pins, everything works great. When using the Beetle CM-32U4 with pins 0 and 1, it cannot connect to the DFPlayer Mini. I tried the same with a Pro Micro and changed the Pins with no luck as well.
I have the DFPlayer setup on a bread board so my setup stays the same when switching between various micro controllers. I am powering the DFPlayer via the micro controllers and have tried powering it separately with no luck.
I am at a loss on what to try next to get this working on the Beetle CM-32U4 and not just the Uno.
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>
// Define pins for the button and the software serial connection to DFPlayer Mini
#define BUTTON_PIN 2
SoftwareSerial mySoftwareSerial(0, 1); // RX, TX pins for communication with DFPlayer
DFRobotDFPlayerMini myDFPlayer;
bool lastButtonState = LOW; // Previous button state
bool currentButtonState = LOW; // Current button state
int songOnPress = 2; // Song number to play on button press (SD card file number)
int songOnRelease = 1; // Song number to play on button release (SD card file number)
void setup() {
// Initialize serial communication for debugging
Serial.begin(9600);
// Initialize button pin
pinMode(BUTTON_PIN, INPUT_PULLUP);
// Initialize software serial for DFPlayer communication
mySoftwareSerial.begin(9600);
// Initialize DFPlayer Mini
if (!myDFPlayer.begin(mySoftwareSerial)) {
Serial.println("DFPlayer Mini not detected!");
while (true); // Stay here if DFPlayer isn't detected
}
// Set volume (0-30)
myDFPlayer.volume(25);
Serial.println("DFPlayer Mini ready.");
}
void loop() {
// Read the button state
currentButtonState = digitalRead(BUTTON_PIN);
// Check if the button state has changed (pressed or released)
if (currentButtonState != lastButtonState) {
if (currentButtonState == LOW) {
// Button pressed
Serial.println("Button Pressed");
myDFPlayer.play(songOnPress);// Play song on button press
} else {
// Button released
Serial.println("Button Released");
myDFPlayer.play(songOnRelease); // Play song on button release
}
// Update the last button state
lastButtonState = currentButtonState;
// Add a small delay to debounce the button press
delay(50);
}
}