I have a friends Pi 3 Model B+ that I hooked up to become the "brain" on a Carrom Bubble Hockey table. The table is very simple, it has two goals and a button, so in total 3 switches.
My program runs on the Pi and listens for events from the GPIO pins and updates a scoreboard on a TV connected through HDMI, among some other goofy features.
It works, except for some weird issues.
Short version of the question: The software seems to randomly detect the switches closing and triggers a goal in the software. Sometimes it makes it through a 10 minute game just fine, sometimes it's every few minutes, sometimes it's non-stop.
What can I do about this?
Longer version of the question: There are actually two Pis in play here, as I have two friends with this same Hockey table and both wanted this setup.
Through trial and error, I originally got the first working fine on my test bench and set it up at his house. Using https://www.etechnophiles.com/raspberry-pi-3-b-pinout-with-gpio-functions-schematic-and-specs-in-detail/ for a pin diagram, it worked like this: (I had and still have little idea what I'm doing, I just found something that works)
- GPIO 5 was the button
- GPIO 26 + 27 were the goals
- All three were connected to GND next to GPIO 5.
The only issue was that the goals would some time randomly fire. It wasn't enough of an issue though so we plowed forward and set up at the second friends house.
After setting this up (same table, same Pi model, same software), we noticed that the goals would fire immediately and constantly. I also found after disconnecting them that touching the wires myself would trigger a goal. Even touching the insulated sides of wires together would trigger a goal.
I took the Pi home, did some research, and set it up like this before sending it back:
- 3.3v pin in top left is connected to a 1K ohm resistor.
- This splits and goes to each of the three switches, which then come back to
- GPIO 26 + 12 (goals) and GPIO 13 (button)
Results:
- The same original issue: random goals would fire off. But it gets worse:
- After more people came over that afternoon to try it out, it went back to immediately and always firing goals. This made it unusable for the evening.
Why could this be happening? Is there anything I can do? At this point it seems like phantom signals or static or radio interference or something weird.
Other notes:
- I cannot for the life of me repro the issue at my house when just touching wires together. It's only happening when hooked up to the tables.
- A continuity test on the switches show they seem to work just fine.
- The software in question is an Electron app using onoff to communicate w/ GPIO. The OS is Arch Linux ARM.
Update after following Milliways helpful suggestions:
The comment about having built an antenna here rings true. If I place a walkie talkie near the wires and push a button, it fires off a signal in my code :).
I've tried the way explained (I think), see diagram. There are two problems still:
- The walkie talkie still causes interference. Not sure what to do here.
- Closing any switch sort of works, but will also just as likely trigger a signal for a different switch. I believe this could be fixed by having separate 3.3v sources, but there are only two on the Pi.
You DEFINITELY "need three pulls, one for each". The whole point of a pullup is to put a defined voltage on the GPIO when NO BUTTON is pressed.
I guess I don't know how to do this without a third 3.3v source.
If I strip the setup in the diagram down to one switch, problem #2 goes away but I still experience problem #1.
pullup resistors