TOP Contributors

  1. MIKROE (2652 codes)
  2. Alcides Ramos (351 codes)
  3. Shawon Shahryiar (307 codes)
  4. jm_palomino (112 codes)
  5. Chisanga Mumba (90 codes)
  6. S P (73 codes)
  7. dany (71 codes)
  8. MikroBUS.NET Team (35 codes)
  9. NART SCHINACKOW (34 codes)
  10. Armstrong Subero (27 codes)

Most Downloaded

  1. Timer Calculator (136632 times)
  2. FAT32 Library (69841 times)
  3. Network Ethernet Library (55891 times)
  4. USB Device Library (46227 times)
  5. Network WiFi Library (41863 times)
  6. FT800 Library (41086 times)
  7. GSM click (28945 times)
  8. PID Library (26402 times)
  9. mikroSDK (26317 times)
  10. microSD click (25328 times)
Libstock prefers package manager

Package Manager

We strongly encourage users to use Package manager for sharing their code on Libstock website, because it boosts your efficiency and leaves the end user with no room for error. [more info]

< Back
mikroSDK Library

Joystick 3 click

Rating:

0

Author: MIKROE

Last Updated: 2024-04-03

Package Version: 2.1.0.9

mikroSDK Library: 2.0.0.0

Category: Pushbutton/Switches

Downloaded: 55 times

Not followed.

License: MIT license  

Joystick 3 Click is a compact add-on board that can fulfill your directional analog input needs. This board features 2765, a high-quality mini 2-axis analog output thumbstick from Adafruit Industries. This small joystick is a 'self-centering' analog-type with a black rocker cap similar to the PSP joysticks. It comprises two 10kΩ potentiometers, one for up/down and another for left/right direction. Knowing that this joystick represents an analog type, it connects with mikroBUS™ through the SPI interface through the MCP3204 12-bit A/D converter.

No Abuse Reported

Do you want to subscribe in order to receive notifications regarding "Joystick 3 click" changes.

Do you want to unsubscribe in order to stop receiving notifications regarding "Joystick 3 click" changes.

Do you want to report abuse regarding "Joystick 3 click".

  • Information
  • Comments (0)

mikroSDK Library Blog


Joystick 3 click

Joystick 3 Click is a compact add-on board that can fulfill your directional analog input needs. This board features 2765, a high-quality mini 2-axis analog output thumbstick from Adafruit Industries. This small joystick is a 'self-centering' analog-type with a black rocker cap similar to the PSP joysticks. It comprises two 10kΩ potentiometers, one for up/down and another for left/right direction. Knowing that this joystick represents an analog type, it connects with mikroBUS™ through the SPI interface through the MCP3204 12-bit A/D converter.

joystick3_click.png

click Product page


Click library

  • Author : Stefan Filipovic
  • Date : Aug 2022.
  • Type : SPI type

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.

Standard key functions :

  • joystick3_cfg_setup Config Object Initialization function.

    void joystick3_cfg_setup ( joystick3_cfg_t *cfg );
  • joystick3_init Initialization function.

    err_t joystick3_init ( joystick3_t *ctx, joystick3_cfg_t *cfg );
  • joystick3_default_cfg Click Default Configuration function.

    err_t joystick3_default_cfg ( joystick3_t *ctx );

Example key functions :

  • joystick3_read_raw_adc This function reads the raw ADC for X and Y axis by using SPI serial interface.

    err_t joystick3_read_raw_adc ( joystick3_t *ctx, uint16_t *raw_x, uint16_t *raw_y );
  • joystick3_get_angle This function calculates and returns joystick angle in degrees from raw ADC values for X and Y axis.

    float joystick3_get_angle ( uint16_t raw_x, uint16_t raw_y );
  • joystick3_get_position This function calculates and returns joystick position flag from raw ADC values for X and Y axis.

    uint8_t joystick3_get_position ( uint16_t raw_x, uint16_t raw_y );

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.

The demo application is composed of two sections :

Application Init

Initializes the driver and logger.


void application_init ( void )
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    joystick3_cfg_t joystick3_cfg;  /**< Click config object. */

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, " Application Init " );

    // Click initialization.
    joystick3_cfg_setup( &joystick3_cfg );
    JOYSTICK3_MAP_MIKROBUS( joystick3_cfg, MIKROBUS_1 );
    if ( SPI_MASTER_ERROR == joystick3_init( &joystick3, &joystick3_cfg ) )
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }

    log_info( &logger, " Application Task " );
}

Application Task

Reads the raw ADC measurements for X and Y axis, and calculates the joystick angle and position from those readings. The results will be displayed on the USB UART approximately every 100ms.

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: %u\r\n RAW Y: %u\r\n", raw_x, raw_y );
        log_printf ( &logger, " Joystick angle: %.1f degrees\r\n", 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, "\r\n\n" );
        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.


ALSO FROM THIS AUTHOR

DC Motor 25 click

0

DC Motor 25 Click is a compact add-on board with a brushed DC motor driver. This board features the A3908, a low-voltage bidirectional DC motor driver from Allegro Microsystems. The A3908 is rated for an operating voltage range compatible with mikroBUS™ power rails and output currents up to 500mA. The unique output full-bridge incorporates source-side linear operation to allow a constant voltage across the motor coil. Logic input pins are provided to control the motor direction of rotation, brake, and standby modes. It also has complete protection capabilities supporting robust and reliable operation.

[Learn More]

Brushless 24 click

0

Brushless 24 Click is a compact add-on board that controls brushless DC (BLDC) motors with any MCU. This board features the DRV10866, a 3- phase sensorless motor driver from Texas Instruments with integrated power MOSFETs with current drive capability up to 800mA peak. The DRV10866 implements a 150° commutation (sensorless BEMF control scheme) for a 3-phase motor alongside a synchronous rectification mode of operation that achieves increased efficiency for motor driver applications. Besides choosing the motor speed and a wide operating voltage range of up to 5V, it also has several built-in protection circuits, such as undervoltage, lock detection, voltage surge protection, and overtemperature.

[Learn More]

A5000 Plug n Trust click

0

A5000 Plug&Trust Click is a compact add-on board representing a ready-to-use secure IoT authenticator. This board features the A5000, an Edge Lock® Secure Authenticator from NXP Semiconductors. The A5000 provides a root of trust at the IC level, giving an IoT authentication system state-of-the-art security capability. It allows for securely storing and provisioning credentials and performing cryptographic operations for security-critical communication and authentication functions. It has an independent Common Criteria EAL 6+ security certification up to OS level and supports ECC asymmetric cryptographic and AES/3DES symmetric algorithms.

[Learn More]