Nano 33 BLE & Dfplayer Mini crash issues

Hi Arduino Friends,

After several years of Arduino Nano development and hobby project creation, decided to move to the 33BLE in order to take advantage of the compact Bluetooth solution (previously used HC-06 etc).

My project utilises a simple ‘Unity 3D’ created app to communicate with the Nano33BLE in order to drive a SparkFun TB6612FNG motor driver – so far so good, working well.

I now want to introduce a DFPlayer Mini MP3 module to play sounds at different motor speeds; I have attempted connecting the MP3 module using Serial1 and (as you can see commented out in my sketch) a custom UART serial port.

My issue is, in both attempts, the BLE connects fine but when I select a motor speed the motor spins up, the sound starts to play but then the Nano33BLE immediately crashes and its game over – reset everything and start again.

Question: have I connected the DFPlayer correctly (physically it should be OK, TX to RX/Rx to TX etc and all running on 3.3v)? Feels like there is a conflict between the BLE and the DFPlayer connection?

I’ve had all kit running correctly using the older Nano and HC-06 etc so no issues there.

Thanks in advance!

James.

// BLE
#include <ArduinoBLE.h>
BLEService trainService("180A");
BLEByteCharacteristic motionCharacteristic("2A57", BLERead | BLEWrite);



// MOTOR - PINS
int motorAIN1 = 2;
int motorAIN2 = 3;
int motorSTBY = 4;
int motorPWM = 5;



// MOTOR - PWM SPEEDS
int motorSTOPpwm = 0;
int motorSLOWpwm = 145;
int motorHALFpwm = 200;
int motorFASTpwm = 255;


// DFPLAYER
#include <DFRobotDFPlayerMini.h>
DFRobotDFPlayerMini myDFPlayer;

//UART myDFSerial (digitalPinToPinName(12), digitalPinToPinName(11), NC, NC);



// MP3
// 1 - BRAKE
// 2 - CHUG SLOW
// 3 - CHUG HALF
// 4 - CHUG FAST

// ADVERT
// 1 - WHISTLE
// 2 - ALL ABOARD
// 3 - MERRY XMAS



void setup()
{
  // MOTOR SETUP PINMODES
  pinMode(motorSTBY, OUTPUT);
  pinMode(motorAIN1, OUTPUT);
  pinMode(motorSTBY, OUTPUT);
  pinMode(motorPWM, OUTPUT);

  // MOTOR SETUP DIGITALWRITES
  digitalWrite(motorSTBY, HIGH);

  // BRAKE MOTOR
  Brake();  


  // DFPLAYER SERIAL
  //myDFSerial.begin(9600);
  Serial1.begin(9600);

  

  // DFPLAYER SETTINGS
  //myDFPlayer.begin(myDFSerial);
  myDFPlayer.begin(Serial1);
  myDFPlayer.volume(30);



  
  // SET PIN MODES & WRITE FOR CONNECTION LED (ONBOARD)
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, LOW);



  // INITIALISE
  if (!BLE.begin())
  {
    while (1);
  }


  
  // SET NAME
  BLE.setLocalName("Nano33BLE");
  
  // ADVERSTISE SERVICE
  BLE.setAdvertisedService(trainService);
  
  // ADD CHARACTERISTICS TO SERVICE
  trainService.addCharacteristic(motionCharacteristic);
  
  // ADD SERVICE
  BLE.addService(trainService);
  
  // WRITE DEFAULT VALUES
  motionCharacteristic.writeValue(0);

  // ADVERTISE
  BLE.advertise();
}






void loop()
{
  // LISTEN FOR BLE PERIPHERALS TO CONNECT
  BLEDevice central = BLE.central();

  // IF A CENTRAL IS CONNECTED TO PERIPHERAL
  if (central)
  {
    // WRITE CONNECTION LED ON
    digitalWrite(LED_BUILTIN, HIGH);
    
    // WHILE THE CENTRAL IS STILL CONNECTED
    while (central.connected())
    {   
      // IF motionCharacteristic WRITTEN TO
      if (motionCharacteristic.written())
      {        
        switch (motionCharacteristic.value())
        {
          case 01:
            // FORWARDS / SLOW
            digitalWrite(motorAIN1, HIGH);
            digitalWrite(motorAIN2, LOW);
            analogWrite(motorPWM, motorSLOWpwm);

            soundChug();
            
            break;
            

          case 02:
            // FORWARDS / HALF
            digitalWrite(motorAIN1, HIGH);
            digitalWrite(motorAIN2, LOW);
            analogWrite(motorPWM, motorHALFpwm);                      
            break;
            

          case 03:
            // FORWARDS / FAST
            digitalWrite(motorAIN1, HIGH);
            digitalWrite(motorAIN2, LOW);
            analogWrite(motorPWM, motorFASTpwm);                     
            break;
            

          case 04:
            // BACKWARDS / SLOW
            digitalWrite(motorAIN1, LOW);
            digitalWrite(motorAIN2, HIGH);
            analogWrite(motorPWM, motorSLOWpwm);                      
            break;


          case 05:
            // BACKWARDS / HALF
            digitalWrite(motorAIN1, LOW);
            digitalWrite(motorAIN2, HIGH);
            analogWrite(motorPWM, motorHALFpwm);                     
            break;


          case 06:
            // BACKWARDS / FAST
            digitalWrite(motorAIN1, LOW);
            digitalWrite(motorAIN2, HIGH);
            analogWrite(motorPWM, motorFASTpwm);                     
            break;
            
                        
          default:
            Brake();            
            break;
        }
      }      
    }  
  }
  else
  {
    // DISCONNECTED
    
    // WRITE CONNECTION LED OFF
    digitalWrite(LED_BUILTIN, LOW);

    // BRAKE MOTOR
    Brake();
  }
  


  
}





void Brake()
{
  // BRAKE MOTOR
  digitalWrite(motorAIN1, LOW);
  digitalWrite(motorAIN2, LOW);
  analogWrite(motorPWM, motorSTOPpwm);  
}





void soundChug()
{
    myDFPlayer.play(5);
}

What do you mean by "crashes"? Are you talking about the Mbed OS crash where the "L" led does the 4X short, 4X long blink pattern?

Hi,
No not a 'traditional' crash; once I connect to the BLE, I tap my app button to initiate a forward/slow motor speed. Simultaneously I get a short motor burst, the DFPlayer red LED illuminates briefly, I hear the start of the MP3 play then everything stops - the Nano33BLE green led is still lit but the builtin LED (for showing BLE connection status) extinguishes. I loose BLE connection and I have to power off/on the board to reset it and then I can reconnect and start again.

Does the problem still occur if you repeat the same procedure, except without the motor connected to the Nano 33 BLE?

It does, exactly the same outcome.
Perhaps the DFPlayer library and Nano33BLE are just not compatible?
Some other details that might be pertinent; the Nano Vcc is +5v and I running the DFPlayer from the Nano 3.3v output to keep their communication @ 3.3v. Could the DFPlayer require its own 3.3v source with common ground?

I'm now wondering if driving the DFPlayer from the Nano +3.3v pin is the issue? Going to try +5v (as supplied to the Nano) on the DFPlayer and connect back to the Nano through a logic level converter to get back to +3.3v and keep the Nano happy.

Nope, same issue!

hi I'm having the same issue, I believe is due to bad alimentation, when the df player mini is connected alone in the Arduino nano 33 in the 5V pin, it works perfectly, but when I try to connect an LCD with the same 5V pin it starts to crash, I even discovered that if you set the volume low it works fine, but if I try to set it to the maximum it crashes, it is like it crashes because it doesn't get enough energy. I'll try to put an external battery just for the MP3 module, I hope this fixes the problem.
by the way, when I say it crashes is because it stops working, the Arduino IDE in my PC crashes and when I try to upload a new sketch it gets stuck on uploading, so I have to double press the reset button to upload in a new port...

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.