As with our previous projects, we now need to make our program start as soon as we switch our Pi Zero on.
First we will create our service definition file, so type this:
sudo nano /lib/systemd/system/pulseRead.service
Now, type the definition into it:
[Unit]
Description=Heart Rate Service
After=multi-user.target
[Service]
Type=idle
ExecStart=/home/pi/WearableTech/Chapter8/pulseRead.py
[Install]
WantedBy=multi-user.target
Save and exit Nano by typing Ctrl + O, followed by Enter, and then Ctrl + X. Now, change the file permissions, reload the systemd daemon, and activate our service by typing this:
sudo chmod 644 /lib/systemd/system/pulseRead.service
sudo systemctl daemon-reload
sudo systemctl enable pulseRead.service
Now, we need to test if this is working, so reboot your Pi by typing sudo reboot; and then when your Pi Zero restarts, place your finger upon your heart rate monitor, and you should see your Scroll pHAT HD start to animate your heart beats and display your heart rate. If this is all working, press and hold your power-off button for three seconds to shut your Pi Zero down.
You are now ready to power your Pi Zero from your portable power pack, and monitor your heart rate while you are out and about!