/linux-gamepad-input

Gets buttons pressed from gamepads

Primary LanguageJavaScriptMIT LicenseMIT

Moved to Raspberry Pi Projects

Goal

Control GPIO using any compatible bluetooth gamepad.

Try it yourself

Install

Make sure you have Node.js v16 (I used v16.17.0, I don't think earlier versions will work. Later versions will probably work) installed. Download Node.js.

Install dependencies (usually with npm i)

Run the examples

GPIO Setup

joystickInput.js

Does not need a GPIO (I think it could work on any Linux device)

autoConnect.js

Has some LEDs and a button. The setup I did: Picture 0 Picture 1

Env vars

The examples need some environmental variables. You can copy the example.env file to .env and then customize (like if you use differnet GPIO pins).

Running Example

node autoConnect.js

Examples

joystickInput.js

  • Watches for gamepads being connected and disconnected
  • Outputs events for every gamepad when you press a button or move an axis

autoConnect.js

  • Interacts with GPIO
  • Bluetooth light turns on when gamepad is connected
  • Pressing button 0 (which is A on the Xbox controller I used) turns on the yellow output light
  • Pressing the button will scan for bluetooth devices and automatically try to connect to any gamepad. Currently only recognizes Xbox Wireless Controller, but if there is another gamepad name you use you can add it and make a pull request. Because of this bug in node-ble you will have to connect the controller fast. After around 20 seconds the code will crash.