this is my first post in Arduino forum so I hope to get it right
I have a DS3231 RTC with an alarm set. When i disconnect 5V from VCC the alarm don't works. I need an RTC or similar for wake up arduino from sleep. My project need low power because will be powered by battery pack (4xAA ~4.8V).
I need setup an alarm or more (i need 3 wake up daily programmable) that wake up arduino from deep sleep (power save). Example:
08:00 wake up --> sampling temparature, weight..etc --> sleep
14:00 wake up --> sampling temparature, weight..etc --> sleep
19:00 wake up --> sampling temparature, weight..etc --> SEND SMS (GSM) --> sleep again
It's possible? RTC on Arduino not work because during deep sleep is stopped so i need external RTC with very very low consumption.
None of the RTCs I'm running ever stop when there is no power to the Arduino. You need to tell us a lot more about your hardware configuration, and the circumstances in which this is happening.
But generally you would connect the RTC Int/SQ pin to an arduino interrupt pin, and enable wake from sleep for that pin.
It's also not clear whether you have written software, or whether you are asking how to write it.
I disconnect 5V from RTC's VCC no from arduino. I thought that battery coin on RTC did work also alarms not only keep the correct time. I hope I'm wrong but without 5V VCC on RTC alarm don't works?
I have connected he RTC Int/SQ pin to an arduino interrupt pin but without VCC on RTC it's don't work. If i check V on SQW pin when RTC works with battery it's 0V.
I'm writing software but i need know a method for wake up arduino at specific time but with very low low power consumption.
My hardware configuration is:
Arduino Mini Pro 328P 5V/16Mz
MOSFETP IRF9024 + BC547 for low consumption (it's necessary for turn off/on GSM with enough power for connect to GSM network (current peek))
DHT 22 temperature sensor
HX771 + Load Cell
SIM900 GSM
RTC DS3231 (zs-042)
My dream was power off all and then at specific time (3 times at day) wake up arduino that then power on relative module (dht22, gsm, etc) only when necessary (example GSM only at 3th wakeup will be powered) and then go to deep sleep waiting for next wake up (forced by RTC).
Sadly, the DS3231 does not check alarms when running on battery, only square waves can be enabled to work on battery ( with the BBSQW bit ). So I believe the best you can do with the DS3231 is to wake up your arduino every second (with the 1Hz square wave of course), and turn on the DS3231 so you can check if the alarm flag was set.
#include <LowPower.h>
// RTC - Real Time Clock
#include <DS3232RTC.h> //http://github.com/JChristensen/DS3232RTC
#include <Time.h> //http://www.arduino.cc/playground/Code/Time
#include <WSWire.h> //http://arduino.cc/en/Reference/Wire (included with Arduino IDE)
// Pin per l'accensione del modulo RTC
int const pinRTC = 11;
void setup()
{
// Power for RTC from Arduino PIN to RTC VCC
pinMode(pinRTC, OUTPUT);
Serial.begin(19200);
Serial.println("Startup...");
delay(100);
// Set Alarm2 every minute
RTC.setAlarm(ALM2_EVERY_MINUTE, 00, 00, 00, (dowSunday | dowMonday | dowTuesday | dowWednesday | dowThursday | dowFriday | dowSaturday));
RTC.alarmInterrupt(ALARM_2, true); //assert the INT pin when Alarm2 occurs.
delay(100);
}
void wakeUp()
{
// handling interrupt code
}
void loop()
{
// Allow wake up pin to trigger interrupt on low.
attachInterrupt(0, wakeUp, FALLING);
// Enter power down state with ADC and BOD module disabled.
// Wake up when wake up pin is low.
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
// Disable external pin interrupt on wake up pin.
detachInterrupt(0);
if (RTC.alarm(ALARM_2))
{
Serial.println("Alarm fired!");
}
else
{
Serial.println("-");
}
delay (100);
// Turn on VCC on RTC from out pin arduino
digitalWrite(pinRTC, HIGH);
LowPower.powerDown(SLEEP_500MS, ADC_OFF, BOD_OFF); // wait a bit
// date and time
tmElements_t tm;
if (RTC.read(tm) == 0) // Se la lettura è avvenuta correttamente tramite I2C
{
Serial.print(tm.Day, DEC);
Serial.print('/');
Serial.print(tm.Month, DEC);
Serial.print('/');
Serial.print(tm.Year, DEC);
Serial.print(' ');
Serial.print(tm.Hour, DEC);
Serial.print(':');
Serial.print(tm.Minute, DEC);
Serial.print(':');
Serial.println(tm.Second, DEC);
}
else
{
Serial.println("Errore RTC");
}
delay(100);
// Spengo il modulo RTC
digitalWrite(pinRTC, LOW);
}
guix:
Sadly, the DS3231 does not check alarms when running on battery, only square waves can be enabled to work on battery ( with the BBSQW bit ). So I believe the best you can do with the DS3231 is to wake up your arduino every second, and turn on the DS3231 so you can check if the alarm flag was set.
It's really? D'oh! Have you a solution for my problem, wake up arduino from sleep at specific time of the day? So, alarms don't work in all RTC modules without power?
You could wake up every second by enabling a 1Hz square wave on *int/sqw , check the alarms and go back to sleep. The duty cycle would be very low, so not much average power consumption.
That's disappointing that it won't generate an interrupt pulse when on battery.
The difference in the current draw between Vcc powered and battery is something like 200:1. It's normal to power these units down in low-power systems.
But having to power the RTC up every second to check the alarm makes the alarm function superfluous for those systems. You might as well just do the check in the uP code. It might make more sense to ignore the RTC time registers and just use the square wave output to generate an interrupt for keeping the time in the uP code.
jboyton:
That's disappointing that it won't generate an interrupt pulse when on battery.
The difference in the current draw between Vcc powered and battery is something like 200:1. It's normal to power these units down in low-power systems.
But having to power the RTC up every second to check the alarm makes the alarm function superfluous for those systems. You might as well just do the check in the uP code. It might make more sense to ignore the RTC time registers and just use the square wave output to generate an interrupt for keeping the time in the uP code.
Not really superfluous, as the alarm test is much faster, just one I2C read to test the flags. In this case, faster means much less power.
Sounds to me that the bits are not getting set correctly in these 2 registers:
Control Register (0Eh)
Bit 7: Enable Oscillator (EOSC). When set to logic 0,
the oscillator is started. When set to logic 1, the oscillator
is stopped when the DS3231 switches to VBAT. This
bit is clear (logic 0) when power is first applied. When
the DS3231 is powered by VCC, the oscillator is always
on regardless of the status of the EOSC bit. When
EOSC is disabled, all register data is static.
Bit 2: Interrupt Control (INTCN). This bit controls the
INT/SQW signal. When the INTCN bit is set to logic 0, a
square wave is output on the INT/SQW pin. When the
INTCN bit is set to logic 1, then a match between the
timekeeping registers and either of the alarm registers
activates the INT/SQW output (if the alarm is also
enabled). The corresponding alarm flag is always set
regardless of the state of the INTCN bit. The INTCN bit
is set to logic 1 when power is first applied.
Bit 1: Alarm 2 Interrupt Enable (A2IE). When set to
logic 1, this bit permits the alarm 2 flag (A2F) bit in the
status register to assert INT/SQW (when INTCN = 1).
When the A2IE bit is set to logic 0 or INTCN is set to
logic 0, the A2F bit does not initiate an interrupt signal.
The A2IE bit is disabled (logic 0) when power is first
applied.
Bit 0: Alarm 1 Interrupt Enable (A1IE). When set to
logic 1, this bit permits the alarm 1 flag (A1F) bit in the
status register to assert INT/SQW (when INTCN = 1).
When the A1IE bit is set to logic 0 or INTCN is set to
logic 0, the A1F bit does not initiate the INT/SQW signal.
The A1IE bit is disabled (logic 0) when power is
first applied.
Status Register (0Fh)
Bit 1: Alarm 2 Flag (A2F). A logic 1 in the alarm 2 flag
bit indicates that the time matched the alarm 2 registers.
If the A2IE bit is logic 1 and the INTCN bit is set to
logic 1, the INT/SQW pin is also asserted. A2F is
cleared when written to logic 0. This bit can only be
written to logic 0. Attempting to write to logic 1 leaves
the value unchanged.
Bit 0: Alarm 1 Flag (A1F). A logic 1 in the alarm 1 flag
bit indicates that the time matched the alarm 1 registers.
If the A1IE bit is logic 1 and the INTCN bit is set to
logic 1, the INT/SQW pin is also asserted. A1F is
cleared when written to logic 0. This bit can only be
written to logic 0. Attempting to write to logic 1 leaves
the value unchanged.
CrossRoads, can you find the language in the datasheet that specifically says it works when powered down? I couldn't. Maybe I will test it. I have one wired up on a breadboard at the moment.
aarg:
Not really superfluous, as the alarm test is much faster, just one I2C read to test the flags. In this case, faster means much less power.
Is it really faster? I haven't written code and done the comparison.
In a low power application the processor is probably also sleeping. Since the RTC apparently doesn't generate interrupts when on battery power, the processor will have to wake up every second just so it can power up the RTC, read a byte and then power it down. Most of the overhead is in the processor waking up. The difference between the power up / I2C read / power down versus comparing two 32-bit variables in RAM isn't the issue.
I'm inclined to believe the bad news, because of the explanation of bit 6 of the control register, BBSQW:
"Bit 6: Battery-Backed Square-Wave Enable
(BBSQW). When set to logic 1 with INTCN = 0 and VCC
< VPF, this bit enables the square wave. When BBSQW
is logic 0, the INT/SQW pin goes high impedance when
VCC < VPF. This bit is disabled (logic 0) when power is
first applied."
jboyton:
Is it really faster? I haven't written code and done the comparison.
In a low power application the processor is probably also sleeping. Since the RTC apparently doesn't generate interrupts when on battery power, the processor will have to wake up every second just so it can power up the RTC, read a byte and then power it down. Most of the overhead is in the processor waking up. The difference between the power up / I2C read / power down versus comparing two 32-bit variables in RAM isn't the issue.
Or at least that's how I imagine it.
Well it is your imagination. To do the software compare, the current RTC time must be read and converted from BCD to one of those 32 bit values.
Although, I concede that there might be other benefits to doing it in software. I just though we were talking about power saving here.
aarg:
Well it is your imagination. To do the software compare, the RTC time must be read and converted from BCD to one of those 32 bit values.
I was imagining keeping time in the processor rather than using the RTC itself. The square wave could feed directly to an interrupt pin on the processor and wake it up every second. Then the processor could keep time internally. Keeping track of time and date is not a complicated algorithm. It could be BCD or any format. Updating time variables takes very few cycles on average.
But you're right, I'm just imagining a system. I don't know what the OP is doing.