Intermediate
30 min

Enhance user experiences based on ambient conditions with TSL2572 and PIC32MZ2048EFM100

Illuminating insights

Ambient 17 Click with Curiosity PIC32 MZ EF

Published Sep 19, 2023

Click board™

Ambient 17 Click

Dev.Board

Curiosity PIC32 MZ EF

Compiler

NECTO Studio

MCU

PIC32MZ2048EFM100

Utilize ambient light intensity sensing to create energy-efficient lighting systems that adapt to the environment, reducing operational costs and environmental impact

A

A

Hardware Overview

How does it work?

Ambient 17 Click is based on the TSL2572, a high-sensitivity light-to-digital converter that transforms light intensity into a digital output signal from ams AG. The TSL2572 provides ambient light sensing (ALS) that approximates the human eye response to light intensity under various lighting conditions and through various attenuation materials. Accurate ALS measurements result from dual-diode technology and the UV rejection filter incorporated in the package. In addition, the TSL2584TSV can detect a wide range of precise lux measurements up to 60klx, even when mounted behind dark glass.

It also has stable performance over a wide temperature range, suitable for measuring the present ambient light. Ambient 17 Click communicates with MCU using the standard I2C 2-Wire interface to read data and configure settings, supporting Standard Mode operation with a clock frequency of 100kHz and Fast Mode up to 400kHz. It also possesses an additional interrupt signal, routed on the INT pin of the mikroBUS™ socket labeled as INT, indicating when a specific interrupt event occurs, such as detecting a meaningful change in light intensity. An interrupt is generated when an ALS

conversion's value exceeds an upper or lower threshold. In addition, a programmable interrupt persistence feature allows the user to determine how many consecutive exceeded thresholds are necessary to trigger an interrupt. 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.

Ambient 17 Click top side image
Ambient 17 Click bottom side image

Features overview

Development board

Curiosity PIC32 MZ EF development board is a fully integrated 32-bit development platform featuring the high-performance PIC32MZ EF Series (PIC32MZ2048EFM) that has a 2MB Flash, 512KB RAM, integrated FPU, Crypto accelerator, and excellent connectivity options. It includes an integrated programmer and debugger, requiring no additional hardware. Users can expand

functionality through MIKROE mikroBUS™ Click™ adapter boards, add Ethernet connectivity with the Microchip PHY daughter board, add WiFi connectivity capability using the Microchip expansions boards, and add audio input and output capability with Microchip audio daughter boards. These boards are fully integrated into PIC32’s powerful software framework, MPLAB Harmony,

which provides a flexible and modular interface to application development a rich set of inter-operable software stacks (TCP-IP, USB), and easy-to-use features. The Curiosity PIC32 MZ EF development board offers expansion capabilities making it an excellent choice for a rapid prototyping board in Connectivity, IOT, and general-purpose applications.

Curiosity PIC32MZ EF double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

PIC32

MCU Memory (KB)

2048

Silicon Vendor

Microchip

Pin count

100

RAM (Bytes)

524288

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
Interrupt
RF13
INT
NC
NC
TX
NC
NC
RX
I2C Clock
RPA14
SCL
I2C Data
RPA15
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Schematic

Ambient 17 Click Schematic schematic

Step by step

Project assembly

Curiosity PIC32MZ EF front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Curiosity PIC32 MZ EF as your development board.

Curiosity PIC32MZ EF front image hardware assembly
Thermo 28 Click front image hardware assembly
Prog-cut hardware assembly
Curiosity PIC32 MZ EF 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
Curiosity PIC32 MZ EF 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

After loading the code example, pressing the "DEBUG" button builds and programs it on the selected setup.

Application Output Step 1

After programming is completed, a header with buttons for various actions available in the IDE appears. By clicking the green "PLAY "button, we start reading the results achieved with Click board™.

Application Output Step 3

Upon completion of programming, the Application Output tab is automatically opened, where the achieved result can be read. In case of an inability to perform the Debug function, check if a proper connection between the MCU used by the setup and the CODEGRIP programmer has been established. A detailed explanation of the CODEGRIP-board connection can be found in the CODEGRIP User Manual. Please find it in the RESOURCES section.

Application Output Step 4

Software Support

Library Description

This library contains API for Ambient 17 Click driver.

Key functions:

  • ambient17_get_int_pin - This function returns the INT pin logic state

  • ambient17_set_atime - This function sets the ATIME register for the selected ALS integration time

  • ambient17_measure_light_level - This function reads the raw ADC data from two channels and then measures the light level in lux based on those readings

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 Ambient17 Click example
 *
 * # Description
 * This example demonstrates the use of Ambient 17 click board by measuring 
 * the ambient light level in Lux.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and performs the click default configuration.
 *
 * ## Application Task
 * Waits for the data ready interrupt, then reads the ambient light level in Lux
 * and displays the results on the USB UART. By default, the data ready interrupt triggers 
 * upon every ADC cycle which will be performed every 200ms.
 *
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "ambient17.h"

static ambient17_t ambient17;
static log_t logger;

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    ambient17_cfg_t ambient17_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.
    ambient17_cfg_setup( &ambient17_cfg );
    AMBIENT17_MAP_MIKROBUS( ambient17_cfg, MIKROBUS_1 );
    if ( I2C_MASTER_ERROR == ambient17_init( &ambient17, &ambient17_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    if ( AMBIENT17_ERROR == ambient17_default_cfg ( &ambient17 ) )
    {
        log_error( &logger, " Default configuration." );
        for ( ; ; );
    }
    
    log_info( &logger, " Application Task " );
}

void application_task ( void ) 
{
    if ( !ambient17_get_int_pin ( &ambient17 ) )
    {
        uint16_t lux;
        if ( AMBIENT17_OK == ambient17_measure_light_level ( &ambient17, &lux ) )
        {
            log_printf ( &logger, " Ambient light level [Lux]: %u\r\n\n", lux );
        }
    }
}

void main ( void ) 
{
    application_init( );

    for ( ; ; ) 
    {
        application_task( );
    }
}

// ------------------------------------------------------------------------ END

Additional Support

Resources