0

I want to built a custom 5 toggle switch controller for my flight simulator that is running on my Windows 7 pc. I have some programming experience but I am not sure where to start.

Basically I would have a switch like this that would be connected to the Raspberry Pi and the Pi would be connected to my PC via USB and either emulate a keyboard key press or be detected as a game controller.

1

I'd go for a slightly different strategy: if you use networking instead of USB (you can go for Cable or WiFi), you'll save yourself a lot of time and headaches. This works in two components:

  1. Application running on the Pi that monitors your switch and forwards the data over the network connection to your PC
  2. Application running on your PC that catches the data from the network connection and sends key-press events to your application

For the application running on your PC:

  1. It should listen on a TCP/IP port for requests (HTTP or your own protocol). Working with GET requests will also make things simpler; i.e. "192.168.1.10:5000/command?switch=1". msdn.microsoft.com/en-us/library/system.net.httplistener(v=vs.110).aspx

  2. It should forward the keystrokes to your application. See: msdn.microsoft.com/en-us/library/ms171548(v=vs.110).aspx for an example of how to do something like this

Ok, so that will give you a way of controlling (and confirming that you can control) the flight simulator running on your PC. You can test that it works by starting up your simulator, opening up a web browser on your Pi and typing in that URL above (changing the IP, Port and other details as needed).

For your Pi, you'll need to write an application that: 1. Monitors GPIO 2. Makes http requests to your PC This looks useful: www.cl.cam.ac.uk/projects/raspberrypi/tutorials/robot/buttons_and_switches/

I'm not sure what your background/experience is: we're touching on quite a few different disciplines and platforms here, but at least this should give you a good start.

  • This is a good answer presuming network latency is insignificant, which it should be on a home LAN. If the Windows box is using wifi and has an ethernet jack, you could use a direct ethernet connection. Worth noting that the only model of Pi which you could connect via USB is the Zero and (potentially, I am not sure how hard it is to achieve) the A/A+. The others use a master only hub and USB is asymmetrical; you cannot connect a master to a master which is why you can't plug two laptops together that way, etc. In fact, you may damage them by trying. – goldilocks Aug 7 '16 at 14:37
0

As far as is known, the RPi cannot emulate a USB peripheral at this time. The solution I'm using is the Microchip PIC:

http://www.sprut.de/electronic/pic/projekte/usbgame/usbgame_en.htm .

Frustratingly, the PRi has no analog inputs: a modified version of the code given above allows me 10 ADC channels.

If network latency is an issue for you, this is the solution you need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.