Giuseppe Parrello

 

Embedded Joystick


Introduction

With this project we will manage a Joystick, using the FTDI FT232H development board (of which there is a dedicated page on this site) and the TI ADS1115 development board (of which there is a dedicated page on this site).

 

Connection

This Joystick must be connected to the TI ADS1115 development board. The connection connectors are listed below:

Image Board FT232H Board ADS1115 Joystick

FT232H - ADS1115 - JOYSTICK

AD0 SCL ------
AD1 + AD2 SDA ------
+5V VDD ------
GND GND ------
GND ------ GND
+5V ------ +5V
------ A0 VRX
------ A1 VRY
------ A2 SW

 

Python code

To manage this Joystick, the presence of the "Adafruit CircuitPython ADS1x15" library is required.
The following Python code example displays both the current value (in "raw" format) and the current voltage of the three parameters (X-axis, Y-axis, button) provided by this Joystick:

import time
import board
import busio
import adafruit_ads1x15.ads1115 as ADS
from adafruit_ads1x15.analog_in import AnalogIn

# Create the I2C bus
i2c = busio.I2C(board.SCL, board.SDA)

# Create the ADC object using the I2C bus
ads = ADS.ADS1115(i2c)

# Create single-ended input on channel 0,1,2
chanX = AnalogIn(ads, ADS.P0)
chanY = AnalogIn(ads, ADS.P1)
chanB = AnalogIn(ads, ADS.P2)

print("{:>6}\t{:>6}\t{:>6}\t{:>6}\t{:>6}\t{:>6}".format("raw_X", "volt_X", "raw_Y", "volt_Y", "raw_B", "volt_B"))

try:
    while True:
        print("{:>6}\t{:>6.3f}\t{:>6}\t{:>6.3f}\t{:>6}\t{:>6.3f}".format(chanX.value, chanX.voltage, chanY.value, chanY.voltage, chanB.value, chanB.voltage))
        time.sleep(0.25)

except KeyboardInterrupt:
    # Capture keyboard ^C to exit the program
    print('\nYou terminated the program. The program ends!')

To manage this Joystick, the presence of the "ADS1115_FTDI" library is required.
The following Python code example displays both the current value (in "raw" format) and the current voltage of the three parameters (X-axis, Y-axis, button) provided by this Joystick:

import time
import ads1x15 as ADS

# Create the ADC object using the I2C bus
ads = ADS.ADS1115()

# Create single-ended input on channel 0,1,2
chanX = ADS.AnalogIn(ads, ADS.P0)
chanY = ADS.AnalogIn(ads, ADS.P1)
chanB = ADS.AnalogIn(ads, ADS.P2)

print("{:>6}\t{:>6}\t{:>6}\t{:>6}\t{:>6}\t{:>6}".format("raw_X", "volt_X", "raw_Y", "volt_Y", "raw_B", "volt_B"))

try:
    while True:
        print("{:>6}\t{:>6.3f}\t{:>6}\t{:>6.3f}\t{:>6}\t{:>6.3f}".format(chanX.value, chanX.voltage, chanY.value, chanY.voltage, chanB.value, chanB.voltage))
        time.sleep(0.25)

except KeyboardInterrupt:
    # Capture keyboard ^C to exit the program
    print('\nYou terminated the program. The program ends!')