one-wire-temperature-sensor 0

One-wire temperature sensor

How to use the one-wire temperature sensor in CamJam Kit 2

Wiring

Note: the default is to use GPIO pin 4. See the note below if you need to use another pin.

Enable software

  1. Open Raspberry Pi Configuration Tool from the Main Menu, under Preferences

  2. Select the Interfaces tab

  3. Enable 1-wire:

Note: using GPIO pin 4 requires no further configuration. If using this pin is not an option, you’ll need to amend the following line in /boot/config.txt:

dtoverlay=w1-gpio

should become:

dtoverlay=w1-gpio,gpiopin=21

(for example, to use GPIO pin 21)

Install library

Open a Terminal window and type:

sudo apt-get update
sudo apt-get install python-w1thermsensor python3-w1thermsensor  -y

Python code

The following code will print the temperature value:

from w1thermsensor import W1ThermSensor

sensor = W1ThermSensor()

temp = sensor.get_temperature()

print(temp)

GPIO Zero

There is a plan to add this sensor to the GPIO Zero library. See GitHub Issue #93 for updates.

Related Repositories

tm

tm

one wire sensor temperature measurement application written in Python and Javascript ...


Top Contributors

bennuttall