Labs / Electronic modules

GraftSense - UV Monitoring Module Based on SI1145 (Open Version)

Author: Li Zisheng · Source: FreakStudio open documentation, v1.1 · License: CC BY 4.0 · Driver code (sensors/si1145_driver): MIT License

Contents
SI1145
SI1145 V1.1.0 U3 3.3V

I. Module Introduction

UV monitoring module based on SI1145, which adopts the Silicon Labs SI1145 3-in-1 optical sensor solution, integrates infrared LED, optical shielding and signal processing circuits, and can simultaneously realize UV index detection, ambient light detection and proximity detection within 1cm~50cm; the module is equipped with LDO voltage regulator circuit, power filtering and indicator circuit, powered by 3.3V and communicates with the main controller via the I²C interface, supports autonomous periodic measurement and interrupt triggering, and is suitable for scenarios such as wearable devices, smart homes, screen dimming, and gesture sensing.

II. Introduction to Main Chips

SI1145 is Silicon Labs 's low-power, highly integrated optical sensor chip that can simultaneously detect ambient light, ultraviolet index, and infrared proximity and output digital signals via the I²C interface.

2.1 Chip Overview

Si1145/46/47 SI1145

SI1145 is a Silicon Labs launched low-power integrated optical sensor chip, which adopts the QFN-10 package, and realizes synchronous detection of infrared proximity (with a detection distance up to 50cm), UV index and ambient light through the I²C interface. It features high sensitivity, low power consumption (with an average current of only 9μA), EMI interference resistance and other characteristics, supports operation in a wide temperature range of -40~85℃, and is widely used in consumer electronics, smart home, industrial automation and other scenarios.

2.2 Pin Definition

SI1145 QFN-10 LED2/CVDD LED3/CVDD LED1 1 3

SI1145 adopts the QFN-10 package with clearly defined core pin functions: Pin 1 is SDA, Pin 2 is SCL — these two pins serve as the I²C communication interface; Pin 3 is VDD for power supply; Pin 4 is INT as open-drain interrupt output; Pin 8 is GND for ground connection; Pins 6/7/9 (LED2 / CVDD, LED3 / CVDD, LED1) are programmable constant-current sink outputs, used to drive infrared LED s for proximity detection, and can be directly connected to VDD when unused; Pins 5 and 10 are no-connect pins that require floating treatment.

2.3 Functional Block Diagram

SI1145

The SI1145 chip uses its on-chip visible light and infrared photodiodes to collect ambient light, ultraviolet and reflection signals, which are sent through a multiplexer to an ADC for conversion. After digital filtering, the signals are processed by the control logic: on one hand, it drives the LED driver to output infrared LED signals to achieve proximity detection; on the other hand, it stores the data in registers and communicates with the main controller via the I²C interface. It also supports interrupt output and power management, enabling multi-parameter optical sensing at low power consumption.

2.4 Performance Parameters

SI1145 1.71 3.6V 40 85 0.7VDD 0.3VDD 128klx

SI1145 has a supply voltage of 1.71-3.6V and an operating temperature range of -40 to 85°C. For the I²C interface, the high and low level thresholds are 0.7 VDD and 0.3 VDD respectively; the infrared LED has a typical emission wavelength of 850nm, a maximum supply voltage of 4.3V, can withstand a maximum illuminance of 128klx under direct sunlight, and the device start-up time is no less than 25ms, which provides key parameter basis for design and application.

SI1145

SI1145 absolute maximum operating conditions: supply voltage VDD range - 0.3~4V, operating temperature - 40~85℃, storage temperature - 65~85℃;LED pins and I/O pins have a maximum voltage rating of 3.6V, the total LED current is up to 500mA, and the ground current is up to 600mA;ESD protection level: 2kV for both human body model and charged device model, 225V for machine model. Exceeding these parameters will cause permanent damage to the device.

2.5 Reference Circuit

Si1145 3.3V 0.1 LED1 30 15

3.3V power supply powers the chip;VDD pin is accompanied by a 0.1μF capacitor for power filtering;SDA and SCL implement I²C communication via pull-up resistors;INT pin is directly connected to the host to output interrupt signals;LED1 pin drives an infrared LED through a 30Ω current-limiting resistor, and cooperates with a 15μF capacitor to filter out ripples, realizing the infrared emission function required for proximity detection. The chip receives the reflected signal through a built-in photodiode, and finally outputs ambient light, ultraviolet index and proximity detection data to the host via the I²C interface.

2.6 Chip Configuration

None.

2.7.1 IIC Communication

SI1145/46/47 0x60 7 SI1145

SI1145 has three pins on its host interface, including SCL, SDA and INT. Among them, SCL / SDA are standard I²C open-drain pins, and INT is an open-drain interrupt output requiring an external pull-up resistor;The chip I²C slave address is 0x60, which supports 7-bit addressing, burst read/write and automatic address increment. A write operation starts with a start condition + device address + register address; for a read operation, the address must be sent first before data is read. It also supports a global reset command, and the master can obtain measurement data via interrupt or direct reading, while attention should be paid to the consistency issue of double-byte measurement reading.

SI1145/48/47 12 13 17 6 SI1145

SI1145 I²C Communication Timing and Operation Format: It covers the complete procedures of standard bit timing, single-byte read/write, and burst read/write. The register address is 6 bits (0x00 – 0x3F), and supports turning off automatic address increment via the AI bit. Communication follows the standard I²C protocol consisting of start, address + R/W, acknowledge, data transmission, and stop. The host and the chip respectively drive the corresponding signals and confirm the transmission status via ACK / NACK.

2.7.2 Registers

2.7.2.1 Register Programming Guide
SI1145 SI1145/46/47

SI1145 chip supports forced measurement and autonomous operation two operating modes: In forced mode, measurement is only triggered when the host writes to the command register, delivering the lowest power consumption; in autonomous mode, the chip wakes up at the cycle set by the non-zero MEAS_RATE parameter, completes proximity and ambient light measurement in the channel order configured by the CHLIST parameter, and measurement data can be accessed via I²C registers or the parameter RAM, enabling flexible power consumption and measurement control.

2.7.2.2 Register Resource Allocation
SI1145 100aaaaa 4 0
SI1145

SI1145 Command Protocol and Status Feedback Mechanism: The host sends commands via the COMMAND register to implement functions including single forced measurement (ALS / PS / PSALS_FORCE), pausing or starting the autonomous measurement loop (PS / ALS / PSALS_PAUSE / AUTO), parameter read/write (PARAM_QUERY / SET), and software reset.After execution, RESPONSE register will update its status: the lower 4 bits serve as a loop counter, and the upper 4 bits act as an error code, which can feed back faults such as invalid settings and ADC overflow of each channel. The host needs to interact in the fixed sequence of "clear response → verify → send command → read status" to ensure the reliability of communication and measurement.

SI1145 1 3 15 0
SI1145 1 2 3

SI1145 configures the measurement channel resources, and defines the interrupt control and ADC parameter mapping for proximity detection (PS1 / 2 / 3), ambient light (ALS visible light / infrared) and auxiliary measurement channels: the corresponding channels can be enabled via the CHLIST register, and the interrupt status and enable are configured in the IRQ_STATUS and IRQ_ENABLE registers;Meanwhile, parameters of each channel including LED selection, ADC mode, output register, recovery count, signal range, clock frequency division and data alignment are all configured via specific registers to achieve precise control over different measurement channels.

SI1145 LED1 LED2 LED3 LED1_I PSLED12 3 0 31
SI1145 PS1 PS2 PS3 10 11 12 13 1

SI1145 ’s LED1 / 2 / 3 pins' drive current, output control and analog input functions can be configured via corresponding registers;the INT pin is enabled by the INT_CFG register, and interrupt management is implemented through registers such as IRQ_ENABLE and IRQ_STATUS;The interrupts of the PS1 / 2 / 3 and ALS channels can be independently enabled via the IRQ_ENABLE register, which triggers an INT signal after each measurement is completed. The host needs to clear the interrupt flag by reading from and writing to the IRQ_STATUS register to achieve efficient measurement status feedback.

2.7.2.3 I2C Communication Registers
SI1145 I2C 14 7 8 0
SI1145 ALS_VIS_DATA1 0x23 0x24 0x25 0x30 0x3B 0x3E

SI1145 I²C register map covers all functions including chip identification, interrupt control, measurement configuration, data reading and status management: registers such as PART_ID / REV_ID identify chip information, the INT_CFG / IRQ series registers control interrupts, MEAS_RATE sets the measurement period, PS_LEDxx configures infrared LED current, UCOEF stores ultraviolet calibration parameters, COMMAND / RESPONSE implements command interaction, the ALS / PS / AUX_DATA series registers store visible light, infrared, proximity and auxiliary measurement data, and CHIP_STAT reflects the chip's operating status; the host can read from and write to these registers via I²C to complete chip configuration, control and data reading.

SI1145 0x00 0x0100 0101 Si1145 0110 Si1146 0111 Si1147 0x01

SI1145 has three read-only identification registers: PART_ID (0x00), REV_ID (0x01) and SEQ_ID (0x02). PART_ID has different reset values to distinguish specific models (SI1145 is 0x45, SI1146 is 0x46, SI1147 is 0x47);REV_ID is fixed at 0x00, representing the chip revision;SEQ_ID The reset value is 0x08, which identifies the internal sequencer version (e. g., A10 version). The host can identify the chip model and version information by reading these registers.

SI1145 0x03 0 1

SI1145 's INT_CFG register (address 0x03) is used to configure the output enable of the interrupt pin INT: only bit0 (INT_OE) of this register is valid, with a reset value of 0, and the remaining bits are reserved. When INT_OE = 0, the INT pin is never driven; when INT_OE = 1, as long as the IRQ_STATUS bits match the corresponding IRQ_ENABLE bits, the INT pin will be pulled low to send an interrupt signal to the host.

SI1145 0x04 0000 bit7 6 5 2 1 bit4 PS3

SI1145 IRQ_ENABLE register (address 0x04) is used to enable the interrupts of each measurement channel: this register is readable and writable with a reset value of 0, in which bit4 to 2 are the interrupt enable bits for the PS3, PS2, and PS1 channels respectively, bit0 is the interrupt enable bit for the ALS (visible light / infrared / ultraviolet) channel, and bit7 to 5 as well as bit1 are reserved bits.When the corresponding bit is set to 1, as long as the measurement of the corresponding channel is completed and the IRQ_STATUS register is set, the INT pin will be pulled low to trigger an interrupt; when set to 0, the interrupt trigger of this channel is masked.

SI1145 0x07 MEAS_RATE0 0x08 7 0x17 Si114x 0 MEAS_RATE1 16

Two key registers of the SI1145: HW_KEY (0x07) and MEAS_RATE0 (0x08).

HW_KEY Register (Address 0x07): To ensure normal operation of the chip, the host must write 0x17 to this register; otherwise, the device will fail to enter normal operating state.

MEAS_RATE0 Register (Address 0x08): It, together with MEAS_RATE1 (0x09), forms a 16-bit MEAS_RATE value, which is used to set the wake-up period in automatic measurement mode with a unit of 31.25μs. When this value is 0, the chip operates in forced measurement mode; when it is non-zero, the chip will automatically wake up at the set period and complete all measurements specified by the CHLIST register.

Si1145/67 MEAS_RATE1 0x09 16 8 7 0 15 31.25 0x01

MEAS_RATE1 register (address 0x09), which together with MEAS_RATE0 (0x08) forms a 16-bit MEAS_RATE value, serving as the upper 8 bits to store period configuration data. When this value is multiplied by 31.25μs, the result is the wake-up interval in automatic measurement mode, and the device will perform all measurements specified by CHLIST according to this period. In addition, the document also notes that some older versions of the chip have an errata issue regarding the address of this register.

SI1145 PS_LED21 0x0F PS_LED3 0x10 4 LED2_I 0 LED1_I 0000

SI1145 has two infrared LED current configuration registers:

PS_LED21 (Address 0x0F): The upper 4 bits LED2_I control the drive current of the LED2 pin, which must be set to 0 on the SI1145; the lower 4 bits LED1_I control the current of the LED1 pin, with the code ranging from 0000 (no current) to 1111 (maximum current).

PS_LED3 (Address 0x10): Only the lower 4 bits of LED3_I are valid, which control the drive current of the LED3 pin. The encoding rule is consistent with the above, and this bit must be set to 0 on the SI1145.

SI1145 0x17 0x0000 0000 7 0 0x18

The two interaction registers of SI1145:

SI1145 0x20 8 0 4 1 0x80 0x88 PS1

SI1145 's RESPONSE register (address 0x20), which serves as the status feedback register for command processing: its upper 4 bits act as an error code (when the MSB is set to 1, it indicates an error), and its lower 4 bits function as a loop counter when no error occurs. When there is no error (the value ranges from 0x00 to 0x0F), the lower 4 bits increment as commands are executed;When an error occurs, a specific error code will be written (e. g., 0x80 for invalid command, 0x88 ~ 0x8E for ADC overflow of each channel). The error code will remain until a RESET or NOP command is received, and the host can read this register to determine the command execution result and device status.

I2C 0x21 ALS_VIS_DATA0 0x22 0000

IRQ_STATUS (Address 0x21): Interrupt status register, which records the measurement completion status of each channel. bit5 is the command interrupt flag, bit4 ~ 2 are the interrupt flags for the PS3, PS2, and PS1 channels respectively, and bit0 is the interrupt flag for the ALS channel. When the corresponding bit and the corresponding bit in the IRQ_ENABLE register are both set to 1, the INT pin will be pulled low to trigger an interrupt, and the host can clear the corresponding flag by writing a 1 to it.

ALS_VIS_DATA0 (Address 0x22): Low-byte register for visible light ambient light measurement data, which forms a 16-bit measurement result together with ALS_VIS_DATA1 (0x23). In automatic measurement mode, this register must be read after the INT pin is triggered and before the next measurement starts to prevent data from being overwritten.

ALS_VIS_DATA1 ALS_IR_DATA0 ALS_IR_DATA1 8 0x23 0x0000 0000 0x24 0x25 I2C

ALS_VIS_DATA1 (Address 0x23): The upper 8 bits (MSB) of the visible light ambient light measurement data, which forms a complete 16-bit measurement result together with ALS_VIS_DATA0 (0x22).

ALS_IR_DATA0 (Address 0x24): Lower 8 bits (LSB) of the infrared ambient light measurement data.

ALS_IR_DATA1 (address 0x25): the upper 8 bits (MSB) of the infrared ambient light measurement data, which forms a complete 16-bit measurement result together with ALS_IR_DATA0.

Si1145 PS1_DATA0 PS1_DATA1 PS2_DATA0 PS1_DATA PS2_DATA 0x26 0x28 0x0000 0000

PS1_DATA0, PS1_DATA1 and PS2_DATA0 registers are all read/write with a reset value of 0. In automatic measurement mode, the host must read the data after the INT pin triggers an interrupt and before the next measurement starts to avoid being overwritten by new results. For the reading method, please refer to the chapter on host interrupt latency in "AN498: Si114x Designer's Guide".

SI1145 I2C PS2_DATA1 0x29 PS2 8 PS3_DATA0 0x2A PS3 PS3_DATA1

PS2_DATA1, PS3_DATA0 and PS3_DATA1 registers are all read-write with a reset value of 0. In automatic measurement mode, the host must read the data after the interrupt is triggered by the INT pin and before the next measurement to prevent the result from being overwritten. For specific operations, please refer to the interrupt latency section in "AN498: Si114x Designer's Guide".

AUX_DATA0/UVINDEX0 0x2C AUX_DATA1/UVINDEX1 0x2D 8 16 7 0 15 0x2E

AUX_DATA0/UVINDEX0 (0x2C) and AUX_DATA1/UVINDEX1 (0x2D): correspond to the lower 8 bits and upper 8 bits of the auxiliary measurement (ultraviolet index) data respectively, forming a 16-bit result. In automatic measurement mode, these registers must be read after an INT trigger and before the next measurement to prevent the data from being overwritten.

PARAM_RD (0x2E): A "mailbox" register for the host to read parameters from the internal sequencer, used in conjunction with the PARAM_QUERY command to obtain configuration parameter values.

SI1145 0x30 0x3B 0x3E 31 0 I2C

CHIP_STAT (Address 0x30): A read-only chip status register that reflects the current operating mode of the device.

ANA_IN_KEY (Address 0x3B-0x3E): Read-write register, consisting of 4 bytes to form 32-bit data; it is reserved for future use and requires no user operation.

2.7.2.4 RAM Register
SI1145 PSLED12_SELECT 0

The parameter RAM (Parameter RAM) configuration table of the SI1145 is used to store internal chip parameters that cannot be directly accessed via I²C, and indirect read and write operations on these parameters need to be performed via the PARAM_QUERY and PARAM_SET commands.

SI1145 I2C 0x00 Bit7 Bit0 7 0

SI1145 I2C address configuration parameter (offset 0x00) is a read-write RAM configuration item with a reset value of 0x00.

0x01 0000 7 0 AUX_DATA1 AUX_DATA0

SI1145 's CHLIST parameter (offset 0x01) is used to configure the enable of measurement channels. Its reset value is 0, and it must be set to a non-zero value to perform forced or automatic measurement.

PSLED12_SELECT 0x02 0010 0001 0x21 7 0 6 4 PS2_LED

SI1145 's PSLED12_SELECT parameter (offset 0x02) has a reset value of 0010 0001 (i. e. 0x21), which is used to configure the infrared PS1 and PS2 channel LED driver pins during proximity detection.

0x03 PSLED3_SELECT 0x05 Bit7 Bit2 Bit0 PS3_LED 2 0 00000100
  1. PSLED3_SELECT (offset 0x03, reset value 0x04)
    • Bits [2:0]PS3_LED are used to configure the infrared LED pin driven during PS3 channel proximity detection, with the encoding rule consistent with that of PSLED12_SELECT:
      • 000: No driving of any LED
      • xx1: Drive LED1
      • x1x: Drive LED2 (only supported by Si1146 / 1147, set to 0 for Si1145)
      • 1xx: Drive LED3 (only supported by Si1147;Si1145 / 1146 should be set to 0)
    • The upper 5 bits are reserved bits and shall be set to 0.
  2. PS_ENCODING (Offset 0x05, Reset Value 0x00)
    • Used to configure the data alignment mode of the three proximity detection channels for ADC, and truncate the 17-bit ADC result to 16-bit output:
      • PS3_ALIGN (bit 6), PS2_ALIGN (bit 5), PS1_ALIGN (bit 4): When set to 1, the lower 16 bits of the 17-bit data are taken; when set to 0, the upper 16 bits are taken.
    • The remaining bits are reserved bits and shall be set to 0.
SI1145 0x06 0x00 7 6 3 0 5 1 17

SI1145 ALS_ENCODING parameter (offset 0x06, reset value 0x00) is used to configure the data alignment mode of the ambient light channel ADC.

PS1_ADCMUX 0x07 0x03 PS1 7 0 0x02 1

SI1145 's PS1_ADCMUX parameter (offset: 0x07, reset value: 0x03) is used to configure the ADC input source selection for the PS1 channel.

SI1145 0x08 PS2_ADCMUX 0x09 PS3_ADCMUX 8 00000011 7 PS2 PS3

SI1145 's PS2_ADCMUX (offset 0x08 ) and PS3_ADCMUX (offset 0x09 ) parameters are both readable and writable 8-bit registers with reset values of 0000 0011 (i.e. 0x03 ). ADC input source selection for configuring PS2 and PS3 channels , respectively:

SI1145 0x0A 0x70 2 0 6 4 3 1

SI1145 's PS_ADC_COUNTER parameters (offset 0x0A , reset value 0x70 ) are used to configure the recovery period of the proximity detection ( PS ) channel ADC .

0x0B 0x00 2 0 7 3 0x0 0x4 16 0x5

SI1145 PS_ADC_GAIN parameter (offset: 0x0B, reset value: 0x00) is used to configure the PS (proximity detection) channel's ADC gain.

0x0C 0x04 Bit7 6 Bit4 3 Bit1 0 Bit5 1

PS_ADC_MISC (offset 0x0C, reset value 0x04)

ALS_IR_ADCMUX (Offset: 0x0E, Reset Value: 0x00)

8 0x65 7 0 12 0x1100 6 4 3 1

AUX_ADCMUX (offset 0x0F, reset value 0x65)

ALS_VIS_ADC_COUNTER (Offset: 0x10, Reset Value: 0x70)

SI1145 0x11 00000000 3 2 0 128 0x12 5

ALS_VIS_ADC_GAIN (offset 0x11, reset value 0x00)

ALS_VIS_ADC_MISC (Offset: 0x12, Reset Value: 0x00)

0x1C 8 0x1D 0111 0000 2 0

LED_REC (offset 0x1C)

ALS_IR_ADC_COUNTER (Offset: 0x1D, Reset Value: 0111 0000)

0x1E 0x00 2 0 128 0x0 0x7 64 0x1F 1

ALS_IR_ADC_GAIN (offset 0x1E, reset value 0x00)

ALS_IR_ADC_MISC (Offset 0x1F, Reset Value 0x00)

2.8 PCB Routing Precautions

None.

III. Circuit Engineering

3.1 Circuit Source Engineering

To obtain the source code of the circuit, please follow the official account [Freak Embedded]

3.2 Module Usage Instructions

The schematic diagram of this module is shown below:

SCH_Schematic1_SI1145-based UV monitoring module_v1.0.0_2026-05-11.pdf 2.1 MB

SI1145 LED1 R5 U3 U2 C4-C10 R1 R6-R8

This module provides a IIC communication interface: it supports standard I2C communication rates, is compatible with 3.3V logic levels, and can stably transmit the digital signals of UV index, ambient light intensity and proximity detection collected by SI1145. Suitable for scenarios such as wearable devices, smart homes, screen dimming and gesture sensing, it provides the system with reliable 3-in-1 optical sensing data interaction capability.

3.3 Application Experiment

Here, we use the GraftPort-RP2040 development board for testing, and the SI1145-based ultraviolet monitoring module uses the I2C interface to communicate with the main controller.

Here, we first use the HY2.0-4P cable to connect the module to the GraftPort-RP2040 development board's I2C0 interface:

The module connections are shown in the following table:

Development Board Pins

Module Pins

Description

Pin 4

SDA

I2C data transmission line, corresponding to I2C0 's SDA

Pin 5

SCL

I2C clock signal line, corresponding to the I2C0 SCL

Here, we need to search for the relevant driver packages on uPyPI: https://upypi.net/zh/

106 0.0.20200321 2020 03 22

Enter si1145_driver to search, and the following will be displayed:

si1145_driver 1.0.8 SI1145

Click to copy the local installation command:

si1145_driver SI1145 2026 09 29 1.0.0

Import the module driver library code via the mip tool. Below are the usage commands for the mpremote tool:

mpremote mip install https://upypi.net/pkgs/si1145_driver/1.0.0

Import the UV monitoring module based on SI1145 - MicroPython driver code, then copy the following main.py code into our project:

# Python env   : MicroPython v1.23.0
# -*- coding: utf-8 -*-
# @Time    : 2026/05/06
# @Author  : Nelio Goncalves Godoi
# @File    : main.py
# @Description : Code to test the SI1145 UV/visible light/infrared light/proximity sensor driver class
# @License : MIT

# ======================================== Import Modules =========================================

import time
import micropython
from machine import Pin, SoftI2C
from si1145 import (
    SI1145,
    SI1145_ADDR,
    SI1145_REG_PARTID,
    SI1145_PSALS_PAUSE,
    SI1145_PSALS_AUTO,
    SI1145_PS_FORCE,
    SI1145_ALS_FORCE,
    SI1145_PSALS_FORCE,
    SI1145_RESET,
    SI1145_REG_COMMAND,
)

# ======================================== Global Variables ============================================

# I2C pin and frequency configuration
I2C_SCL_PIN = 5
I2C_SDA_PIN = 4
I2C_FREQ = 100_000

# List of possible I2C addresses for the SI1145 device
TARGET_SENSOR_ADDRS = [0x60, 0x74]

# Device ID register and expected value (SI1145 PART_ID = 0x45)
DEVICE_ID_REG = SI1145_REG_PARTID
DEVICE_ID_EXPECTED = 0x45

# Print interval (ms)
last_print_time = 0
print_interval = 2000

# ======================================== Functions ============================================

def print_realtime_data():
    """Print real-time high-frequency data (high frequency, call commented out by default, can be called manually in the REPL)"""
    # Read the four channels of high-frequency data and print them
    print("UV index: %.2f" % sensor.read_uv)
    print("Visible: %d" % sensor.read_visible)
    print("IR: %d" % sensor.read_ir)
    print("Proximity: %d" % sensor.read_prox)


def switch_to_pause_mode():
    """Switch to paused measurement mode (mode switch, call commented out by default, can be triggered manually in the REPL)"""
    # Write the PSALS_PAUSE command to pause automatic measurement
    sensor._write8(SI1145_REG_COMMAND, SI1145_PSALS_PAUSE)
    print("Sensor switched to PSALS pause mode")


def switch_to_auto_mode():
    """Switch back to automatic continuous measurement mode (mode switch, call commented out by default, can be triggered manually in the REPL)"""
    # Write the PSALS_AUTO command to resume automatic measurement
    sensor._write8(SI1145_REG_COMMAND, SI1145_PSALS_AUTO)
    print("Sensor switched to PSALS auto mode")


def force_single_measurement():
    """Trigger one forced single PS+ALS measurement (batch operation, can be called in the REPL with one command)"""
    # Send the forced single measurement command
    sensor._write8(SI1145_REG_COMMAND, SI1145_PSALS_FORCE)
    # Wait for the measurement to complete
    time.sleep_ms(50)
    print("Forced single measurement done")
    print("UV: %.2f, Visible: %d, IR: %d, Prox: %d" % (
        sensor.read_uv, sensor.read_visible, sensor.read_ir, sensor.read_prox))



def reset_sensor():
    """Software reset the sensor (batch operation, can be called in the REPL with one command)"""
    # Send the reset command and reload the calibration
    sensor._reset()
    sensor._load_calibration()
    print("Sensor reset and recalibrated")


def test_boundary_address():
    """Boundary parameter scenario: instantiate with a legal address boundary value (can be called manually in the REPL)"""
    # The SI1145 address is fixed at 0x60; test the default address as the boundary
    try:
        tmp = SI1145(i2c=i2c_bus, addr=0x60)
        print("Boundary address 0x60 init ok")
        del tmp
    except Exception as e:
        print("Boundary address init failed: %s" % str(e))


def test_invalid_args():
    """Invalid parameter scenario: pass an illegal i2c parameter and verify that ValueError is raised (can be called manually in the REPL)"""
    # Passing None should trigger ValueError
    try:
        SI1145(i2c=None)
        print("Invalid arg test failed: no exception raised")
    except ValueError as e:
        print("Invalid arg test passed: ValueError caught - %s" % str(e))
    except Exception as e:
        print("Invalid arg test got unexpected exception: %s" % str(e))


# ======================================== Custom Classes ============================================

# ======================================== Initialization ==========================================

# Power-on delay, wait for the peripheral to stabilize
time.sleep(3)
print("FreakStudio: Using SI1145 UV/Visible/IR/Proximity sensor ...")

# Initialize software I2C bus
i2c_bus = SoftI2C(sda=Pin(I2C_SDA_PIN), scl=Pin(I2C_SCL_PIN), freq=I2C_FREQ)

# Scan I2C bus devices
print("START I2C SCANNER")
devices_list = i2c_bus.scan()

# Raise an error if there is no device on the bus
if len(devices_list) == 0:
    raise RuntimeError("No I2C device found")
print("I2C devices found: %d" % len(devices_list))

# Iterate over the scan results and match against the target address list
sensor = None
matched_addr = None
for device in devices_list:
    print("I2C address: %s" % hex(device))
    if device in TARGET_SENSOR_ADDRS:
        matched_addr = device

# Raise an error if none of the target addresses is found
if matched_addr is None:
    raise RuntimeError("Device not found at expected address")

# Read the PART_ID register and compare it with the expected value (the SI1145 may return 0x00 before reset, for reference only)
part_id = i2c_bus.readfrom_mem(matched_addr, DEVICE_ID_REG, 1)[0]
if part_id == DEVICE_ID_EXPECTED:
    print("Device found: SI1145 PART_ID=0x%02X at %s" % (part_id, hex(matched_addr)))
else:
    print("PART_ID=0x%02X (expected 0x%02X), attempting init anyway..." % (part_id, DEVICE_ID_EXPECTED))

# Instantiate the SI1145 sensor (the constructor already performs a reset + loads calibration internally)
sensor = SI1145(i2c=i2c_bus, addr=matched_addr)
print("SI1145 initialization successful")

# Record the time of the first print
last_print_time = time.ticks_ms()

# ========================================  Main Program  ===========================================

try:
    while True:
        current_time = time.ticks_ms()
        # Low-frequency core data acquisition: print once every print_interval milliseconds
        if time.ticks_diff(current_time, last_print_time) >= print_interval:
            # Read the UV index
            uv = sensor.read_uv
            # Read the visible light intensity
            vis = sensor.read_visible
            # Read the infrared light intensity
            ir = sensor.read_ir
            # Read the proximity
            prox = sensor.read_prox
            print("UV: %.2f | Visible: %d | IR: %d | Prox: %d" % (uv, vis, ir, prox))
            last_print_time = current_time

        # High-frequency function, commented out by default, can be called manually in the REPL
        # print_realtime_data()
        # Mode switch, commented out by default, can be triggered manually in the REPL
        # switch_to_pause_mode()
        # switch_to_auto_mode()
        # Batch operation, can be called in the REPL with one command
        # force_single_measurement()
        # reset_sensor()
        # Boundary parameter scenario, can be called manually in the REPL
        # test_boundary_address()
        # Invalid parameter scenario, can be called manually in the REPL
        # test_invalid_args()

        time.sleep_ms(10)

except KeyboardInterrupt:
    print("Program interrupted by user")
except OSError as e:
    print("Hardware communication error: %s" % str(e))
except Exception as e:
    print("Unknown error: %s" % str(e))
finally:
    print("Cleaning up resources...")
    # The SI1145 driver does not provide close/deinit; send the reset command to put the device into low-power standby
    try:
        sensor._write8(SI1145_REG_COMMAND, SI1145_RESET)
    except Exception:
        pass
    del sensor
    print("Program exited")

Burn the code, open the terminal, and the output is as follows:

SI1145

Irradiate the sensor with an ultraviolet lamp to change the value of the terminal sensor:

SI1145

SI1145 UV / Visible / IR / Proximity Sensor features normal I2C communication and initialization, and can stably output four-channel data:

IV. Drivers

si1145_driver-1.0.0.zip 13 KB

None.

VI. Revision History

Document Version

Date Modified

Modifier

Modify Content

v1.0

2026-05-11

Ling Gaoxing

Initialize the document

v1.1

2026-06-06

Xin Ruili

Create an open version of the document based on the internal document version v1.0.

7. Relevant Materials

7.1 Chip Datasheet

SI1145-A10-GMR.pdf 1.4 MB

7.2 Unique Icons for PCB Silk Screen

7.2 SI1145