GPIO driver for Joysticks

Introduction

The GPIO driver for Joysticks is used to analyze the two dimensional position of a joystick and a button press. The selected digital pin for the button can include internal pull-up or pull-down functionality as well as internal button debouncing. The X and Y Axis support the granularity feature, which will make sure that only relevant changes of the Joystick are send to the system.


Driver Parameters

Pin (Service 1, 2, 3)

This is the pin reading the input voltage, any of the GP pins is suitable for this selection if not already used for other drivers.

 Granularity (Service 1, 2)

This is the minimum change from the last notifications value that would trigger sending another notification to the Central Core. This helps us to only wake up and notify when the application specific threshold has been passed. Important values:

  • The Analog In range: 0-4095 (12 bit)

  • The Granularity range: 0-200

Debouncing (Service 3)

What is Debouncing

Pushbuttons often generate spurious open/close transitions when pressed, due to mechanical and physical issues. These transitions may be read as multiple presses in a very short period of time which can fool the program. Debouncing puts a physical delay between the readings so it ensures that the button is really pressed again. Without debouncing, pressing the button once may cause an unpredictable result.

Possible Configurations

Debouncing Enabled:

Debouncing Disabled:

 

Pin Mode (Service 3)

What is a Pull Resistor

Let's say you have an MCU with one pin configured as an input. If there is nothing connected to the pin and your program reads the state of the pin, will it be high or low? It is difficult to tell. This phenomena is referred to as floating. To prevent this unknown state, a pull-up or pull-down resistor will ensure that the pin is in either in a high or low state, while also using a low amount of current.

Possible Configurations

Pull Down:

  • The pin is pulled down internally and a 3.3 voltage level has to be applied to the pin to change its state (see: )

Pull Up:

  • The pin is pulled up internally and a ground level has to be applied to the pin to change its state (see: )

Floating:

  • The pin can be pulled down externally with any resistor above 1000Ω depending on the application (see: )

  • The pin can be pulled up externally with any resistor above 1000Ω depending on the application (see: )

Note: The pin should not be left floating, this can lead to unexpected readings


Wiring

Example

Following image shows you the pinout of the joystick and how to connect it to the Builder Base.

Breadboard

 

Schematic

 

Used Pins

Used Pins

Description

Used Pins

Description

GP0 (can be any GP pin)

Used for Y-Axis of the joystick.

GP1 (can be any GP pin)

Used for the X-Axis of the joystick.

GP2 (can be any GP pin)

Used for the button of the joystick.

3.3V

This pin provides the high level.

GND

This pin provides the low level.


How to write an App

Navigate to the App Builder and create a new application. You can find the “Joystick” hardware object under the “Hardware” Tab in the object drop down menu on the left, or you can also use the search bar.

 

 

 

Drag the “Joystick” object onto the canvas.

Next, find the “Debug” object under the interface tab and drag three of them onto the canvas. 

 

 

Finally, connect each the X-axis, Y-axis, and Button ports on the Joystick object to one of the In ports on the “Debug” objects, and save your project. We suggest that you label each of the Debug objects.

 


How to create a firmware

Navigate to the Firmware Builder and create a new firmware file.

Click the “+ Add Hardware” button which will open a modal window. Scroll down in the list to find the “Electrical” section and select the “Joystick” hardware option.

Give your device a name, and click “Add Hardware”

 

 

Next, select the “GPIO” driver under the driver dropdown menu for each of the 3 services that need to be configured.

 

 

For this example we select:

Service 1:

Pin: GP0

Granularity: 50

Service 2:

Pin: GP1

Granularity: 50

Service 3:

Pin: GP2

Debounce: Enabled

Pin Mode: Input Pull Down

Your joystick may come in a different pin mode configuration. Make sure to read manufacturer documentation on whether the joystick pushbutton is pull up or pull down.

You may now save your firmware file and upload it to one of your clients.

 

 

 


Supported Hardware

  • Joysticks


Downloads

Apps

Firmware

Assets