Advanced
30 min

Enjoy an impeccable performance of your bipolar stepper motors with TB9120AFTG and ATmega328P

Smart. Compact. Reliable. It's all in one package!

Stepper 11 Click with Arduino UNO Rev3

Published Feb 14, 2024

Click board™

Stepper 11 Click

Dev Board

Arduino UNO Rev3

Compiler

NECTO Studio

MCU

ATmega328P

With a compact design and reliable performance, our integrated motor-driver solution takes the hassle out of managing bipolar stepper motors

A

A

Hardware Overview

How does it work?

Stepper 11 Click is based on the TB9120AFTG, a constant-current 2-phase stepping motor driver for automotive applications from Toshiba Semiconductor. The TB9120AFTG incorporates low on-resistance DMOS FETs, which can deliver a 2A maximum current. A built-in mixed decay mode helps to stabilize the current waveforms. Numerous protection mechanisms are also incorporated, such as over-current and over-temperature detection, thermal shutdown, and stall detection. Thanks to the many micro-steps they support, motor noise can be significantly reduced with smoother operation and more precise control. It is suited to a wide range of general automotive applications using stepping motors and supports an operational temperature range covering -40°C to 125°C. The current value is set by the reference voltage obtained by the MCP1804, a low-dropout voltage regulator. The current threshold point for the VREF pin of the TB9120AFTG, alongside MCP1804, can be set manually using an onboard trimmer labeled VR1. Alongside I2C communication, several GPIO pins connected to the mikroBUS™ socket pins are also used to forward the information to the MCU,

associated with the PCA9538A port expander with a maximum frequency of 400kHz. The PCA9538A also allows the choice of the least significant bit (LSB) of its I2C slave address by positioning SMD jumpers labeled as ADDR SEL to an appropriate position marked as 0 and 1. The Enable pin, labeled as EN and routed to the CS pin of the mikroBUS™ socket, optimizes power consumption and is used for power ON/OFF purposes. All circuits, including the interface pins, are inactive in this state, and the TB9120AFTG is in the form of minimum power consumption. A simple DIR pin routed to the AN pin on the mikroBUS™ socket allows MCU to manage the direction of the stepper motor (clockwise or counterclockwise). At the same time, the onboard switches labeled from SW1-SW3 enable users to set the excitation mode, stepper motor step resolution, and SW4-SW5 sets torque and rotational force. In addition to these features, this Click board™ also uses the CLK step clock pin, routed to the PWM pin of the mikroBUS™ socket, for PWM constant-current control, allowing stable output waveforms in mixed decay mode. The RST pin of the mikroBUS™ socket initializes an

electrical angle in the internal counter to set an initial position. Achieving an initial position is indicated via an onboard blue LED labeled as MO. This Click board™ also has two additional LEDs for anomaly indication. Suppose a state such as a motor load open, overtemperature, or overcurrent is detected. In that case, such anomaly is indicated by a red LED marked as DIAG, while an orange LED labeled SD indicates when a stall (step-out) situation is detected. The motor-stall detection threshold can be manually set manually using an onboard trimmer labeled VR2. The Stepper 11 Click supports an external power supply for the TB9120AFTG, which can be connected to the input terminal labeled as VM and should be within the range of 7V to 18V, while the stepper motor coils can be connected to the terminals labeled as B+, B-, A-, and A+. 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 11 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 11 Click accessories image

Used MCU Pins

mikroBUS™ mapper

Rotation Direction
PC0
AN
Electrical Angle intilizing
PD2
RST
Enable
PB2
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Step Clock
PD6
PWM
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 11 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 11 Click driver.

Key functions:

  • stepper11_set_step_resolution - Set step resolution.

  • stepper11_move_motor_angle - Move motor in angle value.

  • stepper11_move_motor_step - Move motor in step value.

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 Stepper11 Click example
 *
 * # Description
 * This example showcases the device's ability to control the motor.
 * It initializes the device for control and moves the motor in two 
 * directions in a variety of resolutions for 360 degrees.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initialization of communication modules(I2C, UART) and additional pins
 * for control of device. Then sets default configuration that enables
 * device for motor control.
 *
 * ## Application Task
 * Firstly it rotates motor in CW direction for 360 degrees in FULL step 
 * resolution. Then changes direction in CCW and rotates backwards 360 degrees
 * in 2 different step resolutions (Quarter and 1/16) in 180 degrees each.
 *
 * @author Luka Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "stepper11.h"

static stepper11_t stepper11;
static log_t logger;

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    stepper11_cfg_t stepper11_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.
    stepper11_cfg_setup( &stepper11_cfg );
    STEPPER11_MAP_MIKROBUS( stepper11_cfg, MIKROBUS_1 );
    err_t init_flag = stepper11_init( &stepper11, &stepper11_cfg );
    if ( I2C_MASTER_ERROR == init_flag ) 
    {
        log_error( &logger, " Application Init Error. " );
        log_info( &logger, " Please, run program again... " );

        for ( ; ; );
    }

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

void application_task ( void ) 
{
    stepper11_set_step_resolution( &stepper11, STEPPER11_RESOLUTION_FULL );
    stepper11_set_direction( &stepper11, 1 );
    log_info( &logger, " Rotate motor CW for 360 degrees in full step" );
    stepper11_move_motor_angle( &stepper11, 360, STEPPER11_SPEED_FAST );
    Delay_ms( 1000 );
    stepper11_set_direction( &stepper11, 0 );
    stepper11_set_step_resolution( &stepper11, STEPPER11_RESOLUTION_QUARTER );
    log_info( &logger, " Rotate motor CCW for 180 degrees in half step" );
    stepper11_move_motor_angle( &stepper11, 180, STEPPER11_SPEED_FAST );
    Delay_ms( 1000 );
    stepper11_set_step_resolution( &stepper11, STEPPER11_RESOLUTION_1div16 );
    log_info( &logger, " Rotate motor CCW for 180 degrees in 1/8 step" );
    stepper11_move_motor_angle( &stepper11, 180, STEPPER11_SPEED_FAST );
    Delay_ms( 1000 );
}

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.