esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
290 stars 34 forks source link

RPi pico W failed to connect #5290

Open MarekW01 opened 8 months ago

MarekW01 commented 8 months ago

The problem

I bought an uart 24ghz mmwave sensor and bh1750 light sensor. i tried to set them up in yaml. but when i added i2c to the conf the logs said:

WARNING Can't connect to ESPHome API for 192.168.1.108: Error connecting to ('192.168.1.108', 6053): [Errno 113] Connect call failed ('192.168.1.108', 6053) (SocketAPIError).

when i tried to put the i2c alone it worked but again when i added the uart for mmwave sensor everything was same again

Which version of ESPHome has the issue?

2023.11.2

What type of installation are you using?

Home Assistant Add-on

Which version of Home Assistant has the issue?

2023.12.3

What platform are you using?

RP2040

Board

RPi pico W

Component causing the issue

uart and i2c

Example YAML snippet

esphome:
  name: rpi-pico
  friendly_name: rpi pico
  includes:
    - R24dvd_new.h

rp2040:
  board: rpipicow
  framework:
    # Required until https://github.com/platformio/platform-raspberrypi/pull/36 is merged
    platform_version: https://github.com/maxgerhardt/platform-raspberrypi.git

# Enable logging
logger:
  hardware_uart: UART1
  level: DEBUG
# Enable Home Assistant API
api:
  encryption:
    key: "qXEXQc3HI6+6s7l4w5+ploRDdZULN6qH83Pit0wGcfI="

ota:
  password: "06753b0330166593d53e85eb04a20cb9"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  manual_ip:
    static_ip: 192.168.1.33
    gateway: 192.168.1.1
    subnet: 255.255.255.0
  # Enable fallback hotspot in case wifi connection fails
  ap:
    ssid: "Rpi-Pico Fallback Hotspot"
    password: "vP2p9mG0zSod"

i2c: #this is the thing when i add whole thing crashes and wont connect
  sda: GPIO0
  scl: GPIO1
  scan: true
  id: bus_a

uart:
  id: uart_bus
  baud_rate:  115200
  rx_pin: 17
  tx_pin: 16

select:
  - platform: template
    name: "Scene mode"
    id: scene_mode
    icon: mdi:hoop-house
    optimistic: true
    options:
      - "0"
      - "1"
      - "2"
      - "3"
      - "4"
    initial_option: "0"
    set_action:
      - logger.log:
            format: "set action option: %s"
            args: ["x.c_str()"]
      - uart.write: !lambda
                  auto index = id(scene_mode).index_of(x);
                  uint8_t value = (uint8_t)index.value() + 1;
                  uint8_t crc = value + 0xB9;
                  return {0x53,0x59,0x05,0x07,0x00,0x01,value,crc,0x54,0x43};

  - platform: template
    name: "unmanned time"
    id: unmanned_time
    icon: mdi:timeline-clock
    optimistic: true
    options:
      - "none"
      - "10s"
      - "30s"
      - "1min"
      - "2min" 
      - "5min" 
      - "10min"
      - "30min"
      - "1hour"
    initial_option: "none"
    set_action:
      - logger.log:
            format: "Chosen option: %s"
            args: ["x.c_str()"]
      - uart.write: !lambda
                  auto index = id(unmanned_time).index_of(x);
                  uint8_t value = (uint8_t)index.value();
                  uint8_t crc = value + 0x37;
                  return {0x53,0x59,0x80,0x0a,0x00,0x01,value,crc,0x54,0x43};

  - platform: template
    name: "Custom Presence of perception boundary"
    id: custom_presence_of_perception_boundary
    optimistic: true
    options:
      - "0.5m"
      - "1.0m"
      - "1.5m"
      - "2.0m" 
      - "2.5m" 
      - "3.0m"
      - "3.5m"
      - "4.0m"
      - "4.5m"
      - "5.0m"
    set_action:
      - logger.log:
            format: "Chosen option: %s"
            args: ["x.c_str()"]
      - uart.write: !lambda
                  auto index = id(custom_presence_of_perception_boundary).index_of(x);
                  uint8_t value = (uint8_t)index.value() + 1;
                  uint8_t crc = value + 0xBF;
                  return {0x53,0x59,0x08,0x0a,0x00,0x01,value,crc,0x54,0x43};

  - platform: template
    name: "Custom Motion trigger boundary"
    id: custom_motion_trigger_boundary
    optimistic: true
    options:
      - "0.5m"
      - "1.0m"
      - "1.5m"
      - "2.0m" 
      - "2.5m" 
      - "3.0m"
      - "3.5m"
      - "4.0m"
      - "4.5m"
      - "5.0m"
    set_action:
      - logger.log:
            format: "Chosen option: %s"
            args: ["x.c_str()"]
      - uart.write: !lambda
                  auto index = id(custom_motion_trigger_boundary).index_of(x);
                  uint8_t value = (uint8_t)index.value() + 1;
                  uint8_t crc = value + 0xC0;
                  return {0x53,0x59,0x08,0x0b,0x00,0x01,value,crc,0x54,0x43};

number:
  - platform: template
    id: sensitivity
    name: "sensitivity"
    icon: mdi:archive-check-outline
    min_value: 0
    max_value: 3
    optimistic: false
    step: 1
    update_interval: 2s
    set_action:
      - uart.write: !lambda
                    uint8_t crc = x + 0xBA;
                    return {0x53,0x59,0x05,0x08,0x00,0x01,(uint8_t)x,crc,0x54,0x43};

  - platform: template
    name: "Maximum detectable range of moving target"
    id: moving_target_detection_max_distance
    icon: mdi:map-marker-path
    unit_of_measurement: "cm"
    min_value: 0
    max_value: 65536
    step: 500
    set_action:
      - uart.write: !lambda
                    int h_num = (int)x >> 8;
                    int l_num = (int)x & 0xff;
                    int crc = 0xB6 + h_num + l_num;
                    return {0x53,0x59,0x07,0x01,0x00,0x02,(uint8_t)(h_num),(uint8_t)(l_num),(uint8_t)crc,0x54,0x43};

  - platform: template
    name: "Maximum detectable range of stationary target"
    id: static_target_detection_max_distance
    icon: mdi:map-marker-path
    unit_of_measurement: cm
    min_value: 0
    max_value: 65536
    step: 500
    set_action:
      - uart.write: !lambda
                    int h_num = (int)x >> 8;
                    int l_num = (int)x & 0xff;
                    int crc = 0xB9 + h_num + l_num;
                    return {0x53,0x59,0x07,0x04,0x00,0x02,(uint8_t)(h_num),(uint8_t)(l_num),(uint8_t)crc,0x54,0x43};

  - platform: template
    name: "Custom Judgment threshold exists"
    id: custom_judgment_threshold_exists
    min_value: 0
    max_value: 250
    step: 1
    set_action:
      - uart.write: !lambda
                    int crc = 0xBD + (int)x;
                    return {0x53,0x59,0x08,0x08,0x00,0x01,(uint8_t)x,(uint8_t)crc,0x54,0x43};

  - platform: template
    name: "Custom Motion amplitude trigger threshold"
    id: custom_motion_amplitude_trigger_threshold
    min_value: 0
    max_value: 250
    step: 1
    set_action:
      - uart.write: !lambda
                    int crc = 0xBE + (int)x;
                    return {0x53,0x59,0x08,0x09,0x00,0x01,(uint8_t)x,(uint8_t)crc,0x54,0x43};

  - platform: template
    name: "Custom Mode Settings"
    id: custom_mode_settings
    icon: mdi:cog
    min_value: 0
    max_value: 4
    step: 1
    set_action:
      - uart.write: !lambda
                    int crc = 0xBB + (int)x;
                    return {0x53,0x59,0x05,0x09,0x00,0x01,(uint8_t)x,(uint8_t)crc,0x54,0x43};

  - platform: template
    name: "Custom Motion trigger time"
    id: custom_motion_trigger_time
    icon: mdi:camera-timer
    unit_of_measurement: "ms"
    min_value: 0
    max_value: 4294967295
    step: 100
    set_action:
      - uart.write: !lambda                   
                    int h24_num = ((int)x >> 24) & 0xff;
                    int h16_num = ((int)x >> 16) & 0xff;
                    int h8_num = ((int)x >> 8) & 0xff;
                    int l8_num = (int)x & 0xff;
                    int crc = 0xC4 + h24_num + h16_num + h8_num + l8_num;
                    return {0x53,0x59,0x08,0x0c,0x00,0x04,(uint8_t)h24_num,(uint8_t)h16_num,(uint8_t)h8_num,(uint8_t)l8_num,(uint8_t)crc,0x54,0x43};

  - platform: template
    name: "Custom Movement to rest time"
    id: custom_movement_to_rest_time
    icon: mdi:camera-timer
    unit_of_measurement: "ms"
    min_value: 0
    max_value: 4294967295
    step: 1000
    set_action:
      - uart.write: !lambda
                    int h24_num = ((int)x >> 24) & 0xff;
                    int h16_num = ((int)x >> 16) & 0xff;
                    int h8_num = ((int)x >> 8) & 0xff;
                    int l8_num = (int)x & 0xff;
                    int crc = 0xC5 + h24_num + h16_num + h8_num + l8_num;
                    return {0x53,0x59,0x08,0x0d,0x00,0x04,(uint8_t)h24_num,(uint8_t)h16_num,(uint8_t)h8_num,(uint8_t)l8_num,(uint8_t)crc,0x54,0x43};

  - platform: template
    name: "Custom Time of entering unmanned state"
    id: custom_time_of_enter_unmanned
    icon: mdi:camera-timer
    unit_of_measurement: "ms"
    min_value: 0
    max_value: 4294967295
    step: 5000
    set_action:
      - uart.write: !lambda
                    int h24_num = ((int)x >> 24) & 0xff;
                    int h16_num = ((int)x >> 16) & 0xff;
                    int h8_num = ((int)x >> 8) & 0xff;
                    int l8_num = (int)x & 0xff;
                    int crc = 0xC6 + h24_num + h16_num + h8_num + l8_num;
                    return {0x53,0x59,0x08,0x0e,0x00,0x04,(uint8_t)h24_num,(uint8_t)h16_num,(uint8_t)h8_num,(uint8_t)l8_num,(uint8_t)crc,0x54,0x43};

text_sensor:
- platform: custom
  lambda: |-
    auto my_custom_sensor = new MyCustomTextSensor();
    App.register_component(my_custom_sensor);
    return {my_custom_sensor->Heartbeat};

  text_sensors:
    - name: "Standard Heartbeat"
      icon: mdi:connection

- platform: template
  name: "Product model"
  id: product_mode
  icon: mdi:information-outline
  on_raw_value:
    then:
      - logger.log: text_sensor on_raw_value

- platform: template
  name: "Product ID"
  id: product_id
  icon: mdi:information-outline

- platform: template
  name: "Hardware model"
  id: hardware_model
  icon: mdi:information-outline

- platform: template
  name: "Firmware version"
  id: firmware_version
  icon: mdi:information-outline

- platform: template
  name: "moving direction"
  id: keep_away
  icon: mdi:walk

- platform: template
  name: "Sports information"
  id: motion_status
  icon: mdi:human-greeting

- platform: template
  name: "Presence information"
  id: someoneExists
  icon: "mdi:motion-sensor"

- platform: template
  name: "Custom Presence of detection"
  id: custom_presence_of_detection
  icon: mdi:signal-distance-variant

button:
  - platform: template
    name: "reset"
    id: "reset"
    icon: mdi:reload
    on_press:
      then:
        - logger.log: Button Pressed
        - uart.write: [0x53,0x59,0x01,0x02,0x00,0x01,0x0F,0xBF,0x54,0x43]

  - platform: template
    name: "Custom Mode Settings End"
    id: custom_mode_setting_completed
    icon: mdi:cog
    on_press:
      then:
        - logger.log: Button Pressed
        - uart.write: [0x53,0x59,0x05,0x0a,0x00,0x01,0x0F,0xCB,0x54,0x43]

  - platform: template
    name: "Custom Mode Query"
    icon: mdi:cog
    id: custom_mode_query
    on_press:
      then:
        - logger.log: Button Pressed
        - uart.write: [0x53,0x59,0x05,0x89,0x00,0x01,0x0F,0x4A,0x54,0x43]

  - platform: template
    name: "Custom Spatial Static Value Query"
    icon: mdi:cog
    id: custom_spatial_static_value_query
    on_press:
      then:
        - logger.log: Button Pressed
        - uart.write: [0x53,0x59,0x08,0x81,0x00,0x01,0x0F,0x45,0x54,0x43]

  - platform: template
    name: "Custom Spatial motion value"
    icon: mdi:cog
    id: custom_spatial_motion_value_query
    on_press:
      then:
        - logger.log: Button Pressed
        - uart.write: [0x53,0x59,0x08,0x82,0x00,0x01,0x0F,0x46,0x54,0x43]

  - platform: template
    name: "Presence Of Detection Range Query"
    icon: mdi:cog
    id: custom_presence_of_detection_query
    on_press:
      then:
        - logger.log: Button Pressed
        - uart.write: [0x53,0x59,0x08,0x83,0x00,0x01,0x0F,0x47,0x54,0x43]

  - platform: template
    name: "Custom Motion Distance Query"
    icon: mdi:cog
    id: custom_motion_distance_query
    on_press:
      then:
        - logger.log: Button Pressed
        - uart.write: [0x53,0x59,0x08,0x84,0x00,0x01,0x0F,0x48,0x54,0x43]

  - platform: template
    name: "Existence Judgment Threshold Setting Query"
    icon: mdi:cog
    id: custom_judgment_threshold_exists_query
    on_press:
      then:
        - logger.log: Button Pressed
        - uart.write: [0x53,0x59,0x08,0x88,0x00,0x01,0x0F,0x4C,0x54,0x43]

  - platform: template
    name: "Motion Amplitude Trigger Threshold Setting Query"
    icon: mdi:cog
    id: custom_motion_trigger_time_query
    on_press:
      then:
        - logger.log: Button Pressed
        - uart.write: [0x53,0x59,0x08,0x89,0x00,0x01,0x0F,0x4D,0x54,0x43]

  - platform: template
    name: "Motion To Rest Time Setting Query"
    icon: mdi:cog
    id: custom_movement_to_rest_time_query
    on_press:
      then:
        - logger.log: Button Pressed
        - uart.write: [0x53,0x59,0x08,0x8d,0x00,0x01,0x0F,0x51,0x54,0x43]

  - platform: template
    name: "Custom Time Of Enter Unmanned Query"
    icon: mdi:cog
    id: custom_time_of_enter_unmanned_query
    on_press:
      then:
        - logger.log: Button Pressed
        - uart.write: [0x53,0x59,0x08,0x8e,0x00,0x01,0x0F,0x52,0x54,0x43]

switch:
  - platform: template
    id: output_info_switch
    name: "Custom Infor output switch"
    icon: mdi:electric-switch
    assumed_state: true
    turn_on_action:
      - uart.write: [0x53,0x59,0x08,0x00,0x00,0x01,0x01,0xB6,0x54,0x43]
      - delay: 1s
      - lambda: !lambda |-
          id(product_mode).publish_state("");
          id(product_id).publish_state("");
          id(hardware_model).publish_state("");
          id(firmware_version).publish_state("");
    turn_off_action:
      - uart.write: [0x53,0x59,0x08,0x00,0x00,0x01,0x00,0xB5,0x54,0x43]

sensor:
  - platform: custom
    lambda: |-
      auto my_custom_sensor = new UartReadLineSensor(id(uart_bus));
      App.register_component(my_custom_sensor);
      return {
        my_custom_sensor->movementSigns,
        my_custom_sensor->inited,
      };

    sensors:
      - name: "body movement"
        id: movementSigns
        icon: "mdi:human-greeting-variant"
        device_class: "temperature"
        state_class: "measurement"

      - name: "inited Status"
        id: inited
        icon: mdi:all-inclusive

  - platform: template
    name: "Custom Motion distance"
    id: custom_motion_distance
    icon: mdi:signal-distance-variant
    on_value:
      then:
        # - logger.log: Custom Motion distance on_value
        - logger.log:
              format: "Custom Motion distance on_value : %d"
              args: ["x"]
    on_raw_value:
      then:
        - logger.log:
              format: "Custom Motion distance on_raw_value : %d"
              args: ["x"]

  - platform: template
    name: "Custom Static distance"
    id: custom_static_distance
    icon: mdi:signal-distance-variant

  - platform: template
    name: "Custom Spatial static value"
    id: custom_spatial_static_value
    icon: mdi:counter

  - platform: template
    name: "Custom Spatial motion value"
    id: custom_spatial_motion_value
    icon: mdi:counter

  - platform: template
    name: "Custom Motion speed"
    id: custom_motion_speed
    icon: mdi:run-fast

Anything in the logs that might be useful for us?

No response

Additional information

No response

tettertot commented 8 months ago

The pico w has trouble with the first i2c bus in ESPHome. Try using the second bus:

i2c:
   - id: bus_a
     sda: GPIO16
     scl: GPIO17
     scan: False

You can still call it "bus_a". This is what I had to do to get i2c working.