Hello everybody, i am new to this forum. I am currently working on a project that needs a ds3231 chip (not the module you buy off amazon or ebay, just the chip) and i am getting so frustrated because i am not able to set, or the time off of it. I used every ds3231 ibrary possible, every sketch that exists ecc.
The connections are the usual and the pullup resistor values are correct, same goes fo rthe connections on the arduino uno.
Whenever i upload the sketch nothing shows up on the serial monitor, i am desperate i don't know what to do anymore.
P.S. I was able to do this with a simple ds1307 and now i can't see why i can't with a simple ds3231
Please post the sketch, using code tags when you do
In my experience the easiest way to tidy up the code and add the code tags is as follows
Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.
Please also post a schematic of your project. A 'photo of a hand drawn circuit is good enough
I have many different RTC modules, including the bare 3231 chip. I have a hard time understanding why you have a problem, but to start, show us your code, but first use the IDE Tools/Auto format tool, then paste it here in code tags. Next is to show us your wiring diagram.
I recommend you use and study the examples of the library DS3232 by Jack Christensen.
You made it work with ds1307, but not work with ds3231. Your ds3231 may be broken, or something wrong in your code or wiring. Please re-check your code and wiring with Arduino DS3231 RTC tutorial
When you post your annotated schematic that shows all hardware parts including resistors, capacitors, etc be sure to post links to technical information on the parts you are using. It appears to be a simple hardware problem. What did the I2C scanner show your? You did run it didn't you?
Here is the schematic, as said before it is the most basic configuration. Note also that i've tried to set the time also with the battery both plugged in and deatached.
For the code i used a ton of them from a ton of different libraries. I literraly followed every existing tutorial but they don't work at all. In the meantime i will start with this tutorial and code in particular: https://www.youtube.com/watch?v=Z-66x-9-7T0
// Arduino DS3232RTC Library
// https://github.com/JChristensen/DS3232RTC
// Copyright (C) 2018 by Jack Christensen and licensed under
// GNU GPL v3.0, https://www.gnu.org/licenses/gpl.html
//
// Example sketch to display the date and time from a DS3231
// or DS3232 RTC every second. Display the temperature once per
// minute. (The DS3231 does a temperature conversion once every
// 64 seconds. This is also the default for the DS3232.)
//
// Set the date and time by entering the following on the Arduino
// serial monitor:
// year,month,day,hour,minute,second,
//
// Where
// year can be two or four digits,
// month is 1-12,
// day is 1-31,
// hour is 0-23, and
// minute and second are 0-59.
//
// Entering the final comma delimiter (after "second") will avoid a
// one-second timeout and will allow the RTC to be set more accurately.
//
// No validity checking is done, invalid values or incomplete syntax
// in the input will result in an incorrect RTC setting.
//
// Jack Christensen 08Aug2013
#include <DS3232RTC.h> // https://github.com/JChristensen/DS3232RTC
#include <Streaming.h> // https://github.com/janelia-arduino/Streaming
DS3232RTC myRTC;
void setup()
{
Serial.begin(115200);
Serial << F( "\n" __FILE__ "\n" __DATE__ " " __TIME__ "\n" );
myRTC.begin();
// setSyncProvider() causes the Time library to synchronize with the
// external RTC by calling RTC.get() every five minutes by default.
setSyncProvider(myRTC.get);
Serial << F("RTC Sync");
if (timeStatus() != timeSet) Serial << F(" FAIL!");
Serial << endl;
}
void loop()
{
static time_t tLast;
time_t t;
tmElements_t tm;
// check for input to set the RTC, minimum length is 12, i.e. yy,m,d,h,m,s
if (Serial.available() >= 12) {
// note that the tmElements_t Year member is an offset from 1970,
// but the RTC wants the last two digits of the calendar year.
// use the convenience macros from the Time Library to do the conversions.
int y = Serial.parseInt();
if (y >= 100 && y < 1000)
Serial << F("Error: Year must be two digits or four digits!") << endl;
else {
if (y >= 1000)
tm.Year = CalendarYrToTm(y);
else // (y < 100)
tm.Year = y2kYearToTm(y);
tm.Month = Serial.parseInt();
tm.Day = Serial.parseInt();
tm.Hour = Serial.parseInt();
tm.Minute = Serial.parseInt();
tm.Second = Serial.parseInt();
t = makeTime(tm);
myRTC.set(t); // use the time_t value to ensure correct weekday is set
setTime(t);
Serial << F("RTC set to: ");
printDateTime(t);
Serial << endl;
// dump any extraneous input
while (Serial.available() > 0) Serial.read();
}
}
t = now();
if (t != tLast) {
tLast = t;
printDateTime(t);
if (second(t) == 0) {
float c = myRTC.temperature() / 4.;
float f = c * 9. / 5. + 32.;
Serial << F(" ") << c << F(" C ") << f << F(" F");
}
Serial << endl;
}
}
// print date and time to Serial
void printDateTime(time_t t)
{
printDate(t);
Serial << ' ';
printTime(t);
}
// print time to Serial
void printTime(time_t t)
{
printI00(hour(t), ':');
printI00(minute(t), ':');
printI00(second(t), ' ');
}
// print date to Serial
void printDate(time_t t)
{
printI00(day(t), 0);
Serial << monthShortStr(month(t)) << _DEC(year(t));
}
// Print an integer in "00" format (with leading zero),
// followed by a delimiter character to Serial.
// Input value assumed to be between 0 and 99.
void printI00(int val, char delim)
{
if (val < 10) Serial << '0';
Serial << _DEC(val);
if (delim > 0) Serial << delim;
return;
}
Hi. I also went down this path/solution but still the same problem, the arduino IDE tells me that it has uploaded everything but i can't read the time on the serial monitor, looks like the ds3231 is "stuck" although i changed the microchip several times, also being very careful about ESD etc..
If you're using an Uno or Nano, you might try running the I2C_Scanner sketch with the RTC connected and powered up. You should get its I2C address, which means you are at least communicating with it.
// --------------------------------------
// i2c_scanner
//
// Version 1
// This program (or code that looks like it)
// can be found in many places.
// For example on the Arduino.cc forum.
// The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
// Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26 2013
// V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
// by Arduino.cc user Krodal.
// Changes by louarnold removed.
// Scanning addresses changed from 0...127 to 1...119,
// according to the i2c scanner by Nick Gammon
// https://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
// As version 4, but address scans now to 127.
// A sensor seems to use address 120.
// Version 6, November 27, 2015.
// Added waiting for the Leonardo serial communication.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//
#include <Wire.h>
void setup()
{
Wire.begin();
Serial.begin(9600);
while (!Serial); // Leonardo: wait for serial monitor
Serial.println("\nI2C Scanner");
}
void loop()
{
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++ )
{
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0)
{
Serial.print("I2C device found at address 0x");
if (address<16)
Serial.print("0");
Serial.print(address,HEX);
Serial.println(" !");
nDevices++;
}
else if (error==4)
{
Serial.print("Unknown error at address 0x");
if (address<16)
Serial.print("0");
Serial.println(address,HEX);
}
}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");
delay(5000); // wait 5 seconds for next scan
}
The pin 1 and 3 are just outputs, so they can be left floating. The other references that you probably found on datasheets, show the configuration to make all the outputs functional. But in my case i only need sda and scl pins. Also playing around a bit more i found that the chip was very hot. I have to investigate on the reason
Please check the voltage of the coin cell battery using a multimeter. If this battery voltage is not sufficient, your DS3231 module is supposed to malfunction. If you need further info regarding this module you can see here: Introduction to DS3231 - The Engineering Projects
Today i will try the i2c scanner. But i am pretty sure that all the ics that i bought are damaged and faulty. I think there a no other explenations. The whole thing should be pretty straight forward from what i saw
Let me ask you a question. Where did you buy the ds3231 chips? Could you send me the link? I bought them from aliexpress and i think they might be faulty at this point. Because if we have the same configuration i am starting to doubt that my ICs are the problem. Also what sketch/library do you use?