Qwiic Joystick Hookup Guide
Arduino Library
The easiest way to install the Arduino library is by searching SparkFun Qwiic Joystick inside the Arduino library manager. To manually install, head on over to the GitHub Page or feel free to download the library here!
Library Functions
The Arduino library is commented and the functions should be self-explanatory. However, below is a detailed list of the available library functions.
.begin()
or .begin(Wire, deviceAddress)
Creates a connection to an I2C device over the I2C bus using the default or specified I2C address.
True- Connected to I2C device.
False- No device found or connected.
.isConnected()
Tries to connect to the device at the I2C address stored in the library.
True- Connected to I2C device.
False- No device found or connected.
.setI2CAddress(newAddress)
Changes the I2C address to newAddress. Once changed, the new I2C address is saved in the EEPROM of the Qwiic Joystick. Reconnects to device using new I2C address. (The new address is printed out in the Serial Monitor.)
Unasssigned 8-bit integer for device address.
.getHorizontal()
Returns the ADC value of the joystick horizontal position.
Unasssigned 10-bit integer [0 - 1023] for ADC value of the joystick position in the horizontal axis.
.getVertical()
Returns the ADC value of the joystick vertical position.
Unasssigned 10-bit integer [0 - 1023] for ADC value of the joystick position in the vertical axis.
.getButton()
Returns the current button state (clears check button indicator - see below).
0 - Button is currently being pressed.
1 - Button is currently unpressed.
.checkButton()
Indicates if the button was pressed between reads of the button state or calls of this function. The register for this indicator is then cleared.
0 - Button is was NOT pressed.
1 - Button is was pressed.
.getVersion()
Returns a string of the firmware version number.
AAA - Firmware Version (Major)
BBB - Firmware Version (Minor)
Examples
There are four examples in the Qwiic Joystick Arduino Library to get you started with using Qwiic Joystick. These example files are named with self-explanatory titles, but in case you want more information, see the descriptions below.
Example1_Basic_Readings
This example connects to the Qwiic Joystick using the default I2C address saved in the library. The sketch looks at the registers for the current joystick position and button state. The example then prints out those values over the Serial Monitor.
Example2_I2C_Address_and_Firmware
This example connects to the Qwiic Joystick using the default I2C address set in the sketch and then prints out the I2C address and firmware version over the Serial Monitor. The sketch then, takes an input from the Serial Monitor to change the I2C address using a decimal value (DEC). Once the I2C address is changed, it is stored in the EEPROM of the Qwiic Joystick. After, the sketch connects to the joystick using the new I2C address and reads the registers for the firmware version again. The example then prints out those values over the Serial Monitor again.
Example3_I2C_Scanner
This example is from the I2C scanner example from the Arduino Playground webpage. The sketch scans for devices on the I2C bus and reports them on the Serial Monitor. This is useful for users who have forgotten the changed I2C address of their boards.
Example4_Joystic_Serial_Output
This example shows a basic example of how to begin to use the Qwiic Joystick as an HID. The example sketch takes values of the joystick and converts it to directional printouts on the Serial Monitor.