mholgatem / GPIOnext

The next evolution of GPioneer! Create virtual gamepads with your GPIO pins!
MIT License
134 stars 37 forks source link

'dtoverlay=act-led,gpio=4' makes "gpionext config" to fail #75

Closed fedekrum closed 1 year ago

fedekrum commented 1 year ago

Adding line dtoverlay=act-led,gpio=4 to the /boot/config.txt makes gpio config to fail. I use this to make gpio 4 an external led to know SD activity.

GPIO 4 is connector number 7, which I don't use on the set pins instruction. In fact it also fails with GPIO 5, so I guess it just fails with dtoverlay=act-led,gpio=X

pi@retropie:~ $ gpionext set pins 12,16,18,22,32,36,37,38,40
setting pins 12,16,18,22,32,36,37,38,40
Setting Flag and Restarting GPIOnext...
pi@retropie:~ $ gpionext reload
pi@retropie:~ $ gpionext config
Traceback (most recent call last):
  File "/home/pi/GPIOnext/config_manager.py", line 315, in <module>
    ConfigurationManager(args)
  File "/home/pi/GPIOnext/config_manager.py", line 85, in __init__
    gpio.setupGPIO( self.args )
  File "/home/pi/GPIOnext/config/gpio.py", line 99, in setupGPIO
    pins.append( pin(pinNumber, pull, args) )
  File "/home/pi/GPIOnext/config/gpio.py", line 59, in __init__
    bouncetime = args.debounce)
RuntimeError: Failed to add edge detection

Any idea why ?

mholgatem commented 1 year ago

yes, I know why, it's because I'm an idiot. I've been sitting on a fix for months that I thought I already uploaded. I'm not home right now, but I'll get it uploaded within a few hours of posting this comment. In the meantime, you can use the '--pins' flag in conjunction with the gpionext config command to get what you are after gpionext config --pins 12,16,18,22,32,36,37,38,40

fedekrum commented 1 year ago

yes, I know why, it's because I'm an idiot. .... haaa haaaa !! You made me laugh !!! It will be your first correction in 4 years.... that is STABILITY !!!! Is it the only correction you are doing to gpionext?

I think that gpionext should not have "ALL" pins selected as its default and that it should force the user to define the pins first and should not run before it.

Thanks, I will wait for your update to do some tests

mholgatem commented 1 year ago

Normally I would agree with you, but early on I tried something like that and it caused a lot more questions than it solved.

Anyway, I just pushed the update, which I had to rewrite because I don't know what happened to it on my tester system, but it seems to have vanished. I probably deleted something thinking that it was already merged to github. lol. Anyway, I think that it was just one little part that I had changed. So let me know if you run into problems and I'll try to deal with it. I'll leave this issue open for a while and if you feel that it is adequate, you can close it.

fedekrum commented 1 year ago

Ok Houston... we have a problem !!

It gives me no error, but as soon as I do a gpionext config, the led STOPS WORKING.

https://user-images.githubusercontent.com/4470683/205544765-2f922902-4bd3-403c-9acd-76ef2342569d.mp4

But if I call gpionext config --pins 12,16,18,22,32,36,37,38,40, the led will not go out.

https://user-images.githubusercontent.com/4470683/205555212-e82c264c-2b97-4096-bf41-b47b782d5ea7.mp4

fedekrum commented 1 year ago

Normally I would agree with you, but early on I tried something like that and it caused a lot more questions than it solved.

Well... this is kind of a philosophical issue here. For me there are 2 retro game users.

a) The plug and play user. This guys will buy a raspberry pi, copy the image, buy some plug and play controls (usb or BT) and go for it.

b) The builder user. This guy is the one implementing gpionext, so this guy has to get enough knowledge to understand that he MUST define the pins first and what a GPIO pin is.

So for me defining the pins that he is going to use will not only make it clearer to the builder, but you will also know where your responsibility as the programmer ends for the GPIO pins.

The config interface can show a first screen saying "Input the pins you are going to assign to GPIOnext delimited by commas". You can even check if the pins are not valid (like pins 1 and 2 that are voltage, or ground pins, etc.) or the ones that are in use and alert him, and then proceed with the following step.

Just my thoughts !!

mholgatem commented 1 year ago

ok, I updated the code to make it more robust. It will check each pin to make sure that it is in input mode before trying to handle it, so your led should be good to go now.


nah, there's a whole spectrum of people building arcades and handhelds. That's the beauty of the pi; it's cheap, accessible, and there's tons of tutorials. You'd be surprised by the number of users I have gotten over the years where its literally their first time doing anything technical and they're like "I saw this cool gameboy build on hackaday and I figured I'd give it a shot."

I thought about including the pin setup in the config, but I figured that since it's more of an advanced user aspect, I'd keep it as a flag to keep the config as streamlined as possible. at some point I may move all of the flags to and advanced users section of the config, but probably not anytime soon. I mostly just do maintenance now as I've moved on to other projects.

fedekrum commented 1 year ago

One of my buttons (pin32-gpio12) is not detected by the config. As you see, is included in my gpionext set pins 12,16,18,22,32,36,37,38,40

raspi-gpio get 12
GPIO 12: level=0 fsel=4 alt=0 func=PWM0

if I run the old config version it can be detected.

Adding gpio=12=ip at the /boot/config.txt file did not change that pin status to input. Any clue ?

mholgatem commented 1 year ago

My guess would be there is something loading after /boot/config.txt that is affecting it, though I don't know what that would be. I just checked mine and pin 32 (gpio 12) is working normally. You could try finding the culprit or you could edit line 56 of GPIOnext/config/gpio.py to this: if GPIO.gpio_function(self.number) != GPIO.OUT: That should make gpionext override everything that isn't set as an output, rather than only using inputs.

fedekrum commented 1 year ago

If you do raspi-gpio get 12, what do you get?

mholgatem commented 1 year ago

GPIO 12: level=0 func=INPUT It's the fact that yours is registering as PWM mode that is throwing the code, because it's only checking for pins set as input. I'm not sure what would be setting it to pwm mode

fedekrum commented 1 year ago

Thanks !! I will investigate my particular case.

mholgatem commented 1 year ago

No problem, let me know if you find the culprit!

fedekrum commented 1 year ago

The culprit is me !! a typo at /boot/config.txt on the pwm audio. !!

mholgatem commented 1 year ago

oops! Glad you figured it out!