Thank you for your donation!


Cloudsmith graciously provides open-source package management and distribution for our project.


Solved: Debugging/debouncing GPIO buttons... (false triggers)
#1
Hello, I've got a few momentary switches wired in, to try the GPIO config feature.

I randomly get a false trigger when I switch on my amps. The moment I press the amp switch, moode toggles between pause/play Big Grin .
Even without dac, nothing connected on the pi apart from GPIOs buttons.
It doesn't happen everytime. But it is 100% caused by switching on the amps (tried 3 amps, A, AB and a class D and all are affected).
I was going crazy to figure it out, and unplugged everything (no dac, no HATs, no IR) but the gpios, and that did it.
Since there are no wires around, the only options are either ghosts or wires are picking it somehow (EMI, mains voltage drop,?). 
It happens like one time out of ten.

It happens both when switching on and also when turning the amp off. It's kind of random.
The weird thing is that it randomly happens even from an amp 1.5m away.
Just by turning it on and off a few times it toggles the pi.
Tried to power the pi from a different power plug (as usually it's all plugged to the same powerstrip), and it still happens. 

UI settings/wires cases
  • GPIO enabled and all buttons enabled in moodeUI - it happens
  • GPIO enabled, disable just the "mpc toggle" button in moodeUI - it still happens  Angry
  • GPIO enabled in moodeUI, wires UNplugged - it doesn't happen
  • GPIO DISabled in moodeUI, wires plugged - it doesn't happen
I still can't explain why it toggles even when disabling the mpd toggle button. 
I have other buttons configured like next, prev, stop, vol+-, etc but that's all it's doing, toggling even when the toggle is disabled...
either have to unplug the wires or totally disable the GPIO script for it to not happen. (or I am going insane after hundred attemps, very possible)

DEBUG/LOGS
As far as debugging, I also tried pigpio's monitor.py hoping to see which gpio was triggered and nothing shows up when the event happens.
I remember there were other tools, like "scope" something in the name, to debug the gpios, will google more later.
Tried the logs (moode, mpd, system, triggerhappy etc), can't find what's pausing it.


mpd.log
Code:
Nov 15 10:55:10  INFO [src/bin.rs:420] Capture finished
Nov 15 10:55:10  INFO [src/bin.rs:410] Playback finished
auth.log at the same time, the only line
Code:
Nov 15 10:55:10  moode sudo: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=33)
sys.log
Code:
Nov 15 10:55:10 moode kernel: [   47.723601] bcm2835_audio bcm2835_audio: failed to close VCHI service connection (status=1)
moode log shows nothing.
Am I missing other logs?

WIRING

GPIO -> momentary tactile switch -> ground
Buttons otherwise works fine.
  • Do you have any idea about how to proceed debugging this? 
  • or how to debounce? the debounce setting in the UI seems only for ignoring double clicks, or I am reading the note wrong?
  • should I try shielding the wires?
  • could I try running the gpio python script from cli and see if it outputs something?
thanks.
Reply
#2
(11-15-2022, 01:56 PM)challenge Wrote: Hello, I've got a few momentary switches wired in, to try the GPIO config feature.

I randomly get a false trigger when I switch on my amps. The moment I press the amp switch, moode toggles between pause/play Big Grin .
Even without dac, nothing connected on the pi apart from GPIOs buttons.
It doesn't happen everytime. But it is 100% caused by switching on the amps (tried 3 amps, A, AB and a class D and all are affected).
I was going crazy to figure it out, and unplugged everything (no dac, no HATs, no IR) but the gpios, and that did it.
Since there are no wires around, the only options are either ghosts or wires are picking it somehow (EMI, mains voltage drop,?). 
It happens like one time out of ten.

It happens both when switching on and also when turning the amp off. It's kind of random.
The weird thing is that it randomly happens even from an amp 1.5m away.
Just by turning it on and off a few times it toggles the pi.
Tried to power the pi from a different power plug (as usually it's all plugged to the same powerstrip), and it still happens. 

UI settings/wires cases
  • GPIO enabled and all buttons enabled in moodeUI - it happens
  • GPIO enabled, disable just the "mpc toggle" button in moodeUI - it still happens  Angry
  • GPIO enabled in moodeUI, wires UNplugged - it doesn't happen
  • GPIO DISabled in moodeUI, wires plugged - it doesn't happen
I still can't explain why it toggles even when disabling the mpd toggle button. 
I have other buttons configured like next, prev, stop, vol+-, etc but that's all it's doing, toggling even when the toggle is disabled...
either have to unplug the wires or totally disable the GPIO script for it to not happen. (or I am going insane after hundred attemps, very possible)

DEBUG/LOGS
As far as debugging, I also tried pigpio's monitor.py hoping to see which gpio was triggered and nothing shows up when the event happens.
I remember there were other tools, like "scope" something in the name, to debug the gpios, will google more later.
Tried the logs (moode, mpd, system, triggerhappy etc), can't find what's pausing it.


mpd.log
Code:
Nov 15 10:55:10  INFO [src/bin.rs:420] Capture finished
Nov 15 10:55:10  INFO [src/bin.rs:410] Playback finished
auth.log at the same time, the only line
Code:
Nov 15 10:55:10  moode sudo: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=33)
sys.log
Code:
Nov 15 10:55:10 moode kernel: [   47.723601] bcm2835_audio bcm2835_audio: failed to close VCHI service connection (status=1)
moode log shows nothing.
Am I missing other logs?

WIRING

GPIO -> momentary tactile switch -> ground
Buttons otherwise works fine.
  • Do you have any idea about how to proceed debugging this? 
  • or how to debounce? the debounce setting in the UI seems only for ignoring double clicks, or I am reading the note wrong?
  • should I try shielding the wires?
  • could I try running the gpio python script from cli and see if it outputs something?
thanks.

it really looks like a spike... and that being due to the connections between the amps and the pi (the only connection among them that I can possibly think is the signal cables... the rca's...
Can you make another run, with just everything plugged in, but the cables from the DAC (if it is a HAT, I mean) to the AMP disconnected?

I'm by no means en expert, but I see no other path... apart from being caused by a voltage drop; and this could explain why, unplugging everything power-hungy did the trick...


Cheers, Al.
Reply
#3
Al, there is nothing connected. No dac, no amps, no hats...
I switch on/off the amps even if they aren't connected to the DAC/rasperry and once every 5/10 flicks of the switch, moode stops/starts playing.
And yes it's the amps it's not casual. Listened a whole afternoon, trying everything, even with remotes and stuff and everything works fine.

I usually use an HDMI sound card on this setup. But I unplugged that too. There's nothing on the pi that could physically connect to the amps.
There's not even a dac plugged/powered when it happens...
I even used different wall socket, nothing changed.

only thing left connected when it happens are the GPIO wires to the buttons. I disconnected everything as I was going crazy, and it still happens  Sad
If I disable the GPIO button script from moode UI it doesn't happen, even with wires and buttons wired. If I unplug the wires it doesn't happen.
So it's their fault somehow.

My only theory is that buttons wires (30cm long) are picking noise and somehow it triggers the toggle when the GPIO script is enabled, even if the "toggle" button is disabled on moode UI. How this happens? Don't know yet. Is there a bug somewhere e.g. python script or moode? don't know yet.

What scares me it's that logs clearly shows that mpd stopped. But can't find anywhere what made it stop exactly.
Ran monitor py from pigpio to see which gpio pin was being triggered, but it shows nothing.

I ran out of time and will double check my affirmations asap. I know it's too vague to find a solution put like that.
Will shield the wires and desolder the wires one by one and see why it's happening.
It happens even with the raspberry and wires and buttons inside a (thin ~= 1mm?) metal hifi case  Huh
Reply
#4
(11-15-2022, 04:52 PM)challenge Wrote: Al, there is nothing connected. No dac, no amps, no hats...
I switch on/off the amps even if they aren't connected to the DAC/rasperry and once every 5/10 flicks of the switch, moode stops/starts playing.
And yes it's the amps it's not casual. Listened a whole afternoon, trying everything, even with remotes and stuff and everything works fine.

I usually use an HDMI sound card on this setup. But I unplugged that too. There's nothing on the pi that could physically connect to the amps.
There's not even a dac plugged/powered when it happens...
I even used different wall socket, nothing changed.

only thing left connected when it happens are the GPIO wires to the buttons. I disconnected everything as I was going crazy, and it still happens  Sad
If I disable the GPIO button script from moode UI it doesn't happen, even with wires and buttons wired. If I unplug the wires it doesn't happen.
So it's their fault somehow.

My only theory is that buttons wires (30cm long) are picking noise and somehow it triggers the toggle when the GPIO script is enabled, even if the "toggle" button is disabled on moode UI. How this happens? Don't know yet. Is there a bug somewhere e.g. python script or moode? don't know yet.

What scares me it's that logs clearly shows that mpd stopped. But can't find anywhere what made it stop exactly.
Ran monitor py from pigpio to see which gpio pin was being triggered, but it shows nothing.

I ran out of time and will double check my affirmations asap. I know it's too vague to find a solution put like that.
Will shield the wires and desolder the wires one by one and see why it's happening.
It happens even with the raspberry and wires and buttons inside a (thin ~= 1mm?) metal hifi case  Huh

does the gpio script come with moOde? I am not familiar with the gpio thing, so I'm asking... I'd like to have a look at it.
Can you tell me where to look for it, or, if it is something you have made/changed, can you post it here?

Cheers, Al.
Reply
#5
yes the script is in moode, nothing custom.
I guess this is the source code for it? :
https://github.com/moode-player/moode/bl...buttons.py

there's a section in moode settings UI that enables the GPIO handler, called "GPIO config" or something like that.
You enable it, and then there's another screen where it allows to associate commands to gpio pins.

Not at home, but have a screen here:
   
Reply
#6
(11-15-2022, 07:12 PM)challenge Wrote: yes the script is in moode, nothing custom.
I guess this is the source code for it? :
https://github.com/moode-player/moode/bl...buttons.py

there's a section in moode settings UI that enables the GPIO handler, called "GPIO config" or something like that.
You enable it, and then there's another screen where it allows to associate commands to gpio pins.

Not at home, but have a screen here:

yes, I found it.

nothing fancy, it sets up a bunch of callbacks on the button (bit). I thought we could check if many (if not all) buttons were active at one time (the spike should affect all of them), we could simply ignore them all...
See what you have set-up as the first button... it should be TOGGLE PLAY PAUSE, in my opinion... if it's possible, set it as NEXT, and then you might confirm that, from now on, instead of toggling play-pause, switching the amps on/off should have moOde skip tracks...
If that's the case, we might think of a all-buttons-on-at-the-same-time ignore thing.

Cheers, Al.
Reply
#7
@challenge

Yeah, one could poke moOde in the eye with a sharp stick to make it ignore inconvenient effects but that makes me cringe. Dodgy

In general, the InterWeb™ is full of posts and blog entries concerning noisy behavior on supposedly digital inputs.

EMI/RFI is always a possibility. The behavior of a Pi's GPIO input is a complicated subject. For example: https://forums.raspberrypi.com/viewtopic...9&t=133740

As an aside, a 30-cm length of wire is called an antenna Smile

Drawing on good practice in the radio and audio industries, one would use a twisted pair of wires between the button or switch and the GPIO block, grounded only at the GPIO end. In severe cases one might also run the twisted pair inside a shield with the shield also grounded only at the GPIO end. In more severe cases, one might have to fashion some passive signal conditioning with one or more resistor(s) and possibly even capacitor(s), also at the GPIO end. Google is your friend.

Regards,
Kent
Reply
#8
(11-15-2022, 01:56 PM)challenge Wrote: Hello, I've got a few momentary switches wired in, to try the GPIO config feature.

I randomly get a false trigger when I switch on my amps. The moment I press the amp switch, moode toggles between pause/play Big Grin .
Even without dac, nothing connected on the pi apart from GPIOs buttons.
It doesn't happen everytime. But it is 100% caused by switching on the amps (tried 3 amps, A, AB and a class D and all are affected).
I was going crazy to figure it out, and unplugged everything (no dac, no HATs, no IR) but the gpios, and that did it.
Since there are no wires around, the only options are either ghosts or wires are picking it somehow (EMI, mains voltage drop,?). 
It happens like one time out of ten.

It happens both when switching on and also when turning the amp off. It's kind of random.
The weird thing is that it randomly happens even from an amp 1.5m away.
Just by turning it on and off a few times it toggles the pi.
Tried to power the pi from a different power plug (as usually it's all plugged to the same powerstrip), and it still happens. 

UI settings/wires cases
  • GPIO enabled and all buttons enabled in moodeUI - it happens
  • GPIO enabled, disable just the "mpc toggle" button in moodeUI - it still happens  Angry
  • GPIO enabled in moodeUI, wires UNplugged - it doesn't happen
  • GPIO DISabled in moodeUI, wires plugged - it doesn't happen
I still can't explain why it toggles even when disabling the mpd toggle button. 
I have other buttons configured like next, prev, stop, vol+-, etc but that's all it's doing, toggling even when the toggle is disabled...
either have to unplug the wires or totally disable the GPIO script for it to not happen. (or I am going insane after hundred attemps, very possible)

DEBUG/LOGS
As far as debugging, I also tried pigpio's monitor.py hoping to see which gpio was triggered and nothing shows up when the event happens.
I remember there were other tools, like "scope" something in the name, to debug the gpios, will google more later.
Tried the logs (moode, mpd, system, triggerhappy etc), can't find what's pausing it.


mpd.log
Code:
Nov 15 10:55:10  INFO [src/bin.rs:420] Capture finished
Nov 15 10:55:10  INFO [src/bin.rs:410] Playback finished
auth.log at the same time, the only line
Code:
Nov 15 10:55:10  moode sudo: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=33)
sys.log
Code:
Nov 15 10:55:10 moode kernel: [   47.723601] bcm2835_audio bcm2835_audio: failed to close VCHI service connection (status=1)
moode log shows nothing.
Am I missing other logs?

WIRING

GPIO -> momentary tactile switch -> ground
Buttons otherwise works fine.
  • Do you have any idea about how to proceed debugging this? 
  • or how to debounce? the debounce setting in the UI seems only for ignoring double clicks, or I am reading the note wrong?
  • should I try shielding the wires?
  • could I try running the gpio python script from cli and see if it outputs something?
thanks.

Yes turn off GPIO buttons in the UI and run the script sudo from the command line. It may or may not reveal whats happening. There a couple of commented out print statements in the script. You could try uncommenting them to see if it helps isolate the issue.
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#9
Thank you all for the help, each of your replies were helpful in its own way.
I've set each button to echo its own pin number in moode settings, turned off the gpio handler and ran the script manually in cli.
That actually works and what I've got is that it's not a single one triggering, but the whole lot, randomly. Having them echoing their name made things crystal clear.

It did seem it was only the toggle acting up because of the way the buttons were setup. 
eg. one was loading the same playlist already loaded, then it was doing next-prev VERY fast, and then the toggle. Even the toggle sometimes was double-triple  pressed very fast, too much for the web ui.

Long story short: the "long/loose-unshielded-buttons-test-wires" are working like antennas and picking the electrical spikes from nearby amps/powerstrip and false triggering the GPIOs.
I'm talking about the spikes when turning on/off stuff, since the amps are literally under the raspberry or close by...
It's just that, really.
if I move the raspberry a few meters away from the amps it's ok. But I want to put it exactly there, so will have to tidy up a bit the spaghetti wires Big Grin

@TheOldPresbyope , yeah you're right. It's not my field, but I get it: no need to overcomplicate the software to hide bad things, when they're easy to fix in hw...
I had a read and found exactly what you wrote. Plenty of threads on raspberry and arduinos, thank you for the input.
Will read a bit about industry standards and do some tests on layout/shielding/filtering as soon as I decide the layout of things inside the hifi case.
Reply
#10
(11-16-2022, 03:50 PM)challenge Wrote: Thank you all for the help, each of your replies were helpful in its own way.
I've set each button to echo its own pin number in moode settings, turned off the gpio handler and ran the script manually in cli.
That actually works and what I've got is that it's not a single one triggering, but the whole lot, randomly. Having them echoing their name made things crystal clear.

It did seem it was only the toggle acting up because of the way the buttons were setup. 
eg. one was loading the same playlist already loaded, then it was doing next-prev VERY fast, and then the toggle. Even the toggle sometimes was double-triple  pressed very fast, too much for the web ui.

Long story short: the "long/loose-unshielded-buttons-test-wires" are working like antennas and picking the electrical spikes from nearby amps/powerstrip and false triggering the GPIOs.
I'm talking about the spikes when turning on/off stuff, since the amps are literally under the raspberry or close by...
It's just that, really.
if I move the raspberry a few meters away from the amps it's ok. But I want to put it exactly there, so will have to tidy up a bit the spaghetti wires Big Grin

@TheOldPresbyope , yeah you're right. It's not my field, but I get it: no need to overcomplicate the software to hide bad things, when they're easy to fix in hw...
I had a read and found exactly what you wrote. Plenty of threads on raspberry and arduinos, thank you for the input.
Will read a bit about industry standards and do some tests on layout/shielding/filtering as soon as I decide the layout of things inside the hifi case.

I'm glad I was on the right path when I suggested it might the whole set of buttons get triggered... :-)

Also glad you figured out... nof fixing it might be all but trivial, but hey, at least you know WHAT.

Cheers, Al.
Reply


Forum Jump: