Control GPIO on Raspberry Pi during booting

Ats
2 min readSep 29, 2024

--

This is a note about what I did to control GPIO pm Raspberry Pi during booting

Photo by Nadine E on Unsplash

Background

Last week, I needed to control an LED on Raspberry Pi during booting. I used GPIOZERO to control LEDs through GPIO.

Once the user space is ready, I can control GPIO through Python and the library. However, I couldn’t do it during booting. Then I assumed there should be something to do because it would be a common issue for everyone. So I started to investigate it.

What I did

I googled it and found the following README.

Based on the README, it seemed possible to control a GPIO once the kernel is ready. I found the patterns to control the LED in the following area.

I executed the cat /sys/class/leds/myled1/trigger in my Raspberry Pi to check what it had and it showed the outputs.

root@9280e27:/usr/src/app# cat /sys/class/leds/myled1/trigger
[none] rc-feedback kbd-scrolllock kbd-numlock kbd-capslock kbd-kanalock kbd-shiftlock kbd-altgrlock kbd-ctrllock kbd-altlock kbd-shiftllock kbd-shiftrlock kbd-ctrlllock kbd-ctrlrlock timer oneshot heartbeat backlight gpio cpu cpu0 cpu1 cpu2 cpu3 default-on input panic actpwr mmc1 mmc0 rfkill-any rfkill-none rfkill0 rfkill1

I didn’t get what each pattern is exactly. So I quickly googled and found the discussion.

Then I decided to go with timer pattern. I think there would be more details in those kernel objects if you want to know more details about the patterns.

Finally, I added the following code line to my config.txt file.

dtoverlay=gpio-led,gpio=25,trigger=timer,label=myled1,active_low=1

Then I came to make a LED connected to GPIO25 turn on and off every 1 second repeatedly.

That’s it!

--

--

Ats
Ats

Written by Ats

I like building something tangible like touch, gesture, and voice. Ruby on Rails / React Native / Yocto / Raspberry Pi / Interaction Design / CIID IDP alumni

No responses yet