Scheduling Two Start-ups with Witty Pi

Update on 2015-08-06: with the V2.00 software, we can define complex schedule using schedule script. There is no point to use this trick any more.

With the default software, Witty Pi can schedule one start-up and one shutdown for your Raspberry Pi, thanks for the two alarms in DS1337 realtime clock chip. By using the wildcard, you can also make repeatable schedules, which can be daily, hourly or minutely schedules.

What if you want to startup your Raspberry Pi twice a day? Is it possible? The answer is positive, and we don’t need to modify any hardware! The idea is that DS1337 chip has two alarms, according to the datasheet of DS1337, we can set the INTCN to 0 and force the second alarm (alarm B) to output at the same IC pin with the first alarm (alarm A). After that, when you schedule the shutdown, you are actually scheduling the second startup 😀

You will need to modify the “” script in the “wittyPi” directory. Below is the modified version:

If you compare it with the original version, you will notice that only line 39 is modified, and only the last byte is changed (from 0x05 to 0x1B).

Remarks: when waiting for the second startup, please make sure that your Raspberry Pi is in OFF state. Otherwise because of line 14 in “”, the second alarm will shutdown your Pi when your Pi is ON. There are reasons that we could not force alarm B to the same pin with alarm A at line 14, also we could not disable alarm B there. I may explain that in a separated post.

As long as your Pi is ON and your program is running, it should not be difficult to shutdown your Pi before the next startup. You can even shut it down via SSH connection, if your Pi has Internet connection. (PS: please do not use “sudo shutdown -h” or “sudo halt”, instead you run “gpio write 7 down” and “gpio mode 7 out” to pull down GP-4, otherwise line 39 will not get executed)

If you just want to get it works, you are ready to go. Just use the modified version of script and make sure to shutdown your Pi before second startup, then you are set. You may also want to update the “” script and replace the messages to display on the console, and that should be quite easy.

By using the wildcard, it is now possible to wake up your Raspberry Pi twice a day :0)

If you want to know more about the technical details, I could explain it a little bit.

Line 39 set a control register, which is a byte at address 0x0E, to a specific value 0x1B, which in binary format is “0001 1011”. The description of this control register is shown below:Screen Shot 2015-06-19 at 12.10.44 PMYou can find more details about it in the datasheet. In our case we only care about the lower 5 bits, which are RS2, RS1, INTCN, A2IE and A1IE.

  • You want to enable alarm A (startup), you set A1IE to 1.
  • You want to enable alarm B (shutdown or second startup), you set A2IE to 1.
  • You want to force alarm B to output at the same pin with alarm A, you set INTCN to 0. But a side-effect is the previous pin for alarm B starts outputting square wave.
  • RS2 and RS1 can control the square wave frequency, please see table below:


The square wave frequency doesn’t seem to be relevant, but the fact is that we could not ignore it. Because square wave is a serial of low and high voltage levels, if low voltage level apply to that pin for long enough, the auto-shutdown function will be triggered, which we should avoid in this case.

The workaround is to use the highest frequency, to reduce the time that apply the low voltage level on the pin. So we set both RS1 and RS2 to 1.

With both alarms enabled, setting INTCN to 0 and use highest square wave frequency, the entire control register becomes “0001 1011”, which is 0x1B.

See also