Measuring Temperature on Raspberry Pi with Maxim 1‑Wire Sensors and DS2482 I2C Bridge
Measuring Temperature on Raspberry Pi with Maxim 1‑Wire Sensors and DS2482 I2C Bridge
Accurate temperature monitoring is essential for many Raspberry Pi projects, from climate control to data logging. The Maxim Integrated 1‑Wire family of sensors, such as the DS18B20, offers a simple, low‑pin solution. By using the DS2482 1‑Wire‑to‑I2C bridge you can attach up to ten sensors to a single I2C bus, keeping the Pi’s GPIO footprint minimal.
Hardware Overview
- Raspberry Pi – any model with an I2C bus (e.g., Pi 2/3/4)
- DS2482‑2 – 1‑Wire master on I2C, address 0x18
- Maxim 1‑Wire temperature sensors – up to 10 units, each with a unique 1‑Wire address
- Pull‑up resistors – 4.7 kΩ on the 1‑Wire data line (optional if DS2482 handles pull‑ups)
Software Prerequisites
These instructions assume a standard Raspbian installation with kernel source available. You will need to rebuild the kernel after making the following changes.
Step 1 – Enable the DS2482 on the I2C Bus
Modify arch/arm/mach-bcm2708/bcm2708.c in the kernel source to register the DS2482 as an I2C device. Add the following platform device definition and board info array:
static struct platform_device bcm2708_bsc1_device = {
.name = "bcm2708_i2c",
.id = 1,
.num_resources = ARRAY_SIZE(bcm2708_bsc1_resources),
.resource = bcm2708_bsc1_resources,
};
static struct i2c_board_info __initdata pi_i2c_devs[] = {
{ I2C_BOARD_INFO("ds1307", 0x68)},
{ I2C_BOARD_INFO("ds2482", 0x18)},
};
...
bcm_register_device(&bcm2835_thermal_device);
After adding the device, recompile and install the kernel.
Step 2 – Handle 1‑Wire Pull‑ups in the Kernel
Modify drivers/w1/w1_io.c to allow the DS2482 to control the pull‑up resistor during conversions. Replace the w1_post_write function with:
static void w1_post_write(struct w1_master *dev)
{
if (dev->pullup_duration) {
if (dev->enable_pullup && dev->bus_master->set_pullup) {
dev->bus_master->set_pullup(dev->bus_master->data, 0);
msleep(dev->pullup_duration);
} else {
msleep(dev->pullup_duration);
}
dev->pullup_duration = 0;
}
}
Step 3 – Add Pull‑up Control to the DS2482 Driver
In drivers/w1/masters/ds2842.c add a helper that activates the DS2482’s strong pull‑up when a delay is requested:
static u8 ds2482_w1_set_pullup(void *data, int delay)
{
struct ds2482_w1_chan *pchan = data;
struct ds2482_data *pdev = pchan->pdev;
u8 retval = 1;
u8 cfg;
if (delay) {
/* Ensure the bus is idle before changing config */
ds2482_wait_1wire_idle(pdev);
/* Enable both SPU and APU for a strong pull‑up */
retval = ds2482_send_cmd_data(pdev, DS2482_CMD_WRITE_CONFIG,
ds2482_calculate_config(DS2482_REG_CFG_SPU | DS2482_REG_CFG_APU));
ds2482_wait_1wire_idle(pdev);
}
return retval;
}
Final Steps
- Rebuild and reboot the Pi with the new kernel.
- Verify that the DS2482 appears under
/sys/bus/i2c/devices/1-0018. - Connect your Maxim 1‑Wire sensors to the DS2482 data line (pin 1) and ground.
- Check that each sensor shows up under
/sys/bus/w1/devices/and thatcat /sys/bus/w1/devices/28‑xxxxxxxxxxxx/w1_slavereturns a temperature value.
With these kernel tweaks in place, the Raspberry Pi can reliably read up to ten 1‑Wire temperature sensors through a single DS2482 bridge, making it ideal for multi‑sensor monitoring projects.
Additional Resources
Manufacturing process
- Build a Raspberry Pi Temperature Logger with a $5 I2C Sensor
- Connect Multiple DS18B20 1‑Wire Sensors to a Raspberry Pi for Accurate Temperature Monitoring
- How to Read Temperature with a DS18B20 on Raspberry Pi 2
- Professional Raspberry Pi Temperature Monitoring with DS18B20
- Accurate Temperature Monitoring in a Server Closet with Raspberry Pi
- Build a ThingSpeak Temperature Monitor with Raspberry Pi & BrickPi
- Build a Multi‑Sensor Temperature & Light Monitoring System with Raspberry Pi & DS18B20
- Build a Raspberry Pi Home Temperature Monitor with MCP9808, InfluxDB & Grafana
- Build a Self‑Balancing Segway with Raspberry Pi
- Accurate Solar Radiation Measurement Using Arduino UNO and Ethernet Shield