A Linux kernel driver for the TI TMP102 I2C temperature sensor on Raspberry Pi. I wrote this because I wanted TMP102 readings to show up in the standard hwmon sysfs interface rather than polling the sensor from userspace directly.
$ cat /sys/class/hwmon/hwmon1/temp1_input
23562
Readings are in millidegrees Celsius — divide by 1000 to get °C. Standard tools like sensors (from lm-sensors) pick it up automatically once the module is loaded.
Wiring — Raspberry Pi 40-pin header:
| TMP102 Pin | Raspberry Pi Pin |
|---|---|
| VCC | Pin 1 — 3.3V |
| GND | Pin 6 — GND |
| SDA | Pin 3 — GPIO 2 / I2C SDA |
| SCL | Pin 5 — GPIO 3 / I2C SCL |
| ADD0 | Pin 6 — GND (address 0x48) |
Tying ADD0 to GND sets the I2C address to 0x48. If you tie it to VCC (pin 1) instead, the address becomes 0x49 — just update
regintmp102-overlay.dtsaccordingly.
- Raspberry Pi running Raspberry Pi OS Bookworm (64-bit recommended)
- Kernel headers:
sudo apt install raspberrypi-kernel-headers - Build tools:
sudo apt install build-essential - Device tree compiler:
sudo apt install device-tree-compiler - I2C tools (optional but handy):
sudo apt install i2c-tools
sudo raspi-config
# Interface Options → I2C → EnableOr manually add dtparam=i2c_arm=on to /boot/firmware/config.txt and reboot.
sudo i2cdetect -y 1
# You should see 0x48 in the gridIf nothing shows up, double-check the wiring before going any further.
make dtbo
make install-overlayThen register the overlay by appending to /boot/firmware/config.txt:
echo "dtoverlay=tmp102-overlay" | sudo tee -a /boot/firmware/config.txt
sudo rebootmake
sudo insmod tmp102.ko
dmesg | grep tmp102If everything is wired correctly, you should see something like:
tmp102 1-0048: TMP102 at 0x48, temperature: 23.562°C
cat /sys/class/hwmon/hwmon*/temp1_input
# e.g. 23562 (= 23.562°C)Or install lm-sensors and use sensors:
sudo apt install lm-sensors
sensorsmake uninstall
# or just: sudo rmmod tmp102| File | Description |
|---|---|
tmp102.c |
Kernel driver source |
tmp102-overlay.dts |
Device tree overlay source |
Makefile |
Build, install, and clean targets |
The driver follows the standard Linux I2C driver pattern:
- Device tree matching — the
"ti,tmp102"compatible string in the overlay is what links the hardware description to this driver. Without the overlay, the kernel never calls probe. - Probe —
tmp102_probe()allocates the private state struct, does a quick temperature read to verify the sensor is actually responding, then registers with the hwmon subsystem. - sysfs attribute —
SENSOR_DEVICE_ATTRwires uptemp1_input. Each read goes throughi2c_smbus_read_word_swapped(), which handles the byte-order difference, and I convert the raw 12-bit two's-complement value to millidegrees from there. - Cleanup — everything is allocated with
devm_helpers, so the kernel cleans up automatically on removal without me needing to do anything in the remove callback.
The kernel driver (tmp102.c) is licensed under GPL-2.0, as required for Linux kernel modules.
All other files are licensed under the MIT License — see LICENSE.