Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All sensors are "Unknown" after compilation and upload #5

Closed
miljume opened this issue Dec 2, 2022 · 8 comments
Closed

All sensors are "Unknown" after compilation and upload #5

miljume opened this issue Dec 2, 2022 · 8 comments

Comments

@miljume
Copy link

miljume commented Dec 2, 2022

All sensors become "Unknown" (Okänd = Unknown) after startup
Sensor used HLK-LD2410B from [https://www.aliexpress.com/item/1005004673573740.html?
Sensor works fine with HLKRadarTool

spm=a2g0o.order_list.order_list_main.21.26a0a396CURqHX](url)
image

@rainchi
Copy link
Owner

rainchi commented Dec 7, 2022

Can you share your wiring for ld2410?

@miljume
Copy link
Author

miljume commented Dec 7, 2022

Of course, see below:

ESP8266 | LD2410
5V <-> VCC
GND <-> GND
TX <-> RX
RX <-> TX

@cmille34
Copy link

cmille34 commented Dec 8, 2022

I am in the same boat with a D1 mini. I don't see any uart data when viewing the logs remotely with debugging on. The output pin seems to be working though.

Im powering the LD2410 from the 5v pin on the D1 mini, i tried 5v directly from a power supply as well to the sensor and that didn't make a difference. Any other ideas why the sensors show unknown?

Below is my YAML as well in case it helps.

`esphome:
name: chrisofficemmwave
includes:
- ld2410_uart.h
on_boot:
priority: 600
# ...
then:
- lambda: |-
auto uart_component = static_cast<LD2410 *>(ld2410);
uart_component->setNumbers(maxMovingDistanceRange, maxStillDistanceRange, noneDuration);

esp8266:
board: d1_mini
framework:
version: latest

logger:
level: DEBUG #You Can Use "INFO" Level
baud_rate: 0
api:
ota:
web_server:
port: 80
wifi:
ssid: ****
password: ***

uart:
id: uart1
rx_pin: GPIO3 #ESP8266 UART_0
tx_pin: GPIO1 #ESP8266 UART_0
baud_rate: 256000
data_bits: 8
stop_bits: 1
parity: NONE
debug:
direction: BOTH
dummy_receiver: false
after:
delimiter: "\n"
sequence:
- lambda: UARTDebug::log_string(direction, bytes);

custom_component:

  • lambda: |-
    return {new LD2410(id(uart1))};
    components:
    • id: ld2410

binary_sensor:

  • platform: custom
    lambda: |-
    auto uart_component = static_cast<LD2410 *>(ld2410);
    return {uart_component->hasTarget,uart_component->hasMovingTarget,uart_component->hasStillTarget,uart_component->lastCommandSuccess};
    binary_sensors:
    • name: "Has Target"
    • name: "Has Moving Target"
    • name: "Has Still Target"
    • name: "Last Command Success"
  • platform: gpio
    id: MovOcc_gpio
    pin:
    number: D4
    mode:
    input: true
    pullup: true
    name: "mmWave Pin"
    device_class: occupancy

sensor:

  • platform: custom
    lambda: |-
    auto uart_component = static_cast<LD2410 *>(ld2410);
    return {uart_component->movingTargetDistance,uart_component->movingTargetEnergy,uart_component->stillTargetDistance,uart_component->stillTargetEnergy,uart_component->detectDistance};
    sensors:
    • name: "Moving Target Distance"
      unit_of_measurement: "cm"
      accuracy_decimals: 0
    • name: "Moving Target Energy"
      unit_of_measurement: "%"
      accuracy_decimals: 0
    • name: "Still Target Distance"
      unit_of_measurement: "cm"
      accuracy_decimals: 0
    • name: "Still Target Energy"
      unit_of_measurement: "%"
      accuracy_decimals: 0
    • name: "Detect Distance"
      unit_of_measurement: "cm"
      accuracy_decimals: 0

number:

  • platform: template
    name: "Max Moving Distance Range"
    id: maxMovingDistanceRange
    min_value: 1
    max_value: 8
    step: 1
    update_interval: never
    optimistic: true
    set_action:
    • lambda: |-
      auto uart_component = static_cast<LD2410 *>(ld2410);
      uart_component->setMaxDistancesAndNoneDuration(x,id(maxStillDistanceRange).state,id(noneDuration).state);
  • platform: template
    name: "Max Still Distance Range"
    id: maxStillDistanceRange
    min_value: 1
    max_value: 8
    step: 1
    update_interval: never
    optimistic: true
    set_action:
    • lambda: |-
      auto uart_component = static_cast<LD2410 *>(ld2410);
      uart_component->setMaxDistancesAndNoneDuration(id(maxMovingDistanceRange).state,x,id(noneDuration).state);
  • platform: template
    name: "None Duration"
    id: noneDuration
    min_value: 0
    max_value: 32767
    step: 1
    mode: box
    update_interval: never
    optimistic: true
    set_action:
    • lambda: |-
      auto uart_component = static_cast<LD2410 *>(ld2410);
      uart_component->setMaxDistancesAndNoneDuration(id(maxMovingDistanceRange).state,id(maxStillDistanceRange).state,x);

button:

  • platform: template
    name: "Reboot LD2410"
    on_press:
    lambda: 'static_cast<LD2410 *>(ld2410)->reboot();'
  • platform: template
    name: "Turn on config mode"
    on_press:
    • lambda: 'static_cast<LD2410 *>(ld2410)->setConfigMode(true);'
  • platform: template
    name: "Turn off config mode"
    on_press:
    • lambda: 'static_cast<LD2410 *>(ld2410)->setConfigMode(false);'
  • platform: template
    name: "Get config"
    on_press:
    • lambda: 'static_cast<LD2410 *>(ld2410)->queryParameters();'
  • platform: template
    name: "Set baud rate to 256000"
    on_press:
    • lambda: 'static_cast<LD2410 *>(ld2410)->setBaudrate(7);'
  • platform: template
    name: "Set baud rate to 115200"
    on_press:
    • lambda: 'static_cast<LD2410 *>(ld2410)->setBaudrate(5);'
  • platform: template
    name: "Set baud rate to 9600"
    on_press:
    • lambda: 'static_cast<LD2410 *>(ld2410)->setBaudrate(1);'`

@cmille34
Copy link

cmille34 commented Dec 8, 2022

I swapped over to using RX = GPIO13/D7 and TX=GPIO15/D8 on the D1 mini and now I am getting uart data. Leaving this here in case it helps someone else.

@n1kDon
Copy link

n1kDon commented Dec 19, 2022

@cmille34 Wow that worked!!! Bought 5 more after the first one worked flawless. There was no uart data on all of the new ones. BIG thanks, I dont know why but now it works! I've been messing around with these things for 2 days.

@rain931215 maybe you should point this out in the docu

@miljume
Copy link
Author

miljume commented Dec 20, 2022

I swapped over to using RX = GPIO13/D7 and TX=GPIO15/D8 on the D1 mini and now I am getting uart data. Leaving this here in case it helps someone else.

@cmille34:
Can you please attach both your .yaml file and your .h include?
Cant get it to compile

@cmille34
Copy link

cmille34 commented Dec 20, 2022

I swapped over to using RX = GPIO13/D7 and TX=GPIO15/D8 on the D1 mini and now I am getting uart data. Leaving this here in case it helps someone else.

@cmille34: Can you please attach both your .yaml file and your .h include? Cant get it to compile

Below is my full yaml (Sorry if the formatting is all messed up). My .h file is the one from this repository. I didn't mess with that.

`esphome:
name: chrisofficemmwave
includes:
- ld2410_uart.h
on_boot:
priority: 600
# ...
then:
- lambda: |-
auto uart_component = static_cast<LD2410 *>(ld2410);
uart_component->setNumbers(maxMovingDistanceRange, maxStillDistanceRange, noneDuration);

esp8266:
board: d1_mini
framework:
version: latest

logger:
level: DEBUG #You Can Use "INFO" Level
baud_rate: 0
api:
ota:
web_server:
port: 80
wifi:
ssid: **
password: **

uart:
id: uart1
rx_pin: GPIO13 #ESP8266 UART_0
tx_pin: GPIO15 #ESP8266 UART_0
baud_rate: 256000
data_bits: 8
stop_bits: 1
parity: NONE

custom_component:

  • lambda: |-
    return {new LD2410(id(uart1))};
    components:
    • id: ld2410

binary_sensor:

  • platform: custom
    lambda: |-
    auto uart_component = static_cast<LD2410 *>(ld2410);
    return {uart_component->hasTarget,uart_component->hasMovingTarget,uart_component->hasStillTarget,uart_component->lastCommandSuccess};
    binary_sensors:
    • name: "Has Target"
    • name: "Has Moving Target"
    • name: "Has Still Target"
    • name: "Last Command Success"
  • platform: gpio
    id: MovOcc_gpio
    pin:
    number: GPIO14
    mode:
    input: true
    pullup: true
    name: "mmWave Pin"
    filters:
    • delayed_on: 10ms
      device_class: occupancy

sensor:

  • platform: custom
    lambda: |-
    auto uart_component = static_cast<LD2410 *>(ld2410);
    return {uart_component->movingTargetDistance,uart_component->movingTargetEnergy,uart_component->stillTargetDistance,uart_component->stillTargetEnergy,uart_component->detectDistance};
    sensors:
    • name: "Moving Target Distance"
      unit_of_measurement: "cm"
      accuracy_decimals: 0
    • name: "Moving Target Energy"
      unit_of_measurement: "%"
      accuracy_decimals: 0
    • name: "Still Target Distance"
      unit_of_measurement: "cm"
      accuracy_decimals: 0
    • name: "Still Target Energy"
      unit_of_measurement: "%"
      accuracy_decimals: 0
    • name: "Detect Distance"
      unit_of_measurement: "cm"
      accuracy_decimals: 0

number:

  • platform: template
    name: "Max Moving Distance Range"
    id: maxMovingDistanceRange
    min_value: 1
    max_value: 8
    step: 1
    update_interval: never
    optimistic: true
    set_action:
    • lambda: |-
      auto uart_component = static_cast<LD2410 *>(ld2410);
      uart_component->setMaxDistancesAndNoneDuration(x,id(maxStillDistanceRange).state,id(noneDuration).state);
  • platform: template
    name: "Max Still Distance Range"
    id: maxStillDistanceRange
    min_value: 1
    max_value: 8
    step: 1
    update_interval: never
    optimistic: true
    set_action:
    • lambda: |-
      auto uart_component = static_cast<LD2410 *>(ld2410);
      uart_component->setMaxDistancesAndNoneDuration(id(maxMovingDistanceRange).state,x,id(noneDuration).state);
  • platform: template
    name: "None Duration"
    id: noneDuration
    min_value: 0
    max_value: 32767
    step: 1
    mode: box
    update_interval: never
    optimistic: true
    set_action:
    • lambda: |-
      auto uart_component = static_cast<LD2410 *>(ld2410);
      uart_component->setMaxDistancesAndNoneDuration(id(maxMovingDistanceRange).state,id(maxStillDistanceRange).state,x);

button:

  • platform: template
    name: "Reboot LD2410"
    on_press:
    lambda: 'static_cast<LD2410 *>(ld2410)->reboot();'
  • platform: template
    name: "Turn on config mode"
    on_press:
    • lambda: 'static_cast<LD2410 *>(ld2410)->setConfigMode(true);'
  • platform: template
    name: "Turn off config mode"
    on_press:
    • lambda: 'static_cast<LD2410 *>(ld2410)->setConfigMode(false);'
  • platform: template
    name: "Get config"
    on_press:
    • lambda: 'static_cast<LD2410 *>(ld2410)->queryParameters();'
  • platform: template
    name: "Set baud rate to 256000"
    on_press:
    • lambda: 'static_cast<LD2410 *>(ld2410)->setBaudrate(7);'
  • platform: template
    name: "Set baud rate to 115200"
    on_press:
    • lambda: 'static_cast<LD2410 *>(ld2410)->setBaudrate(5);'
  • platform: template
    name: "Set baud rate to 9600"
    on_press:
    • lambda: 'static_cast<LD2410 *>(ld2410)->setBaudrate(1);'`

@miljume
Copy link
Author

miljume commented Dec 20, 2022

@cmille34 Worked perfect, thanks a lot!

@miljume miljume closed this as completed Dec 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants