Im using a DHT11 and an modded LCD can i use the battery on the ds3231 Clock to store the information of my code?
So my dht is reading the Temperature and Humididty and i wanted to store the information in case lights go out, i was wondering if the little battery can store that information because it uses a CR2032 battery that can store the clock information
The battery does not store the clock information.
The DS3231 has a (limited) number of registers that store the current state of the clock. The battery on the DS3231 allows the register contents only to be saved and also keeps the clock running.
Store your information, for when the lights go out, in something like a FRAM, which needs no power to save its contents. Common FRAMs can store 2Kbytes or 8Kbytes of information.
If you are using one of the common DS3231 boards, there is usually a small EEPROM that can be used to store data.
Why can't you just read the temperature and humidity when the lights come back on?
Because i have a thing were i select the humidity that i want and it starts using an humidifier to increase the humidity , so i need that value to be stored
If what you want is to store the desired humidity level, that is not something that will change very often, and can be stored in the internal EEPROM (depending on the type of arduino board you are using).
im using an arduino uno
The UNO has 1024 bytes of EEPROM, you can store data there then read it back after a power failure. The main limitation is that each byte can only be written 100,000 times (easy to exceed if you run a fast loop() and write every time), but for storing the settings for a humidifier that should not be a problem. There is no limit on how many times the data can be read back.
Im on a loop of 2 seconds , What happends if it reaches the max capacity of written times ?
After the maximum write times are exceeded, the data will not store correctly and what you read back will no longer match what was written.
The fact that the loop takes 2 seconds should not be a problem if you only want to store the target amount of humidity. As long as you only write to the EEPROM when you change the target humidity, it would take you a very long time to enter a new amount 100,000 times. There is not likely to be a reason you would need to store the current humidity reading from the humidity sensor, since what you want from that is the current humidity, not what the humidity was hours or days ago when the power failed.
If you use the put() function to write to EEPROM the cell will not be written to if the data has not changed. That helps the EEPROM to last longer. Another way to mitigate EEPROM wear is called wear leveling.
Only store it when you set a new humidity. If you store it in EEPROM, I'm sure that you don't change that setting every 2 seconds.
Where will the sketch store the address of the next EEPROM location to be used such that it will be available after a power failure ?
Good question
How much information? The clock chip has a few registers you could hijack and use for your own purposes, but only a few bytes.
a7
I believe that the DS3231 has some EEPROM built in but I have never experimented with it
Only the modules (or some of them) have an additional EEPROM chip. But why use that if you have EEPROM in the microcontroller. And we have no idea what the OP is actually using.
@alto777 , I did try to find the info about the RAM in the DS3231 in its datasheet but could not find it. Is it the user buffer?
No. The user buffer appears to be a convenience measure. I do not see a way to exploit it for other purposes.
I am referring to the configuration registers from 0x7 to 0xd inclusive. The alarm one and alarm two registers.
Although their proper use is with BCD data, the registers do hold all values 0..255 without prejudice or complaint.
If you aren't using the alarms, you can stash seven bytes in battery-backed RAM using the DS1307 or DS3231.
// https://wokwi.com/projects/369239221064627201
// https://forum.arduino.cc/t/can-u-use-the-battery-on-a-ds3231-to-save-information/1143894
# include <Wire.h>
# define DS3231_I2C_ADDRESS 0x68
void setup()
{
Serial.begin(115200);
Wire.begin();
for (unsigned char add = 0x7; add < 0xe; add++) {
for (unsigned int data = 0; data < 256; data++) {
pokeRTC(add, data);
unsigned char stored = peekRTC(add);
Serial.print(add); Serial.print(" ");
Serial.print(data); Serial.print(" ");
Serial.print(stored); Serial.print(" ");
if (data != stored) Serial.print(" *");
Serial.println();
}
}
}
void pokeRTC(unsigned char regAddress, unsigned char value) // iDayOfWeek
{
Wire.beginTransmission(DS3231_I2C_ADDRESS);
Wire.write(regAddress);
Wire.write(value);
Wire.endTransmission();
}
unsigned char peekRTC(unsigned char regAddress)
{
Wire.beginTransmission(DS3231_I2C_ADDRESS);
Wire.write(regAddress); // set DS3231 register pointer to 00h
Wire.endTransmission();
Wire.requestFrom(DS3231_I2C_ADDRESS, 1);
// if (regAddress == 7) return (0);
return (Wire.read());
}
void loop()
{
}
a7
Thanks for the explanation.
The EEPROM chip generally has a much greater limit on how many times it can be written to.