As mentioned, 1-Wire is a communication protocol that allows microcontrollers and other devices to communicate through one data line and ground. It is generally used in many sensors, ADCs, and EEPROMs.
00:00
In other words, 1-Wire is a communications protocol between a single master and one or more slave devices – all of which interface to the bus using a single data line.
00:00
It is capable of half-duplex bidirectional communication. What's that? A way to think about this is to compare the use of a walkie-talkie with a mobile phone. In the case of a walkie-talkie, only one party can talk at one time. On the other hand, a mobile phone allows both parties to talk simultaneously. So with devices using 1-Wire, data can flow in either direction, but only one direction at a time.
00:00
There are three pins on the DS18B20 Digital Temperature Sensor. They are VCC, DATA, and GND.
00:00
Connect a resistor between the VCC and DATA pins of the DS18B20 Temperature Sensor.
00:00
Then connect a red jumper wire to VCC on the DS18B20 and 3.3V on Pico.
00:00
Next, connect a jumper wire to DATA on DS18B20 and GPIO16 on Pico.
00:00
Last but not least, connect a black jumper wire from GND on the DS18B20 to GND on Pico.
00:00
Import the following libraries, in previous lessons, we imported machine and time. Aside from those, you'll notice we'e also imported onewire and ds18x20.
00:00
Create a pin called ds_pin. Remember, we connected the data pin of the temperature sensor to GPIO16 on the Pico, so use 
machine.Pin(16)
00:00
The next line of code creates the onewire object.
00:00
The next line of code scans for devices on the 1-Wire bus, then prints to the shell when it has found a 1-Wire device.
00:00
According to the MicroPython documentation, you must execute the convert_temp() function to initiate a temperature reading with the DS18B20. Then wait at least 750ms before reading the value.
00:00
The final bit of code prints the temperature reading to the shell in Thonny!
00:00
main.py
xxx
Terminal
screen /dev/tty.usbmodem0000000000001 115200
>>> led = Pin(25, Pin.OUT)
>>> from machine import Pin
Breadboard
Breadboard
Mark
© 2022 Chick Commerce Pty Ltd