esphome / issues

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

mcp9808 reports ~16deg too low temperature #1754

Closed tvwerkhoven closed 3 years ago

tvwerkhoven commented 3 years ago

Operating environment/Installation (Hass.io/Docker/pip/etc.):

Installed from source via setup.py as root.

ESP (ESP32/ESP8266, Board/Sonoff):

WeMos D1 mini pro with modules: BME280 (I2C), OLED (I2C), MH-Z19B CO2 (UART), SDS fine-dust (UART)

ESPHome version (latest production, beta, dev branch)

v1.16.0b2

Affected component:

mcp9808 (dev branch docs not available online)

Description of problem: The mcp9808 sensor reports 4.0x too low temperatures when compared to a BME280 on the same board. I can verify the BME280 is correct as it's more like 20deg than 5deg in my room ;)

Problem-relevant YAML-configuration entries:

esphome:
  name: esp_mobile
  platform: ESP8266
  board: d1_mini_pro

wifi:
  redacted

logger:
  baud_rate: 0

api:
  reboot_timeout: 0s

ota:

mqtt:
  redacted

uart:
  - id: myuart0 # SDS pm2.5/pm10
    rx_pin: GPIO3
    tx_pin: GPIO1
    baud_rate: 9600
  - id: myuart1 # MH-z19B CO2
    rx_pin: GPIO12 # GPIO3 = RX hardware
    tx_pin: GPIO13 # GPIO1 = TX hardware
    baud_rate: 9600

i2c:
  sda: 4
  scl: 5
  scan: True

sensor:
  - platform: sds011
    redacted
  - platform: wifi_signal
    redacted
  - platform: uptime
    redacted
  - platform: mhz19
    redacted
  - platform: mcp9808
    name: "MCP Temperature"
    update_interval: 30s
    state_topic: influx/environv3/quantity/T/source/mcp9808/board/esp_mobile/location/home/room/guestoffice/value/state
  - platform: bme280
    redacted

display:
  - platform: ssd1306_i2c
    redacted

Logs (if applicable):

[11:59:21][I][app:105]: ESPHome version 1.16.0b2 compiled on Jan 11 2021, 10:51:31
[...]
[11:59:21][C][i2c:028]: I2C Bus:
[11:59:21][C][i2c:029]:   SDA Pin: GPIO4
[11:59:21][C][i2c:030]:   SCL Pin: GPIO5
[11:59:21][C][i2c:031]:   Frequency: 50000 Hz
[11:59:21][I][i2c:033]: Scanning i2c bus for active devices...
[11:59:21][I][i2c:040]: Found i2c device at address 0x18
[11:59:21][I][i2c:040]: Found i2c device at address 0x3C
[11:59:21][I][i2c:040]: Found i2c device at address 0x76
[...]
[11:59:56][C][mcp9808:037]: MCP Temperature:
[11:59:56][C][mcp9808:038]:   Address: 0x18
[11:59:56][C][mcp9808:042]:   Update Interval: 30.0s
[11:59:56][C][mcp9808:043]:   Temperature 'MCP Temperature'
[11:59:56][C][mcp9808:043]:     Unit of Measurement: '°C'
[11:59:56][C][mcp9808:043]:     Accuracy Decimals: 1
[11:59:56][C][mcp9808:043]:     Icon: 'mdi:thermometer'
[11:59:56][C][bme280.sensor:142]: BME280:
[11:59:56][C][bme280.sensor:143]:   Address: 0x76
[11:59:56][C][bme280.sensor:155]:   IIR Filter: OFF
[11:59:56][C][bme280.sensor:156]:   Update Interval: 60.0s
[11:59:56][C][bme280.sensor:158]:   Temperature 'BME280 Temperature'
[11:59:56][C][bme280.sensor:158]:     Unit of Measurement: '°C'
[11:59:56][C][bme280.sensor:158]:     Accuracy Decimals: 1
[11:59:56][C][bme280.sensor:158]:     Icon: 'mdi:thermometer'
[11:59:56][C][bme280.sensor:159]:     Oversampling: 1x
[11:59:56][C][bme280.sensor:160]:   Pressure 'BME280 Pressure'
[11:59:56][C][bme280.sensor:160]:     Unit of Measurement: 'hPa'
[11:59:56][C][bme280.sensor:160]:     Accuracy Decimals: 1
[11:59:56][C][bme280.sensor:160]:     Icon: 'mdi:gauge'
[11:59:56][C][bme280.sensor:161]:     Oversampling: 16x
[11:59:56][C][bme280.sensor:162]:   Humidity 'BME280 Humidity'
[11:59:56][C][bme280.sensor:162]:     Unit of Measurement: '%'
[11:59:56][C][bme280.sensor:162]:     Accuracy Decimals: 1
[11:59:56][C][bme280.sensor:162]:     Icon: 'mdi:water-percent'
[11:59:56][C][bme280.sensor:163]:     Oversampling: 16x
[11:59:56][C][ssd1306_i2c:023]: I2C SSD1306
[11:59:56][C][ssd1306_i2c:023]:   Rotations: 90 °
[11:59:56][C][ssd1306_i2c:023]:   Dimensions: 48px x 64px
[11:59:56][C][ssd1306_i2c:024]:   Address: 0x3C
[11:59:56][C][ssd1306_i2c:025]:   Model: SSD1306 64x48
[11:59:56][C][ssd1306_i2c:026]:   Reset Pin: GPIO16 (Mode: OUTPUT)
[11:59:56][C][ssd1306_i2c:027]:   External VCC: NO
[11:59:56][C][ssd1306_i2c:028]:   Update Interval: 1.0s
[...]
[12:00:09][D][bme280.sensor:197]: Got temperature=19.6°C pressure=1017.6hPa humidity=47.5%
[12:00:09][D][sensor:092]: 'BME280 Temperature': Sending state 19.58000 °C with 1 decimals of accuracy
[12:00:09][D][sensor:092]: 'BME280 Pressure': Sending state 1017.55939 hPa with 1 decimals of accuracy
[12:00:09][D][sensor:092]: 'BME280 Humidity': Sending state 47.53125 % with 1 decimals of accuracy
[12:00:09][D][mcp9808:074]: MCP Temperature: Got temperature=4.8125°C
[12:00:09][D][sensor:092]: 'MCP Temperature': Sending state 4.81250 °C with 1 decimals of accuracy
[...]
[12:02:09][D][sensor:092]: 'BME280 Temperature': Sending state 19.97000 °C with 1 decimals of accuracy
[12:02:09][D][sensor:092]: 'BME280 Pressure': Sending state 1017.49908 hPa with 1 decimals of accuracy
[12:02:09][D][sensor:092]: 'BME280 Humidity': Sending state 46.69824 % with 1 decimals of accuracy
[12:02:09][D][mcp9808:074]: MCP Temperature: Got temperature=5.1875°C
[12:02:09][D][sensor:092]: 'MCP Temperature': Sending state 5.18750 °C with 1 decimals of accuracy
[...]
[12:08:09][D][bme280.sensor:197]: Got temperature=20.6°C pressure=1017.4hPa humidity=45.2%
[12:08:09][D][sensor:092]: 'BME280 Temperature': Sending state 20.65000 °C with 1 decimals of accuracy
[12:08:09][D][sensor:092]: 'BME280 Pressure': Sending state 1017.43781 hPa with 1 decimals of accuracy
[12:08:09][D][sensor:092]: 'BME280 Humidity': Sending state 45.18457 % with 1 decimals of accuracy
[12:08:09][D][mcp9808:074]: MCP Temperature: Got temperature=5.6875°C
[12:08:09][D][sensor:092]: 'MCP Temperature': Sending state 5.68750 °C with 1 decimals of accuracy

Additional information and things you've tried:

  1. Power cycling doesn't help
  2. It doesn't seem to have to do with resolution setting, adding a resolution setter loop does not help (see below)
  3. Disconnecting one other I2C device (BME280) does not help
  4. Printing (raw_temp & 0x0FFF)/16.0f from original Adafruit library gives identical value, so no typos with masking etc.
  5. Using another board (also Wemos D1 mini pro) gives the same result.

Details of 2. Adding the following code to update() of the component:

  uint8_t reg_resolution = (tim_runloop % 4);
  if (this->write_byte(0x08, reg_resolution)) {
    ESP_LOGD(TAG, "%s: Set resolution %d", this->name_.c_str(), reg_resolution);
  }

  uint16_t resolution;
  if (this->read_byte_16(0x08, &resolution, 0)) {
    ESP_LOGD(TAG, "%s: Got resolution reg=%d", this->name_.c_str(), (uint8_t)((resolution & 0xff00) >> 8));
  }
  tim_runloop++;

Gives

[17:10:30][D][mcp9808:053]: MCP Temperature: Set resolution 1
[17:10:30][D][mcp9808:058]: MCP Temperature: Got resolution reg=1
[17:10:30][D][mcp9808:091]: MCP Temperature: Got temperature=4.5000°C
[17:11:00][D][mcp9808:053]: MCP Temperature: Set resolution 2
[17:11:00][D][mcp9808:058]: MCP Temperature: Got resolution reg=2
[17:11:00][D][mcp9808:091]: MCP Temperature: Got temperature=4.7500°C
[17:11:30][D][mcp9808:053]: MCP Temperature: Set resolution 3
[17:11:30][D][mcp9808:058]: MCP Temperature: Got resolution reg=3
[17:11:30][D][mcp9808:091]: MCP Temperature: Got temperature=4.7500°C
[17:12:00][D][mcp9808:053]: MCP Temperature: Set resolution 0
[17:12:00][D][mcp9808:058]: MCP Temperature: Got resolution reg=0
[17:12:00][D][mcp9808:091]: MCP Temperature: Got temperature=4.8125°C
[17:12:30][D][mcp9808:053]: MCP Temperature: Set resolution 1
[17:12:30][D][mcp9808:058]: MCP Temperature: Got resolution reg=1
[17:12:30][D][mcp9808:091]: MCP Temperature: Got temperature=5.0000°C
[17:13:00][D][mcp9808:053]: MCP Temperature: Set resolution 2
[17:13:00][D][mcp9808:058]: MCP Temperature: Got resolution reg=2
[17:13:00][D][mcp9808:091]: MCP Temperature: Got temperature=4.5000°C
[17:13:30][D][mcp9808:053]: MCP Temperature: Set resolution 3
[17:13:30][D][mcp9808:058]: MCP Temperature: Got resolution reg=3
[17:13:30][D][mcp9808:091]: MCP Temperature: Got temperature=4.8750°C
[17:14:00][D][mcp9808:053]: MCP Temperature: Set resolution 0
[17:14:00][D][mcp9808:058]: MCP Temperature: Got resolution reg=0
[17:14:00][D][mcp9808:091]: MCP Temperature: Got temperature=4.8125°C
[17:14:30][D][mcp9808:053]: MCP Temperature: Set resolution 1
[17:14:30][D][mcp9808:058]: MCP Temperature: Got resolution reg=1
[17:14:30][D][mcp9808:091]: MCP Temperature: Got temperature=4.5000°C
tvwerkhoven commented 3 years ago

On second thought, it seems there is a ~16 degree offset, not 4.0x.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.