This is a little CircuitPython program to run on a pi pico. It acts as a HID (keyboard) for whatever device it is plugged into.
This solves a couple problems with a windows-based arcade cabinet:
- you can wire up arbitrary buttons to the Pico's GPIO, and send keypresses to windows when the buttons are used. A good example is "pause": most emulators recognize "p" as pause. With the Pico running arcade_brain.py, you can wire up any button to issue a "p" keystroke to windows.
- Power management and soft shutdown. When the cabinet is off, I want power cut completely. arcade_brain.py controls a 120v relay via GPIO, so it can A) issue a command to windows for a soft shutdown, and B) cut power to everything with the relay. The only exception is, it doesn't cut power to itself - it needs to watch the power button and power-on the relay again when needed.
This is currently coded for a persistent-state power button (that's what the ALU cabinet comes with), but it could easily be modified for a momentary-press button. That would work well with a cabinet that you wanted to be able to remotely turn on and off, such as in a vacation rental.
Updating arcade_brain.py will restart it. Under normal circumstances, that will flip the relay power off then on, because the relay only provides power to the PC while the PICO maintains 3.3v output via GP16 to the relay. So when any updates need to be made to arcade_brain.py, move the main power off the relay and onto an always-on power source. Otherwise the PC will blip off everytime you try to update arcade_brain.
"USB drive mode" is enabled on the pico, so arcade_brain.py can be updated through the file system. To update:
- Use VSCode, and install the Circuit Python V2 plugin
- The Pico should present itself as a drive letter in windows. Open up the code on that drive letter in VSCode
- NOTE: the USB storage seems to become read-only when you reboot Windows. To rectify this, power cycle the pico (you have to unplug it from windows AND from its own power source, since it will draw power from either)
- In the lower right, there shuld be a serial port icon. Click that, and the pico should be presented as an option in the command bar.
- Now, just editing and one of the
*.py
files on the pico should reboot the pico and runcode.py
(which is the CircuitPython's entry point)
Pi PICO wiring:
# -------------------------------------------------------------------
# |USB|
# +-----------------------+
# volumeUp | GP0 VBUS | 1
# volumeDown | GP1 VSYS | 2 Power in 5v
# volume GND | -GND- -GND- | 3 Power in ground
# save | GP2 3V3_EN | 4
# load | GP3 3V3(OUT)| 5 power button (red)
# | GP4 --- | 6
# | GP5 GP28 | 7 power button (gpio)
# | -GND- -GND- | 8 power button GND
# | GP6 GP27 | 9
# | GP7 GP26 | 10 Pause
# | GP8 RUN | 11
# | GP9 GP22 | 12
# | -GND- -GND- | 13
# | GP10 GP21 | 14 Pause GND
# | GP11 GP20 | 15
# | GP12 GP19 | 16
# | GP13 GP18 | 17
# | -GND- -GND- | 18
# | GP14 GP17 | 19
# | GP15 GP16 | 20 powerRelay (GPIO OUT)
# +-----------------------+
# Pi Pico 2 viewed from top!
#
#
# retroarch mame
# --------- ----------------------------------
# save F2 shift-F7, then a number for a slot
# load F5 F7, then a number for a slot
# -------------------------------------------------------------------