Is it possible to send button clicks from buttons attached to a raspberry pi gpio to a pc (windows 10). I plan to use a button panel with elite dangerous . Either a wired or wireless connection is fine and no solution however roundabout is out of the question.
2 Answers
USB keyboards are understood by Win10. Consider using the HID protocol of USB. Do this by emulating a keyboard using the Raspberry Pi. There are a number of projects on the web with this in mind. For instance here is one on GitHub.
Find a project that accommodates your needs. For example, not all projects may allow interfacing with the GPIO library and GPIO pins. If you find none, then you will have to learn how to handle the Raspberry Pi's GPIO resources and how to send button presses to the application you chose to handle the USB HID Keyboard feature.
Alternatively, this question is similar to an often asked Arcade Game Console question. To paraphrase: "How can I attach arcade buttons to my computer?" Here is a raspberry pi stackexchange answer which addresses this approach.
- 384
- 1
- 6
My pigpio Python module will run on a Windows box and allows access to the GPIO of networked Pis.
The pigpio daemon needs to be running on each Pi whose GPIO you want to access.
The following Python script will run on Windows and print a value when a GPIO changes level.
You need to specify the Pi's address in one of two ways.
- define an environment variable
PIGPIO_ADDRgiven the Pi's host name or IP address. E.g.PIGPIO_ADDR="fred"orPIGPIO_ADDR="192.168.0.23". - pass the address in the
pi = pigpio.pi()call. E.g.pi = pigpio.pi("fred")orpi = pigpio.pi("192.168.0.23").
#!/usr/bin/env python
# monitor.py
# 2016-09-17
# Public Domain
# monitor.py # monitor all GPIO
# monitor.py 23 24 25 # monitor GPIO 23, 24, and 25
import sys
import time
import pigpio
last = [None]*32
cb = []
def cbf(GPIO, level, tick):
if last[GPIO] is not None:
diff = pigpio.tickDiff(last[GPIO], tick)
print("G={} l={} d={}".format(GPIO, level, diff))
last[GPIO] = tick
pi = pigpio.pi()
if not pi.connected:
exit()
if len(sys.argv) == 1:
G = range(0, 32)
else:
G = []
for a in sys.argv[1:]:
G.append(int(a))
for g in G:
cb.append(pi.callback(g, pigpio.EITHER_EDGE, cbf))
try:
while True:
time.sleep(60)
except KeyboardInterrupt:
print("\nTidying up")
for c in cb:
c.cancel()
pi.stop()
- 71,014
- 5
- 73
- 106