### Install espsoftwareserial Library for XIAO ESP32
Source: https://github.com/limengdu/mmwave_for_xiao/blob/main/README.md
This snippet details the process of installing the espsoftwareserial library, which is necessary for using the soft-serial ports on ESP32 series XIAO boards to enable the provided examples. It links to the library's GitHub repository for download.
```html
```
--------------------------------
### Get Sensor Configuration (C++)
Source: https://github.com/limengdu/mmwave_for_xiao/blob/main/README.md
Reads the current configuration parameters of the Seeed_HSP24 sensor. This includes detection distance, stationary detection gates, and unoccupied duration.
```C++
RadarStatus getConfig()
```
--------------------------------
### Get Sensor Software Version (C++)
Source: https://github.com/limengdu/mmwave_for_xiao/blob/main/README.md
Retrieves the software version number of the Seeed_HSP24 radar sensor. This function returns the version as a String.
```C++
String getVersion()
```
--------------------------------
### Get Sensor Status Information (C++)
Source: https://github.com/limengdu/mmwave_for_xiao/blob/main/README.md
Fetches the current status information from the Seeed_HSP24 radar sensor. This includes radar mode, target status, distance, and detailed energy values in engineering mode.
```C++
RadarStatus getStatus()
```
--------------------------------
### Get Distance Resolution (C++)
Source: https://github.com/limengdu/mmwave_for_xiao/blob/main/README.md
Retrieves the current distance resolution setting of the Seeed_HSP24 sensor. Returns the resolution value (1 for 0.25M, 0 for 0.75M).
```C++
RadarStatus getResolution()
```
--------------------------------
### Initialize Seeed_HSP24 Sensor (C++)
Source: https://github.com/limengdu/mmwave_for_xiao/blob/main/README.md
Initializes the Seeed_HSP24 radar sensor by passing the serial port it is connected to. This is the basic initialization function.
```C++
Seeed_HSP24(Stream &serial)
```
--------------------------------
### Initialize Seeed_HSP24 Sensor with Debug (C++)
Source: https://github.com/limengdu/mmwave_for_xiao/blob/main/README.md
Initializes the Seeed_HSP24 radar sensor, allowing for serial debugging output. It requires both the primary serial port and a debug serial port.
```C++
Seeed_HSP24(Stream &serial, Stream &debugSerial)
```
--------------------------------
### Configure and Query mmWave Sensor with XIAO
Source: https://github.com/limengdu/mmwave_for_xiao/blob/main/README.md
This C++ code for Arduino initializes communication with a mmWave sensor using SoftwareSerial. It retrieves the sensor's software version and configuration details such as detection distance, moving set distance, static set distance, and no target duration time. It also includes functionality to restore the sensor to factory settings.
```cpp
#if defined(ARDUINO_SEEED_XIAO_NRF52840_SENSE) || defined(ARDUINO_SEEED_XIAO_NRF52840)
#error "XIAO nRF52840 please use the non-mbed-enable version."
#endif
#include
#include
// Define the SoftwareSerial object, D2 as RX, D3 as TX, connect to the serial port of the mmwave sensor
SoftwareSerial COMSerial(D2, D3);
// Creates a global Serial object for printing debugging information
#define ShowSerial Serial
// Initialising the radar configuration
// Seeed_HSP24 xiao_config(COMSerial, ShowSerial);
Seeed_HSP24 xiao_config(COMSerial);
Seeed_HSP24::RadarStatus radarStatus;
void setup() {
COMSerial.begin(9600);
ShowSerial.begin(9600);
while(!ShowSerial); // Turn on the serial monitor and start executing
delay(500);
ShowSerial.println("Programme Starting!");
ShowSerial.print("Sensor Software Version: ");
ShowSerial.println(xiao_config.getVersion());
radarStatus = xiao_config.getConfig();
if (radarStatus.detectionDistance != -1) {
ShowSerial.println("Detection Distance: " + String(radarStatus.detectionDistance) + " m ");
ShowSerial.println("Moveing Set Distance: " + String(radarStatus.moveSetDistance) + " m ");
ShowSerial.println("Static Set Distance: " + String(radarStatus.staticSetDistance) + " m ");
ShowSerial.println("No Target Duration Time: " + String(radarStatus.noTargrtduration) + " seconds ");
}
else ShowSerial.println("Failed to get configuration information, please retry.");
/*** Restore or reset the radar settings, please operate with caution.
* * After restoring or resetting the factory settings, please re-modify
* * the baud rate to 9600 before using XIAO!
* */
xiao_config.refactoryRadar();
// xiao_config.rebootRadar(); // Reboot the Sensor
}
void loop() {}
```
--------------------------------
### Download mmWave Arduino Library
Source: https://github.com/limengdu/mmwave_for_xiao/blob/main/README.md
Provides a direct link to download the Arduino library for the mmWave sensor. This library is essential for integrating the sensor's functionality with the XIAO microcontroller.
```html
Download the Library
```
--------------------------------
### Set Gate Sensitivity (C++)
Source: https://github.com/limengdu/mmwave_for_xiao/blob/main/README.md
Configures the sensitivity thresholds for different distance gates of the Seeed_HSP24 sensor. Takes the gate, motion sensitivity, and static sensitivity as parameters. Returns a status code.
```C++
AskStatus setGatePower(int gate,int movePower, int staticPower)
```
--------------------------------
### Restore Radar to Factory Settings (C++)
Source: https://github.com/limengdu/mmwave_for_xiao/blob/main/README.md
Restores the Seeed_HSP24 radar sensor to its factory default settings. Returns a status code indicating success or failure.
```C++
AskStatus refactoryRadar()
```
--------------------------------
### Send Custom Command to Sensor (C++)
Source: https://github.com/limengdu/mmwave_for_xiao/blob/main/README.md
Sends a custom command to the Seeed_HSP24 radar sensor. Requires the command data as a byte array and its length. Returns the result buffer and its length.
```C++
DataResult sendCommand(const byte* sendData, int sendDataLength)
```
--------------------------------
### Parse mmWave Sensor Basic Output
Source: https://github.com/limengdu/mmwave_for_xiao/blob/main/README.md
This C++ code snippet demonstrates how to initialize and read basic status information from the mmWave sensor using the Seeed XIAO board. It configures the serial communication, retrieves radar status including target presence and distance, and prints this information. The code includes error handling for sensor status and a helper function to convert status codes to human-readable strings.
```cpp
#if defined(ARDUINO_SEEED_XIAO_NRF52840_SENSE) || defined(ARDUINO_SEEED_XIAO_NRF52840)
#error "XIAO nRF52840 please use the non-mbed-enable version."
#endif
#include
#include
// Define the SoftwareSerial object, D2 as RX, D3 as TX, connect to the serial port of the mmwave sensor
SoftwareSerial COMSerial(D2, D3);
// Creates a global Serial object for printing debugging information
#define ShowSerial Serial
// Initialising the radar configuration
// Seeed_HSP24 xiao_config(COMSerial, ShowSerial);
Seeed_HSP24 xiao_config(COMSerial);
Seeed_HSP24::RadarStatus radarStatus;
void setup() {
COMSerial.begin(9600);
ShowSerial.begin(9600);
delay(500);
ShowSerial.println("Programme Starting!");
xiao_config.disableEngineeringModel();
}
void loop() {
int retryCount = 0;
const int MAX_RETRIES = 10; // Maximum number of retries to prevent infinite loops
//Get radar status
do {
radarStatus = xiao_config.getStatus();
retryCount++;
} while (radarStatus.targetStatus == Seeed_HSP24::TargetStatus::ErrorFrame && retryCount < MAX_RETRIES);
//Parses radar status and prints results from debug serial port
if (radarStatus.targetStatus != Seeed_HSP24::TargetStatus::ErrorFrame) {
ShowSerial.print("Status: " + String(targetStatusToString(radarStatus.targetStatus)) + " ---- ");
ShowSerial.println("Distance: " + String(radarStatus.distance) + " Mode: " + String(radarStatus.radarMode));
}
delay(200);
}
// Parsing the acquired radar status
const char* targetStatusToString(Seeed_HSP24::TargetStatus status) {
switch (status) {
case Seeed_HSP24::TargetStatus::NoTarget:
return "NoTarget";
case Seeed_HSP24::TargetStatus::MovingTarget:
return "MovingTarget";
case Seeed_HSP24::TargetStatus::StaticTarget:
return "StaticTarget";
case Seeed_HSP24::TargetStatus::BothTargets:
return "BothTargets";
default:
return "Unknown";
}
}
```
--------------------------------
### Set Detection Distance and Duration (C++)
Source: https://github.com/limengdu/mmwave_for_xiao/blob/main/README.md
Configures the maximum detection distance gate and the unoccupied duration for the Seeed_HSP24 sensor. Returns a status code indicating success or failure.
```C++
AskStatus setDetectionDistance(int distance,int times)
```
--------------------------------
### Reboot Radar Sensor (C++)
Source: https://github.com/limengdu/mmwave_for_xiao/blob/main/README.md
Sends a command to reboot the Seeed_HSP24 radar sensor. Returns a status code indicating success or failure.
```C++
AskStatus rebootRadar()
```
--------------------------------
### Enable Engineering Mode (C++)
Source: https://github.com/limengdu/mmwave_for_xiao/blob/main/README.md
Enables the engineering mode output for the Seeed_HSP24 sensor, providing more detailed data. Returns a status code.
```C++
AskStatus enableEngineeringModel()
```
--------------------------------
### Enable and Parse mmWave Engineering Mode Output (C++)
Source: https://github.com/limengdu/mmwave_for_xiao/blob/main/README.md
This C++ code snippet configures the mmWave sensor for engineering mode output using the mmWave for XIAO library. It initializes serial communication, enables the engineering model on the sensor, and then enters a loop to continuously retrieve and display radar status, including target status, distance, radar mode, and energy values for different distance gates. A helper function `targetStatusToString` is included to convert the target status enum to a human-readable string.
```cpp
#if defined(ARDUINO_SEEED_XIAO_NRF52840_SENSE) || defined(ARDUINO_SEEED_XIAO_NRF52840)
#error "XIAO nRF52840 please use the non-mbed-enable version."
#endif
#include
#include
// Define the SoftwareSerial object, D2 as RX, D3 as TX, connect to the serial port of the mmwave sensor
SoftwareSerial COMSerial(D2, D3);
// Creates a global Serial object for printing debugging information
#define ShowSerial Serial
// Initialising the radar configuration
// Seeed_HSP24 xiao_config(COMSerial, ShowSerial);
Seeed_HSP24 xiao_config(COMSerial);
Seeed_HSP24::RadarStatus radarStatus;
void setup() {
COMSerial.begin(9600);
ShowSerial.begin(9600);
delay(500);
ShowSerial.println("Programme Starting!");
xiao_config.enableEngineeringModel();
}
void loop() {
int retryCount = 0;
const int MAX_RETRIES = 10; // Maximum number of retries to prevent infinite loops
//Get radar status
do {
radarStatus = xiao_config.getStatus();
retryCount++;
} while (radarStatus.targetStatus == Seeed_HSP24::TargetStatus::ErrorFrame && retryCount < MAX_RETRIES);
//Parses radar status and prints results from debug serial port
if (radarStatus.targetStatus != Seeed_HSP24::TargetStatus::ErrorFrame) {
ShowSerial.print("Status: " + String(targetStatusToString(radarStatus.targetStatus)) + " ---- ");
ShowSerial.println("Distance: " + String(radarStatus.distance) + " Mode: " + String(radarStatus.radarMode));
if (radarStatus.radarMode == 1) {
ShowSerial.print("Move:");
for (int i = 0; i < 9; i++) {
ShowSerial.print(" " + String(radarStatus.radarMovePower.moveGate[i]) + ",");
}
ShowSerial.println("");
ShowSerial.print("Static:");
for (int i = 0; i < 9; i++) {
ShowSerial.print(" " + String(radarStatus.radarStaticPower.staticGate[i]) + ",");
}
ShowSerial.println("");
ShowSerial.println("Photosensitive: " + String(radarStatus.photosensitive));
}
}
delay(100);
}
// Parsing the acquired radar status
const char* targetStatusToString(Seeed_HSP24::TargetStatus status) {
switch (status) {
case Seeed_HSP24::TargetStatus::NoTarget:
return "NoTarget";
case Seeed_HSP24::TargetStatus::MovingTarget:
return "MovingTarget";
case Seeed_HSP24::TargetStatus::StaticTarget:
return "StaticTarget";
case Seeed_HSP24::TargetStatus::BothTargets:
return "BothTargets";
default:
return "Unknown";
}
}
```
--------------------------------
### Set Distance Resolution (C++)
Source: https://github.com/limengdu/mmwave_for_xiao/blob/main/README.md
Sets the distance resolution for the Seeed_HSP24 sensor. A value of 1 sets it to 0.25M, and 0 sets it to the default 0.75M. Returns a status code.
```C++
AskStatus setResolution(int resolution)
```
--------------------------------
### C++ Seeed_HSP24 Class Definition
Source: https://github.com/limengdu/mmwave_for_xiao/blob/main/README.md
Defines the Seeed_HSP24 class for processing mmWave radar data. It includes constants for frame structures, enumerations for target and ask status, and structures for radar status and data results. This class is designed to interpret data from the mmWave sensor.
```C++
#define BUFFER_SIZE 256 // Serial Buffer Size
class Seeed_HSP24
{
public:
static const int FRAME_START_SIZE = 4;
static const int FRAME_END_SIZE = 4;
static const byte frameStart[FRAME_START_SIZE];
static const byte frameEnd[FRAME_END_SIZE];
static const byte frameAskStart[FRAME_START_SIZE];
static const byte frameAskEnd[FRAME_END_SIZE];
struct RadarMovePower // Energy value per movement distance gate
{
int moveGate[9] = {-1, -1, -1, -1, -1, -1, -1, -1, -1};
};
struct RadarStaticPower // Energy value per stationary distance gate
{
int staticGate[9] = {-1, -1, -1, -1, -1, -1, -1, -1, -1};
};
// Define the TargetStatus enum class
enum class AskStatus : byte
{
Success = 0x00, // Success
Error = 0x01, // Failed
};
// 定义TargetStatus枚举类
enum class TargetStatus : byte
{
NoTarget = 0x00, // No target
MovingTarget = 0x01, // Moving target
StaticTarget = 0x02, // Static target
BothTargets = 0x03, // It can be interpreted as motion, meaning that both the set motion and stationary thresholds are above the set value
ErrorFrame = 0x04 // Failed to get status
};
// Define the RadarStatus structure
struct RadarStatus
{
TargetStatus targetStatus = TargetStatus::ErrorFrame; // Target status of the radar
int distance = -1; // Target distance of the radar in mm
int moveSetDistance = -1; // The number of motion detection distance gates of the radar, which generally do not have to be configured
int staticSetDistance = -1; // Number of static detection distance gates of the radar, which generally do not have to be configured
int detectionDistance = -1; // Radar's longest detection range gate
int resolution = -1; // Distance gate resolution of radar
int noTargrtduration = -1; // Unmanned duration
int radarMode = -1; // Used to distinguish whether the module is in basic reporting mode (2) or engineering reporting mode (1)
RadarMovePower radarMovePower; // Exercise Energy Value
RadarStaticPower radarStaticPower; // Stationary energy value
int photosensitive = -1; // Photosensitive 0-255
};
// Used to return the result of an issued command
struct DataResult
{
byte *resultBuffer; // Points to a dynamically allocated array
int length; // Length of the array
};
};
```
--------------------------------
### Disable Engineering Mode (C++)
Source: https://github.com/limengdu/mmwave_for_xiao/blob/main/README.md
Disables the engineering mode output for the Seeed_HSP24 sensor, returning it to standard operation. Returns a status code.
```C++
AskStatus disableEngineeringModel()
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.