How does it work?
Joystick 3 Click, as its foundation, uses 2765, a high-quality mini 2-axis analog-type thumbstick from Adafruit Industries. This type of joystick has a self-centering feature that allows it to center itself the moment when you release the joystick. It also contains a comfortable cup-type black knob/cap, which gives the feel of a thumbstick, making it very similar to the ‘analog’ joysticks on PSP joysticks, suitable for numerous applications as a human-machine interface.
It comprises two 10kΩ potentiometers, one for up/down and another for left/right direction, used as dual adjustable voltage dividers providing 2-axis analog input in a control stick form. With the joystick fully assembled and functioning, the voltage will follow the motion of the thumbstick as it is moved around.
The measurements of the potentiometer resistance change are needed to read the joystick’s physical position. That’s why the MCP3204, a 12-bit A/D converter from Microchip, connects the joystick with mikroBUS™ using a simple serial interface compatible with the SPI protocol to determine the value of the joystick’s X and Y. As the MCP3204 has a resolution of 12 bits, the values on each analog channel (axis) can vary from 0 to 4095. So, if the stick is moved on the X axis from one end to the other, the X values will change from 0 to 4095, and a similar thing happens when moved along the Y axis. The value of the joystick staying in its center position is around 2048. Also, the MCP3204 is capable of conversion rates of up to 100ksps.
This Click board™ can be operated only with a 3.3V logic voltage level. The board must perform appropriate logic voltage level conversion before using MCUs with different logic levels. However, the Click board™ comes equipped with a library containing functions and an example code that can be used, as a reference, for further development.
Specifications
Type
Pushbutton/Switches
Applications
Can be used for numerous applications as a human-machine interface device (HMI), robotics, and other control interfaces
On-board modules
2765 – mini 2-axis analog-type thumbstick from Adafruit Industries
Key Features
Low power consumption, high quality, high mechanical and electrical durability, self-centering feature, 2-axis, SPI interface, and more
Interface
SPI
Feature
No ClickID
Compatibility
mikroBUS™
Click board size
M (42.9 x 25.4 mm)
Input Voltage
3.3V
Pinout diagram
This table shows how the pinout on Joystick 3 Click corresponds to the pinout on the mikroBUS™ socket (the latter shown in the two middle columns).
Onboard settings and indicators
Label | Name | Default | Description |
---|---|---|---|
LD1 | PWR | – | Power LED Indicator |
Joystick 3 Click electrical specifications
Description | Min | Typ | Max | Unit |
---|---|---|---|---|
Supply Voltage | – | 3.3 | – | V |
2765 Potentiometer Resistance | – | 10 | – | kΩ |
ADC Resolution | – | 12 | – | bits |
Operating Temperature Range | 0 | +25 | +80 | °C |
Software Support
We provide a library for the Joystick 3 Click as well as a demo application (example), developed using MikroElektronika compilers. The demo can run on all the main MikroElektronika development boards.
Package can be downloaded/installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.
Library Description
This library contains API for Joystick 3 Click driver.
Key functions
-
joystick3_read_raw_adc
This function reads the raw ADC for X and Y axis by using SPI serial interface. -
joystick3_get_angle
This function calculates and returns joystick angle in degrees from raw ADC values for X and Y axis. -
joystick3_get_position
This function calculates and returns joystick position flag from raw ADC values for X and Y axis.
Example Description
This example demonstrates the use of the joystick 3 Click board™ by reading and displaying the raw ADC for X and Y axis, as well as the joystick angle and position calculated from those ADC readings.
void application_task ( void )
{
uint16_t raw_x, raw_y;
if ( JOYSTICK3_OK == joystick3_read_raw_adc ( &joystick3, &raw_x, &raw_y ) )
{
log_printf ( &logger, " RAW X: %urn RAW Y: %urn", raw_x, raw_y );
log_printf ( &logger, " Joystick angle: %.1f degreesrn", joystick3_get_angle ( raw_x, raw_y ) );
log_printf ( &logger, " Joystick position: " );
switch ( joystick3_get_position ( raw_x, raw_y ) )
{
case JOYSTICK3_POSITION_NEUTRAL:
{
log_printf ( &logger, "NEUTRAL" );
break;
}
case JOYSTICK3_POSITION_UP:
{
log_printf ( &logger, "UP" );
break;
}
case JOYSTICK3_POSITION_UPPER_RIGHT:
{
log_printf ( &logger, "UPPER-RIGHT" );
break;
}
case JOYSTICK3_POSITION_RIGHT:
{
log_printf ( &logger, "RIGHT" );
break;
}
case JOYSTICK3_POSITION_LOWER_RIGHT:
{
log_printf ( &logger, "LOWER-RIGHT" );
break;
}
case JOYSTICK3_POSITION_DOWN:
{
log_printf ( &logger, "DOWN" );
break;
}
case JOYSTICK3_POSITION_LOWER_LEFT:
{
log_printf ( &logger, "LOWER-LEFT" );
break;
}
case JOYSTICK3_POSITION_LEFT:
{
log_printf ( &logger, "LEFT" );
break;
}
case JOYSTICK3_POSITION_UPPER_LEFT:
{
log_printf ( &logger, "UPPER-LEFT" );
break;
}
default:
{
log_printf ( &logger, "UNKNOWN" );
break;
}
}
log_printf ( &logger, "rnn" );
Delay_ms ( 100 );
}
}
The full application code, and ready to use projects can be installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.
Other Mikroe Libraries used in the example:
- MikroSDK.Board
- MikroSDK.Log
- Click.Joystick3
Additional notes and informations
Depending on the development board you are using, you may need USB UART click, USB UART 2 Click or RS232 Click to connect to your PC, for development systems with no UART to USB interface available on the board. UART terminal is available in all MikroElektronika compilers.
mikroSDK
This Click board™ is supported with mikroSDK – MikroElektronika Software Development Kit. To ensure proper operation of mikroSDK compliant Click board™ demo applications, mikroSDK should be downloaded from the LibStock and installed for the compiler you are using.
For more information about mikroSDK, visit the official page.