Intermediate
30 min

Make every move an epic adventure with SKRHABE010 and PIC32MZ2048EFM100

Play your game, your way

Joystick 2 Click with Curiosity PIC32 MZ EF

Published Oct 17, 2023

Click board™

Joystick 2 Click

Dev Board

Curiosity PIC32 MZ EF

Compiler

NECTO Studio

MCU

PIC32MZ2048EFM100

Experience the future of navigation with the smart joystick concept, providing users with a seamless and intuitive way to explore digital worlds

A

A

Hardware Overview

How does it work?

Joystick 2 Click is based on the SKRHABE01, a 4-direction joystick switch with Center-push Function from Alps Alpine. It is positioned on the board so it is easily accessible for interacting and the lever could be pressed, activating the microswitch that way. The microswitch is actuated by applying very little physical force, using a tipping-point mechanism which results in fast and reliable snap-in action. It has both NO (Normal open) contacts routed to the mikroBUS™ over the port expander. The switch lines are equipped with the RC filters, which serve as debouncing

elements for the switch and also to pull-up the lines when they are left afloat. This way, the contact bouncing is reduced even further, resulting in an accurate detection of the switching event. As already mentioned above, this click board™ contains the port expander, relatively large number of needed GPIO pins for the joystick switch. Used IC is PCA9538A, Low-voltage 8-bit I2C-bus I/O port with interrupt and reset, from NXP Semiconductors. It uses the I2C communication for interfacing with the main MCU, which simplifies the number of needed pins,

and therefore the design itself. The Active LOW reset input (RESET) and Open-drain active LOW interrupt output (INT) pins helps simplifying the design even further. This Click board™ can operate with either 3.3V or 5V logic voltage levels selected via the VCC SEL jumper. This way, both 3.3V and 5V capable MCUs can use the communication lines properly. Also, this Click board™ comes equipped with a library containing easy-to-use functions and an example code that can be used as a reference for further development.

Joystick 2 Click top side image
Joystick 2 Click bottom side image

Features overview

Development board

Curiosity PIC32 MZ EF development board is a fully integrated 32-bit development platform featuring the high-performance PIC32MZ EF Series (PIC32MZ2048EFM) that has a 2MB Flash, 512KB RAM, integrated FPU, Crypto accelerator, and excellent connectivity options. It includes an integrated programmer and debugger, requiring no additional hardware. Users can expand

functionality through MIKROE mikroBUS™ Click™ adapter boards, add Ethernet connectivity with the Microchip PHY daughter board, add WiFi connectivity capability using the Microchip expansions boards, and add audio input and output capability with Microchip audio daughter boards. These boards are fully integrated into PIC32’s powerful software framework, MPLAB Harmony,

which provides a flexible and modular interface to application development a rich set of inter-operable software stacks (TCP-IP, USB), and easy-to-use features. The Curiosity PIC32 MZ EF development board offers expansion capabilities making it an excellent choice for a rapid prototyping board in Connectivity, IOT, and general-purpose applications.

Curiosity PIC32MZ EF double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

PIC32

MCU Memory (KB)

2048

Silicon Vendor

Microchip

Pin count

100

RAM (Bytes)

524288

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
Reset
RA9
RST
NC
NC
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
Interrupt
RF13
INT
NC
NC
TX
NC
NC
RX
I2C Clock
RPA14
SCL
I2C Data
RPA15
SDA
Power Supply
5V
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

Joystick 2 Click Schematic schematic

Step by step

Project assembly

Curiosity PIC32MZ EF front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Curiosity PIC32 MZ EF as your development board.

Curiosity PIC32MZ EF front image hardware assembly
Thermo 28 Click front image hardware assembly
Prog-cut hardware assembly
Curiosity PIC32 MZ EF MB 1 - upright/background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
Necto image step 5 hardware assembly
Necto image step 6 hardware assembly
Curiosity PIC32 MZ EF MCU Step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Debug Image Necto Step hardware assembly

Track your results in real time

Application Output via Debug Mode

1. Once the code example is loaded, pressing the "DEBUG" button initiates the build process, programs it on the created setup, and enters Debug mode.

2. After the programming is completed, a header with buttons for various actions within the IDE becomes visible. Clicking the green "PLAY" button starts reading the results achieved with the Click board™. The achieved results are displayed in the Application Output tab.

DEBUG_Application_Output

Software Support

Library Description

This library contains API for Joystick 2 Click driver.

Key functions:

  • joystick2_set_cfg_register - Functions for configuration joystick

  • joystick2_get_position - Functions for get Joystick position

  • joystick2_get_interrupt_state - Functions for read interrupt state

Open Source

Code example

The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.

/*!
 * \file 
 * \brief Joystick2 Click example
 * 
 * # Description
 * The demo application shows reading the joistick position ..
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Configuring clicks and log objects.
 * Reset device and settings the click in the default configuration.
 * 
 * ## Application Task  
 * It reads the position of the joystick,
 * if it detects that the joystick has moved from the zero position,
 * it prints a message about the current position.
 *
 * @note: The I2C peripheral lines external pull up can be required.
 * 
 * \author Katarina Perendic
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "joystick2.h"

// ------------------------------------------------------------------ VARIABLES

static joystick2_t joystick2;
static log_t logger;

// ------------------------------------------------------ APPLICATION FUNCTIONS

void application_init ( void )
{
    log_cfg_t log_cfg;
    joystick2_cfg_t cfg;

    /** 
     * 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.

    joystick2_cfg_setup( &cfg );
    JOYSTICK2_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    joystick2_init( &joystick2, &cfg );

    joystick2_reset( &joystick2 );
    joystick2_default_cfg( &joystick2 );
    log_info( &logger, "---- JOYSTICK START ----" );
}

void application_task ( void )
{
    uint8_t joystick_pos;

    //  Task implementation.

    joystick_pos = joystick2_get_position( &joystick2 );

    switch ( joystick_pos )
    {
        case JOYSTICK2_BUTTON_ACTIVE:
        {
            log_info( &logger, "--- Button is pressed!!! ---" );
            Delay_ms( 300 );
            break;
        }
        case JOYSTICK2_POSITION_RIGHT:
        {
            log_info( &logger, "--- Joystick position [RIGHT] ---" );
            Delay_ms( 300 );
            break;
        }
        case JOYSTICK2_POSITION_LEFT:
        {
            log_info( &logger, "--- Joystick position [LEFT] ---" );
            Delay_ms( 300 );
            break;
        }
        case JOYSTICK2_POSITION_UP:
        {
            log_info( &logger, "--- Joystick position [UP] ---" );
            Delay_ms( 300 );
            break;
        }
        case JOYSTICK2_POSITION_DOWN:
        {
            log_info( &logger, "--- Joystick position [DOWN] ---" );
            Delay_ms( 300 );
            break;
        }
    }
}

void main ( void )
{
    application_init( );

    for ( ; ; )
    {
        application_task( );
    }
}


// ------------------------------------------------------------------------ END

Additional Support

Resources

Love this project?

'Buy This Kit' button takes you directly to the shopping cart where you can easily add or remove products.