LD2410Async
Asynchronous Arduino ESP32 library for the LD2410 mmWave radar sensor
Loading...
Searching...
No Matches
changeDistanceResolution.ino File Reference
#include <Arduino.h>
#include "LD2410Async.h"

Go to the source code of this file.

Macros

#define RADAR_RX_PIN   16
 Example: Changing detection resolution on LD2410.
 
#define RADAR_TX_PIN   17
 
#define RADAR_BAUDRATE   256000
 

Functions

HardwareSerial RadarSerial (1)
 
void onReboot (LD2410Async *sender, LD2410Async::AsyncCommandResult result)
 Callback after the reboot command has been confirmed.
 
void onConfigApplied (LD2410Async *sender, LD2410Async::AsyncCommandResult result)
 Callback after applying modified config.
 
void onConfigReceived (LD2410Async *sender, LD2410Async::AsyncCommandResult result)
 Callback after requesting config data.
 
void setup ()
 Arduino setup function which initializes the radar and starts the config change process.
 
void loop ()
 Arduino loop function which does nothing.
 

Variables

LD2410Async radar (RadarSerial)
 Creates LD2410Async object bound to the serial port defined in RadarSerial.
 

Macro Definition Documentation

◆ RADAR_BAUDRATE

#define RADAR_BAUDRATE   256000

Definition at line 28 of file changeDistanceResolution.ino.

◆ RADAR_RX_PIN

#define RADAR_RX_PIN   16

Example: Changing detection resolution on LD2410.

This sketch demonstrates how to:

  1. Initialize the radar on Serial1.
  2. Query all current configuration values from the sensor.
  3. Clone the config into a local variable.
  4. Modify the distance resolution.
  5. Apply the new config.
  6. Reboot the sensor to ensure changes take effect.
Warning
Important: Make sure to adjust RADAR_RX_PIN and ADAR_TX_PIN to match you actual wiring.

Definition at line 24 of file changeDistanceResolution.ino.

◆ RADAR_TX_PIN

#define RADAR_TX_PIN   17

Definition at line 25 of file changeDistanceResolution.ino.

Function Documentation

◆ loop()

void loop ( )

Arduino loop function which does nothing.

The LD2410Async library runs a FreeRTOS background task that automatically handles all jobs that are related to the radar sensor. Therefore the main loop doesnt have to da any LD2410 related work and is free for anything else you might want to do.

Definition at line 172 of file changeDistanceResolution.ino.

◆ onConfigApplied()

void onConfigApplied ( LD2410Async * sender,
LD2410Async::AsyncCommandResult result )

Callback after applying modified config.

After checking if the async configureAllConfigSettingsAsync() method was successful (always do that!), it will initiate a reboot of the sensor to activate the changed distance resolution.

Note
Always check the result of the async command that has triggered the callback. Otherweise async commands can fail, timeout or get canceled without you relizing it. In callback methods is is generally advised to access members of the LD2410Async instance via the sender pointer. This ensures that you are allways working with the correct instance, which is important if you have multiple LD2410Async instances. Also keep in mind that callbacks should be as short and efficient as possible to avoid blocking the background task of the library.

Definition at line 70 of file changeDistanceResolution.ino.

◆ onConfigReceived()

void onConfigReceived ( LD2410Async * sender,
LD2410Async::AsyncCommandResult result )

Callback after requesting config data.

This method is called when the config data has been received from the sensor. After checking if the async requestAllConfigSettingsAsync() method was successful (always do that!), it clones the config using getConfigData(), modifies the distance resolution and applies the new config using configureAllConfigSettingsAsync()

Note
Always check the result of the async command that has triggered the callback. Otherweise async commands can fail, timeout or get canceled without you relizing it. In callback methods is is generally advised to access members of the LD2410Async instance via the sender pointer. This ensures that you are allways working with the correct instance, which is important if you have multiple LD2410Async instances. Also keep in mind that callbacks should be as short and efficient as possible to avoid blocking the background task of the library.

Definition at line 101 of file changeDistanceResolution.ino.

◆ onReboot()

void onReboot ( LD2410Async * sender,
LD2410Async::AsyncCommandResult result )

Callback after the reboot command has been confirmed.

This method just checks and prints the result

Definition at line 48 of file changeDistanceResolution.ino.

◆ RadarSerial()

HardwareSerial RadarSerial ( 1 )

Create a HardwareSerial instance (ESP32 has multiple UARTs) bound to UART1

◆ setup()

void setup ( )

Arduino setup function which initializes the radar and starts the config change process.

begin() starts the background task of the LD2410Async library which automatically handles incoming data and triggers callbacks. The onDetectionDataReceived callback is registered to receive detection data. requestAllConfigSettingsAsync() will fetch all config data from the sensor and triggers the onConfigReceived callback when done.

Definition at line 137 of file changeDistanceResolution.ino.

Variable Documentation

◆ radar

Creates LD2410Async object bound to the serial port defined in RadarSerial.