Speaker 2 Click with Clicker 4 for STM32F4

Published May 07, 2025

Click board™

Speaker 2 Click
POT 4 Click

Dev. board

Clicker 4 for STM32F4

Compiler

NECTO Studio

MCU

STM32F407VGT6

Speak Numbers with Potentiometer Solution

Analog-to-audio interface that speaks selected numbers aloud based on potentiometer position

What you'll learn and build

Intro

The Speak Numbers with Potentiometer solution transforms simple analog input into a fully interactive audio experience by combining the POT 4 Click with the Speaker 2 Click. As the user rotates the potentiometer, the system continuously tracks voltage levels, converts them into percentages, and maps those to one of six spoken digits. When a new digit is selected, the corresponding voice prompt is played aloud, providing immediate and intuitive auditory feedback. The system also responds to button presses on the POT 4 Click by playing a fast beep, adding another layer of interactivity. Designed for accessibility, user training, and tactile interface development, this solution offers a straightforward but effective analog-to-audio control method.

mikroBUS 1

Speaker 2 Click

Speaker 2 Click is a compact add-on board for high-quality audio playback and voice prompt applications. This board features the ISD2360, a 3-channel digital ChipCorder® from Nuvoton, which integrates flash memory for non-volatile audio storage and playback. The ISD2360 supports up to 64 seconds of audio storage with digital decompression, independent multi-channel playback, and a Class D speaker driver for driving the onboard AS01508AO-SC-R speaker. It features a standard SPI interface, configurable I/O pins, and built-in program verification, ensuring reliable operation with minimal external components. The board also includes selectable logic voltage levels (3.3V or 5V) and a jumper for independent digital power selection. Speaker 2 Click is ideal for embedded applications requiring clear voice prompts, sound effects, or pre-recorded messages, making it suitable for automation systems, consumer electronics, and industrial devices.

Speaker 2 Click front-background image

mikroBUS 2

POT 4 Click

POT 4 Click is a compact add-on board with accurate selectable reference voltage output. This board features the PRS11R-425F-S103B1, a high-quality 11mm rotary 10k potentiometer from Bourns. The PRS11R-425F-S103B1 features a small form factor, offers an push-on momentary switch, a flatted shaft style, and a wide operating temperature range. It comes with a high-resolution 12-bit ADC, capable of detecting even the slightest movement while digitizing its position, alongside a rail-to-rail buffering operational amplifier, which provides constant input and output impedance. The user can process the output signal in analog or digital form. This Click board™ can be used in audio and lighting applications, laboratory equipment, industrial automation controls, and other applications where a reliable potentiometer is required.

POT 4 Click front-background image

Features overview

Development board

Clicker 4 for STM32F4 is a compact development board designed for quickly building custom gadgets. It features an STM32F407VGT6 MCU, four mikroBUS™ sockets for Click board™ connectivity, power management, and more—making it ideal for rapid application development. At its core, the STM32F407VGT6 MCU, powered by an Arm® Cortex®-M4 32-bit processor running up to 168 MHz, ensures ample processing power for demanding tasks. Alongside two 1x20 pin headers, its four mikroBUS™ sockets provide access to a vast and growing range of Click boards™. Clearly marked sections offer an intuitive, user-friendly interface for faster development. Clicker 4 not only accelerates prototyping but can also be integrated directly into projects without additional hardware modifications. Four 4.2mm (0.165”) mounting holes at each corner enable easy installation with screws.

Clicker 4 for STM32F4 front image

Microcontroller Overview

MCU Card / MCU

default

Architecture

ARM Cortex-M4

MCU Memory (KB)

10

Silicon Vendor

STMicroelectronics

Pin count

100

RAM (Bytes)

100

Step by step

Project assembly

Clicker 4 for STM32F4 front image hardware assembly

Start by selecting your development board - Clicker 4 for STM32F4

Clicker 4 for STM32F4 front image hardware assembly
LTE IoT 5 Click front-background image hardware assembly
Calypso Click front-background image hardware assembly
Board mapper by product7 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 Output Selection Step Image hardware assembly
Necto image step 6 hardware assembly
Clicker 4 for STM32F4 HA MCU Step hardware assembly
Necto image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Necto PreFlash Image hardware assembly

Track your results in real time

Application Output

1. Application Output - In Debug mode, the 'Application Output' window enables real-time data monitoring, offering direct insight into execution results. Ensure proper data display by configuring the environment correctly using the provided tutorial.

2. UART Terminal - Use the UART Terminal to monitor data transmission via a USB to UART converter, allowing direct communication between the Click board™ and your development system. Configure the baud rate and other serial settings according to your project's requirements to ensure proper functionality. For step-by-step setup instructions, refer to the provided tutorial.

3. Plot Output - The Plot feature offers a powerful way to visualize real-time sensor data, enabling trend analysis, debugging, and comparison of multiple data points. To set it up correctly, follow the provided tutorial, which includes a step-by-step example of using the Plot feature to display Click board™ readings. To use the Plot feature in your code, use the function: plot(*insert_graph_name*, variable_name);. This is a general format, and it is up to the user to replace 'insert_graph_name' with the actual graph name and 'variable_name' with the parameter to be displayed.

Software Support

Library Description

Speak Numbers with Potentiometer solution is developed using the NECTO Studio, ensuring compatibility with mikroSDK's open-source libraries and tools. Designed for plug-and-play implementation and testing, this solution is fully compatible with all development, starter, and mikromedia boards featuring a mikroBUS™ socket.

Example Description
The Speak Numbers with Potentiometer application provides an audio-only interface where a potentiometer position determines which digit is spoken aloud. The potentiometer voltage is continuously sampled and translated into a percentage, which is then mapped to one of six digits. When the selected digit changes (due to a knob turn), the Speaker 2 Click plays the appropriate voice prompt, ensuring clear and accurate auditory feedback. Additionally, if the onboard switch on the POT 4 Click is pressed, a FAST BEEP is played as an auxiliary signal. This solution demonstrates simple yet effective analog-to-audio interaction, ideal for embedded interfaces, user input feedback systems, and accessibility-focused applications.

Key functions:

  • pot4_read_voltage - Reads the current analog voltage from the POT 4 Click and returns it in volts.

  • pot4_convert_voltage_to_percents - Converts the read voltage into a percentage value (0–100%).

  • pot4_get_switch_pin - Reads the digital input state of the onboard switch on the POT 4 Click.

  • speaker2_play_voice - Plays a specified voice message (digit or beep) via the Speaker 2 Click.

  • log_printf - Sends status messages to the UART terminal for debugging and feedback.

Application Init
During initialization, the UART logger is first configured for debugging output. The Speaker 2 Click is initialized and set to its default audio configuration. The POT 4 Click is then initialized for analog voltage reading and digital switch monitoring. Once both peripherals are ready, the application logs a status message and begins the main interaction loop.

Application Task
The main task continuously monitors the analog value of the potentiometer. It converts the voltage into a percentage and maps that value into one of six index levels (0 to 5), each corresponding to digits 1 to 6. If the newly calculated digit differs from the previously stored one, the system plays the updated digit via the Speaker 2 Click, ensuring that the spoken number reflects the current knob position. Additionally, if the user presses the button on the POT 4 Click, a FAST BEEP is played immediately. All readings and playback events are logged through UART.

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.

/*
 * Solution Name: Speak Numbers With Potentiometer
 *
 * Description:
 * This embedded solution provides an interactive audio experience by linking
 * analog input from a potentiometer to voice prompts played through a speaker.
 * The position of the potentiometer on the **POT 4 Click** is read and mapped
 * to one of six pre-recorded digits (1 to 6), which are then played through
 * the **Speaker 2 Click**.
 *
 * A press of the onboard button on the POT 4 Click triggers a distinct **FAST BEEP**
 * as an auditory feedback event. The system continuously monitors analog voltage
 * levels, converts them to percentages, and logs all activity through the UART
 * terminal for transparency and debugging.
 *
 * The system utilizes the following Click boards:
 *   - **Speaker 2 Click**: Plays pre-recorded audio via SPI interface.
 *   - **POT 4 Click**: Measures analog voltage from a potentiometer and provides
 *     digital input via a button pin.
 *
 * The `application_init` function initializes both Click boards and configures
 * the SPI and ADC communication channels. It prepares the audio system for
 * voice playback and the potentiometer for analog-to-percentage conversion.
 *
 * The `application_task` function continuously reads the potentiometer voltage,
 * converts it to a percentage, and maps it to a digit index. When the value
 * changes, the matching voice prompt is played. Additionally, if the button is
 * pressed, a FAST BEEP tone is played. All actions are logged via UART.
 *
 * Hardware Setup:
 *   - **MIKROBUS_1**: Speaker 2 Click (SPI audio playback)
 *   - **MIKROBUS_2**: POT 4 Click (Analog voltage input + button pin)
 *
 * Key Features:
 *   - Audio-based digit representation via potentiometer position.
 *   - Voice output changes only when the knob is rotated into a new range.
 *   - Button-triggered beep functionality.
 *   - UART terminal logging for diagnostics and playback tracking.
 *
 * Development Environment:
 *   - **NECTO Studio** ([link](https://www.mikroe.com/necto))
 *   - **mikroSDK v2.0** ([link](https://www.mikroe.com/mikrosdk))
 *   - MIKROE **Click boards** ([link](https://www.mikroe.com/click-boards))
 *
 * Author: Branko Jaksic
 * Date: April, 2025
 */

// ------------------------------------------------------------------- INCLUDES
#include "log.h"
#include "pot4.h"
#include "board.h"
#include "speaker2.h"

// ------------------------------------------------------------------ VARIABLES
// --- Driver Instances ---
static pot4_t pot4;                     // POT 4 Click driver object
static log_t logger;                    // Logger instance
static speaker2_t speaker2;             // Speaker 2 Click driver instance

// --- Speaker 2 Click Voice Map ---
const uint8_t voices[6] = {             // Voice prompt mappings (1-6)
    SPEAKER2_VP9_ONE,
    SPEAKER2_VP10_TWO,
    SPEAKER2_VP11_THREE,
    SPEAKER2_VP12_FOUR,
    SPEAKER2_VP13_FIVE,
    SPEAKER2_VP14_SIX
};

// ------------------------------------------------------ APPLICATION FUNCTIONS
void application_init ( void )
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    pot4_cfg_t pot4_cfg;  /**< Click config object. */
    speaker2_cfg_t speaker2_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 " );

    // Speaker 2 Click initialization.
    speaker2_cfg_setup( &speaker2_cfg );
    SPEAKER2_MAP_MIKROBUS( speaker2_cfg, MIKROBUS_1 );
    if ( SPI_MASTER_ERROR == speaker2_init( &speaker2, &speaker2_cfg ) )
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }

    if ( SPEAKER2_ERROR == speaker2_default_cfg ( &speaker2 ) )
    {
        log_error( &logger, " Default configuration." );
        for ( ; ; );
    }

    // POT 4 Click initialization.
    pot4_cfg_setup( &pot4_cfg );
    POT4_MAP_MIKROBUS( pot4_cfg, MIKROBUS_2 );
    err_t init_flag = pot4_init( &pot4, &pot4_cfg );
    if ( ( ADC_ERROR == init_flag ) || ( I2C_MASTER_ERROR == init_flag ) )
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }

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

void application_task ( void )
{
    float voltage = 0;
    uint8_t pot_percent = 0;

    // Switch I2C communication to POT 4 Click
    i2c_master_set_slave_address(&pot4.i2c, pot4.slave_address);

    // Play a beep if POT had been pressed
    if ( !pot4_get_switch_pin ( &pot4 ) )
    {
        err_t beep_status = speaker2_play_voice( &speaker2,
                                                SPEAKER2_VP15_FAST_BEEP );
        log_printf( &logger, " Playing FAST BEEP: %s\r\n\n",
                    ( beep_status == SPEAKER2_OK ) ? "DONE" : "ERROR" );
    }

    // Read analog voltage from POT 4
    if ( POT4_OK == pot4_read_voltage( &pot4, &voltage ) )
    {
        pot_percent = ( uint8_t ) pot4_convert_voltage_to_percents( &pot4, voltage );
        log_printf( &logger, " Potentiometer : %u %%\r\n", pot_percent );

        // Map percentage [0-100] into 6 levels (0-5)
        uint8_t index = ( pot_percent * 6 ) / 101;  // Ensure max 5

        // Play voice for the digit
        err_t status = speaker2_play_voice( &speaker2, voices[ index ] );
        log_printf( &logger, " Playing voice %d: %s\r\n\n",
                    index + 1, ( status == SPEAKER2_OK ) ? "DONE" : "ERROR" );
    }
}

int main ( void )
{
    /* Do not remove this line or clock might not be set correctly. */
    #ifdef PREINIT_SUPPORTED
    preinit();
    #endif

    application_init( );

    for ( ; ; )
    {
        application_task( );
    }

    return 0;
}

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