201 Wiring Solar Test Rig
After a few rounds of solar testing using 3 Panels and 4 batteries with a Trinket M0 to shut down the rover at night, was the clear winner. I got 20 days on Solar Test 9, but it rained and let the smoke out of the Pi and the chargers.
Here is the wiring diagram for version 2, the same version that is running right now on Solar Test 11.

Compute Power Control v2
The Trinket M0 will shut down the Raspberry Pi Zero W using GPIO pin 4 on the Pi. This is the same pin the Pimoroni Zero Lipo uses when it shuts down the Pi at low voltage. Then after waiting, it will ground the enable port on the Zero Lipo, which will turn off the power. There are a couple of pieces of code, both using Python.
Trinket M0 Code: main.py
# Created by Bill Debevc
# for the Great Mojave Rover Project
# Version 1.0 Min Pro Version in C
# Version 2.0 M0 version in CircuitPython
import time
import board
import analogio
from digitalio import DigitalInOut, Direction
shutdownpin = DigitalInOut(board.D4)
shutdownpin.direction = Direction.OUTPUT
shutdownpin.value = True
enable = DigitalInOut(board.D3)
enable.direction = Direction.OUTPUT
enable.value = True
# Initialize analog input connected to photocell.
photocell = analogio.AnalogIn(board.A1)
# Main loop reads value and voltage every second and prints them out.
print('Starting the Great Mojave Rover Pi shutdown and restart')
while True:
# Read the value, then the voltage.
val = photocell.value
print('Photocell value: {0} - shutdownpin = {1} - enable = {2}'.format(val, shutdownpin.value, enable.value))
if val < 1500: # Shutdown Pi
print('lower than 1500')
shutdownpin.value = True
print('Shutdown Pin is now True')
time.sleep(30.0)
print('killing power to the pi')
enable.value = False
print('Enable Pin is now True')
else: # Startup Pi
print('higher than 1500')
shutdownpin.value = False
print('Shutdown Pin is now False')
enable.value = True
print('Enable Pin is now True')
# Wait 5 min to check again
print ('waiting 30')
time.sleep(2)
# Version 3.0 Ideas:
# Use M4 to measure Voltage from Batteries to not power up PI if low battery
# Write Battery Data to file on M0, overwriting the data each day.
Raspberry Pi code: shutdown.py
# Created by Bill Debevc
# for the Great Mojave Rover Project
# Version 1.0 Inital Build
# Version 1.1 Added Email at startup
# Version 1.3 Added IP address to Subject
# Version 1.4 Added Log to body
# version 1.5 Add Internal IP (next)
import time
import smtplib
import os
from subprocess import call
from requests import get
#wait for services to start
time.sleep(120)
#Get external IP address
ip = get('https://api.ipify.org').content.decode('utf8')
print('My public IP address is: {}'.format(ip))
#setup gpio
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.IN, pull_up_down=GPIO.PUD_UP)
#Setup Mail
replyto='SEND FROM EMAIL ADDRESS' # where a reply to will go
sendto='SEND TO EMAIL ADDRESS' # list to send to
sendtoShow='SEND FROM EMAIL ADDRESS' # what shows on the email as send to
username='SEND FROM EMAIL ADDRESS'
password='EMAIL PASSWORD'
# get startup log
os.system ('rm /home/bill/gmr/startlog.txt')
os.system ('dmesg >/home/bill/gmr/startlog.txt')
with open('/home/bill/gmr/startlog.txt', 'r') as textfile:
content = textfile.readlines()
email_body = ''.join(content)
textfile.close()
# start talking to the SMTP server for Gmail
print ("Username: " + username)
print ("password: " + password)
s = smtplib.SMTP('smtp.gmail.com', 587)
s.starttls()
s.ehlo()
s.login(username,password)
subject='Solar Test 10 Status: Awake' + format(ip) # subject line
mailtext='From: '+ replyto + '\nTo: ' + sendtoShow + '\n'
mailtext=mailtext + 'Subject:' + subject + '\n' + email_body
s.sendmail(replyto, sendto, mailtext)
rslt=s.quit()
print('Sendmail result=' + str(rslt[1]))
# Check for showdown
while True:
input_state = GPIO.input(4)
if input_state == False:
print('Button NotPressed')
else:
print('Shutdown')
# get startup log
os.system ('rm /home/bill/gmr/shutdownlog.txt')
os.system ('journalctl -n 250 >/home/bill/gmr/shutdownlog.txt')
os.system ('dmesg >/home/bill/gmr/startlog.txt')
with open('/home/bill/gmr/startlog.txt', 'r') as textfile:
content = textfile.readlines()
email_body = ''.join(content)
textfile.close()
s = smtplib.SMTP('smtp.gmail.com', 587)
s.starttls()
s.ehlo()
s.login(username,password)
subject='Solar Test 10 Status: Sleeping' # subject line
mailtext='From: '+ replyto + '\nTo: ' + sendtoShow + '\n'
mailtext=mailtext + 'Subject:' + subject + '\n' + email_body
s.sendmail(replyto, sendto, mailtext)
rslt=s.quit()
print('Sendmail result=' + str(rslt[1]))
time.sleep(3.0)
print('Shutting down the pi')
call ('sudo poweroff', shell=True)
time.sleep(2)
#2.0 Ideas
#