![]() Use a conditional test to check the value stored in the temperature object against a hard coded value. temperature = round(sensor.read_temp(rom),1)ġ3. The output is wrapped in a round() function that will round the returned data to 1 decimal place. Create an object, temperature, and use it to store the output of reading the DS18B20 sensor. As we only have one DS18B20 on the one-wire interface, only one ROM will be stored in the list that we iterate over. Use a for loop to iterate through the returned list of ROMs. This gives the DS18B20 time to settle before we take a reading. Note that the code within the while True loop is indented to show that it belongs in the loop. Set the temperature reading to use Celsius. Use a while True loop to run the next lines of code in a never ending loop. All one-wire devices, such as our DS18B20, have a unique registration number stored in ROM that we need to identify before they can be used. Create an object, roms and use the sensor object to scan the interface to find our DS18B20 temperature sensor. sensor = ds18x20.DS18X20(onewire.OneWire(SensorPin))ħ. This line also uses the onewire module, as that is the protocol that the sensor uses for connection. ![]() Create an object, sensor and use it to tell the ds18x20 module where to find our DS18B20 temperature sensor. Alert is the GPIO pin that connects to the anode (long leg) of the LED. SensorPin is the GPIO pin used to connect the data pin from the DS18B20 to the Pico. This will enable our code to interact with the components connected to the GPIO. From the Machine module import the Pin class. Lastly we import time which is used to pace our project code. Next is ds18x20, a module that interprets the sensor data from the DS18B20 and provides us with human readable data. First is onewire, a module that enables the Pico to talk to the one-wire interface of the DS18B20. Import three modules of pre-written code. Follow the steps up to and including connecting the Raspberry Pi Pico to Thonny.ģ. Follow this guide to download and install the latest MicroPython release for your model of Raspberry Pi Pico. This reduces the amount of current that the LED can consume. The LED has a 330 Ohm resistor on the cathode leg, inline with GND.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |