I can't see the code that produces that output.
This is the code thaT WAS running fine prior to the re-load of the Sketch:
#include<Wire.h>
#include <SoftwareSerial.h>
#include <DFRobot_PLAY.h>
// Use pins 2 and 3 to communicate with DFPlayer Mini
SoftwareSerial DF1201SSerial(3, 2); //RX TX
DFRobot_PLAY DF1201S;
const int MPU_addr = 0x68; // I2C address of the MPU-6050
int16_t AcX, AcY, AcZ, Tmp, GyX, GyY, GyZ;
bool movementStarted = false;
bool isRinging = false;
bool Ypositive = true;
bool onTable = false;
bool skipReSet = false;
bool startedRinging = false;
#define Addr 0x53
void setup() {
Serial.begin(115200);
DF1201SSerial.begin(115200);
while (!DF1201S.begin(DF1201SSerial)) {
Serial.println("Init failed, please check the wire connection!");
delay(1000);
}
/Set volume to 20/
DF1201S.setVol(25);
//Serial.print("VOL:");
/Get volume/
//Serial.println(DF1201S.getVol());
/Enter music mode/
DF1201S.switchFunction(DF1201S.MUSIC);
/*Wait for the end of the prompt tone */
delay(2000);
/Set playback mode to "repeat all"/
DF1201S.setPlayMode(DF1201S.SINGLE);//SINGLECYCLE,ALLCYCLE,SINGLE,RANDOM,FOLDER
//Serial.print("PlayMode:");
/Get playback mode/
//Serial.println(DF1201S.getPlayMode());
Wire.begin();
Wire.beginTransmission(MPU_addr);
Wire.write(0x6B); // PWR_MGMT_1 register
Wire.write(0); // set to zero (wakes up the MPU-6050)
Wire.endTransmission(true);
Serial.begin(9600);
//Serial.print("e");
}
void loop() {
//bool startedRinging = false;
//Serial.println("this is a test"); //I genuinely have no idea why, but if this exact line of code is removed or modified then the entire program breaks
Wire.beginTransmission(MPU_addr);
Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H)
Wire.endTransmission(false);
Wire.requestFrom(MPU_addr, 14); // request a total of 14 registers
int t = Wire.read();
AcX = (t << 8) | Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
t = Wire.read();
AcY = (t << 8) | Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
t = Wire.read();
AcZ = (t << 8) | Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
t = Wire.read();
Tmp = (t << 8) | Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
t = Wire.read();
GyX = (t << 8) | Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
t = Wire.read();
GyY = (t << 8) | Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
t = Wire.read();
GyZ = (t << 8) | Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
t = Wire.read();
Serial.print(AcX); Serial.print(" ");
Serial.print(AcY); Serial.print(" ");
Serial.print(AcZ); Serial.print(" ");
Serial.print(GyX); Serial.print(" ");
Serial.print(GyY); Serial.print(" ");
Serial.println(GyZ);
if (GyX < -30000 && !startedRinging) {
// Play the "0001.mp3" in the "mp3" folder on the SD card
DF1201S.playFileNum(1);
movementStarted = true;
isRinging = true;
onTable = true;
skipReSet = false;
startedRinging = true;
Serial.println("+++++++++++++++++......");
}
if (AcZ < -4000 ) {
//STOP RINGING on shoulder
DF1201S.playFileNum(2);
startedRinging = false;
Serial.println("STOP RINGING");
}
if (AcX < -6000 && AcX > -10000 && AcY < -1000 && AcY > -8000 && AcZ > 10000 && AcZ < 14000 && !onTable) {//bell is POSSIBLY on table, possibly stop ringing
for (int i = 0; i < 10; i++) { //give 0.5 sec to check if bell is truly laying flat
delay(10);
if (AcX < -6000 && AcX > -10000 && AcY < -1000 && AcY > -8000 && AcZ > 10000 && AcZ < 14000 && !onTable) { //bell IS on TABLE
if (!startedRinging) {
DF1201S.playFileNum(2);
startedRinging = false;
Serial.println("On TABLE");
}
}
}
}
// Re-set On Table & StartedRinging as Bell m oves up
if (AcY > 8000) {
onTable = false;
startedRinging = false;
}
}
I thought software serial was speed-limited, and the player expects 9600 bits per second.
Please remember to use code tags when posting code
I've tried Both 115200 and 9600 with same result
The code for the DFRobot came with 115200
Like I said this code was working fine before I uploaded it, so I'm really not looking at coding problems.
Something happened yesterday at 9:15
Maybe I changed some setting in the IDE, but I can't find it?
Ed
I did a very quick search, (on my phone, poolside, waiting to teach).
It does indeed look like the 1201 player uses 115200 bits per second.
I always thought that SoftwareSerial was limited to about 19.2 or 38.4kbps.
Sorry, I'm out, but at 115200, I'd always use a hardware USART.
That's fine
I ALWAYS use 115200
I had just changed it to 9600 prior to pasting it into the forum message.
Neither sp[eed works today
They both worked yesterday
Ed
Here's the cvode that I just ran @ 115200
It does not work
Init failed, please check the wire connection!
Init failed, please check the wire connection!
Init failed, please check the wire connection!
Init failed, please check the wire connection!
Init failed, please check the wire connection!
Init failed, please check the wire connection!
Init failed, please check the wire connection!
Init failed, please check the wire connection!
Init failed, please check the wire connection!
Init failed, please check the wire connection!
#include<Wire.h>
#include <SoftwareSerial.h>
#include <DFRobot_PLAY.h>
// Use pins 2 and 3 to communicate with DFPlayer Mini
SoftwareSerial DF1201SSerial(3, 2); //RX TX
DFRobot_PLAY DF1201S;
const int MPU_addr = 0x68; // I2C address of the MPU-6050
int16_t AcX, AcY, AcZ, Tmp, GyX, GyY, GyZ;
bool movementStarted = false;
bool isRinging = false;
bool Ypositive = true;
bool onTable = false;
bool skipReSet = false;
bool startedRinging = false;
#define Addr 0x53
void setup() {
Serial.begin(115200);
DF1201SSerial.begin(115200);
while (!DF1201S.begin(DF1201SSerial)) {
Serial.println("Init failed, please check the wire connection!");
delay(1000);
}
/Set volume to 20/
DF1201S.setVol(25);
//Serial.print("VOL:");
/Get volume/
//Serial.println(DF1201S.getVol());
/Enter music mode/
DF1201S.switchFunction(DF1201S.MUSIC);
/*Wait for the end of the prompt tone */
delay(2000);
/Set playback mode to "repeat all"/
DF1201S.setPlayMode(DF1201S.SINGLE);//SINGLECYCLE,ALLCYCLE,SINGLE,RANDOM,FOLDER
//Serial.print("PlayMode:");
/Get playback mode/
//Serial.println(DF1201S.getPlayMode());
Wire.begin();
Wire.beginTransmission(MPU_addr);
Wire.write(0x6B); // PWR_MGMT_1 register
Wire.write(0); // set to zero (wakes up the MPU-6050)
Wire.endTransmission(true);
Serial.begin(9600);
//Serial.print("e");
}
void loop() {
//bool startedRinging = false;
//Serial.println("this is a test"); //I genuinely have no idea why, but if this exact line of code is removed or modified then the entire program breaks
Wire.beginTransmission(MPU_addr);
Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H)
Wire.endTransmission(false);
Wire.requestFrom(MPU_addr, 14); // request a total of 14 registers
int t = Wire.read();
AcX = (t << 8) | Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
t = Wire.read();
AcY = (t << 8) | Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
t = Wire.read();
AcZ = (t << 8) | Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
t = Wire.read();
Tmp = (t << 8) | Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
t = Wire.read();
GyX = (t << 8) | Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
t = Wire.read();
GyY = (t << 8) | Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
t = Wire.read();
GyZ = (t << 8) | Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
t = Wire.read();
Serial.print(AcX); Serial.print(" ");
Serial.print(AcY); Serial.print(" ");
Serial.print(AcZ); Serial.print(" ");
Serial.print(GyX); Serial.print(" ");
Serial.print(GyY); Serial.print(" ");
Serial.println(GyZ);
if (GyX < -30000 && !startedRinging) {
// Play the "0001.mp3" in the "mp3" folder on the SD card
DF1201S.playFileNum(1);
movementStarted = true;
isRinging = true;
onTable = true;
skipReSet = false;
startedRinging = true;
Serial.println("+++++++++++++++++......");
}
if (AcZ < -4000 ) {
//STOP RINGING on shoulder
DF1201S.playFileNum(2);
startedRinging = false;
Serial.println("STOP RINGING");
}
if (AcX < -6000 && AcX > -10000 && AcY < -1000 && AcY > -8000 && AcZ > 10000 && AcZ < 14000 && !onTable) {//bell is POSSIBLY on table, possibly stop ringing
for (int i = 0; i < 10; i++) { //give 0.5 sec to check if bell is truly laying flat
delay(10);
if (AcX < -6000 && AcX > -10000 && AcY < -1000 && AcY > -8000 && AcZ > 10000 && AcZ < 14000 && !onTable) { //bell IS on TABLE
if (!startedRinging) {
DF1201S.playFileNum(2);
startedRinging = false;
Serial.println("On TABLE");
}
}
}
}
// Re-set On Table & StartedRinging as Bell m oves up
if (AcY > 8000) {
onTable = false;
startedRinging = false;
}
}
I'm still waiting to see the library sources you have, so they can be compared against a known-good version.
Please remember the code tags - it's starting to get tedious.
Sorry,
I don't understand Library sources
SoftwareSerial comes with the Arduino IDE
I'm, trying to read about 'code tags'
But, please understand this is NOT a code problem
'The Codes all worked fine until 9:15 Saturday 12/11/2021
There is some other problem, like the IDE, Uploading,
Ed
OK.
Good luck.
Can you tell us where pin 2 and 3 are connected ?
——
please edit your previous posts, select the code part and press the </> icon in the tool bar to mark it as code. It’s barely readable as it stands. (also make sure you indented the code in the IDE before copying, that’s done by pressing ctrlT on a PC or cmdT on a Mac)
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.