Beginner
10 min

Unlock the hidden UV world with ML8511A and PIC18F57Q43

See beyond the spectrum

UV Click with Curiosity Nano with PIC18F57Q43

Published Feb 13, 2024

Click board™

UV Click

Dev Board

Curiosity Nano with PIC18F57Q43

Compiler

NECTO Studio

MCU

PIC18F57Q43

Illuminate your surroundings with our UV intensity detector

A

A

Hardware Overview

How does it work?

UV Click is based on the ML8511A, an ultraviolet light sensor suitable for acquiring UV intensity indoors or outdoors from Rohm Semiconductor. The ML8511A is equipped with an internal amplifier converting photocurrent to voltage depending on the UV intensity working with a wavelength between 280-390nm (sensitive to UV-A (315-365nm) and UV-B (280-315nm) rays). After that, the MP8511A outputs an analog signal concerning the detected amount of UV light (mW/cm2). The output signal of the ML8511A can be converted

to a digital value using MCP3201, a successive approximation A/D converter with a 12-bit resolution from Microchip using a 3-wire SPI compatible interface, or can be sent directly to an analog pin of the mikroBUS™ socket labeled as AN. Selection can be performed by onboard SMD jumper labeled as A/D SEL, placing it in an appropriate position marked as AN or ADC. Also, the ML8511A can be enabled or disabled through the EN pin routed to the RST pin of the mikroBUS™ socket, hence, offering a switch

operation to turn Active or Stand-by mode of operation depending on the set logic level. 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. However, the Click board™ comes equipped with a library containing functions and an example code that can be used, as a reference, for further development.

UV Click hardware overview 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

Analog Signal
PA0
AN
Enable
PA7
RST
SPI Chip Select
PD4
CS
SPI Clock
PC6
SCK
SPI Data OUT
PC5
MISO
SPI Data IN
PC4
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
NC
NC
INT
NC
NC
TX
NC
NC
RX
NC
NC
SCL
NC
NC
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Schematic

UV 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
Barometer 13 Click front image hardware assembly
PIC18F57Q43 Curiosity Nano front image hardware assembly
Prog-cut hardware assembly
Curiosity Nano with PICXXX 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 UV Click driver.

Key functions:

  • uv_read_data - Read 12-bit UV data function

  • uv_set_poewr_mode - Set power mode 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 UV Click Driver Example
 *
 * # Description
 * This is a example which demonstrates the use of UV Click board.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Configuration of the click and log objects.
 *
 * ## Application Task
 * This is a example which demonstrates the use of the UV Click board.
 * This example should read a result of AD conversion and calculate it to UV
 * index level.
 * Results are being sent to the Usart Terminal where you can track their
 * changes.
 * All data logs on usb uart is changed for every 1 second.
 *
 * \author Nemanja Medakovic
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "uv.h"

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

static uv_t uv;
static log_t logger;

static float uv_voltage;
static uint8_t uv_index;

// ------------------------------------------------------- ADDITIONAL FUNCTIONS

void application_callback ( uint8_t *message )
{
    log_printf( &logger, "*** %s ***\r\n", message );
}

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

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

    uv_cfg_setup( &cfg );
    UV_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    if ( uv_init( &uv, &cfg ) == SPI_MASTER_ERROR )
    {
        log_info( &logger, "---- Application Init Error ----" );
        log_info( &logger, "---- Please, run program again ----" );

        for ( ; ; );
    }
    uv_set_callback_handler( &uv, application_callback );
    uv_device_enable( &uv );
    Delay_ms( 1000 );
    uv_voltage = 0;
    uv_index = 0;
    log_info( &logger, "---- Application Init Done ----\r\n" );
}

void application_task ( void )
{
    if ( uv_read_adc_voltage( &uv, &uv_voltage ) != SPI_MASTER_ERROR )
    {
        uv_calc_index( &uv, uv_voltage, &uv_index );

        log_printf( &logger, " UV Index [0-15] : %u\r\n", (uint16_t)uv_index );
        log_printf( &logger, " UV ADC Voltage [V] : %.2f\r\n", uv_voltage );
        log_printf( &logger, "------------------------------\r\n" );
    }

    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.