Ultrasonic Sensor: Incorrect Distance Reading

Hi All,

I recently bought a M5 Atom Echo and the M5 Ultrasonic I2C sensor to attach to it.

My configuration for the Echo and the sensor is below, if i strip the sensor code out the echo works fine but i just can’t get the sensor to pick up readings. I assume im being a Potato :potato: as im new to this space. Can someone please help me fix this or point me in the right direction? Thanks in advance

esphome:
  name: atom-echo--test
  friendly_name: Atom Echo - test

i2s_audio:
  i2s_lrclk_pin: GPIO33
  i2s_bclk_pin: GPIO19

esp32:
  board: m5stack-atom
  framework:
    type: arduino

logger:
api:
  encryption: 
    key: !secret atom_echo_test_encryption_key
ota:
  - platform: esphome
    password: "56ab3e28b1"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Atom-Echo Fallback Hotspot"
    password: "somepassword"

captive_portal:

improv_serial:
    
microphone:
  - platform: i2s_audio
    id: atom_echo_microphone
    adc_type: external
    i2s_din_pin: GPIO23
    pdm: true

voice_assistant:
  microphone: atom_echo_microphone
  on_start:
    - light.turn_on:
        id: led
        blue: 100%
        red: 0%
        green: 0%
        effect: none
  on_tts_start:
    - light.turn_on:
        id: led
        blue: 0%
        red: 0%
        green: 100%
        effect: none
  on_tts_end:
    - media_player.play_media: !lambda return x;
    - light.turn_on:
        id: led
        blue: 0%
        red: 0%
        green: 100%
        effect: pulse
  on_end:
    - delay: 1s
    - wait_until:
        not:
          media_player.is_playing: media_out
    - light.turn_off: led
  on_error:
    - light.turn_on:
        id: led
        blue: 0%
        red: 100%
        green: 0%
        effect: none
    - delay: 1s
    - light.turn_off: led

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO39
      inverted: true
    name: Button
    id: echo_button
    on_multi_click:
      - timing:
          - ON FOR AT MOST 350ms
          - OFF FOR AT LEAST 10ms
        then:
          - media_player.toggle: media_out
      - timing:
          - ON FOR AT LEAST 350ms
        then:
          - voice_assistant.start:
      - timing:
          - ON FOR AT LEAST 350ms
          - OFF FOR AT LEAST 10ms
        then:
          - voice_assistant.stop:

media_player:
  - platform: i2s_audio
    id: media_out
    name: None
    dac_type: external
    i2s_dout_pin: GPIO22
    mode: mono

light:
  - platform: esp32_rmt_led_strip
    id: led
    name: None
    pin: GPIO27
    default_transition_length: 0s
    chipset: SK6812
    num_leds: 1
    rgb_order: grb
    rmt_channel: 0
    effects:
      - pulse:
          transition_length: 250ms
          update_interval: 250ms

external_components:
  - source:
      type: git
      url: https://github.com/chill-Division/M5Stack-ESPHome/
      ref: main
    components: sonic_i2c

i2c:
  sda: GPIO32
  scl: GPIO26
  scan: true
  id: bus_1

sensor:
 - platform: sonic_i2c
   i2c_id: bus_1
   address: 0x57
   name: "Ultrasonic Sensor 1"
   id: ultrasonic1
   unit_of_measurement: mm
   update_interval: 5s

From the logs after this finishes installing this is what i get(repeated):

[13:08:41][I][sonic_i2c:047]: Incorrect Distance Reading
[13:08:41][D][sensor:094]: 'Ultrasonic Sensor 1': Sending state 0.00000 mm with 2 decimals of accuracy
[13:08:41][W][component:237]: Component sonic_i2c.sensor took a long time for an operation (167 ms).
[13:08:41][W][component:238]: Components should block for at most 30 ms.
[13:08:46][650854][E][Wire.cpp:513] requestFrom(): i2cRead returned Error 263
[13:08:46][I][sonic_i2c:047]: Incorrect Distance Reading
[13:08:46][D][sensor:094]: 'Ultrasonic Sensor 1': Sending state 0.00000 mm with 2 decimals of accuracy
[13:08:46][W][component:237]: Component sonic_i2c.sensor took a long time for an operation (167 ms).
[13:08:46][W][component:238]: Components should block for at most 30 ms.

Try the other way round

thanks for the suggestion :wink:

I tried that and even tried a lot of different GPIO pins and nothing, swappping them round simply gives me exactly the same error. Hopefully someone has this working and can share :rofl:

Your library gives that.

Try to increase I2C timeout