My 4-7-8 Breathing Coding on Raspberry Pi Pico

Date: Apr 25, 2021

Remember I shared this before.

When you have trouble sleeping, you can follow this 4-7-8 breathing technique to make your eye lid heavy, and it will be much easier to sleep after that. Of course, it depends on people.

I had my 2nd dose Moderna vaccine this morning at 8am. I tried to sleep after I came back, but I could not, because I am simply not a napping person lor. Everything seems ok. The hand a bit sore and numb in the morning. But it went away in the afternoon after 2pm.

So, while I am awake, let’s make a circuit using Raspberry Pi Pico and program it using MicroPython.

So, the circuit will need 3x LEDs. I used the traffic light. Green for breath in, red for holding breath, and yellow for breath out. Of course, you cannot just plug in the LED to the power and ground of Raspberry Pi Pico directly, you need to add a 330 ohms for each LED to bring down the current. (I actually burned 1x LED because I wired wrongly!!)

We will pump power via Micro USB.

The LED will connect to GP16/17/18. And connect to 330 ohms resistor each and then to the Ground.

We will need a buzzer which connect to GP15.

That’s it.

Take a look. The Right side. All 330 ohms connect to the ground from this side. The other end connect to the LEDs. Then from the other end of LED, connects back to GP16/17/18.

The Left side. All 3 LEDs goes here.

The Top side.

The Raspberry Pi Pico. Lovely microcontroller, latest product from Raspberry Pi.

And it works!!!

Let’s test it out.

Try it in my room, all curtains closed. Dark mode.

I code it on my raspberry Pi 4 camera.

Plug the Pico onto the RP4, and start programing via VNC viewer.

The Thonny IDE is the official tools to write your Python codes as it can interface directly into the Pico.

The codes are very simple.

import sleep from utime, inport Pin and PWM from machine (special code for Pico).

Define the pins for each LED. Hook up the buzzer. Then, set the frequency for the breathe in tone, play the tone, toggle the green LED for half a second and sleep for 3.5 seconds to toggle the green LED off. That makes up for 4 seconds.

Then, play another tone for hold the breath. Toggle red LED. time for 7 seconds, and toggle off red LED.

Lastly, do the same for breathe out routine. toggle yellow LED. time for 8 seconds. toggle off yellow LED. and make all these inside a while LOOP. That’s it. A simple 4-7-8 breathing code on Pico.

As you know, my son is taking the “Engineering” stream in SST (School of Science and Technology) secondary school. So he is going to be tested on Electronics and Computer Science in O-Level. (No Chemestry and Biology). So, from time to time, I must write something to “impress” him. Wahahahaha

Ok, coming June, you will help me to design a 3D STL file for housing this, and I will solder everything togerther.

Oh ya… Here is a tip.

When you connect your Raspberry Pi Pico micro-controller to your power bank. Nowadays almost all power banks are too clever and smart. So, don’t be surprise that the Current Sense Resistor will AUTO-POWER off the power bank. Because the current drawn by Pico is so so so small. So, the power bank thought there is no current and hence it auto off the power bank.

So, it is kind of frustrated. Because I do not want to connect my Pico to a computer. I want to connect to the power bank. So how???

Not to worry. I already done the research. It seems that Xiaomi power bank comes with a feature where you double click on the power button on the power bank, it will provide a not so smart FORCE current. Means, it will not not AUTO OFF the power bank.

This works on the Xiaomi Torchlight that can be a power bank too.

That’s all for this blog entry.

Leave a Reply