Preview build — page text is a draft awaiting human review. Code badges come from real compiles. The flasher is real but not yet hardware-tested; the Playground is still a preview.
MicroPython · timeout

Fix MicroPython “OSError: [Errno 110] ETIMEDOUT”

A device or server did not answer in time. With a DHT11/DHT22 it is wiring or reading too fast; with sockets and I2C it is the network or a stuck bus.

Raspberry Pi Pico WRaspberry Pi PicoESP32ESP8266Updated 3 Nov 2026

Community draft — report a mistake

What you see

OutputOutput
>>> %Run -c $EDITOR_CONTENT
DHT22 on GP15 - first reading in 2 s
Traceback (most recent call last):
  File "<stdin>", line 9, in <module>
  File "dht.py", line 17, in measure
OSError: [Errno 110] ETIMEDOUT

ETIMEDOUT means MicroPython waited for an answer that never came. The same error is raised by three very different things, so look at the traceback first.

For a DHT sensor — by far the most common case — the fix is nearly always wiring or timing. The sketch below reads a DHT22 every 2 s and catches the error instead of crashing:

try:
    sensor.measure()
except OSError as e:
    print("DHT read failed:", e)   # retry on the next loop

Quick fix — try in order

  1. 1

    Find which line timed out

    The last frame in the traceback names it: measure = DHT sensor, readfrom/writeto = I2C, connect/recv/urequests = network.

  2. 2

    DHT: check the data pin and pull-up

    DATA to the GPIO you passed to dht.DHT22(Pin(15)), 10 kΩ from DATA to 3V3 (3-pin modules have it). Power from 3V3 on a Pico. A bare 4-pin DHT22 has pin 3 unused.

  3. 3

    DHT: use the right class and slow down

    dht.DHT11 for the blue sensor, dht.DHT22 for the white one. Read at most once every 2 s (DHT22) or 1 s (DHT11) and wrap measure() in try/except so one bad read doesn’t stop the program.

  4. 4

    Network: give it a timeout and retry

    Make sure wlan.isconnected() is True first, then use sock.settimeout(10) and retry a few times. Slow servers (Google Apps Script, free hosting) often need more than 5 s.

  5. 5

    I2C: lower the speed and check pull-ups

    Create the bus with freq=100_000. A device holding SCL low (clock stretching too long, or a crashed sensor) needs a power cycle.

Diagnostic sketch

Verified — micropython (mpy-cross v1.29.0), 3 Nov 2026Compile-only
main.pyMicroPythonOpen in PlaygroundOpen in Playground
# DHT22 temperature + humidity on a Raspberry Pi Pico W (MicroPython).
# DATA -> GP15, VCC -> 3V3 (pin 36), GND -> GND, 10 kOhm pull-up DATA -> 3V3 (breakouts have one).
from machine import Pin
import dht
import time

sensor = dht.DHT22(Pin(15))
print("DHT22 on GP15 - first reading in 2 s")

while True:
    time.sleep(2)  # the DHT22 can't be read faster than once every 2 s
    try:
        sensor.measure()
    except OSError:
        print("Failed to read from DHT sensor - check wiring and pull-up")
        continue
    t = sensor.temperature()
    h = sensor.humidity()
    print("Temp {:.1f} C  Humidity {:.1f} %".format(t, h))

Why it happens

Why 110 on the Pico but 116 on the ESP32?

Same error, different numbering. The RP2040 port uses Linux-style numbers (ETIMEDOUT = 110); the ESP32 port uses ESP-IDF’s C library, where ETIMEDOUT = 116. Catch it by name: except OSError as e: if e.errno == errno.ETIMEDOUT.

DHT works for a while, then times out

Long cable without a stronger pull-up, reading every loop with no delay, or a loose breadboard contact. A DHT on 3.3 V over more than about 1 m of wire is unreliable — power it from 5 V only if your board’s pin is 5 V tolerant (the Pico’s and ESP32’s are not).

MQTT connect() times out

Wrong broker IP or port, the broker only listens on localhost, or a firewall on the PC running Mosquitto. Try the broker from your phone on the same Wi-Fi first.

Board-specific notes

Pico W: Full DHT22 wiring on the DHT22 with Pico W guide; part notes on DHT22.

ESP32: Prints OSError: [Errno 116] ETIMEDOUT. Avoid GPIO 6–11 (flash) and 34–39 (input-only) for DHT data — the sensor needs a pin that can drive the line.

↑↓ to move · Enter to open