mmPi-Pico HAT

Updated 02 June 2022

I use a Raspberry Pi running EmonCms for collecting sensor data and controlling devices around the home but several things have been on my To-Do list to enhance its functionality.

  • A Shutdown/Power Down/Startup circuit.
  • Proportional fan control
  • UPS monitoring (optional - see the section below)

My preferred coding platform these days is to use MMBasic (see below) and I originally designed and coded the original “mmPi" prototype on a Microchip PIC32MX170F256B microcontroller (standard MicroMite) however just more recently the MMBasic language has been ported to the new Raspberry Pi Pico so I created a version using this device Pico-Mite


MMBasic is written and maintained by Geoff Graham. Geoff also runs a hobby website at  http://geoffg.net which has a wealth of information, updates etc. on all the microcontrollers that run MMBasic.


PicoMite MMBasic Geoff Graham, Peter Mather Copyright (c) 2021, All rights reserved.

Project Description

Parts required to construct mmPi.

Details

The main purpose of the program is to control a DC to DC power module via its shutdown pin. A push-button connected to the circuit board initiates a Shutdown or Restart sequence via the mmPi program running on the microprocessor which provides the correct timing and hardware control to gracefully Shutdown or Restart the Raspberry Pi. The program also provides LED user feedback and intelligent cooling fan control based on the Raspberry Pi cpu temperature. When in “Standby” there is no power going to the Raspberry Pi , the only power usage is the RPI Pico, it’s low power regulator  and the quiescent current used by the DC to DC power module. The standby current is less than ~10mA. The Standby status is retained even if the Low Voltage/UPS supply is completely removed from the whole mmPi/Raspberry Pi combination and will not restart following re-connection until the button is pressed.

 

mmpi system diagram, showing power connections and operations

A word about the push button. The push button Shutdown/Restart action requires a "LongPress"(greater than 1-2 sec) this means the button is free to be used in a user program for shorter press actions

Raspberry Pi connections. The mmPi pcb only connects to the first 16 pins of the RPI 36/40 pin connector and then only 8 of those are actually used . 5v Power and Grd to the Raspberry Pi from the DC-DC power supply is provided via pins 2,46,9 (5v,5V,Gnd,Gnd). Serial port(UART0) on pins 9,10 (GPIO14/15). Then pins 7 ,11 (GPIO4/17) are used for Pi control signals (rpi-running, rpi-shutdown), these signals must be configured in the Raspberry Pi by editing the config.txt file. (Instructions Below)

Setting up the Raspberry Pi

It is assumed that the Raspberry Pi is already set up and working correctly either in Desktop or Headless configuration. In order for the RPI to work correctly with the mmPi pcb a couple lines must be added to the /boot/config.txt file on the Raspberry Pi SD card.

Open /boot/config.txt in nano (or your preferred editor):

sudo nano /boot/config.txt

Copy or re-type the below into the file. The “#” line is just a comment .

#This sets up the ability for a pushbutton switch to shut it down:
#Also the Raspberry Pi's status is signaled via Gpio Pin4 
dtoverlay=gpio-shutdown,gpio_pin=17
dtoverlay=gpio-poweroff,gpiopin=4,active_low=1

Save and exit the file with control-X, Y <return>.

To have your enclosure fan controlled by mmPi and the Raspberry's cpu temp you will need to create the following script on the Pi. Create the file,

cat > temp

Edit the file just created,

sudo nano temp

Enter the following lines in the file,

#!/bin/bash
temp=`cat /sys/class/thermal/thermal_zone0/temp`
echo "{pi-temp:$(($temp/1000))}" > /dev/ttyAMA0
echo "{pi-temp:$(($temp/1000))}"

Save and exit the file with control-X, Y <return>. Lastly, create a Crontab entry to execute this file every minute.

crontab -e

Append the following entry

* * * * * temp

Save and close the file.

 

Construction

Here is the circuit diagram. 

 

mmpi schematic featuring the raspberry pi pico

When a RPI - Pico is used there are few discrete components and the circuit could easily be constructed using a vero or protoboard. The circuit can be mounted as a “Hat or Shield” directly onto the Raspberry Pi ¾ or standalone , it is completely up to the constructor. I did also make a pcb which is shown installed in my RPI server. Probably the most important component apart from the RPI Pico is the modified DC to DC power supply which allows the microcontroller to switch the 5VDC supply. Below is an image which is probably the simplest way to describe the modification required to the module.


Modifications to DC to DC regulator module (based on LM2596 IC regulator)

This image shows how to modify a typical low cost DC Buck regulator module for use with the project

 

required modifications to the lm2596 regulator

Software:

The RPI - Pico is very easy to set up and program with the mmPi program. Initially you will need to program the Pico with MMBasic which is very clearly explained here where you will find all the up to date info and downloads etc. You will also find a link to MM Edit which is recommended for writing programs. A standard serial terminal program may also be used if preferred. eg. Teraterm or Putty. 

When you have set up your Pico with MMBasic it is time to load and test the user program. 

When the mmPi circuit is functioning on its own the Pico gets its power from a separate 5vdc supply but initially all setup and loading of the user program code may by connecting to the pico via the USB connector. 

The simplest way to upload the program is to use Teraterm and the Xmodem protocol.

Open up Teraterm connected to the Pico.

 

mmpi startup string in teraterm

 

teraterm send file menu dialog

 

teraterm select file window
Click Open and the file will be sent to the Pico. Nb. If you take too long selecting the file it may time out as happened below, the second time was successful!

 

teraterm flash file failure and success

Type XMODEM RECEIVE (enter)

 

send list command, returns the details about the mmpi and its functions

List to show the program

 

starting the program with the run command

Now RUN the program to test, if it's loaded and working correctly you should get.

 

OK as it's working correctly there is one more step to make the program run automatically on power-up.

Stop the program with Ctrl-C, then type at the cursor OPTION AUTORUN ON 

Check with OPTION LIST then power off then on again and the program should startup.

 

enabling autorun on the mmpi hat

Now complete the circuit can be tested, Press the Power button for 1-2 secs.

 

mmpi returning the picos temperature

 

mmpi chaging status and respective serial return string

 

The Pico will still be running but the Raspberry Pi will be Shutdown and powered off.

Now remove the power completely, wait a minute or so and reconnect the power. Check the  Raspberry Pi is still off but the Pico should be running again. If OK then press the Power button for 1-2 secs, the LED should acknowledge and the Pi should startup. 

 

mmpi return string explanation

If all this checks out MMPi is working correctly.

PCB

A PCB is available!

mmpi pico hat pcb honourable mention to the components under the pico

The Gerbers are in the attachment's file below. The pcb was designed to be CNC Isolation milling “friendly” if you have access to this equipment.

Resources

Check out Mikes website for other mmPi related projects!

mmpi-pico-hat-attachments.zip

Have a question? Ask the Author of this guide today!

Please enter minimum 20 characters

Your comment will be posted (automatically) on our Support Forum which is publicly accessible. Don't enter private information, such as your phone number.

Expect a quick reply during business hours, many of us check-in over the weekend as well.

Comments


Feedback

Please continue if you would like to leave feedback for any of these topics:

  • Website features/issues
  • Content errors/improvements
  • Missing products/categories
  • Product assignments to categories
  • Search results relevance

For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.