Skip to content

Latest commit

 

History

History
 
 

onewire

Interfacing 1-Wire devices to the Pico

This example demonstrates how to use 1-Wire devices with the Raspberry Pi Pico (RP2040). 1-Wire is an interface that enables a master to control several slave devices over a simple shared serial bus.

The example provides a 1-Wire library that is used to take readings from a set of connected DS18B20 1-Wire temperature sensors. The results are sent to the default serial terminal connected via USB or UART as configured in the SDK.

The library uses a driver based on the RP2040 PIO state machine to generate accurate bus timings and control the 1-Wire bus via a GPIO pin.

1-Wire® is a registered trademark of Maxim Integrated Products, Inc.

Wiring information

Connect one or more DS18B20 sensors to the Pico as shown in the diagram and table below.

Connect GPIO 15 to 3V3(OUT) with a pull-up resistor of about 4k ohms.

pio onewire
Figure 1. Wiring diagram
Table 1. Connections table
Pico pin DS18B20 pin / sensor wire

GND

38 or equivalent

GND

1 / Black

GPIO 15

20

DQ

2 / Yellow

3V3(OUT)

36

VDD

3 / Red

Bill of materials

Table 2. A list of materials for the example circuit

Item

Quantity

Details

Breadboard

1

generic part

Raspberry Pi Pico

1

https://www.raspberrypi.com/products/raspberry-pi-pico/

DS18B20

3

chip or wired sensor

3900 ohm resistor

1

generic part

M/M jumper wire

13

generic part

List of files

CMakeLists.txt

CMake file to incorporate the example in the build tree.

onewire.c

Source code for the example program.

ow_rom.h

Header file with generic ROM command codes for 1-Wire devices.

ds18b20.h

Header file with function command codes for the DS18B20 device.

onewire_library/

Subdirectory containing the 1-Wire library and driver.

onewire_library/CMakeLists.txt

CMake file to build the 1-Wire library and driver.

onewire_library/onewire_library.c

Source code for the 1-Wire user functions.

onewire_library/onewire_library.h

Header file for the 1-Wire user functions and types.

onewire_library/onewire_library.pio

PIO assembly code for the 1-Wire driver.