ESPHome and Level Shifter: annoying behaviour

Hi all.
I have to interface a 0-5V analog pressure sensor to ESPHome (AZDelivery ESP32 platform)
I know I must shift the level in the 3.3V domain so I get a level shifter (specifically the TXS0108E sold by AZDelivery: see this link)

I triple check soldering and connection and used a 10K pullup resistor on the OE for the level shifter as required.

I observed this behaviour:

  • I checked the sensor using a voltmeter (no load) and it works correctly on the 0-5V range with linear performances

  • I connect power to the level shifter (VA to 3.3v given by ESPHOME, GND to GND by ESPHOME, VB to 5V used for the sensor. GND was the same for ESPHOME, the level shifter and the pressure sensor)

  • I checked with voltmeter the output of the “low voltage” from the shifter for the channel I used for pressure sensor (again: no load, just voltmeter) It was very precisely converted from the 5V domain to the 3.3V domain and it was really linear.

  • At this point I connect the SAME pin I just measured with volt meter to the GPIO34 of the ESPHOME and suddendly I read 3.3V, disregarding the level of the pressure sensor

This is very strange, it seems that as soon as I attach the ESPHOME pin (which I configured as ADC) it imposes the maximum voltage on the pin and do not use it as input.

Please find hereafter the configuration of my ESPHOME.

Any suggestion is more than welcome, as I do not know what I did wrong.

esphome:
  name: "epshome-carico"
  friendly_name: ESPHome Carico automatico

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: !secret carico_HA_key

ota:


wifi:
  networks:
    - ssid: !secret wifi_ssid
      password: !secret wifi_password
    - ssid: !secret wifi_ssid_2
      password: !secret wifi_password_2

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esphome-Web-6Bda40"
    password: !secret ap_password

captive_portal:

sensor:
  - platform: adc
    pin: GPIO34
      #allow_other_uses: True
    name: "Lettura analogica"
    unit_of_measurement: "V"
    attenuation: auto
    update_interval: 1s
    id: lettura  

  - platform: copy
    source_id: lettura
    name: "Lettura pressione"
    unit_of_measurement: "atm"
    id: conversione
    filters:
      - round: 1
      - calibrate_linear:
          method: least_squares
          datapoints:
            - 0.69 -> 1.0
            - 3.00 -> 2.0
    on_value_range:
      - below: 1.0
        then:
          - switch.turn_on: relay1
          - switch.turn_on: relay2
      - above: 1.5
        then:
          - switch.turn_off: relay1
          - switch.turn_off: relay2
      



switch:
  - platform: gpio
    pin: GPIO22
    inverted: True
    name: "Canale 1"
    id: relay1 
    on_turn_on:
      then:
        - switch.turn_on: relay2 
    on_turn_off:
      then:
        - switch.turn_off: relay2

  - platform: gpio
    pin: GPIO23
    inverted: True
    name: "Canale 2"
    id: relay2
    on_turn_on:
      then:
        - switch.turn_on: relay1
    on_turn_off:
      then:
        - switch.turn_off: relay1

The TXS0108E was such a pain in my a$$ the first time I tried them. I find the transistor based ones to be about as simple as it gets and they just work every single time. Did you check the data sheet or spec sheet for the TXS0108E? That’s not typically how you work with ADC Inputs and I’m not 100% sure you even can use that chip for ADC, it’s really for digital signals. You want a voltage divider for ADC and if you would have used the transistor style logic shifters, you can actually modify one of the channels to make it a 3 channel logic shifter and use the 4th for a voltage divider or however many you need, they also come in 8 channel. There’s info in these forums, you can do a search and find info on how to do it.

If you do get that working, I definately am curious to know how that goes.

if you are going from 5v down to 3v3 just use a voltage divider, no need for a logic level converter, and you dont need bi-directional… thats probably part of the problem.

and ESP32 analog in is not 3.3v, some boards have a voltage divider to make it 3.3 but not all. you need to find the schematic for your board and check.
have a read of the attenuation section… it explains it better than i can!

As soon You read TXS0108E description on AzDelivery, AliExpress, AllDataSheet, … - will see the name is “LOGIC level converter”.

Beware, LOGIC (aka Digital) is not an Analog…

TXS0108E is designed to translate/shift/… LOGIC/Digital levels between f.e. 3.3/5V logic.
For Analog signal must use different solutions, like I2C connected ADC boards or just simple resistor voltage divider to use internal ESP ADC input.

Thats all been covered more than once already but, good job! 3 is the magic number.