pdf-icon

Ltr553

The M5CoreS3 comes with a built-in LTR553 proximity sensor. Reference the API & examples below to implement proximity state reading.

begin()

Functionality:

  • Initializes the proximity sensor

Prototype:

bool begin(Ltr5xx_Init_Basic_Para *init_base_para)

bool begin(Ltr5xx_Init_Interrupt_Para *init_interrupt_para)

Parameters:

Parameter Type Description
init_base_para Ltr5xx_Init_Basic_Para * Basic monitoring initialization
init_interrupt_para Ltr5xx_Init_Interrupt_Para * Interrupt monitoring initialization

Return Values:

Return Value Description
true Initialization successful
false Initialization failed

setPsMode()

Functionality:

  • Initializes the proximity sensor

Prototype:

bool setPsMode(uint8_t mode)

Parameters:

Parameter Type Description
mode uint8_t 1: Enable proximity sensor monitoring
0: Sensor standby

Return Values:

Return Value Description
true Initialization successful
false Initialization failed

setAlsMode()

Functionality:

  • Initializes the proximity sensor

Prototype:

bool setAlsMode(uint8_t mode)

Parameters:

Parameter Type Description
mode uint8_t 1: Enable ambient light sensor monitoring
0: Sensor standby

Return Values:

Return Value Description
true Initialization successful
false Initialization failed

getPsValue()

Functionality:

  • Retrieves the proximity sensor value

Prototype:

uint16_t getPsValue(void)

Parameters:

  • None

Return Values:

Return Value Description
uint16_t Monitored proximity value

getAlsValue()

Functionality:

  • Retrieves the ambient light sensor value

Prototype:

uint16_t getAlsValue(void)

Parameters:

  • None

Return Values:

Return Value Description
uint16_t Monitored ambient light lux

Example Usage:

#include "M5CoreS3.h"

Ltr5xx_Init_Basic_Para device_init_base_para = LTR5XX_BASE_PARA_CONFIG_DEFAULT;

uint16_t read_ps_value;
uint16_t read_als_value;

void setup() {
    auto cfg = M5.config();
    CoreS3.begin(cfg);
    CoreS3.Display.setTextColor(GREEN);
    CoreS3.Display.setTextDatum(middle_center);
    CoreS3.Display.setFont(&fonts::Orbitron_Light_24);
    CoreS3.Display.setTextSize(1);

    device_init_base_para.ps_led_pulse_freq   = LTR5XX_LED_PULSE_FREQ_40KHZ;
    device_init_base_para.ps_measurement_rate = LTR5XX_PS_MEASUREMENT_RATE_50MS;
    device_init_base_para.als_gain            = LTR5XX_ALS_GAIN_48X;

    if (!CoreS3.Ltr553.begin(&device_init_base_para)) {
        CoreS3.Display.drawString("Ltr553 Init Fail",
                                  CoreS3.Display.width() / 2,
                                  CoreS3.Display.height() / 2);
        while (1) {
            delay(10);
        }
    }

    CoreS3.Display.drawString("Ltr553 Init Success", CoreS3.Display.width() / 2,
                              CoreS3.Display.height() / 2);
    // Activate proximity sensor
    CoreS3.Ltr553.setPsMode(LTR5XX_PS_ACTIVE_MODE);

    // Activate ambient light sensor
    CoreS3.Ltr553.setAlsMode(LTR5XX_ALS_ACTIVE_MODE);
    // Deactivate proximity sensor
    // CoreS3.Ltr553.setPsMode(LTR5XX_PS_STAND_BY_MODE);

    // Deactivate ambient light sensor
    // CoreS3.Ltr553.setAlsMode(LTR5XX_ALS_STAND_BY_MODE);
}

void loop() {
    CoreS3.Display.clear();
    read_ps_value  = CoreS3.Ltr553.getPsValue();
    read_als_value = CoreS3.Ltr553.getAlsValue();

    CoreS3.Display.drawString(
        "PS:" + String(read_ps_value) + " / " + "ALS:" + String(read_als_value),
        CoreS3.Display.width() / 2, CoreS3.Display.height

() / 2);

    Serial.printf("ps value = %d\r\n", read_ps_value);
    Serial.printf("als value = %d\r\n", read_als_value);
    delay(100);
}
On This Page