I have DIGISPARK running on 4 AA batteries (measured voltage is 5.3V). What it does, is that it sleeps most of the time. RTC wakes it up usin PinChange interrupts, and then it turns ON pin 4 for actTime. It works fine for few days, but at some point DIGISPARK stops responding (meaning even pressing the switch doesn't wake it up). When I reset the power thus resetting microcontroller, everything works correctly for few days, then it stops responding again.

Do you have any idea what's going on?

Here is the schematic:


simulate this circuit – Schematic created using CircuitLab

And here is the code:

    #include "Rtc_Pcf8563.h"

/* Demonstration of Rtc_Pcf8563 Set Time. 
 * Set the clock to a time then loop over reading time and 
 * output the time and date to the serial console.
 * I used a RBBB with Arduino IDE, the pins are mapped a 
 * bit differently. Change for your hw
 * SCK - A5, SDA - A4, INT - D3/INT1
 * After loading and starting the sketch, use the serial monitor
 * to see the clock output.
 * setup:  see Pcf8563 data sheet.
 *         1x 10Kohm pullup on Pin3 INT
 *         No pullups on Pin5 or Pin6 (I2C internals used)
 *         1x 0.1pf on power
 *         1x 32khz chrystal
 * Joe Robertson, jmr
 * orbitalair@bellsouth.net

#include <TinyPinChange.h>
#include <avr/sleep.h>

//init the real time clock
Rtc_Pcf8563 rtc;
uint8_t VirtualPortNb;

const unsigned int actTime = 3000;

const unsigned int HOUR   =   20;
const unsigned int MIN    =   30;

volatile bool flag =0 ;

void wakeUpRTC(){
  flag = 1;

void goToSleep(){
  set_sleep_mode( SLEEP_MODE_PWR_DOWN );
  TinyPinChange_EnablePin( 3);
  TinyPinChange_DisablePin( 3);

void setup()

  VirtualPortNb = TinyPinChange_RegisterIsr(3,  wakeUpRTC);

  pinMode(3, INPUT);           // set pin to input
  pinMode(1, OUTPUT);
  pinMode(4, OUTPUT);

  rtc.setAlarm( MIN, HOUR, 99, 99 );

  for( int i=0; i<3; i++ ){
      digitalWrite( 1, 1);
      digitalWrite( 1, 0);

void loop(){
  if (flag==1){
    flag = 0;
    digitalWrite( 4, HIGH);
    delay( actTime );
    digitalWrite( 4, LOW);

    rtc.setAlarm( MIN, HOUR, 99, 99 );
  • \$\begingroup\$ You have a way through your code to go to sleep without setting flag=0. If you really need that flag, shouldn't you move it into the goToSleep function? \$\endgroup\$ – HandyHowie Jun 12 at 10:50
  • \$\begingroup\$ @HandyHowie But I do set flag to 0, inside if in loop. Flag is also initialised as 0 \$\endgroup\$ – Em Ka Jun 12 at 11:03
  • \$\begingroup\$ But if you wake up by a GPIO level change, flag will still be 0, therefore nothing in your main loop will be executed and hence it will never go back to sleep. I don't know anything about this processor, so maybe I am missing something. \$\endgroup\$ – HandyHowie Jun 12 at 11:09
  • \$\begingroup\$ @HandyHowie When it wakes up, wakeUpRtc function is called. Inside this function I set the flag. Besides, as I wrote, it works perfectly for few days, then it stops working \$\endgroup\$ – Em Ka Jun 12 at 12:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.