ncmreynolds / ld2410

An Arduino library for the Hi-Link LD2410 24Ghz FMCW radar sensor.
GNU Lesser General Public License v2.1
179 stars 37 forks source link

how do i get the individual information From each gate? #14

Open WalrusHat opened 1 year ago

ncmreynolds commented 1 year ago

As separately discussed, this would require adding support for engineering mode. Which I did look at briefly but never finished. Unfortunately I can't look at this for a few weeks.

doc123307 commented 1 year ago

Good afternoon. I want to connect LD2410b to ARDUINO NANO using the UART protocol. I looked and tried everything, but nothing works. Found an article on the Internet: https://wiki.dfrobot.com/SKU_SEN0557_24GHz_Human_Presence_Sensing_Module But this code doesn't work either. I will be very grateful for your help in the project.

I managed to output something with this code:

include

SoftwareSerial mySerial(2, 3); // Определение программного последовательного порта: TX - 3, RX - 2

uint8_t Cache[23] = {0}; // Кэш для данных

void setup() { Serial.begin(115200); mySerial.begin(57600); // Инициализация программного последовательного порта }

void loop() { if (recdData(Cache)) { // Данные успешно получены и обработаны // Можно выполнять операции с полученными данными здесь } }

size_t readN(uint8_t buf, size_t len) { size_t offset = 0, left = len; int16_t Timeout = 1500; // Тайм-аут чтения uint8_t buffer = buf; long curr = millis(); while (left) { if (mySerial.available()) { buffer[offset] = mySerial.read(); offset++; left--; } if (millis() - curr > Timeout) { break; // Выход по тайм-ауту } } return offset; }

bool recdData(uint8_t *buf) { int16_t Timeout = 50000; // Тайм-аут для получения данных long curr = millis(); uint8_t ch; bool ret = false; while (!ret) { if (millis() - curr > Timeout) { break; // Выход по тайм-ауту } if (readN(&ch, 1) == 1) { // Обработка данных // В данном примере мы просто выводим данные на Serial Serial.print("Received data: "); Serial.println(ch); ret = true; // Устанавливаем флаг, что данные получены успешно } } return ret; }

But it's not even close to centimeters: https://drive.google.com/file/d/11epqswciyHE2KdFIjeal90KgwiE5nhZi/view?usp=sharing

ncmreynolds commented 1 year ago

The examples in this library should work with an LD2410, have you tried them?

doc123307 commented 1 year ago

Yes, I tried to use this library. But it is written for ESP32, but I want to use this sensor with arduino nano STM32. When copying the code, an error occurs: exit status 1 Compilation error: 'MONITOR_SERIAL' was not declared in this scope.

I tried to change the code to this:

include

include // Для создания SoftwareSerial соединения с

радаром LD2410

include

ld2410 radar;

uint32_t lastReading = 0; bool radarConnected = false;

define RADAR_RX_PIN 0 // Укажите пин RX, к которому подключен радар

define RADAR_TX_PIN 1 // Укажите пин TX, к которому подключен радар

SoftwareSerial MONITOR_SERIAL(0, 1); // Создайте SoftwareSerial соединение для монитора SoftwareSerial RADAR_SERIAL(RADAR_RX_PIN, RADAR_TX_PIN); // Создайте SoftwareSerial соединение для радара

void setup() { MONITOR_SERIAL.begin(115200); // Начальная настройка монитора через SoftwareSerial delay(500); MONITOR_SERIAL.println(F("\nConnect LD2410 radar TX to GPIO:")); MONITOR_SERIAL.println(RADAR_RX_PIN); MONITOR_SERIAL.println(F("Connect LD2410 radar RX to GPIO:")); MONITOR_SERIAL.println(RADAR_TX_PIN); MONITOR_SERIAL.println(F("LD2410 radar sensor initializing: "));

// Инициализация объекта radar с использованием SoftwareSerial соединения if (radar.begin(RADAR_SERIAL)) { MONITOR_SERIAL.println(F("OK")); MONITOR_SERIAL.print(F("LD2410 firmware version: ")); MONITOR_SERIAL.print(radar.firmware_major_version); MONITOR_SERIAL.print('.'); MONITOR_SERIAL.print(radar.firmware_minor_version); MONITOR_SERIAL.print('.'); MONITOR_SERIAL.println(radar.firmware_bugfix_version, HEX); } else { MONITOR_SERIAL.println(F("not connected")); } }

void loop() { radar.read(); if (radar.isConnected() && millis() - lastReading > 1000) { lastReading = millis(); if (radar.presenceDetected()) { if (radar.stationaryTargetDetected()) { MONITOR_SERIAL.print(F("Stationary target: ")); MONITOR_SERIAL.print(radar.stationaryTargetDistance()); MONITOR_SERIAL.print(F("cm energy:")); MONITOR_SERIAL.print(radar.stationaryTargetEnergy()); MONITOR_SERIAL.print(' '); } if (radar.movingTargetDetected()) { MONITOR_SERIAL.print(F("Moving target: ")); MONITOR_SERIAL.print(radar.movingTargetDistance()); MONITOR_SERIAL.print(F("cm energy:")); MONITOR_SERIAL.print(radar.movingTargetEnergy()); } MONITOR_SERIAL.println(); } else { MONITOR_SERIAL.println(F("No target")); } } }

It was possible to upload the firmware, but in the port monitor it says: Connect LD2410 radar TX to GPIO: 0 Connect LD2410 radar RX to GPIO: 1 LD2410 radar sensor initializing: not connected

I also tried to change the contacts to 2.3, but nothing happened.