Joystick / Gamepad

It's a good idea to use a gamepad that is known to work well with the BeagleBone or BeagleBone Black. Most of the low-end gamepads and joysticks work very well (because they use commonly used chipsets), and also some of the higher-end devices, like the Logitech F710 works very well and is very accurate.

  1. Plug the joystick or gamepad into the BeagleBone.
  2. Verify that you get a /dev/input/js0 device (or js1, js2, etc.)

Read the Joystick using BoneScript / Cloud9 / node.js:

Install the node-joystick module with this command line:
  • npm install joystick
Add this code to your project:
// Set a deadzone of +/-3500 (out of +/-32k) and a sensitivty
// of 350 to reduce signal noise in joystick axis
var joystick = new (require('joystick'))(0, 3500, 350);
joystick.on('button', onJoystickData);
joystick.on('axis', onJoystickData);
function onJoystickData(event) { // Todo: Use joystick data here }

In the callback you will get data on this format:
Axis event:
 { time: 10352486, value: -3716, number: 0, type: 'axis', id: 0 }

Button event:
 { time: 10414941, value: 1, number: 2, type: 'button', id: 0 }

Comments