Beginner
10 min

Control both industrial and consumer-grade stepper motors with DRV8424 and ATmega328P

PWM microstepping stepper motor driver with simple STEP/DIR interface and up to 1/256 microstepping indexer

Stepper 19 Click with Arduino UNO Rev3

Published Mar 25, 2024

Click board™

Stepper 19 Click

Dev Board

Arduino UNO Rev3

Compiler

NECTO Studio

MCU

ATmega328P

Capable of delivering up to 2.5A of full-scale output current, ideal for driving various stepper motors in robotics, precision systems, and automation

A

A

Hardware Overview

How does it work?

Stepper 19 Click is based on the DRV8424, a stepper motor driver from Texas Instruments, made for both industrial and consumer applications. This integrated circuit stands out with its comprehensive integration, including dual N-channel power MOSFET H-bridge drivers, a microstepping indexer, and integrated current sensing. The DRV8424 operates on an external power supply ranging from 5V to 30V and can drive up to 2.5A of full-scale output current. Its design eliminates the need for external power sense resistors by utilizing an internal current sense architecture, conserving PCB space and reducing overall system cost. The DRV8424 optimizes performance through an internal PWM current regulation scheme, offering smart tune, slow, and mixed decay options selections. The smart tune feature dynamically adjusts to ensure optimal current regulation,

compensates for motor variations and aging, and minimizes audible noise produced by the motor. Control over the stepper motor is achieved via a straightforward STEP/DIR interface, which permits an external controller to dictate the motor's stepping direction and rate. Microstepping resolution ranges from full-step to 1/256, selectable through the STP pin of the mikroBUS™ socket, with the direction controlled by the DIR pin. The device also includes a low-power sleep mode accessible via the RST pin. It has several protection features for conditions like supply undervoltage, charge pump faults, overcurrent, short circuits, and overtemperature, with fault indications through the FLT pin. The DRV8424's enable/disable function is managed by the EN pin. Additional functionalities on this Click board™ are achieved over the PCA9538A, an 8-bit I/O port from NXP, which

interfaces with the main MCU via I2C, offering selectable addresses through the ADDR SEL jumpers. Besides DIR and STP pins on the mikroBUS™ socket, the PCA9538A can also control these functions if the R12 and R16 resistors are populated on the board. This configuration flexibility, combined with the DRV8424's efficiency and the PCA9538A's extensive control capabilities, makes Stepper 19 Click a powerful solution for driving stepper motors in various application scenarios. 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.

Stepper 19 Click hardware overview image

Features overview

Development board

Arduino UNO is a versatile microcontroller board built around the ATmega328P chip. It offers extensive connectivity options for various projects, featuring 14 digital input/output pins, six of which are PWM-capable, along with six analog inputs. Its core components include a 16MHz ceramic resonator, a USB connection, a power jack, an

ICSP header, and a reset button, providing everything necessary to power and program the board. The Uno is ready to go, whether connected to a computer via USB or powered by an AC-to-DC adapter or battery. As the first USB Arduino board, it serves as the benchmark for the Arduino platform, with "Uno" symbolizing its status as the

first in a series. This name choice, meaning "one" in Italian, commemorates the launch of Arduino Software (IDE) 1.0. Initially introduced alongside version 1.0 of the Arduino Software (IDE), the Uno has since become the foundational model for subsequent Arduino releases, embodying the platform's evolution.

Arduino UNO Rev3 double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

AVR

MCU Memory (KB)

32

Silicon Vendor

Microchip

Pin count

28

RAM (Bytes)

2048

You complete me!

Accessories

Click Shield for Arduino UNO has two proprietary mikroBUS™ sockets, allowing all the Click board™ devices to be interfaced with the Arduino UNO board without effort. The Arduino Uno, a microcontroller board based on the ATmega328P, provides an affordable and flexible way for users to try out new concepts and build prototypes with the ATmega328P microcontroller from various combinations of performance, power consumption, and features. The Arduino Uno has 14 digital input/output pins (of which six can be used as PWM outputs), six analog inputs, a 16 MHz ceramic resonator (CSTCE16M0V53-R0), a USB connection, a power jack, an ICSP header, and reset button. Most of the ATmega328P microcontroller pins are brought to the IO pins on the left and right edge of the board, which are then connected to two existing mikroBUS™ sockets. This Click Shield also has several switches that perform functions such as selecting the logic levels of analog signals on mikroBUS™ sockets and selecting logic voltage levels of the mikroBUS™ sockets themselves. Besides, the user is offered the possibility of using any Click board™ with the help of existing bidirectional level-shifting voltage translators, regardless of whether the Click board™ operates at a 3.3V or 5V logic voltage level. Once you connect the Arduino UNO board with our Click Shield for Arduino UNO, you can access hundreds of Click boards™, working with 3.3V or 5V logic voltage levels.

Click Shield for Arduino UNO accessories 1 image

The 28BYJ-48 is an adaptable 5VDC stepper motor with a compact design, ideal for various applications. It features four phases, a speed variation ratio of 1/64, and a stride angle of 5.625°/64 steps, allowing precise control. The motor operates at a frequency of 100Hz and has a DC resistance of 50Ω ±7% at 25°C. It boasts an idle in-traction frequency greater than 600Hz and an idle out-traction frequency exceeding 1000Hz, ensuring reliability in different scenarios. With a self-positioning torque and in-traction torque both exceeding 34.3mN.m at 120Hz, the 28BYJ-48 offers robust performance. Its friction torque ranges from 600 to 1200 gf.cm, while the pull-in torque is 300 gf.cm. This motor makes a reliable and efficient choice for your stepper motor needs.

Stepper 19 Click accessories 1 image

Used MCU Pins

mikroBUS™ mapper

Stepping Direction Control
PC0
AN
Sleep Mode Control / ID SEL
PD2
RST
Device Enable / ID COMM
PB2
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Step Input Control
PD6
PWM
Fault Interrupt
PC3
INT
NC
NC
TX
NC
NC
RX
I2C Clock
PC5
SCL
I2C Data
PC4
SDA
Power Supply
5V
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

Stepper 19 Click Schematic schematic

Step by step

Project assembly

Click Shield for Arduino UNO front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Arduino UNO Rev3 as your development board.

Click Shield for Arduino UNO front image hardware assembly
Arduino UNO Rev3 front image hardware assembly
Charger 27 Click front image hardware assembly
Prog-cut hardware assembly
Charger 27 Click complete accessories setup image hardware assembly
Arduino UNO Rev3 Access 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
Arduino UNO 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

This Click board can be interfaced and monitored in two ways:

  • Application Output - Use the "Application Output" window in Debug mode for real-time data monitoring. Set it up properly by following this tutorial.

Software Support

Library Description

This library contains API for Stepper 19 Click driver.

Key functions:

  • stepper19_rotate_by_angle - This function rotates the shaft through a desired step speed and angle

  • stepper19_rotate_by_step - This function rotates the shaft through for the specific number of steps at the selected speed

  • stepper19_set_direction - This function sets the desired direction of motor movement: clockwise or counterclockwise

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 main.c
 * @brief Stepper 19 Click example
 *
 * # Description
 * This example demonstrates the use of Stepper 19 Click board 
 * by driving the motor in both directions for a desired rotation angle.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * The initialization of I2C module and log UART.
 * After driver initialization, the app sets the default configuration.
 *
 * ## Application Task
 * The application task represents an example that demonstrates 
 * the use of the Stepper 19 Click board with which the user can sequentially move the motor. 
 * The first part of the sequence executes the clockwise/counterclockwise motor movement 
 * for an angle of 90 degrees with a step speed of 50%, 
 * all the way to the last sequence of the same movement routine 
 * of 360 degree angle with a step speed of 90%. 
 * Results are being sent to the UART Terminal, where you can track their changes.
 *
 * @author Nenad Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "stepper19.h"


// Bipolar stepper motor, resolution of 200 steps per revolution (1.8 degrees)
#define STEPPER19_STEP_RES_200    200

static stepper19_t stepper19;
static log_t logger;

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    stepper19_cfg_t stepper19_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.
    stepper19_cfg_setup( &stepper19_cfg );
    STEPPER19_MAP_MIKROBUS( stepper19_cfg, MIKROBUS_1 );
    if ( I2C_MASTER_ERROR == stepper19_init( &stepper19, &stepper19_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    if ( STEPPER19_ERROR == stepper19_default_cfg ( &stepper19 ) )
    {
        log_error( &logger, " Default configuration." );
        for ( ; ; );
    }
    
    log_info( &logger, " Application Task " );
    log_printf( &logger, "-----------------------------\r\n" );
}

void application_task ( void ) 
{
    log_printf( &logger, " Clockwise motion\r\n" );
    log_printf( &logger, " Angle of rotation :  90 degrees\r\n" );
    log_printf( &logger, " Step speed        :  50 %%\r\n" );
    stepper19_set_direction( &stepper19, STEPPER19_DIR_CLOCKWISE );
    if ( STEPPER19_OK == stepper19_rotate_by_angle( &stepper19, 50, 90, STEPPER19_STEP_RES_200 ) )
    {
        log_printf( &logger, "-----------------------------\r\n" );
        Delay_ms( 2000 );
    }
    
    log_printf( &logger, " Counterclockwise motion\r\n" );
    log_printf( &logger, " Angle of rotation :  180 deg\r\n" );
    log_printf( &logger, " Step speed        :  50 %%\r\n" );
    stepper19_set_direction( &stepper19, STEPPER19_DIR_COUNTERCLOCKWISE );
    if ( STEPPER19_OK == stepper19_rotate_by_angle( &stepper19, 50, 180, STEPPER19_STEP_RES_200 ) )
    {
        log_printf( &logger, "-----------------------------\r\n" );
        Delay_ms( 2000 );
    }
    
    log_printf( &logger, " Clockwise motion\r\n" );
    log_printf( &logger, " Angle of rotation : 270 deg\r\n" );
    log_printf( &logger, " Step speed        :  90 %% \r\n" );
    stepper19_set_direction( &stepper19, STEPPER19_DIR_CLOCKWISE );
    if ( STEPPER19_OK == stepper19_rotate_by_angle( &stepper19, 90, 270, STEPPER19_STEP_RES_200 ) )
    {
        log_printf( &logger, "-----------------------------\r\n" );
        Delay_ms( 2000 );
    }
    
    log_printf( &logger, " Counterclockwise motion\r\n" );
    log_printf( &logger, " Angle of rotation : 360 deg\r\n" );
    log_printf( &logger, " Step speed        : 90 %%\r\n" );
    stepper19_set_direction( &stepper19, STEPPER19_DIR_COUNTERCLOCKWISE );
    if ( STEPPER19_OK == stepper19_rotate_by_angle( &stepper19, 90, 360, STEPPER19_STEP_RES_200 ) )
    {
        log_printf( &logger, "-----------------------------\r\n" );
        Delay_ms( 2000 );
    }
    
    log_printf( &logger, " Clockwise motion\r\n" );
    log_printf( &logger, " Angle of rotation : 360 deg\r\n" );
    log_printf( &logger, " Step speed        : 90 %% \r\n" );
    stepper19_set_direction( &stepper19, STEPPER19_DIR_CLOCKWISE );
    if ( STEPPER19_OK == stepper19_rotate_by_angle( &stepper19, 90, 360, STEPPER19_STEP_RES_200 ) )
    {
        log_printf( &logger, "-----------------------------\r\n" );
        Delay_ms( 2000 );
    }
}

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.