Qwiic Joystick Hookup Guide

Pages
Contributors: santaimpersonator
Favorited Favorite 4

Python Examples

Update: We've written a full Python package for the Qwiic Joystick that can be found here:


For installation instructions, please refer to the repository's README file.
Note: This section is an example of using the Qwiic Joystick with the Raspberry Pi in Python. It is not intended to be a guide for using I2C devices with a Raspberry Pi or a tutorial on Python.

Please use the following links and the internet for a better understanding of I2C and how it works in the Arduino IDE:

Enable I2C Interface

If it isn't already enabled, enable I2C interface in Preferences > Raspberry Pi Configuration panel.

Accessing configuration panel from the desktop Enabling the I2C on the configuration panel

Enabling the I2C through the configuration panel.

Check for Device Using Command Line

On the (full) Raspbian OS, i2ctools should be pre-installed (if it is not, follow the instructions here). With the Qwiic Joystick and Qwiick Hat attached to the Raspberry Pi, run the following command in the terminal/commandline.

i2cdetect -y 1

Download and Run Python Examples

Download the Python Examples from the GitHub repository. All you need to do is open an example python file and execute the module. You can do this in Python 3 or another compatible, programming text editor like Geany.

Basic Readings

Below is a screenshot of the python shell from the Basic Readings example file.

screenshot of python shell print out

Snake Game

When you run the Snake Game example code, you only need to click the button to start the game. (*Shout out to Al Sweigart for his Wormy example, which was adapted to work with the Qwiic Joystick.)

screenshot of the snake game example

Troubleshooting Tip: I did run into an error with the python example codes. Unfortunately, I am not an expert in Python and the Raspberry Pi. However, I got around this by having the error print out instead of terminating the script. From what I could deduce based on the available information on the internet, the error [Errno 121] Remote I/O error is an issue with the I2C bus and how SMBUS interacts with the slave device.

You will also get an [Errno 121] Remote I/O error if your I2C address is defined wrong.