-1

I have a Raspberry Pi with six LEDs and button (also with LED) on the custom circuit board that is connected to GPIO pins. This RPi previously had an AdaFruit Neopixel with LEDs, but later my client decided to switch to that custom board. I have to modify a Python application to turn off all lights, but the problem is that it doesn't work. Any light change is discarded when my application is closed and all lights are turn on. What to do with it? Another interesting thing is that two of LEDs are turned on after plugging power cable into RPi and after shutting down the system. It seems that default state of at least two lights is "on", but why only two lights are in "on" state during and after boot, but before running my application? Turning things like active_high for a LED in gpiozero don't help as it's discarded at the end.

Can I do something with it or I just should tell my client to rework a circuit board? I have zero knowledge about electronics, but it seems that they messed something up with high/low states on that circuit board.

EDIT:

I found a way to turn off lights, at least for a few seconds before the system is fully shut down:

import subprocess
from gpiozero import LED

led = LED(8)
led.off()
led.close()

subprocess.run(['raspi-gpio', 'set', '8', 'ip', 'pd'])

I had to close LED first, and then use subprocess to run raspi-gpio command to really turn off the light.

But the problem remains, after shutting down the system, it lights up again.

1

Some pins are high at boot time. If you connected LEDs to each pin, you'd see which ones.

gpiozero will always turn a pin low when you initialise it, so if GPIO7 was on at boot, running led = LED(7) would initially set it to low (off) until you turned it on with led.on(). But when your script ended it would clean-up - and restore it back to its initial state - high.

If you want to make sure all pins are off, use a command line program to turn them all off, or use a library that doesn't do implicit cleanup to specifically turn them all off before you reboot. For example you could use raspi-gpio set 2-28 op dl (set all pins to output and drive low).

1
  • Thank you. Your explanation helped me a bit. The problem still remains, after completing shutdown I have a a high signal on these pins. Is there something I can try to fix it? – Dawid Loranc Feb 10 at 12:20
0

I solved it by using in Python app (it's an example):

import subprocess
from gpiozero import LED

led = LED(8)
led.off()
led.close()

subprocess.run(['raspi-gpio', 'set', '8', 'ip', 'pd'])

Where last line is calling system's command that sets 8 GPIO pin to input mode and pull down.

I also had to add some params to /boot/config.txt:

gpio=7=ip,pd
gpio=8=ip,pd

dtoverlay=gpio-poweroff,active_low=1

Where 7 i 8 pins are used by LEDs that are problematic.

By using:

gpio=7=ip,pd

I'm ensuring that LEDs is turned off when system is running, but app not yet.

I'm not sure what this code is doing, but it seems it turn off my LEDs after shutdown which was desired result.

dtoverlay=gpio-poweroff,active_low=1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.