How to read a 1-wire temp sensor on an Ubuntu 22.04 PC?
Robert Heller
heller at deepsoft.com
Sat Mar 16 12:57:35 UTC 2024
At Sat, 16 Mar 2024 13:31:37 +0100 bo.berglund at gmail.com, "Ubuntu user technical support,? not for general discussions" <ubuntu-users at lists.ubuntu.com> wrote:
>
> On Wed, 13 Mar 2024 09:24:31 +0000, Chris Green <cl at isbd.net> wrote:
>
> >On Wed, Mar 13, 2024 at 10:08:51AM +0100, Bo Berglund wrote:
> >> I would like to know if it is possible to connect a DS18B20 1-wire device to an
> >> Ubuntu PC (running on PC hardware) and if so how?
> >>
> >> On a Raspberry Pi running the Pi-OS (Debian variant) it is just a matter of
> >> configuring the RPi for the 1-wire use and then connect the sensor to +Vcc, GND
> >> and the 1-wire line with a pull-up to Vcc and it works.
> >>
> >> Can something similar be done on PC hardware running Ubuntu?
> >>
> >> I have a few candidates, both Mini type and laptops.
> >>
> >Get a USB 1-wire interface, that will work on any old PC, I can dig
> >out details if you can't find one.
>
> I decided to stick with the RaspberryPi Zero-W device as interface to the temp
> sensors instead.
> For that I have a simple solution using just the RPiZero board, one 4K7 pull-up
> resistor and the DS18B20 sensor device (plus 3 wires to hook it up).
>
Yes, while there might be 1-wire, I2C, and SPI interface pins on x86-ish
processors, they are not exposed on headers on PC motherboards (at least not
x86-ish PC motherboards -- but see the Turing Pi 2.5 (an ITX motherboard) :
https://turingpi.com/product/turing-pi-2-5/). Most of the various ARM SBCs
feature the RPi 40-pin GPIO header, with the full collection of GPIO and
various 1-wire, I2C, and SPI interface pins. These SBCs can then be connected
via Ethernet, WiFi, Serial, or USB to a "host" PC.
> On the Pi one can easily enable the 1-wire interface, which uses the GPIO-04
> pin.
> And then this code to extract the temperature:
>
> -----------
> #!/bin/bash
> IP="192.168.xxx.yyy" #adddress of MQTT broker
> givare8="28-3ce1e3814893" #TO-92 style sensor soldered into the board
>
> Temp1=$(cat /sys/bus/w1/devices/${givare}/temperature)
> printf -v Temp1 "%06d" "$Temp1"
> if [ $? != "0" ]; then
> echo "Error, no response from sensor!"
> exit 1
> fi
> CurrTemp1=$(sed 's/.\{3\}$/.&/' <<< "$Temp1")
>
> #Show result:
> echo "Temp1 = $CurrTemp1"
> eval "mosquitto_pub -h ${IP} -t \"sensors/cottage/temp\" -m \"$CurrTemp1\""
>
> exit 0
> ------------
>
>
--
Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
Deepwoods Software -- Custom Software Services
http://www.deepsoft.com/ -- Linux Administration Services
heller at deepsoft.com -- Webhosting Services
More information about the ubuntu-users
mailing list