Skip to content

Day34 - IIO I2C Multi-Channel Driver

Objective

  • Implement an IIO driver over I2C
  • Map multi-channel sensor data to sysfs
  • Verify end-to-end data path

Step 1 - Verify I2C Sensor

i2cdetect -y 1
i2cget -y 1 0x48 0x00

Expected:

0xa1

Step 2 - Read Raw Registers

i2ctransfer -y 1 w1@0x48 0x10 r2
i2ctransfer -y 1 w1@0x48 0x12 r2
i2ctransfer -y 1 w1@0x48 0x14 r2

Verify:

  • Values change over time
  • Channel offset differences exist

Step 3 - Load IIO Core

sudo modprobe industrialio

Step 4 - Insert Driver

sudo insmod myadc_iio.ko
dmesg | tail -n 20

Expected:

myadc IIO device registered

Step 5 - Check IIO Device

ls /sys/bus/iio/devices/

Expected:

iio:device0

Step 6 - Inspect sysfs

cd /sys/bus/iio/devices/iio:device0
find . | sort

Step 7 - Read Values

cat in_voltage0_raw
cat in_voltage1_raw
cat in_voltage2_raw
cat in_voltage_scale

Expected:

~100+n
~200+n
~300+n
0.001000

Step 8 - Continuous Monitoring

watch -n 0.5 'cat in_voltage0_raw; cat in_voltage1_raw; cat in_voltage2_raw'

Result

Verified:

  • I2C communication
  • IIO device registration
  • multi-channel mapping
  • dynamic data update