This video, the 14th in a CH32 microcontroller tutorial series, details the integration of a CH32V006K8U6 microcontroller with a TSL2591 light sensor. The tutorial covers advanced I2C communication, the sensor's unique dual-diode architecture for infrared and full-spectrum light detection, and sophisticated interrupt-driven threshold monitoring with optional persistence. The presenter demonstrates custom C code for sensor interaction, including multi-byte I2C transfers, data acquisition, and lux calculation, highlighting the sensor's low power consumption and the microcontroller's cost-effectiveness. A live demonstration showcases real-time light readings and interrupt triggering based on defined thresholds.
Exploring CH32 Microcontrollers and the TSL2591 Light Sensor: Advanced I2C and Interrupts
0:00 Project Introduction: The video initiates the 14th episode of the CH32 tutorial series, focusing on interfacing a CH32V006K8U6 microcontroller with a TSL2591 light sensor, emphasizing the microcontroller's capabilities and its role in an upcoming low-power project.
0:59 TSL2591 Sensor Architecture: The TSL2591 is a light sensor featuring a dual-diode system (infrared and full-spectrum light) with dedicated ADCs for two channels, communicating via a fixed-address I2C bus.
1:38 Flexible Data Polling & Interrupts: The sensor supports continuous light integration and polling, or an interrupt-driven mode where it signals the microcontroller when light levels cross defined upper or lower thresholds.
2:07 Low Power and Minimal Circuitry: Designed for low-power applications (3.3V operation), the sensor requires only a decoupling capacitor and pull-up resistors for its I2C lines (SDA and SCL). The interrupt line can conveniently use the microcontroller's internal pull-up resistor.
2:40 Enhanced I2C Library: The presenter builds upon previous basic I2C implementations, upgrading the send_byte and receive_byte functions to efficiently handle multiple byte transfers, crucial for configuring the TSL2591.
6:46 Command Register (0x00) Functions: The video explains the command register, used for both normal operation (e.g., sending values to registers) and special functions (e.g., clearing various sensor interrupts).
10:25 Enable Register Control: Details on using the enable register to power the device on/off and activate specific functionalities and interrupts within the sensor.
13:08 Control Register for Gain and Integration Time: The control register allows setting the sensor's sensitivity (four gain levels) and light integration time (six options), enabling adaptation to various lighting conditions.
16:16 Advanced ALS Interrupt Thresholds: Comprehensive implementation of 16-bit lower and upper thresholds for ambient light sensing (ALS) interrupts, including "persist" mode (requiring a specified number of consecutive threshold breaches) and "no-persist" mode (immediate triggering).
20:16 Preventing False Interrupts: A critical takeaway is to configure the sensor's interrupt thresholds and persistence values before enabling the interrupts, preventing the microcontroller from being flooded with false triggers upon initialization.
25:16 ALS Data Acquisition: Demonstrates reading the 16-bit full-spectrum and infrared data from the ALS data registers, leveraging the sensor's auto-increment feature to efficiently retrieve both channels.
28:02 Visible Light Extraction & Lux Calculation: The video presents methods to calculate visible light by subtracting infrared data and implements a Lux calculation formula (inspired by Adafruit) using the acquired data, gain, and integration time.
30:10 Microcontroller Interrupt Setup: Detailed explanation of configuring the CH32's PB6 pin as an external interrupt input with an internal pull-up resistor and a falling edge trigger.
35:41 Interrupt Handler and Main Loop: The interrupt service routine sets a flag (lux_interrupt), which the main loop monitors to detect threshold breaches, allowing for responsive processing and serial output.
37:07 Live Demonstration: A practical demonstration using the custom CH32 development board and the TSL2591 sensor showcases real-time light readings and verifies both "no-persist" (immediate interrupt) and "persist" (delayed interrupt after consecutive breaches) functionality by manipulating light exposure.
41:38 Conclusion and Resources: The video concludes by reiterating the successful implementation of the TSL2591 library and the upgraded I2C functions, inviting viewers to explore provided resources (website, GitHub) and support future projects.