Skip to content

Day19 - I2C Sensor Driver

Objective

  • Implement a Linux I2C sensor driver
  • Communicate with STM32 I2C slave
  • Expose sensor data via sysfs

Step 1 - Build Driver

make

Step 2 - Load Module

sudo insmod myi2c_sensor.ko

Check:

dmesg | tail

Expected:

myi2c_sensor probe start
myi2c_sensor probed: addr=0x48 chip_id=0xa1

Step 3 - Load Device Tree Overlay

sudo dtoverlay myi2c_snr

Step 4 - Verify Device

ls /sys/bus/i2c/devices/

Expected:

1-0048

Step 5 - Read Attributes

cat chip_id
cat temp_raw
cat temp_input

Step 6 - Trigger Update

echo 1 > update_once

Step 7 - Modify Configuration

echo 3 > config
cat config

Step 8 - Update Period

echo 1000 > update_period
cat update_period

Step 9 - Remove Driver

sudo rmmod myi2c_sensor