Dear all,
I am facing the issue during one of my project, I tried to intefacing the Mini df player and HX711 at one time to the arduino uno but, its not working, when i check it by using serial monitor it stuck on one point which is after printing version of hx711.
i am going to upload the full code and serial monitor window. Please help to find the problem.
Here the full code :
// #include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
#include "HX711.h"
HX711 scale;
uint8_t dataPin = 6;
uint8_t clockPin = 7;
float weight =0;
SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);
int output;
int button=4;
//---------------------------------------------setup of pins and fuction of arduino -----------------------------------------------------------------------------
void setup()
{
mySoftwareSerial.begin(9600);
Serial.begin(115200);
Serial.println();
Serial.println(F("DFRobot DFPlayer Mini Demo"));
Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
// -----------------------------------------------------------------------------------------------------------------------------------------------------------
Serial.println(__FILE__);
Serial.print("HX711_LIB_VERSION: ");
Serial.println(HX711_LIB_VERSION);
Serial.println();
scale.begin(dataPin, clockPin);
scale.set_scale(420.0983);
// reset the scale to zero = 0
scale.tare(20);
// -------------------------------------------------------------------------------------------------------------------------------------------------
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){ //loop 1
delay(0); // Code to compatible with ESP8266 watch dog.
}
}
Serial.println(F("DFPlayer Mini online."));
int sensor=A0;
pinMode(sensor,INPUT);
digitalWrite(sensor,LOW);
// Set volume to maximum (0 to 30).
myDFPlayer.volume(5);
myDFPlayer.volume(30);
// Play the first MP3 file on the SD card
myDFPlayer.loop(2);
}
//----------------------------------infinite loop ------------------------------------------------------------------------------------------------------------------
void loop() {
// -----------------------------------------------------------------
if (scale.is_ready())
{
Serial.println(scale.get_units(1));
weight = scale.get_units(1);
delay(100);
if(weight > 30 || weight <-30){
Serial.println("Doctor pressed the jaw !!!");
Serial.println(weight);
Serial.println(" Now patient is safe");
myDFPlayer.stop();
}
weight=0;
}
// ------------------------------------------------------------------------------------
if(output==0){
myDFPlayer.play(1);
while(output!=1){
// Serial.println("sensor detected");
output=sensor();
}
}else{
myDFPlayer.play(1);
while(output!=0){
// Serial.println("sensor not detected");
output=sensor();
}
}
if (myDFPlayer.available()) {
printDetail(myDFPlayer.readType(), myDFPlayer.read()); //Print the detail message from DFPlayer to handle different errors and states.
}
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//-----Function for flex sensor detection- ----------------------------------------------
int sensor(){ //function for sensor detection
int fsrAnalogPin = 0; // FSR is connected to analog 0
int fsrReading; // the analog reading from the FSR resistor divider
int output =0;
fsrReading = analogRead(fsrAnalogPin);
// delay(600);
Serial.println(digitalRead(button));
Serial.print("Analog reading = ");
Serial.println(fsrReading);
if(fsrReading<200){
output=0;
}else{
output=1;
}
return output;
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//Other Error and function of DF player notifications......
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!"));
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;
}
}