ESP8266 ESP-01S and ALMOCN INA219 I2C Current Sensor - Found no i2c devices!

I am at my first project with ESP8266 ESP-01S and esphome. To my understanding I set up everything right, checked all the wiring with a voltmeter but I can’t get the ESP to find the I2C current sensor.

  • The LED symbolizes a water level sensor which has an output range of 4 to 20 mA.
  • The switch is for reset. The ESP8266 ESP-01S and the INA219 (it’s datasheet) should talk over I2C.
  • The INA219 seems to have pull up resistors, as I have around 3.3V on the SCL and SDA pins.
  • The batteries symbolize a 24V DC supply which is needed is input by the sensor.
  • The step down buck converter is adjusted to deliver 3.3V for the ESP8266 and the INA219.

Fritzing:

Corresponding wiring:

My esphome configuration:

esphome:
  name: sensor-well-water-level

esp8266:
  board: esp01_1m

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  password: "..."

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  manual_ip:
    static_ip: 10.116.0.120
    gateway: 10.116.0.1
    subnet: 255.255.255.0
    dns1: 10.116.0.25
    dns2: 10.116.0.26

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Sensor-Well-Water-Level"
    password: "..."

captive_portal:

i2c:
  scl: 5 # GPIO - 0
  sda: 3 # GPIO - 2
  scan: true
  frequency: 50kHz

sensor:
- platform: ina219
  address: 0x40
  shunt_resistance: 0.1 ohm
  current:
    name: "INA219 Current - Well Level Sensor"
  power:
    name: "INA219 Power - Well Level Sensor"
  bus_voltage:
    name: "INA219 Bus Voltage - Well Level Sensor"
  shunt_voltage:
    name: "INA219 Shunt Voltage - Well Level Sensor"
  max_voltage: 32.0V
  max_current: 3.2A
  update_interval: 60s

The log:

INFO Reading configuration /config/esphome/sensor-well-water-level.yaml...
INFO Generating C++ source...
INFO Compiling app...
Processing sensor-well-water-level (board: esp01_1m; framework: arduino; platform: platformio/espressif8266 @ 3.2.0)
--------------------------------------------------------------------------------
HARDWARE: ESP8266 80MHz, 80KB RAM, 1MB Flash
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
Dependency Graph
|-- <ESPAsyncTCP-esphome> 1.2.3
|-- <ESPAsyncWebServer-esphome> 2.1.0
|   |-- <ESPAsyncTCP-esphome> 1.2.3
|   |-- <Hash> 1.0
|   |-- <ESP8266WiFi> 1.0
|-- <DNSServer> 1.1.1
|-- <ESP8266WiFi> 1.0
|-- <ESP8266mDNS> 1.2
|-- <Wire> 1.0
RAM:   [====      ]  44.9% (used 36820 bytes from 81920 bytes)
Flash: [====      ]  42.2% (used 431833 bytes from 1023984 bytes)
========================= [SUCCESS] Took 6.23 seconds =========================
INFO Successfully compiled program.
INFO Connecting to 10.116.0.120
INFO Uploading /data/sensor-well-water-level/.pioenvs/sensor-well-water-level/firmware.bin (435984 bytes)
INFO Compressed to 301329 bytes
Uploading: [============================================================] 100% Done...

INFO Waiting for result...
INFO OTA successful
INFO Successfully uploaded program.
INFO Starting log output from 10.116.0.120 using esphome API
WARNING Can't connect to ESPHome API for 10.116.0.120: Timeout while connecting to ('10.116.0.120', 6053)
INFO Trying to reconnect to 10.116.0.120 in the background
INFO Successfully connected to 10.116.0.120
[09:59:34][I][app:102]: ESPHome version 2022.4.0 compiled on Apr 24 2022, 09:28:57
[09:59:34][C][wifi:491]: WiFi:
[09:59:34][C][wifi:353]:   Local MAC: 58:BF:25:DC:31:9C
[09:59:34][C][wifi:354]:   SSID: [redacted]
[09:59:34][C][wifi:355]:   IP Address: 10.116.0.120
[09:59:34][C][wifi:356]:   BSSID: [redacted]
[09:59:34][C][wifi:358]:   Hostname: 'sensor-well-water-level'
[09:59:34][C][wifi:360]:   Signal strength: -66 dB ▂▄▆█
[09:59:34][V][wifi:362]:   Priority: 0.0
[09:59:34][C][wifi:364]:   Channel: 11
[09:59:34][C][wifi:365]:   Subnet: 255.255.255.0
[09:59:34][C][wifi:366]:   Gateway: 10.116.0.1
[09:59:34][C][wifi:367]:   DNS1: 10.116.0.25
[09:59:34][C][wifi:368]:   DNS2: 10.116.0.26
[09:59:34][C][logger:233]: Logger:
[09:59:34][C][logger:234]:   Level: VERY_VERBOSE
[09:59:34][C][logger:235]:   Log Baud Rate: 115200
[09:59:34][C][logger:236]:   Hardware UART: UART0
[09:59:34][C][i2c.arduino:038]: I2C Bus:
[09:59:34][C][i2c.arduino:039]:   SDA Pin: GPIO3
[09:59:34][C][i2c.arduino:040]:   SCL Pin: GPIO5
[09:59:34][C][i2c.arduino:041]:   Frequency: 50000 Hz
[09:59:34][C][i2c.arduino:044]:   Recovery: bus successfully recovered
[09:59:34][I][i2c.arduino:054]: Results from i2c bus scan:
[09:59:34][I][i2c.arduino:056]: Found no i2c devices!
[09:59:34][C][ina219:133]: INA219:
[09:59:34][C][ina219:134]:   Address: 0x40
[09:59:34][E][ina219:137]: Communication with INA219 failed!
[09:59:34][C][captive_portal:088]: Captive Portal:
[09:59:34][C][mdns:084]: mDNS:
[09:59:34][C][mdns:085]:   Hostname: sensor-well-water-level
[09:59:34][V][mdns:086]:   Services:
[09:59:34][V][mdns:088]:   - _esphomelib, _tcp, 6053
[09:59:34][V][mdns:090]:     TXT: version = 2022.4.0
[09:59:34][V][mdns:090]:     TXT: mac = 58bf25dc319c
[09:59:34][V][mdns:090]:     TXT: platform = ESP8266
[09:59:34][V][mdns:090]:     TXT: board = esp01_1m
[09:59:34][C][ota:085]: Over-The-Air Updates:
[09:59:34][C][ota:086]:   Address: 10.116.0.120:8266
[09:59:34][C][ota:089]:   Using Password.
[09:59:34][C][api:138]: API Server:
[09:59:34][C][api:139]:   Address: 10.116.0.120:6053
[09:59:34][C][api:143]:   Using noise encryption: NO
[09:59:45][VV][api.service:355]: on_ping_request: PingRequest {}
[09:59:45][VV][api.service:043]: send_ping_response: PingResponse {}
[09:59:49][VV][api.service:355]: on_ping_request: PingRequest {}
[09:59:49][VV][api.service:043]: send_ping_response: PingResponse {}
[10:00:00][VV][api.service:355]: on_ping_request: PingRequest {}
[10:00:00][VV][api.service:043]: send_ping_response: PingResponse {}

I have tried to use different pins, different frequencies.I also tried another INA219 and a different ESP8266 ESP-01S.

I am really running out of ideas what to try else…

Has anybody a suggestion?

Edit:

  • fixed not up to date i2c pin config
  • replaced the fritzing with the current one. SCL & SDA changed.
  • logger to very_verbose

hoped to see some more information, how the i2c scanning works. but nope.

Gpio3 is not gpio 0

Tx is gpio1

A schematic would help. A Fritzing picture is not a schematic.

If the wiring is all correct the only thing that has caused this problem for me is a bad device. Try them 1 at a time

Clearly the wiring is not correct.

Connect SDA to GPIO0, SCL to GPIO2, and change your config accordingly:

sda: 0
scl: 2

The logfile states your device is using UART0, which uses TXD, so don’t use it for i2c.

You are right, it’s really much easier to read. Added one.

Changed it to use GPIO 0 & GPIO 2. But still no device found.

This had been my initial setup anyway, just got desperate and started to try random things.

I changed the pins to use GPIO 0 & GPIO 2 again. This had been my initial setup. If I remember correctly, this had been the state at the Fritzing. I updated config, fritzing, and physical wires to reflect each other. All the graphes should be corresponding now.
Double checked the wiring again and again but can’t find an issue.

I think everything should be fine now, but still no device found.

In that case, cut everything back to basics, just the ESP and the INA, powered by a regular 3.3V supply. If that still doesn’t work, I would suspect the sensor to be faulty.

Everything stripped down to the bare minimum, but still no success…

I will write my own code I2C test code in Arduino IDE and upload it to test the hardware. If this works, I have to debug esphome. My suspicion is not too many people use the ESP8266 ESP-01S module and there might be an undetected bug.

I will report back. Thanks for all your help so far.

Well what is this then? You are telling esphome to use gpio5 for scl. I think you are confusing the physical layout with gpio.

Damn! You are right of course.

I always thought I have to tell him which physical pin should be used! O boy… Hours down the drain…
It’s even described in the documentation.

Now it’s working (log level INFO. Hence, not that chatty):

INFO Reading configuration /config/esphome/sensor-well-water-level.yaml...
INFO Starting log output from 10.116.0.120 using esphome API
INFO Successfully connected to 10.116.0.120
[15:48:01][I][app:102]: ESPHome version 2022.4.0 compiled on Apr 24 2022, 15:40:39
[15:48:01][I][i2c.arduino:054]: Results from i2c bus scan:
[15:48:01][I][i2c.arduino:060]: Found i2c device at address 0x40

Also @robertklep, you mentioned it before. Obviously I had been blind… :slight_smile:

Thanks again all of you for your time!

Now solder everything on a stripboard, mount it in a box, drill some holes, pull a cable out to the well and we can measure how little water we have in this dry winter…

At least I can avoid the run out of water while taking a shower with shampoo in the hair! :smiley:

1 Like

I have at least a dozen in my house. Various sensors, they control my garage doors and vehicle presence.

Your attempt at a schematic is almost as useless as a Fritzing picture because it is still just a connection diagram. But is does show a couple of flaws that the Fritzing doesn’t. Just what is the INA219 supposed to be measuring? Where is the shunt resistor?

Disconnect Vin +/- completely. Then work on your code.

This is wrong. There is no GPIO5 on the ESP8266-01 board. Try this:

i2c:
  sda: GPIO0
  scl: GPIO2

This is the same as:

i2c:
  sda: 0
  scl: 2

but using GPIO numbers is more readable.

Hi @stevemann,

thanks for helping again. Due to bad timing, I wrote my wrap up of the issue at the same time you responded. Everything works now as I hoped for. Just need to add a template sensor now, which converts the measured current to water level in meters…

Good to hear you run dozens ESP-01s. The conclusion there might be a bug was after hours of desperate error search. You should take it with a grain of salt. :wink:

Regarding the shunt. It’s on the IAN219 shield, as described in the link from the original post.

And the INA219 It is supposed to measure the current from a well water level sensor, as described in my first post. Currently it’s only measuring the air pressure at my desk. But as soon the stripboard is wired and soldered it will measure water in our well.

Regarding the schematic… why do you consider it useless? It depicts all the involved elements and how they are wired. I just used a LED instead of the well sensor, but noted this in the text. What would you like to have instead?

I said almost useless. It still just a connection diagram that shows little more than the Fritzing picture.
The schematic is a functional description describing the flow of operation, not just how things are connected.

To decipher your drawing, I came up with this:

This is much more readable and the first thing that jumped out at me was, what the heck is the diode for? The second was, is there a common ground on the power supply?

Using Fritzing will reduce the pool of folks prepared to even look at your problem. Do not hurry drawing a schematic, it is a very valuable tool to help you and us understand your project.

1 Like

I see. This makes sense to me. It’s really much easier to comprehend.

My times of electrical engineering are more than 25 years ago, had never been my strong side, never worked in the field and since that I only did IT and software development. I am trying to resuscitate that part of my knowledge that didn’t rot to dust completely. :smiley:

It’s really fascinating what’s possible today with this micro controller and the related shields! A lot to (re)discover and to (re)learn.

1 Like