ADS1015 driver for Joystick
Introduction
The ADS1015 driver for Joysticks is used to analyze the two dimensional position of a joystick and a button press utilizing an I2C connection. 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
I2C Address (Service 1, 2)
This is the address the device is being referenced by on the I2C bus.
Channel (Service 1, 2)
The channel is the port/pin combination on the chip. Just input a value between 0 and 3.
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
Pin (Service 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.
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:
The pin is debounced internally and will disregard mechanical feedback during a single button depression (see: https://quantumintegrate.atlassian.net/wiki/spaces/HELP/pages/148308356/How+to+use+the+GPIO+driver+for+Digital+Inputs#Debouncing-Enabled )
Debouncing Disabled:
The pin can be debounced externally with a debouncing circuit fitting the application (see: https://quantumintegrate.atlassian.net/wiki/spaces/HELP/pages/148308356/How+to+use+the+GPIO+driver+for+Digital+Inputs#Debouncing-Disabled-with-External-debouncing )
The pin can also be left just as it is, but unpredictable results might occur (see: https://quantumintegrate.atlassian.net/wiki/spaces/HELP/pages/148308356/How+to+use+the+GPIO+driver+for+Digital+Inputs#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: https://quantumintegrate.atlassian.net/wiki/spaces/HELP/pages/148308356/How+to+use+the+GPIO+driver+for+Digital+Inputs#Pull-Down )
Pull Up:
The pin is pulled up internally and a ground level has to be applied to the pin to change its state (see: https://quantumintegrate.atlassian.net/wiki/spaces/HELP/pages/148308356/How+to+use+the+GPIO+driver+for+Digital+Inputs#Pull-Up )
Floating:
The pin can be pulled down externally with any resistor above 1000Ω depending on the application (see: https://quantumintegrate.atlassian.net/wiki/spaces/HELP/pages/148308356/How+to+use+the+GPIO+driver+for+Digital+Inputs#Floating )
The pin can be pulled up externally with any resistor above 1000Ω depending on the application (see: https://quantumintegrate.atlassian.net/wiki/spaces/HELP/pages/148308356/How+to+use+the+GPIO+driver+for+Digital+Inputs#Floating )
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, ADS1015 and how to connect it to the Builder Base.
Used Pins
Used Pins | Description |
---|---|
GP0 (can be any GP pin) | Used for the button of the joystick. |
SDA | Used for the I2C connection (Serial Data). |
SCL | Used for the I2C connection (Serial Clock). |
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 “Light” code 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:
Driver: ADS1015
I2C Address: 0x48
Channel: 0
Granularity: 50
Service 2:
Driver: ADS1015
I2C Address: 0x48
Channel: 1
Granularity: 50
Service 3:
MCP 23017/8
I2C Address: 0x20
Channel A0: Enabled
Pull Up: Disabled
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
Joystick
Downloads
Apps
Firmware
Assets