Only when "CLK_PIN = 7" and "softSerial(6, 7)" are set, will the serial port return the normal time. If softSerial(6, 8)" or softSerial(7,9)" are set, they will return 200/0/0 0:0:0 I don't understand
Please show a schematic of your circuit and a photo of how you have everything connected. Also upload the code/sketch you're running.
Okay!
#include <Arduino.h>
#include <Ds1302.h>
#include "DFRobotDFPlayerMini.h"
#include <SoftwareSerial.h>
const int RST_PIN = 2;
const int DAT_PIN = 3;
const int CLK_PIN = 7;
// DS1302 RTC instance
Ds1302 rtc(RST_PIN, CLK_PIN, DAT_PIN);
SoftwareSerial softSerial(8, 9); // RX, TX for DFPlayer Mini
DFRobotDFPlayerMini myDFPlayer;
void setup() {
Serial.begin(115200);
softSerial.begin(9600);
Serial.println(F("Checking RTC..."));
if (rtc.isHalted()) {
Serial.println(F("RTC is halted. Setting time..."));
Ds1302::DateTime dt = {
.year = 24,
.month = Ds1302::MONTH_JUN,
.day = 15,
.hour = 19,
.minute = 50,
.second = 0,
.dow = Ds1302::DOW_SAT
};
rtc.setDateTime(&dt);
} else {
Ds1302::DateTime now;
rtc.getDateTime(&now);
printTime(now);
Serial.println(F("RTC is running."));
}
if (!myDFPlayer.begin(softSerial)) {
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) {
// delay(0);
// }
}
Serial.println(F("DFPlayer Mini online."));
myDFPlayer.volume(20);
}
void loop() {
Ds1302::DateTime now;
rtc.getDateTime(&now);
printTime(now);
if (now.year == 24 && now.month == Ds1302::MONTH_JUN && now.day == 15 &&
now.hour == 20 && now.minute == 05 && now.second == 0) {
//myDFPlayer.playFolder(1, 1);
}
delay(1000);
if (myDFPlayer.available()) {
printDetail(myDFPlayer.readType(), myDFPlayer.read());
}
}
void printTime(const Ds1302::DateTime& time) {
Serial.print("Current time: ");
Serial.print("20");
Serial.print(time.year);
Serial.print('/');
Serial.print(time.month);
Serial.print('/');
Serial.print(time.day);
Serial.print(' ');
Serial.print(time.hour);
Serial.print(':');
Serial.print(time.minute);
Serial.print(':');
Serial.println(time.second);
}
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;
}
}
But DFPlayer is currently not part of the system, right?
I'd start by making a sketch that only interfaces with the DS1302 to verify it works correctly. Have you tried this?
Yeah, you need that because you have the DS1302 CLK pin connected to D7 on your Arduino.
The possible conflict with your softSerial code should not occur if you test with only the DS1302 as outlined above. Once that works, add the DFPlayer and make sure to not use any pins you're already using for the DS1302. You have plenty of pins, so it's easy to prevent any conflicts.
YES,No problem connecting only to DS1302
OK, then show a schematic of the project with the DFPlayer connected as well plus a photo of those connections.
Please don't leave out the schematic.
I think I didn’t express it clearly. It shouldn’t affect normal operation if you don’t connect to DFplay. Now that you don’t connect to DFplay, the time will become 200/0/0 0:0:0
Anyway, thank you, I will study it further
I moved your topic to an appropriate forum category @fangzi.
In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.
This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.
Thanks in advance for your cooperation.
Depends. You mentioned this:
The problem with starting softSerial on 7 & 9 is that you're using pin 7 for the CLK of the RTC, so I can see how this would create a conflict. I can't quite explain why starting softSerial on 6 & 8 would cause a similar problem; I wouldn't expect this. It's conceivable you have another problem going on at the same time, like a poor contact (I see the purple wire sticking halfway out of the 5V header for instance).
You could do some further testing to figure out which definitions create a conflict resulting in the RTC not working. Then see if you can spot a pattern in this. Again, I expect that there won't be a problem as long as you don't use any of the RTC's pins for other purposes.
Please edit your post with the code, select all code and apply code tags as described in How to get the best out of this forum; next save your post. It makes the code easier to read and to copy and the forum software will display it correctly.
- Edit post
- Select all code
- Click the
<CODE/>
button. - Save the post
okay
Okay, that's ok for now
I'll check again