Fuse test benchRaspberry PLC 19R1-WireAcquisition
Reading a DS18B20 over 1-Wire, no libraries needed
A DS18B20 on a Raspberry PLC needs three things: a 4.7 kOhm pull-up, one line in
/boot/config.txt (dtoverlay=w1-gpio,gpiopin=8) and about forty lines of pure Python — the kernel exposes the sensor as a text file in sysfs. This example adds CRC validation and a 0.6 °C noise filter, exactly as used to log ambient temperature in a real fuse test bench deployment, where fusing current depends on it.Why ambient temperature matters in a test bench
A fuse rated at its nominal current at 23 °C behaves differently at 35 °C — the melting integral shifts with ambient. Recording temperature alongside every test makes the report defensible: if a sample fails marginally, the certificate shows the thermal conditions it failed under.
The sysfs interface, no pip installs
Once the overlay loads, each sensor appears as
/sys/bus/w1/devices/28-*/w1_slave. Reading it returns two lines: a CRC verdict and t=23125 (millidegrees). The example globs for the device, checks the CRC says YES, and parses the integer — discarding any corrupted reading instead of propagating it.Filtering out the flicker
Raw DS18B20 readings jitter a few tenths of a degree, which makes an HMI display flicker and pollutes reports. The filter keeps the last accepted value and only updates when the change reaches 0.6 °C — small enough to track real drift, large enough to ignore conversion noise.
A snippet from the implementation
Straight from the example as deployed on the Raspberry PLC 19R — copy it freely:
def find_sensor():
"""Return the path of the first DS18B20 detected, or None."""
devices = glob.glob(SENSOR_GLOB)
return devices[0] if devices else NoneThe full example is a complete program — wiring header, setup and main loop — ready to adapt to your application.
Frequently asked questions
Can I connect several DS18B20 sensors to the same pin?
Yes, 1-Wire is a bus. Each sensor has a unique 64-bit ROM code and shows up as its own 28-* directory in sysfs, so the same parsing code works per device.
Why GPIO8 instead of the default GPIO4?
On the Raspberry PLC some default pins are taken by the industrial I/O hardware. The overlay accepts any free GPIO with the gpiopin parameter; GPIO8 is what the bench wiring used.
How fast can I poll the sensor?
A 12-bit conversion takes about 750 ms, so polling every 2 s is comfortable. Ambient temperature moves slowly anyway — the bench logs it once per test plus a live display refresh.