Intermediate
30 min

Make informed choices by obtaining trustworthy weight data with PGA302 and ATmega328P

Where every gram counts!

Load Cell 3 Click with Arduino UNO Rev3

Published Feb 14, 2024

Click board™

Load Cell 3 Click

Dev Board

Arduino UNO Rev3

Compiler

NECTO Studio

MCU

ATmega328P

Enable fair and reliable trade through dependable weight measurements.

A

A

Hardware Overview

How does it work?

Load Cell 3 Click is based on the PGA302, a high accuracy, low drift, low noise, low power, and versatile signal conditioner automotive grade-qualified device for resistive bridge pressure and temperature-sensing applications from Texas Instruments. The PGA302 provides bridge excitation voltages of 2.5V. The PGA302 conditions sensing and temperature signals by amplifying and digitizing through the analog front-end chain and performing linearization and temperature compensation. The conditioned signals can be output in analog form, and besides that, the signal data can be accessed by an I2C digital interface. The PGA302 contains two separated analog-front

end (AFE) chains with their gain amplifiers for resistive bridge and temperature sensing inputs. The resistive bridge input AFE chain consists of a programmable gain with eight steps from 1.33V/V to 200V/V. For the temperature-sensing input AFE chain, the PGA302 provides a current source of up to 1mA for the optional external temperature sensing available on the onboard terminal labeled with TMP+ and TMP-. After the ADC decimation filters, the digitalized signals are sent to the linearization and compensation calculation digital signal logic. All required parameters for the linearization algorithm and other user data are stored in the integrated EEPROM memory.

At the device's output, a 14-bit DAC is followed by a ratiometric-voltage supply output buffer with a gain of 4 V/V, allowing a 0-5V ratiometric voltage system output available on the AN pin on the mikroBUS™ socket. This Click board™ can be operated only with a 5V logic voltage level. The board must perform appropriate logic voltage level conversion before using MCUs with different logic levels. Also, it comes equipped with a library containing functions and an example code that can be used as a reference for further development.

Load Cell 3 Click top side image
Load Cell 3 Click bottom side 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

Used MCU Pins

mikroBUS™ mapper

Analog Output
PC0
AN
NC
NC
RST
NC
NC
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
NC
NC
3.3V
Ground
GND
GND
NC
NC
PWM
NC
NC
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

Schematic

Load Cell 3 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 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 Load Cell 3 Click driver.

Key functions:

  • loadcell3_tare - Load Cell 3 tare the scales function

  • loadcell3_calibration - Load Cell 3 calibration function

  • loadcell3_get_weight - Load Cell 3 get weight function

Open Source

Code example

This example can be found in NECTO Studio. Feel free to download the code, or you can copy the code below.

/*!
 * @file main.c
 * @brief LoadCell3 Click example
 *
 * # Description
 * This library contains API for the Load Cell 3 click driver.
 * The library also includes a function for tare and calibration and weight measurement.
 * This demo application shows an example of weight measurement.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initialization of I2C module and log UART.
 * After driver initialization and default settings, the app sets tare the scale, 
 * calibrate scale and start measurements. 
 *
 * ## Application Task
 * This is an example that shows the use of a Load Cell 3 click board™.
 * The Load Cell 3 click board can be used to measure weight,
 * shows the measurement of scales in grams [ g ].
 * Results are being sent to the Usart Terminal where you can track their changes.
 *
 * @author Nenad Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "loadcell3.h"

static loadcell3_t loadcell3;
static log_t logger;

static loadcell3_data_t cell_data;
static float weight_val;

void application_init ( void ) {
    log_cfg_t log_cfg;              /**< Logger config object. */
    loadcell3_cfg_t loadcell3_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.

    loadcell3_cfg_setup( &loadcell3_cfg );
    LOADCELL3_MAP_MIKROBUS( loadcell3_cfg, MIKROBUS_1 );
    err_t init_flag = loadcell3_init( &loadcell3, &loadcell3_cfg );
    if ( init_flag == I2C_MASTER_ERROR ) {
        log_error( &logger, " Application Init Error. " );
        log_info( &logger, " Please, run program again... " );

        for ( ; ; );
    }

    loadcell3_default_cfg ( &loadcell3 );
    log_info( &logger, " Application Task " );
    Delay_ms( 100 );

    log_printf( &logger, "-------------------------\r\n" );
    log_printf( &logger, "     Tare the scale :    \r\n" );
    log_printf( &logger, "- - - - - - - - - - - - -\r\n" );
    log_printf( &logger, " >> Remove all object << \r\n" );
    log_printf( &logger, "- - - - - - - - - - - - -\r\n" );
    log_printf( &logger, " In the following 10 sec \r\n" );
    log_printf( &logger, " please remove all object\r\n" );
    log_printf( &logger, "     from the scale.     \r\n" );
    Delay_ms( 10000 );

    log_printf( &logger, "-------------------------\r\n" );
    log_printf( &logger, "    Start tare scales    \r\n" );
    loadcell3_tare ( &loadcell3, &cell_data );
    Delay_ms( 500 );
    
    log_printf( &logger, "-------------------------\r\n" );
    log_printf( &logger, "   Tarring is complete   \r\n" );
    log_printf( &logger, "-------------------------\r\n" );
    log_printf( &logger, "    Calibrate Scale :    \r\n" );
    log_printf( &logger, "- - - - - - - - - - - - -\r\n" );
    log_printf( &logger, "   >>> Load etalon <<<   \r\n" );
    log_printf( &logger, "- - - - - - - - - - - - -\r\n" );
    log_printf( &logger, " In the following 10 sec \r\n" );
    log_printf( &logger, "place 100g weight etalon \r\n" );
    log_printf( &logger, "    on the scale for     \r\n" );
    log_printf( &logger, "   calibration purpose.  \r\n" );
    Delay_ms( 10000 );

    log_printf( &logger, "-------------------------\r\n" );
    log_printf( &logger, "    Start calibration    \r\n" );

    if ( loadcell3_calibration ( &loadcell3, LOADCELL3_WEIGHT_100G, &cell_data ) == LOADCELL3_OK ) {
        log_printf( &logger, "-------------------------\r\n" );
        log_printf( &logger, "    Calibration  Done    \r\n" );

        log_printf( &logger, "- - - - - - - - - - - - -\r\n" );
        log_printf( &logger, "  >>> Remove etalon <<<  \r\n" );
        log_printf( &logger, "- - - - - - - - - - - - -\r\n" );
        log_printf( &logger, " In the following 10 sec \r\n" );
        log_printf( &logger, "   remove 100g weight    \r\n" );
        log_printf( &logger, "   etalon on the scale.  \r\n" );
        Delay_ms( 10000 );
    }
    else {
        log_printf( &logger, "-------------------------\r\n" );
        log_printf( &logger, "   Calibration  Error    \r\n" );
        for ( ; ; );
    }

    log_printf( &logger, "-------------------------\r\n" );
    log_printf( &logger, "   Start measurements :  \r\n" );
    log_printf( &logger, "-------------------------\r\n" );
}

void application_task ( void ) {
    weight_val = loadcell3_get_weight( &loadcell3, &cell_data );
    log_printf( &logger, "   Weight : %.2f g\r\n", weight_val );
    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.