Interlude – on & off
This thing has really nothing to do with listening to the music but comes directly from the Raspberry features or, as in this case, the lack of them: an on-off button is missing, and in my project this situation is unacceptable :-).
For the sake of clarity, when I say ‘off’ i really mean to put it into a halt state, where even if the linux Kernel is off the board is still powered and capable of rebooting. To manage a complete power off I would need some additional circuitry, maybe I will add later, for now halt is enough.
Returning to my button, after some googling I found out that:
- to wake up the Raspberry from a halted state is enough to pull GPIO 3 low shorting it momentarily to ground;
- an ordinate shutdown sequence can be started pulling an arbitrary GPIO to low if the DT overlay gpio-shutdown is enabled within /boot/config.txt. If no pin is specified, default is GPIO 3.
Given this, mounting a normally open push button between GPIO 3 and ground should do the trick unless you’re using the I2C bus: GPIO 3 is the predefined I2C clock line and is configured as an output, so when the PI is running pulling it low doesn’t have the desired effect…you have to explicitly use another pin by specifying it into the overlay params. Needless to say, I use I2C to drive both the audio board and the LCD display.
In my configuration GPIO 4 is not used, so I enabled it as a ‘shutdown switch’ putting in /etc/config.txt the following line:
This way I can use GPIO 4 to shutdown and GPIO 3 to wake up, but I still want a single button, not two…but an idea began to take shape.
Sometimes ago I played a bit with NPN transistors and I still have some of them laying around in my electronics box: transistors can be used as switches so I put together on the breadboard a ‘tentative’ circuit:
[Here I need to put a disclaimer: it worked on MY Pi. Nothing can be said about different system configurations…try it at your own risk!]
The idea is pretty simple: pushing the button activate the two NPN transistors that pull low (short to ground) both GPIO 3 AND GPIO4. The following situation can occur:
- The Raspberry is running. GPIO 4 on low cause the start of the ordinate shutdown procedure. GPIO 3 on low is ignored by the board..remember that on my system GPIO 3 is the I2C clock. Pulling low the clock line could have some impact on connected I2C devices, but I’m not sending any data, so I think it’ definitely not relevant.
- The Raspberry is in a halted state: GPIO 3 on low cause the start of the boot sequence. GPIO 4 on low is ignored.
Now I can wake up and shutdown the board using one button only: mission accomplished (hopefully).
This is the tiny circuit:
And the new super duper on-off button:
I know it lacks a debouncing circuit, but it will be soon replaced with something more ‘stylish’ (the final run – Episode 5)….stay tuned!