Intermediate
30 min

Determine if something is nearby or not using VCNL4035X01 and PIC32MZ2048EFM100

Unlocking the potential of close-range sensing

Proximity 5 Click with Curiosity PIC32 MZ EF

Published Oct 14, 2023

Click board™

Proximity 5 Click

Dev Board

Curiosity PIC32 MZ EF

Compiler

NECTO Studio

MCU

PIC32MZ2048EFM100

Discover how our cutting-edge proximity detection technology is reshaping how we interact with the world around us

A

A

Hardware Overview

How does it work?

Proximity 5 Click is based on the VCNL4035X01, a fully integrated proximity and ambient light sensor with I2C interface and the interrupt function for gesture applications, from Vishay Semiconductors. This sensor features very advanced 16bit Ambient Light Sensor (ALS) which makes use of the proprietary Filtron™ technology, providing spectral response sensitivity near to human eye. The ALS sensor also effectively cancels out infrared light, has immunity to the flickering of fluorescent light sources and has a programmable detection range, with the resolution of up to 0.004 lux per count. The Proximity Sensing (PS) section of the VCNL4035X01 J IC implements several solutions for the improved proximity detection of objects of any color. It relies on detection of the reflected IR light from the emitting LEDs. Features such as the immunity to a red glow, intelligent crosstalk phenomenon reduction, smart persistence scheme, programmable IR LED current, and selectable sampling resolution, help in achieving a reliable and accurate proximity detection. The processed readings of the ALS and PS sections can be fetched from the respective registers via the I2C interface. The I2C bus lines are routed to the respective mikroBUS™ I2C pins:

SCL is the I2C clock and SDA is the I2C data line. The VCNL4035X01 J sensor IC integrates three independent LED drivers, which can drive the external IR LEDs with up to 200mA, allowing a wide range of external IR LEDs to be used. Proximity 5 click uses the VSMY2850RG LEDs, 850nm IR LEDs with lenses, from Vishay. These IR LEDs are operating within the wavelength range which is recommended by the sensor manufacturer. The IR LEDs can be driven by the variable duty cycle, which affects the total power consumption, as well as the PS response time. The VCNL4035X01 J sensor IC is powered by the 3.3V rail from the mikroBUS™ directly. However, since it uses the I2C communication protocol, it is possible to choose the voltage for the I2C pull-up resistors between 3.3V and 5V. This is accomplished by moving the SMD jumper labeled as VCCIO SEL to the appropriate position. This jumper allows communication with both 3.3V and 5V MCUs. Proximity 5 click offers programmable interrupt engine. The INT pin is routed to the mikroBUS™ INT pin and it is pulled up by the onboard resistor. When asserted, it is driven to a LOW logic level. The interrupt can be programmed for a wide range of events for both ALS and PS sections:

ALS threshold window with two 16bit values for the upper and lower threshold levels, ALS Persistence which affects the integration time before an interrupt is triggered. The PS section offers similar interrupt sources, with the addition of the object detection which triggers an interrupt if the object is detected and PS Active Force mode. This last mode is used when more conservative power consumption is required, as it allows one reading to be made, before reverting back to the standby mode. When the interrupt event occurs, a flag is set in the status register. To detect a gesture, the Gesture Enable bit has to be set, and the sensor has to be configured to work in the PS Active Force mode. When a trigger bit for the reading is set, all three LEDs will be sequentially triggered. The result will be flagged by the gesture data ready flag and the data can be read from the appropriate register. Also, the interrupt line can be asserted if set so. The provided library offers functions used to read the data and configure the Proximity 5 click in an easy way. The provided example application demonstrates using these functions. It can be used as a reference for a custom design.

Proximity 5 Click top side image
Proximity 5 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
Power Supply
5V
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

Proximity 5 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 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 Proximity 5 Click driver.

Key functions:

  • proximity5_get_values - Starts the conversion and waits for the interrupt to finish. After the interrupt finishes the proximity data from the proximity registers is returned to a 3 member uint16_t array.

  • proximity5_get_id - Read the ID from the ID register of the sensor.

  • proximity5_read_reg - Generic function for reading both high and low register value and returns those combined values to a 16bit variable.

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 Proximity5 Click example
 * 
 * # Description
 * This application enables usage of the proximity and ablient light sensing.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Configures the micro controller for communication
 * and initializes the click board. 
 * 
 * ## Application Task  
 * The proximity data is read from the sensor and it is printed
 * to the UART.
 * 
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "proximity5.h"

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

static proximity5_t proximity5;
static log_t logger;

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

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

    proximity5_cfg_setup( &cfg );
    PROXIMITY5_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    proximity5_init( &proximity5, &cfg );

    proximity5_default_cfg( &proximity5 );
}

void application_task ( void )
{
    //  Task implementation.

    uint16_t bff[ 4 ];

    proximity5_get_values( &proximity5, bff );
 
    log_printf( &logger, "PS1 %d  ", bff[ 0 ] );
    
    log_printf( &logger, "PS2 %d  ", bff[ 1 ] );
    
    log_printf( &logger, "PS3 %d \r\n\r\n", bff[ 2 ] );

    Delay_ms( 500 );
}

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.