The 10K resistor is used to pull the switch input High (3.3V). You could read the Switch value using a normal GPIO pin but in this case I decided to use an analogue input for convenience. In this case we are using three of the analogue inputs. The MCP3008 is wired up just as it was in my previous post : MCP3008 Pi Wire Colour VRy (Y voltage) MCP3008 Pin 3 (CH2) Green GND (Ground) Pi GPIO Pin 6 (Ground) Black Here is the wiring information for the joystick module : Joystick Pi/MCP3008 Wire Colour The pin-out of my joystick is slightly different to the Sparkfun symbol I used in this diagram but the wire colour coding matches the photos. See my previous MCP3008 post for details of how I used one to read light levels and temperature. In this tutorial we will only need three of its inputs. These devices are cheap, easy to setup and allow 8 analogue inputs to be read by the Pi using it’s SPI interface. In order to measure the X and Y voltages I decided to use an MCP3008 10 bit Analogue to Digital Converter. There are no fancy components on the board and because it is really just two variable resistors works fine with 3.3V despite the 5V PCB label. Pressing the stick activates a small switch. It consists of two potentiometers which give an analogue voltage based on the horizontal and vertical position of the thumb-stick. The device I bought was labelled “Keyes_SJoyes”. Perhaps a Python game written using the Pygame module?
Once working this could be used as an input device for all sorts of projects.
In this post I’ll show how you can you use this device with the Pi. The outputs are analogue so you need a mechanism for the Pi to read these voltages. They are similar to the thumb-sticks you would find on a modern games console controller. These modules are cheap and easy to connect to a circuit so I decided to get one.
The first item was a small 2-axis analogue joystick. While browsing eBay looking at electronics stuff I found a few interesting items to connect to the Pi.