Intermediate
30 min

Set the standard for weight accuracy using NAU7802 and PIC18F57Q43

Weighing made smarter

Load Cell 2 Click with Curiosity Nano with PIC18F57Q43

Published Feb 13, 2024

Click board™

Load Cell 2 Click

Dev Board

Curiosity Nano with PIC18F57Q43

Compiler

NECTO Studio

MCU

PIC18F57Q43

Unlock data-driven decisions with precise weight measurements in diverse settings

A

A

Hardware Overview

How does it work?

Load Cell 2 Click is based on the NAU7802, a precision low-power 24-bit analog-to-digital converter (ADC) from Nuvoton, with an onboard low-noise programmable gain amplifier (PGA), onboard RC or Crystal oscillator, and a precision 24-bit sigma-delta (Σ-Δ) analog to digital converter (ADC). The NAU7802 device can perform up to 23-bit ENOB (Effective Number Of Bits). This device provides a complete front-end solution for bridge/sensor measurement, such as in weigh scales, strain gauges, and many other high-resolution, low-sample rate applications. The NAU7802 has many built-in features, which enable high-performance applications with low external

parts count. Additionally, operating current and standby current are low, and many power management features are included. These enable powering only those elements of the chip that are needed and operate at greatly reduced power if the full 23-bit ENOB performance is not required. The Programmable Gain Amplifier (PGA) provides selectable gains from 1 to 128. The A/D conversion is performed with a Sigma-Delta modulator and programmable FIR filter, which provides a simultaneous 50Hz and 60Hz notch filter to improve interference immunity. Also, this device provides a standard 2-wire interface compatible with I2C protocol for simple and straightforward

connection to and interoperation with a wide range of possible host processors. Calibration is not required for low-accuracy applications but may be needed in sensitive applications. When calibration is used, the system designer has three options (details in NAU7802 datasheet). This Click board™ can be operated only with a 3.3V 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 2 Click top side image
Load Cell 2 Click bottom side image

Features overview

Development board

PIC18F57Q43 Curiosity Nano evaluation kit is a cutting-edge hardware platform designed to evaluate microcontrollers within the PIC18-Q43 family. Central to its design is the inclusion of the powerful PIC18F57Q43 microcontroller (MCU), offering advanced functionalities and robust performance. Key features of this evaluation kit include a yellow user LED and a responsive

mechanical user switch, providing seamless interaction and testing. The provision for a 32.768kHz crystal footprint ensures precision timing capabilities. With an onboard debugger boasting a green power and status LED, programming and debugging become intuitive and efficient. Further enhancing its utility is the Virtual serial port (CDC) and a debug GPIO channel (DGI

GPIO), offering extensive connectivity options. Powered via USB, this kit boasts an adjustable target voltage feature facilitated by the MIC5353 LDO regulator, ensuring stable operation with an output voltage ranging from 1.8V to 5.1V, with a maximum output current of 500mA, subject to ambient temperature and voltage constraints.

PIC18F57Q43 Curiosity Nano double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

PIC

MCU Memory (KB)

128

Silicon Vendor

Microchip

Pin count

48

RAM (Bytes)

8196

You complete me!

Accessories

Curiosity Nano Base for Click boards is a versatile hardware extension platform created to streamline the integration between Curiosity Nano kits and extension boards, tailored explicitly for the mikroBUS™-standardized Click boards and Xplained Pro extension boards. This innovative base board (shield) offers seamless connectivity and expansion possibilities, simplifying experimentation and development. Key features include USB power compatibility from the Curiosity Nano kit, alongside an alternative external power input option for enhanced flexibility. The onboard Li-Ion/LiPo charger and management circuit ensure smooth operation for battery-powered applications, simplifying usage and management. Moreover, the base incorporates a fixed 3.3V PSU dedicated to target and mikroBUS™ power rails, alongside a fixed 5.0V boost converter catering to 5V power rails of mikroBUS™ sockets, providing stable power delivery for various connected devices.

Curiosity Nano Base for Click boards accessories 1 image

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
NC
NC
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
Data Ready
PA6
INT
NC
NC
TX
NC
NC
RX
I2C Clock
PB2
SCL
I2C Data
PB1
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Schematic

Load Cell 2 Click Schematic schematic

Step by step

Project assembly

Curiosity Nano Base for Click boards front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Curiosity Nano with PIC18F57Q43 as your development board.

Curiosity Nano Base for Click boards front image hardware assembly
Charger 27 Click front image hardware assembly
PIC18F47Q10 Curiosity Nano front image hardware assembly
Prog-cut hardware assembly
Charger 27 Click complete accessories setup image hardware assembly
Curiosity Nano with PICXXX 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
PIC18F57Q43 Curiosity 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 2 Click driver.

Key functions:

  • loadcell2_get_weight - Get weight function

  • loadcell2_get_result - Get results function

  • loadcell2_calibration - Calibration 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 
 * \brief LoadCell2 Click example
 * 
 * # Description
 * Load Cell 2 click is a weight measurement click 
 * which utilizes a load cell element, 
 * in order to precisely measure the weight of an object. 
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initializes I2C driver and performs the device reset, 
 * and performs the device reset, set power on and default configuration.
 * Sets tare the scale, calibrate scale and start measurements.
 * 
 * ## Application Task  
 * This is an example which demonstrates the 
 * use of Load Cell 2 Click board. 
 * Display the measurement of scales in grams [g].
 * Results are being sent to the Usart Terminal 
 * where you can track their changes.
 * All data logs write on USB uart changes for every 1 sec.
 * 
 * \author Nenad Filipovic
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "loadcell2.h"

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

static loadcell2_t loadcell2;
static log_t logger;

static loadcell2_data_t cell_data;
static float weight_val;

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

void application_init ( void )
{
    log_cfg_t log_cfg;
    loadcell2_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.

    loadcell2_cfg_setup( &cfg );
    LOADCELL2_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    loadcell2_init( &loadcell2, &cfg );
    
    log_printf( &logger, "-------------------------\r\n");
    log_printf( &logger, "     Load cell click     \r\n");
    log_printf( &logger, "-------------------------\r\n");
    Delay_ms( 100 );
    
    log_printf( &logger, "-------------------------\r\n");
    log_printf( &logger, "   Reset all registers   \r\n");
    loadcell2_reset( &loadcell2 );
    Delay_ms( 100 );
    
    log_printf( &logger, "-------------------------\r\n");
    log_printf( &logger, "        Power On         \r\n");
    loadcell2_power_on( &loadcell2 );
    Delay_ms( 100 );

    log_printf( &logger, "-------------------------\r\n");
    log_printf( &logger, "   Set default config.   \r\n");
    loadcell2_default_cfg( &loadcell2 );
    Delay_ms( 100 );

    log_printf( &logger, "-------------------------\r\n");
    log_printf( &logger, "      Calibrate AFE      \r\n");
    loadcell2_calibrate_afe( &loadcell2 );
    Delay_ms( 1000 );

    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");
    loadcell2_tare ( &loadcell2, &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 1000g 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 ( loadcell2_calibration ( &loadcell2, LOADCELL2_WEIGHT_1000G, &cell_data ) == LOADCELL2_GET_RESULT_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 1000g 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 = loadcell2_get_weight( &loadcell2, &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.