It's easy to use the DS2482S-800 with Python or CircuitPython, and the Adafruit_CircuitPython_DS248x module. This module allows you to easily write Python code to read 1-Wire sensors over I2C.
You can use this driver with any CircuitPython microcontroller board or with a computer that has GPIO and Python thanks to Adafruit_Blinka, our CircuitPython-for-Python compatibility library.
You'll need two DS18B20 sensors to use this example with the breakout:
CircuitPython Microcontroller Wiring
First, wire up two DS18B20 sensors to the breakout exactly as follows. Then, wire up the breakout to your board. The following is the breakout wired to a Feather RP2040 with two DS18B20 sensors using the STEMMA connector. The DS18B20 sensor are connected directly to the breakout.
- Breakout STEMMA VIN to Feather STEMMA 3.3V (red wire)
- Breakout STEMMA GND to Feather STEMMA GND (black wire)
- Breakout STEMMA SDA to Feather STEMMA SDA (blue wire)
- Breakout STEMMA SCL to Feather STEMMA SCL (yellow wire)
- Breakout channel 0 - to DS18B20 GND
- Breakout channel 0 1W to DS18B20 signal
- Breakout channel 0 + to DS18B20 VIN
- Breakout channel 4 - to DS18B20 GND
- Breakout channel 4 1W to DS18B20 signal
- Breakout channel 4 + to DS18B20 VIN
The following is the breakout wired to a Feather RP2040 and two DS18B20 sensors using a solderless breadboard:
- Breakout VIN to Feather 3.3V (red wire)
- Breakout GND to Feather GND (black wire)
- Breakout SDA to Feather SDA (blue wire)
- Breakout SCL to Feather SCL (yellow wire)
- Breakout channel 0 - to DS18B20 GND (black wire)
- Breakout channel 0 1W to DS18B20 signal (green wire)
- Breakout channel 0 + to DS18B20 VIN (red wire)
- Breakout channel 4 - to DS18B20 GND (black wire)
- Breakout channel 4 1W to DS18B20 signal (green wire)
- Breakout channel 4 + to DS18B20 VIN (red wire)
Python Computer Wiring
Since there are dozens of Linux computers/boards you can use, we will show wiring for Raspberry Pi. For other platforms, please visit the guide for CircuitPython on Linux to see whether your platform is supported.
Here's the Raspberry Pi wired with I2C using the STEMMA connector. The DS18B20 sensors are connected directly to the breakout on channel 0 and channel 4.
- Breakout STEMMA VIN to Pi 3.3V (red wire)
- Breakout STEMMA GND to Pi GND (black wire)
- Breakout STEMMA SDA to Pi SDA (blue wire)
- Breakout STEMMA SCL to Pi SCL (yellow wire)
- Breakout channel 0 - to DS18B20 GND
- Breakout channel 0 1W to DS18B20 signal
- Breakout channel 0 + to DS18B20 VIN
- Breakout channel 4 - to DS18B20 GND
- Breakout channel 4 1W to DS18B20 signal
- Breakout channel 4 + to DS18B20 VIN
Here's the Raspberry Pi wired with I2C using a solderless breadboard:
- Breakout VIN to Pi 3.3V (red wire)
- Breakout GND to Pi GND (black wire)
- Breakout SDA to Pi SDA (blue wire)
- Breakout SCL to Pi SCL (yellow wire)
- Breakout channel 0 - to DS18B20 GND (black wire)
- Breakout channel 0 1W to DS18B20 signal (green wire)
- Breakout channel 0 + to DS18B20 VIN (red wire)
- Breakout channel 4 - to DS18B20 GND (black wire)
- Breakout channel 4 1W to DS18B20 signal (green wire)
- Breakout channel 4 + to DS18B20 VIN (red wire)
Python Installation of DS248x Library
You'll need to install the Adafruit_Blinka library that provides the CircuitPython support in Python. This may also require enabling I2C on your platform and verifying you are running Python 3. Since each platform is a little different, and Linux changes often, please visit the CircuitPython on Linux guide to get your computer ready!
Once that's done, from your command line run the following command:
pip3 install adafruit-circuitpython-ds248x
If your default Python is version 3 you may need to run 'pip' instead. Just make sure you aren't trying to use CircuitPython on Python 2.x, it isn't supported!
CircuitPython Usage
To use with CircuitPython, you need to first install the Adafruit_CircuitPython_DS248x library, and its dependencies, into the lib folder on your CIRCUITPY drive. Then you need to update code.py with the example script.
Thankfully, we can do this in one go. In the example below, click the Download Project Bundle button below to download the necessary libraries and the code.py file in a zip file. Extract the contents of the zip file, and copy the entire lib folder and the code.py file to your CIRCUITPY drive.
Your CIRCUITPY/lib folder should contain the following folder and file:
- adafruit_bus_device/
- adafruit_ds248x.mpy
Python Usage
Once you have the library pip3
installed on your computer, copy or download the following example to your computer, and run the following, replacing code.py with whatever you named the file:
python3 code.py
Example Code
If running CircuitPython: Once everything is saved to the CIRCUITPY drive, connect to the serial console to see the data printed out!
If running Python: The console output will appear wherever you are running Python.
# SPDX-FileCopyrightText: Copyright (c) 2024 Liz Clark for Adafruit Industries # # SPDX-License-Identifier: MIT """Adafruit DS2482S-800 8-Channel DS18B20 Example""" import time import board from adafruit_ds248x import Adafruit_DS248x # Initialize I2C bus and DS248x i2c = board.STEMMA_I2C() ds248x = Adafruit_DS248x(i2c) while True: for i in range(8): ds248x.channel = i print(f"Reading channel {ds248x.channel}") temperature = ds248x.ds18b20_temperature() print(f"Temperature: {temperature:.2f} °C") print() time.sleep(1)
First, the DS2482S-800 is instantiated over I2C. In the loop, each of the 8 channels is selected and read. The selected channel and its temperature reading are printed to the serial console. If you don't have a DS18B20 sensor attached to a channel that is read, a negative value of -0.06 will be printed to the console. The print out below shows data on channels 0 and 4.
Text editor powered by tinymce.