esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
291 stars 36 forks source link

Multiple spi bus. ADC128S102 #4164

Closed chihirox closed 1 year ago

chihirox commented 1 year ago

The problem

Both SPI busses works, but the ADC128S102 doesn't respect spi_id, only working with the last spi bus entry.

Seems to be same problem as: https://github.com/esphome/issues/issues/3817

https://github.com/esphome/issues/issues/1708

Which version of ESPHome has the issue?

2022.9.4

What type of installation are you using?

pip

Which version of Home Assistant has the issue?

No response

What platform are you using?

ESP32

Board

az-delivery-devkit-v4

Component causing the issue

Spi

Example YAML snippet

esphome:
  name: ct_sensors_mcp
  platform: ESP32
  board: az-delivery-devkit-v4

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: "password"

ota:
  password: "password"

wifi:
  ssid: "ssid"
  password: "password"

  manual_ip:
    static_ip: xxx.xxx.x.x
    gateway: xxx.xxx.x.x
    subnet: 255.255.255.0

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "CT_sensors_mcp"
    password: "password"

captive_portal:

spi:

  - id: first
    clk_pin: GPIO14
    mosi_pin: GPIO13
    miso_pin: GPIO12  

  - id: second
    clk_pin: GPIO18
    mosi_pin: GPIO23  
    miso_pin: GPIO19

mcp3204:
  spi_id: first
  cs_pin: GPIO27
  reference_voltage: 2.5V

mcp3008:
  spi_id: second
  cs_pin: GPIO17
  id: mcp3008_bus

sensor:

  - platform: mcp3008             # Attached to pin 0 of the MCP3008.
    reference_voltage: 2.5v
    update_interval: 1s
    mcp3008_id: mcp3008_bus
    id: mcp_3008_0
    number: 0
    on_value:
      - sensor.template.publish:
          id: volt_mcp3008_0
          state: !lambda 'return x;'

  - platform: mcp3204             # Attached to pin 0 of the MCP3204.
    update_interval: 10s
    mcp3204_id: mcp3204_bus
    id: mcp_3208_0
    name: mcp_3208_0
    number: 0   
    on_value:
        - sensor.template.publish:
            id: volt_mcp3208_0
            state: !lambda 'return x;'

  - platform: mcp3204             # Attached to pin 1 of the MCP3204.
    update_interval: 10s
    mcp3204_id: mcp3204_bus
    id: mcp_3208_1
    name: mcp_3208_1
    number: 1
    on_value:
        - sensor.template.publish:
            id: volt_mcp3208_1
            state: !lambda 'return x;'

  - platform: mcp3204             # Attached to pin 2 of the MCP3204.
    update_interval: 10s
    mcp3204_id: mcp3204_bus
    id: mcp_3208_2
    name: mcp_3208_2
    number: 2
    on_value:
        - sensor.template.publish:
            id: volt_mcp3208_2
            state: !lambda 'return x;'

Anything in the logs that might be useful for us?

←[32mINFO Successfully connected to 192.168.60.118←[0m
[23:54:52][I][app:102]: ESPHome version 2022.9.4 compiled on Feb 11 2023, 23:54:21
[23:54:52][C][wifi:502]: WiFi:
[23:54:52][C][wifi:360]:   Local MAC: EC:94:CB:4C:7B:C0
[23:54:52][C][wifi:361]:   SSID: 'KGB Limit'
[23:54:52][C][wifi:362]:   IP Address: 192.168.60.118
[23:54:52][C][wifi:364]:   BSSID: 72:D7:9A:27:47:DE
[23:54:52][C][wifi:365]:   Hostname: 'ct_sensors_mcp'
[23:54:52][C][wifi:367]:   Signal strength: -48 dB ▂▄▆█
[23:54:52][C][wifi:371]:   Channel: 6
[23:54:52][C][wifi:372]:   Subnet: 255.255.255.0
[23:54:52][C][wifi:373]:   Gateway: 192.168.60.1
[23:54:52][C][wifi:374]:   DNS1: 0.0.0.0
[23:54:52][C][wifi:375]:   DNS2: 0.0.0.0
[23:54:52][C][logger:275]: Logger:
[23:54:52][C][logger:276]:   Level: DEBUG
[23:54:52][C][logger:277]:   Log Baud Rate: 115200
[23:54:52][C][logger:278]:   Hardware UART: UART0
[23:54:52][C][spi:101]: SPI bus:
[23:54:52][C][spi:102]:   CLK Pin: GPIO14
[23:54:52][C][spi:103]:   MISO Pin: GPIO12
[23:54:52][C][spi:104]:   MOSI Pin: GPIO13
[23:54:52][C][spi:106]:   Using HW SPI: YES
[23:54:52][C][spi:101]: SPI bus:
[23:54:52][C][spi:102]:   CLK Pin: GPIO18
[23:54:52][C][spi:103]:   MISO Pin: GPIO19
[23:54:52][C][spi:104]:   MOSI Pin: GPIO23
[23:54:52][C][spi:106]:   Using HW SPI: YES
[23:54:52][C][mcp3204:017]: MCP3204:
[23:54:52][C][mcp3204:018]:   CS Pin:GPIO27
[23:54:52][C][mcp3204:019]:   Reference Voltage: 2.50V
[23:54:52][C][mcp3008:017]: MCP3008:
[23:54:52][C][mcp3008:018]:   CS Pin:GPIO17
[23:54:52][C][template.sensor:023]: Template Sensor 'Volt mcp3208_0'
[23:54:52][C][template.sensor:023]:   State Class: ''
[23:54:52][C][template.sensor:023]:   Unit of Measurement: 'v'
[23:54:52][C][template.sensor:023]:   Accuracy Decimals: 5
[23:54:52][C][template.sensor:024]:   Update Interval: 60.0s
[23:54:52][C][template.sensor:023]: Template Sensor 'Volt mcp3208_0_2'
[23:54:52][C][template.sensor:023]:   State Class: ''
[23:54:52][C][template.sensor:023]:   Unit of Measurement: 'v'
[23:54:52][C][template.sensor:023]:   Accuracy Decimals: 5
[23:54:52][C][template.sensor:024]:   Update Interval: 60.0s
[23:54:52][C][template.sensor:023]: Template Sensor 'Volt mcp3208_0_3'
[23:54:52][C][template.sensor:023]:   State Class: ''
[23:54:52][C][template.sensor:023]:   Unit of Measurement: 'v'
[23:54:52][C][template.sensor:023]:   Accuracy Decimals: 5
[23:54:52][C][template.sensor:024]:   Update Interval: 60.0s
[23:54:52][C][template.sensor:023]: Template Sensor 'Volt mcp3208_0_4'
[23:54:52][C][template.sensor:023]:   State Class: ''
[23:54:52][C][template.sensor:023]:   Unit of Measurement: 'v'
[23:54:52][C][template.sensor:023]:   Accuracy Decimals: 5
[23:54:52][C][template.sensor:024]:   Update Interval: 60.0s
[23:54:52][C][template.sensor:023]: Template Sensor 'Volt mcp3208_1'
[23:54:52][C][template.sensor:023]:   State Class: ''
[23:54:52][C][template.sensor:023]:   Unit of Measurement: 'v'
[23:54:52][C][template.sensor:023]:   Accuracy Decimals: 5
[23:54:52][C][template.sensor:024]:   Update Interval: 60.0s
[23:54:52][D][ct_clamp:038]: 'CT mcp3008_0' - Raw AC Value: 0.001A after 8 different samples (40 SPS)
[23:54:52][D][ct_clamp:038]: 'CT mcp3208_1' - Raw AC Value: 1.237A after 7 different samples (35 SPS)
[23:54:52][C][template.sensor:023]: Template Sensor 'Volt mcp3208_2'
[23:54:52][C][template.sensor:023]:   State Class: ''
[23:54:52][C][template.sensor:023]:   Unit of Measurement: 'v'
[23:54:52][C][template.sensor:023]:   Accuracy Decimals: 5
[23:54:52][C][template.sensor:024]:   Update Interval: 60.0s
[23:54:52][C][template.sensor:023]: Template Sensor 'Volt mcp3208_3'
[23:54:52][C][template.sensor:023]:   State Class: ''
[23:54:52][C][template.sensor:023]:   Unit of Measurement: 'v'
[23:54:52][C][template.sensor:023]:   Accuracy Decimals: 5
[23:54:52][C][template.sensor:024]:   Update Interval: 60.0s
[23:54:52][C][template.sensor:023]: Template Sensor 'Volt mcp3208_3'
[23:54:52][C][template.sensor:023]:   State Class: ''
[23:54:52][C][template.sensor:023]:   Unit of Measurement: 'v'
[23:54:52][C][template.sensor:023]:   Accuracy Decimals: 5
[23:54:52][C][template.sensor:024]:   Update Interval: 60.0s
[23:54:52][C][template.sensor:023]: Template Sensor 'Volt mcp3208_0_1'
[23:54:52][C][template.sensor:023]:   State Class: ''
[23:54:52][C][template.sensor:023]:   Unit of Measurement: 'v'
[23:54:52][C][template.sensor:023]:   Accuracy Decimals: 5
[23:54:52][C][template.sensor:024]:   Update Interval: 60.0s
[23:54:52][C][template.sensor:023]: Template Sensor 'Volt mcp3208_1_0'
[23:54:52][C][template.sensor:023]:   State Class: ''
[23:54:52][C][template.sensor:023]:   Unit of Measurement: 'v'
[23:54:52][C][template.sensor:023]:   Accuracy Decimals: 5
[23:54:52][C][template.sensor:024]:   Update Interval: 60.0s
[23:54:52][C][template.sensor:023]: Template Sensor 'Volt mcp3008_0'
[23:54:52][C][template.sensor:023]:   State Class: ''
[23:54:52][C][template.sensor:023]:   Unit of Measurement: 'v'
[23:54:52][C][template.sensor:023]:   Accuracy Decimals: 5
[23:54:52][C][template.sensor:024]:   Update Interval: 60.0s
[23:54:52][D][sensor:127]: 'mcp_3008_0': Sending state 1.25122  with 0 decimals of accuracy
[23:54:52][D][sensor:127]: 'Volt mcp3008_0': Sending state 1.25122 v with 5 decimals of accuracy
[23:54:52][C][mcp3008:047]: MCP3008Sensor:
[23:54:52][C][mcp3008:048]:   Pin: 0
[23:54:52][C][mcp3008:049]:   Reference Voltage: 2.50V
[23:54:52][C][mcp3204.sensor:015]: MCP3204 Sensor 'mcp_3208_0'
[23:54:52][C][mcp3204.sensor:015]:   State Class: ''
[23:54:52][C][mcp3204.sensor:015]:   Unit of Measurement: ''
[23:54:52][C][mcp3204.sensor:015]:   Accuracy Decimals: 0
[23:54:52][C][mcp3204.sensor:016]:   Pin: 0
[23:54:52][C][mcp3204.sensor:017]:   Update Interval: 10.0s
[23:54:52][C][mcp3204.sensor:015]: MCP3204 Sensor 'mcp_3208_1'
[23:54:52][C][mcp3204.sensor:015]:   State Class: ''
[23:54:52][C][mcp3204.sensor:015]:   Unit of Measurement: ''
[23:54:52][C][mcp3204.sensor:015]:   Accuracy Decimals: 0
[23:54:52][C][mcp3204.sensor:016]:   Pin: 1
[23:54:52][C][mcp3204.sensor:017]:   Update Interval: 10.0s
[23:54:52][C][mcp3204.sensor:015]: MCP3204 Sensor 'mcp_3208_2'
[23:54:52][C][mcp3204.sensor:015]:   State Class: ''
[23:54:52][C][mcp3204.sensor:015]:   Unit of Measurement: ''
[23:54:52][C][mcp3204.sensor:015]:   Accuracy Decimals: 0
[23:54:52][C][mcp3204.sensor:016]:   Pin: 2
[23:54:52][C][mcp3204.sensor:017]:   Update Interval: 10.0s
[23:54:52][C][mcp3204.sensor:015]: MCP3204 Sensor 'mcp_3208_3'
[23:54:52][C][mcp3204.sensor:015]:   State Class: ''
[23:54:52][C][mcp3204.sensor:015]:   Unit of Measurement: ''
[23:54:52][C][mcp3204.sensor:015]:   Accuracy Decimals: 0
[23:54:52][C][mcp3204.sensor:016]:   Pin: 3
[23:54:52][C][mcp3204.sensor:017]:   Update Interval: 10.0s
[23:54:52][D][ct_clamp:038]: 'CT mcp3008_0' - Raw AC Value: 0.001A after 4 different samples (20 SPS)
[23:54:52][D][sensor:127]: 'CT mcp3008_0': Sending state 8.80214 w with 2 decimals of accuracy
[23:54:52][C][mcp3204.sensor:015]: MCP3204 Sensor 'mcp_3208_4'
[23:54:52][C][mcp3204.sensor:015]:   State Class: ''
[23:54:52][C][mcp3204.sensor:015]:   Unit of Measurement: ''
[23:54:52][C][mcp3204.sensor:015]:   Accuracy Decimals: 0
[23:54:52][C][mcp3204.sensor:016]:   Pin: 3
[23:54:52][C][mcp3204.sensor:017]:   Update Interval: 10.0s
[23:54:52][D][ct_clamp:038]: 'CT mcp3208_1' - Raw AC Value: 1.250A after 4 different samples (20 SPS)
[23:54:52][D][sensor:127]: 'CT mcp3208_1': Sending state 5506.46777 w with 2 decimals of accuracy
[23:54:52][C][ct_clamp:012]: CT Clamp Sensor 'CT mcp3208_0_3'
[23:54:52][C][ct_clamp:012]:   Device Class: 'current'
[23:54:52][C][ct_clamp:012]:   State Class: 'measurement'
[23:54:52][C][ct_clamp:012]:   Unit of Measurement: 'w'
[23:54:52][C][ct_clamp:012]:   Accuracy Decimals: 2
[23:54:52][C][ct_clamp:013]:   Sample Duration: 0.20s
[23:54:52][C][ct_clamp:014]:   Update Interval: 0.4s
[23:54:52][C][ct_clamp:012]: CT Clamp Sensor 'CT mcp3208_1'
[23:54:52][C][ct_clamp:012]:   Device Class: 'current'
[23:54:52][C][ct_clamp:012]:   State Class: 'measurement'
[23:54:52][C][ct_clamp:012]:   Unit of Measurement: 'w'
[23:54:52][C][ct_clamp:012]:   Accuracy Decimals: 2
[23:54:52][C][ct_clamp:013]:   Sample Duration: 0.20s
[23:54:52][C][ct_clamp:014]:   Update Interval: 0.4s
[23:54:52][C][ct_clamp:012]: CT Clamp Sensor 'CT mcp3208_3'
[23:54:53][C][ct_clamp:012]:   Device Class: 'current'
[23:54:53][C][ct_clamp:012]:   State Class: 'measurement'
[23:54:53][C][ct_clamp:012]:   Unit of Measurement: 'w'
[23:54:53][C][ct_clamp:012]:   Accuracy Decimals: 2
[23:54:53][C][ct_clamp:013]:   Sample Duration: 0.20s
[23:54:53][C][ct_clamp:014]:   Update Interval: 0.4s
[23:54:53][C][ct_clamp:012]: CT Clamp Sensor 'CT mcp3008_0'
[23:54:53][C][ct_clamp:012]:   Device Class: 'current'
[23:54:53][C][ct_clamp:012]:   State Class: 'measurement'
[23:54:53][C][ct_clamp:012]:   Unit of Measurement: 'w'
[23:54:53][C][ct_clamp:012]:   Accuracy Decimals: 2
[23:54:53][C][ct_clamp:013]:   Sample Duration: 0.20s
[23:54:53][C][ct_clamp:014]:   Update Interval: 0.4s
[23:54:53][C][captive_portal:088]: Captive Portal:
[23:54:53][C][mdns:100]: mDNS:
[23:54:53][C][mdns:101]:   Hostname: ct_sensors_mcp
[23:54:53][C][ota:089]: Over-The-Air Updates:
[23:54:53][C][ota:090]:   Address: 192.168.60.118:3232
[23:54:53][C][ota:093]:   Using Password.
[23:54:53][C][api:138]: API Server:
[23:54:53][C][api:139]:   Address: 192.168.60.118:6053
[23:54:53][C][api:143]:   Using noise encryption: NO

Additional information

No response

kbx81 commented 1 year ago

Please test https://github.com/esphome/esphome/pull/4669 and let me know if it fixes the issue for you.

Add this to your config to give it a try:

external_components:
  - source: github://pr#4669
    components: [ spi ]