====== lamaPLC: RP2040_ETH_Modul: MLX90614 simple ======
Read [[sensor:mlx90614|MLX90614 (GY-906) infrared non-contact thermometer sensor]] to serial.
Important: The Ethernet module is accessible by **RP2040_ETH** via **UART1** with the following configuration:
//uart1 = UART(1, baudrate=115200, tx=Pin(20), rx=Pin(21), timeout=50)//
import machine
from machine import Pin, I2C
import time
import ustruct
# I2C configuration for RP2040-ETH
# Default: GP4 (SDA), GP5 (SCL), I2C port 0
i2c = I2C(0, sda=Pin(4), scl=Pin(5), freq=100000)
# MLX90614 Constants
MLX90614_I2C_ADDR = 0x5A
REG_AMBIENT_TEMP = 0x06
REG_OBJECT_TEMP = 0x07
def read_temp(reg):
"""
Reads 2 bytes from the sensor, converts the 16-bit value
to Celsius based on the MLX90614 datasheet formula.
Formula: (Raw * 0.02) - 273.15
"""
try:
# Read 2 bytes from the specific register
data = i2c.readfrom_mem(MLX90614_I2C_ADDR, reg, 2)
# Unpack the 16-bit little-endian unsigned integer
raw_val = ustruct.unpack('
**Running example**
Ambient: 19.91C | Object: 20.65C
Ambient: 19.91C | Object: 26.79C
Ambient: 19.91C | Object: 28.11C
Ambient: 19.91C | Object: 28.01C
Ambient: 19.93C | Object: 20.67C
{{tag>code! micropython 2026 RP2040_ETH i2c communication MLX90614}}
This page has been accessed for: Today: {{counter|today}}, Until now: {{counter|total}}