Multiple Devices on I2C bus

@goeste Could you share your setup please?
Best regards :smiley:

@KaherdinTristan @animeshp1: sry for coming back only now… also i got rid of the AM… and switched to a bme280

this is my complete config: unfortunately there is no diagram, but according to the pins you should be able to figure it all out. I connected nearly all grounds to one single GND though

esphome:
  name: "esphome-garage"

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esphome-Web-xxxxxx"
    password: "xxxxxx"
###
# Los geht's
###
captive_portal:

###
# I2C
###
i2c:
  - id: bus_a
    sda: 16
    scl: 17
    scan: true

###
# BinarySensors
###
binary_sensor:
  - platform: gpio
    name: Regensensor
    device_class: moisture
    pin:
      number: GPIO14
      inverted: True
      mode:
        input: True
        pullup: True
#Regenmenge
  - platform: gpio
    name: "Regenmenge"
    device_class: window
    pin:
      number: GPIO26
      inverted: True
      mode:
        input: True
        pullup: True
###
# Sensors
###
sensor:
#Helligkeit
#  - platform: bh1750
#    i2c_id: bus_b
#    name: "Lux Garage"
#    address: 0x23
#    #address: 0xc5
#    update_interval: 30s
#    filters:
#      - sliding_window_moving_average:
#          window_size: 10
#          send_every: 10
#          send_first_at: 1
#      - or:
#          - throttle: 60s
#          - delta: 10
#Temperatur
  - platform: bme280
    i2c_id: bus_a
    temperature:
      name: "Garage Temperature"
      oversampling: 16x
    pressure:
      name: "Garage Pressure"
    humidity:
      name: "Garage Humidity"
    address: 0x76
    update_interval: 5s
#Windsensor
  - platform: pulse_meter
    pin: 
      number: GPIO20
      mode: INPUT_PULLUP
    name: 'Garage Windgeschwindigkeit'
    icon: 'mdi:weather-windy'
    unit_of_measurement: 'm/s'
    internal_filter: 13us
    timeout: 5s
    filters:
      - multiply: 0.005560619
      - sliding_window_moving_average:
          window_size: 5
          send_every: 5

###
# Switches
###
switch:
  - platform: restart
    name: "Garage Restart"
1 Like

I think this comment just saved my day. Thanks alot @tom_l I was really starting to get crazy…

1 Like

Hello,

I’m facing quite same problem handling multiple I2C elements linked to my ESP32 using espHome.

In fact I would like both BH1750 and esp32cam to work together on same board.

For now I suceeded making only one working at a time.

I found the Pinout of the board Here https://github.com/Freenove/Freenove_Basic_Starter_Kit_for_ESP32/blob/5e168c36288cd304ef906464573b25e59ed3ef6a/Datasheet/ESP32-Pinout.pdf

Here is my yaml file

esphome:
  name: illuminance-mezzanine
  friendly_name: illuminance-mezzanine

esp32:
  board: esp32dev
  framework:
    type: arduino

# .....

captive_portal:

i2c:
  - sda: 26
    scl: 27
    id: bus_a
    scan: True

sensor:
  - platform: bh1750
    name: "BH1750 illuminance"
    update_interval: 1s
    i2c_id: bus_a
    #address: 0x5c


switch:
  - platform: restart
    name: "ESP32 Restart"

As for now Camera seams to be found using the scan parameter but not accessible.

When I tried to add the esp32cam component it obviously failed due to same pin usage.

Is someone can help me find out a way to share the pins or maybe to find some other I2C pins that are not used by the camera ?

Thanks

Hi,
I’m trying the AS5600 magnetic angle sensor AS5600 12-Bit Magnetic Position Sensor — ESPHome on an ESPwroom32D: it works perfectly on the i2c “bus” by default. I want to add a second one and because we cannot change its address i have to activate the 2nd i2c bus I²C Bus — ESPHome.

But i got this error message :
[i2c_id] is an invalid option for [sensor.as5600]. Please check the indentation.

here is part of my yaml:

i2c:
   - sda: 12
     scl: 13
     id: bus_a
     scan: true
   #- id: bus_b
   #  sda: 14
   #  scl: 27
   #  scan: true

#capteur d'angle magnetique
as5600:  
  id: my_as5600
  
# CAPTEURS connectés 
sensor:
  - platform: as5600
    i2c_id: bus_a
    #address: 0x36
    name: Azimuth_angle
    unit_of_measurement: '°'
    accuracy_decimals: 0 #2
    icon: mdi:rotate-right
    update_interval: 1s
    
    filters:
      - delta: 1
      - lambda: 'return x * as5600::RAW_TO_DEGREES * id(my_as5600).get_range_scale();'
    status:
      name: Status  

Does the AS5600 component not support assigning a specific i2c bus to it? or Did I make a mistake in my yaml?

THANKS

Change:

i2c:
   - sda: 12
     scl: 13
     id: bus_a
     scan: true

with:

i2c:
   - id: bus_a
     sda: 12
     scl: 13
     scan: true

thanks for reply but same error :

Failed config

sensor.as5600: [source espwroom32_2xas5600.yaml:109]
  platform: as5600

  [i2c_id] is an invalid option for [sensor.as5600]. Please check the indentation.
  i2c_id: bus_a
  name: Azimuth_angle
i2c:
   - id: bus_a
     sda: 12
     scl: 13
     scan: true

sensor:
  - platform: as5600
    i2c_id: bus_a

it looks like he doesn’t want the: i2c_id: bus_a ??

Have you set the sensor address? I see in a previous message that you have comment out it.

ok, I have made the settings correctly:

i2c:
   - id: bus_a
     sda: 21
     scl: 22
     scan: true
   - id: bus_b
     sda: 18
     scl: 5
     scan: true

#capteur d'angle magnetique
as5600:  
  id: my_as5600
  
# CAPTEURS connectés 
sensor:
  - platform: as5600
    i2c_id: bus_a
    address: 0x36
    name: Azimuth_angle
    unit_of_measurement: '°'
    accuracy_decimals: 0 #2
    icon: mdi:rotate-right
    update_interval: 1s
    filters:
      - delta: 1
      - lambda: 'return x * as5600::RAW_TO_DEGREES * id(my_as5600).get_range_scale();'
    status:
      name: Status
      id: azimuth_status

and the message is still present:

Failed config

sensor.as5600: [source espwroom32_2xas5600.yaml:115]
  platform: as5600

  [i2c_id] is an invalid option for [sensor.as5600]. Please check the indentation.
  i2c_id: bus_a

  [address] is an invalid option for [sensor.as5600]. Please check the indentation.
  address: 54
  name: Azimuth_angle
  unit_of_measurement: °
  accuracy_decimals: 0
  icon: mdi:rotate-right
  update_interval: 1s
  filters:
    - delta: 1

P.S. I tested the hardware with an arduino sketch and the 2 i2c buses are activated and I display my 2 as5600 values, so it is not a hardware problem.

Another idea ?