from machine import Pin import time, ds18x20 import onewire ow = onewire.OneWire(Pin(4)) # create a OneWire bus on GPIO12 ds = ds18x20.DS18X20(ow) roms = ds.scan() ds.convert_temp() time.sleep_ms(750) for rom in roms: print(ds.read_temp(rom))
Here is what the above code is Doing:
1. Importing the required libraries.
2. Creating a OneWire bus on GPIO4.
3. Creating a DS18X20 object.
4. Scanning for DS18X20 sensors.
5. Converting the temperature readings.
6. Reading the temperature readings.
7. Printing the temperature readings.