artrpi
Posts: 13
Joined: Mon Apr 10, 2017 8:44 pm

Turning on Zero W every hour

Mon Apr 10, 2017 8:54 pm

I'm trying to build a battery powered system with an e-paper display. It would wake up every hour, make an HTTP request (e.g., to a twitter feed), update the display and shut down. Everything seems to be pretty straightforward, except for the waking up every hour part. I'd like to avoid using bulky additional boards such as Witty Pi. Is there an easy solution for disconnecting and reconnecting the power every hour? It doesn't have to be very accurate, +/- 5 minutes is acceptable.

User avatar
solar3000
Posts: 1051
Joined: Sat May 18, 2013 12:14 am

Re: Turning on Zero W every hour

Tue Apr 11, 2017 12:45 am

A timer such as a 555 integrated circuit that I grew up with ( ancient ). Or any timer that provides a single pole, single throw switch.
And on the pi there a power switch connector. Its marked 'run'.
BTW when the pi zero w is completely off, it still uses power.

The rpi0 w at idle: 110mA
file xfer 160mA
"off" 30mA
Antikythera

tweak42
Posts: 498
Joined: Tue Mar 22, 2016 3:16 am
Location: Los Angeles, California

Re: Turning on Zero W every hour

Tue Apr 11, 2017 3:09 am

artrpi wrote:I'm trying to build a battery powered system with an e-paper display. It would wake up every hour, make an HTTP request (e.g., to a twitter feed), update the display and shut down. Everything seems to be pretty straightforward, except for the waking up every hour part. I'd like to avoid using bulky additional boards such as Witty Pi. Is there an easy solution for disconnecting and reconnecting the power every hour? It doesn't have to be very accurate, +/- 5 minutes is acceptable.
Low Power Timer Breakout wired to reset header that triggers a Pi in shutdown state to start up. The Pi would boot, run update scripts then shutdown. This wouldn't totally unplug the Pi, but it does reduce power consumption by keeping it in shutdown state most of the time.

For actual power control, ATXRaspi might work well in conjunction with the above timer.
https://lowpowerlab.com/shop/product/91

geoffr
Posts: 85
Joined: Wed Aug 22, 2012 11:25 am
Location: Melbourne, VIC

Re: Turning on Zero W every hour

Tue Apr 11, 2017 3:55 am

artrpi wrote:I'm trying to build a battery powered system with an e-paper display. It would wake up every hour, make an HTTP request (e.g., to a twitter feed), update the display and shut down. Everything seems to be pretty straightforward, except for the waking up every hour part. I'd like to avoid using bulky additional boards such as Witty Pi. Is there an easy solution for disconnecting and reconnecting the power every hour? It doesn't have to be very accurate, +/- 5 minutes is acceptable.
As you have probably gathered, there are a few different ways to approach this.
My favoured approaches would be either to use a small Atmel microcontroller (like an ATTiny85) to pulse the reset line on the Pi after an hour, or to use the alarm of a RTC. The trick, if you use the alarm of a RTC like a DS3231, when the alarm triggers, it holds, rather than sending a pulse. One way of dealing with that is to use an edge detector to detect the rising edge of the alarm signal and pulse the reset on the Pi. Alternatively, dig out the ATTiny85 again and get it to pulse the reset pin when it detects the edge of the alarm from the RTC.
Doing this would still entail an external board, but would not be as complex as a WittyPi.

User avatar
Gavinmc42
Posts: 3633
Joined: Wed Aug 28, 2013 3:31 am

Re: Turning on Zero W every hour

Tue Apr 11, 2017 4:41 am

Zero in halt/sleep - 30ma is a lot.
Low power timers like the TI TLP range are nano amp.
Something a bit more accurate would be nice, so an RTC.
That does require a bit of code to set the next wake up time.
Any RTC with periodic wakeups?

Zero's can also handle low voltage so direct LiPo power on 5V GPIO?
This would be great for Time lapse photos.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

tpylkko
Posts: 381
Joined: Tue Oct 14, 2014 5:21 pm

Re: Turning on Zero W every hour

Tue Apr 11, 2017 5:19 am

I don't know why using and RTC would require a lot of code. On any normal laptop/desktop (that is one that has an RTC) with linux you can suspend or sleep the machine and have it automatically awake by using a simple rtcwake command. You could insert the command into a .service file and use a timer to active it. This is simple, but it requires a real time clock (RTC).

But to me this project sounds like it would work better without a RPi. Because as mentioned here earlier many microcontrollers can be made to sleep and when they sleep they use currents way under 1 ma. For example the esp8266 has a wifi antenna and can even host web pages. It costs 2-10 USD depending on the model. That combined with a e-ink display would allow for a device that essentially uses no power except when it needs to fetch new information. But, of course, if this project requires something to be done where you need a full blown OS then you would need the Pi. But that will consume much energy. One solution is to use one of those simple timers that can be attahed to the power socket.

peterlite
Posts: 720
Joined: Sun Apr 17, 2016 4:00 am

Re: Turning on Zero W every hour

Tue Apr 11, 2017 6:06 am

There are a few posts on saving battery power that have the Pi sleep and wake up or switch off completely. Some use a real time clock. Some use an external device. Because you want only once per hour, you could look at the posts on adding an on/off button, implement that, then use an external RTC to switch the Pi on.

http://www.instructables.com/id/Raspber ... /?ALLSTEPS
viewtopic.php?t=102015
Last edited by peterlite on Tue Apr 11, 2017 6:26 am, edited 2 times in total.

geoffr
Posts: 85
Joined: Wed Aug 22, 2012 11:25 am
Location: Melbourne, VIC

Re: Turning on Zero W every hour

Tue Apr 11, 2017 6:15 am

Gavinmc42 wrote:Zero in halt/sleep - 30ma is a lot.
Low power timers like the TI TLP range are nano amp.
Something a bit more accurate would be nice, so an RTC.
That does require a bit of code to set the next wake up time.
Any RTC with periodic wakeups?

Zero's can also handle low voltage so direct LiPo power on 5V GPIO?
This would be great for Time lapse photos.
Some RTCs have periodic alarms - the DS3231 does. Whether rtcwake will work with a DS3231 on Raspbian/Jessie - I don't know. Even if it doesn't you could program the DS3231 using I2C commands.
If the 30mA of the Pi in suspend/sleep mode is too much, you could use an ATTiny85 (or similar) to control a P-channel MOSFET to switch the power to the Pi. The gotcha of doing this is that if you rely on the Pi's 3.3V supply to power your RTC, your RTC will lose power if you switch off the 5V supply to the Pi.
You can run a RTC such as a DS3231 on 5V, but then you need to put level converters on the I2C bus to convert between 3.3V and 5V - that requires 2 N-channel MOSFETs and some resistors.

The solution I am describing here requires a bit of work - so it may not be the simplest.

User avatar
Gavinmc42
Posts: 3633
Joined: Wed Aug 28, 2013 3:31 am

Re: Turning on Zero W every hour

Tue Apr 11, 2017 6:59 am

Even if it doesn't you could program the DS3231 using I2C commands.
Yes but you put it permanently asleep if you reprogram the alarm times wrong :oops:
Some RTC have periodic outputs, but it would be nice if they were EEPROM and programmable from 1 minute to x minutes.
Then program once and don't worry.

Which is why the TI TLP timers look interesting, but they are not that flexible.
Read every RTC data sheet :o

Been going through my micro controller datasheets to see if I can turn them into RTCs.
Got some Smart BT modules, reprogram wakeup with Smartphone?
To bad the battery power to the WiFi/BT CY8CW43438 was not taken out to external pins :(
Got a Cortex ARM in it, use it for wake up? Hmm 32khz xtal input?
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

User avatar
startrek.steve
Posts: 383
Joined: Thu Aug 30, 2012 7:19 pm

Re: Turning on Zero W every hour

Tue Apr 11, 2017 7:18 am

Have you thought about using one of these?
https://www.amazon.co.uk/gp/product/B00 ... 1938312031

I use one to power up my DAB+Minidisk combo, the minidisk can be set to start recording on powerup. I use it to record radio shows on DAB on a timer, works a treat!!

Steve
Pi 2 running LibreElec Krypton, Pi 2 running Wheezy Desktop, Pi 1 headless Wheezy, downloading Radio, Pi 1 running Picore headless Media Server, Pi Zero to be an Old Time Radio Project. Pi 3 testing. Pi Zero W downloading Radio shows headless.

User avatar
Gavinmc42
Posts: 3633
Joined: Wed Aug 28, 2013 3:31 am

Re: Turning on Zero W every hour

Tue Apr 11, 2017 8:04 am

Big AC battery needed :lol:
Mains power is no problem, just use Cron.

Battery operation is a different matter if you want to run more than a day or so.
USB power bank will give hours to a day.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

gregeric
Posts: 1509
Joined: Mon Nov 28, 2011 10:08 am

Re: Turning on Zero W every hour

Tue Apr 11, 2017 10:49 am

geoffr wrote:Whether rtcwake will work with a DS3231 on Raspbian/Jessie - I don't know.
rtcwake doesn't work, but the ds3231 works well as a wakeup-source with current Jessie. In config.txt,

Code: Select all

dtoverlay=i2c-rtc,ds3231,wakeup-source
Clear current alarm & set new one with:

Code: Select all

sudo sh -c "echo 0 > /sys/class/rtc/rtc0/wakealarm"
sudo sh -c "echo 1491907055 > /sys/class/rtc/rtc0/wakealarm"
Check alarm:

Code: Select all

date -d @$(cat /sys/class/rtc/rtc0/wakealarm)
The INT pin will then give a short pulse low at the programmed time.

Raspberry Paul
Posts: 80
Joined: Mon Jun 10, 2013 3:40 pm
Contact: Website

Re: Turning on Zero W every hour

Tue Apr 11, 2017 6:59 pm

Adafruit have developed a break out board using a TPL5110 that allows power "cycles". Seems ideal for this kind of scheduled power up and down.

I'm just put off by high postage to uk. Waiting for Pimoroni to stock it.

https://blog.adafruit.com/2017/03/09/ne ... -breakout/

The Adafruit TPL5110 Power Timer is a stand-alone breakout that will turn any electronics into low-power electronics! It will take care of turning your project on/off using a built in timer that can vary from once every 100ms up to once every two hours. Basically, the TPL will turn on periodically, adjustable by potentiometer or resistor, and turn on your project’s power. It will then wait until a signal is received from the project to tell the TPL that it can safely turn off the power.
http://www.raspberrypaul.co.uk

User avatar
Pi Supply
Posts: 12
Joined: Wed Dec 14, 2016 10:39 am
Location: UK
Contact: Website

Re: Turning on Zero W every hour

Tue Apr 11, 2017 8:02 pm

For an RTC I would recommend the mcp7940n-i/sn from microchip.

Reason being that it can hold the run pin high, and short to ground on alarm to "wake" the Pi from halt. It can do this with no additional chips.

We use it with a pogo pin on our PaPiRus HAT.

It has device tree drivers and we have lots of code examples for it here - https://github.com/PiSupply/PaPiRus/tre ... t-Examples

I believe there's a standalone RTC board that uses this chip from PiFace also.
Pi Supply - The Maker Emporium!
https://www.pi-supply.com

i486
Posts: 172
Joined: Sun Aug 28, 2016 3:41 pm
Location: BG

Re: Turning on Zero W every hour

Tue Apr 11, 2017 8:20 pm

Simple solution (there are cheaper):

https://www.aliexpress.com/item/Plug-in ... 52751.html

gregeric
Posts: 1509
Joined: Mon Nov 28, 2011 10:08 am

Re: Turning on Zero W every hour

Tue Apr 11, 2017 10:53 pm

Pi Supply wrote:For an RTC I would recommend the mcp7940n-i/sn from microchip.
The MCP794xx series are supported as a wakeup-source by the Pi's i2c-rtc overlay. Unfortunately, the upstream driver needs a patch to make the wakealarm sysfs entry writable. I've submitted a simple patch to allow that. Saves you having to roll your own code for the alarm functions - let the kernel driver do it all.

danjperron
Posts: 3392
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Turning on Zero W every hour

Wed Apr 12, 2017 12:07 am

I did that with an RTC . You need one with an interrupt pin.

I post this on the french post.

viewtopic.php?f=65&t=166853&p=1074313#p1074313

The RTC will interrupt when the alarm set and power up the DC/DC converter. When you are ready to power off the Pi, you just need to set the next alarm and do a shutdown.

The trick is a GPIO pin set to be a power off pin. you simply set it up with the /boot/config.txt

i486
Posts: 172
Joined: Sun Aug 28, 2016 3:41 pm
Location: BG

Re: Turning on Zero W every hour

Wed Apr 12, 2017 7:35 am

Looks like good solution.

User avatar
startrek.steve
Posts: 383
Joined: Thu Aug 30, 2012 7:19 pm

Re: Turning on Zero W every hour

Wed Apr 12, 2017 12:14 pm

Pi 2 running LibreElec Krypton, Pi 2 running Wheezy Desktop, Pi 1 headless Wheezy, downloading Radio, Pi 1 running Picore headless Media Server, Pi Zero to be an Old Time Radio Project. Pi 3 testing. Pi Zero W downloading Radio shows headless.

artrpi
Posts: 13
Joined: Mon Apr 10, 2017 8:44 pm

Re: Turning on Zero W every hour

Wed Apr 12, 2017 7:28 pm

Raspberry Paul wrote:Adafruit have developed a break out board using a TPL5110 that allows power "cycles". Seems ideal for this kind of scheduled power up and down.

I'm just put off by high postage to uk. Waiting for Pimoroni to stock it.

https://blog.adafruit.com/2017/03/09/ne ... -breakout/

The Adafruit TPL5110 Power Timer is a stand-alone breakout that will turn any electronics into low-power electronics! It will take care of turning your project on/off using a built in timer that can vary from once every 100ms up to once every two hours. Basically, the TPL will turn on periodically, adjustable by potentiometer or resistor, and turn on your project’s power. It will then wait until a signal is received from the project to tell the TPL that it can safely turn off the power.
Thank you. TPL5110 looks like the best option for my project. In the description it says:
In your project’s code or design, just make sure that it sets the Done pin high once it is completed with its task.
Will it be possible to set the Done pin high after the Linux completed all the shutdown procedures?
Last edited by artrpi on Wed Apr 12, 2017 10:01 pm, edited 1 time in total.

MarkR
Posts: 154
Joined: Fri Jan 25, 2013 1:55 pm

Re: Turning on Zero W every hour

Wed Apr 12, 2017 9:00 pm

It should be possible to set the "done" pin high after Linux has shut down (or at least, nearly shut down).

The main issues might be:

* The "done" pin will need to stay high for long enough to power off the machine
* You probably want the "done" pin to stay low if you do "reboot" rather than "poweroff".

I'm sure there is a way to get the init-system to do this. Just try to ensure that the done-pin goes high after the filesystem is unmounted.

artrpi
Posts: 13
Joined: Mon Apr 10, 2017 8:44 pm

Re: Turning on Zero W every hour

Wed Apr 12, 2017 10:08 pm

MarkR wrote:It should be possible to set the "done" pin high after Linux has shut down (or at least, nearly shut down).

The main issues might be:

* The "done" pin will need to stay high for long enough to power off the machine
* You probably want the "done" pin to stay low if you do "reboot" rather than "poweroff".

I'm sure there is a way to get the init-system to do this. Just try to ensure that the done-pin goes high after the filesystem is unmounted.
It looks like it can be done using device tree overlay in /boot/config.txt:
viewtopic.php?t=178015&p=1135124

I can sacrifice the reboot functionality.

artrpi
Posts: 13
Joined: Mon Apr 10, 2017 8:44 pm

Re: Turning on Zero W every hour

Thu Apr 13, 2017 9:43 pm

I'm planning to use the following configuration (all components are from Adafruit):

Lithium Ion Polymer Battery - 3.7v 1200mAh

PowerBoost 500 Charger

Adafruit TPL5110 Low Power Timer Breakout

Raspberry Pi Zero W

PaPiRus Zero ePaper/eInk pHAT

artrpi
Posts: 13
Joined: Mon Apr 10, 2017 8:44 pm

Re: Turning on Zero W every hour

Mon Jun 19, 2017 10:54 pm

Finally found time to put together all the components listed in my previous post. I connected the Done pin of TPL5110 to BCM 12 pin of the Pi, and added the following line to /boot/config.txt:

Code: Select all

dtoverlay=gpio-poweroff,active_high,gpiopin=12
I also added a script to /etc/rc.local that updates the display and executes sudo poweroff.

It works perfectly! I've only been running it for a couple of days, but hopefully it can last at least a week on one charge.

Thanks everyone for help!

tweak42
Posts: 498
Joined: Tue Mar 22, 2016 3:16 am
Location: Los Angeles, California

Re: Turning on Zero W every hour

Thu Jun 22, 2017 5:20 am

artrpi wrote:Finally found time to put together all the components listed in my previous post. I connected the Done pin of TPL5110 to BCM 12 pin of the Pi, and added the following line to /boot/config.txt:

Code: Select all

dtoverlay=gpio-poweroff,active_high,gpiopin=12
I also added a script to /etc/rc.local that updates the display and executes sudo poweroff.

It works perfectly! I've only been running it for a couple of days, but hopefully it can last at least a week on one charge.

Thanks everyone for help!
Great to hear your update. Please post more once you have some performance figures, perhaps some using different battery capacities.

Return to “General discussion”