Using Joystick with Raspberry Pi

Description:
This project shows how you can link the input from a Joystick on a Windows machine to some output on a Raspberry Pi
Created:
3/5/2017 8:33:02 PM
Last Updated:
3/5/2017 8:33:02 PM

To do this project, you will need:

  • Raspberry Pi
  • Windows machine with DirectX 8 or greater

Note: This has only been tested on a Windows 10 machine.

The general idea of this project is to show how input from one device can be used to control other devices in near real-time.

We've started work on a simple service, named Controllers, that allows input from - you guessed it, controllers.  At the time of this writing, the only inputs are joysticks and it only works on Windows. 

The following is the NodeCode wiring setup to get a two motor rover working using a Joystick:

wiring

The only outputs used from the Joystick are the X Axis and the Y Axis.  The outputs from each of these range from -32,768 to 32,767.  This is how DirectX reads the values and NodeCode does nothing but output them for you to use as you see fit.

We plan to have scripting Services that allow you to dynamically program inputs to have custom outputs but we are not yet ready to release these. As such, we have a stand in.

We've added a simple converter to take those numbers and converts them to a more suitable output that can be used directly by the Raspberry Pi's GPIO. That node is called Joystick To Motor.  The only thing the converter does is to convert that range into speeds of the range 0-255 to a directions, of a range 0 and 1 (true and false). 

The outputs from the Joystick To Motor node can be wired directly to two different H Bridge nodes (part of RpiGpio service) to drive two motors. 

H Bridges are useful little chips that allow you to control things like the speed and direction of a large 12V motor (or two) with a 5V, low power, computer like a RPi. You NEVER want to drive a motor from the RPi's on-board power.  You will be out of a Pi :(

We usually end up using a 12v SLA battery to drive the motors of our rover. They are heavy and are probably not recommended for a starter robot but the same idea works for smaller motors and/or voltages.

You can find a lot of information on how to wire up H Bridges to a Raspberry Pi but we've included a simple image found on RaspberryPi.org:

rpi-hbridge

The NC RPiGpio H Bridge service is nothing more than a combination of a PWM node and Digital Pin Writer node crammed into one Node.  You'll need to set which pin you've wired to PWM (speed) and which pin you've wired to the H Bridge control (direction). If you have two motors, you'll have to do this for each.

We'll be adding more to this project as time allows but hope that it helps at least point you in the right direction to get started!

Happy building!

Back to Project List