Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize temperature Sensor with Python

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

Today, I would like to share with you how to achieve Python temperature sensor related knowledge, detailed content, clear logic, I believe that most people still know too much about this knowledge, so share this article for your reference, I hope you can learn something after reading this article, let's take a look at it.

MicroPython is a Python that can run on a single-chip microcomputer. With MicroPython, users can access and control the underlying hardware through Python scripting language, such as controlling LED light bulbs, LCD displays, reading voltage, controlling motors, accessing SD cards and so on. At present, there are several kinds of development boards that support MicroPython. Here is a brief introduction to the production method of a simple temperature sensor with TPYBoard as an example.

1. Purpose of the experiment

1. Learn the method of extending the simple Iripple O interface in the PC system.

two。 Further learn the design method of compiling data output program.

3. Learn the wiring method of DS18B20 and use DS18B20 to detect the current temperature

3. Learn the 8*8LED lattice wiring method and display the current temperature

2. Required components

TPYBoard board

A data line

Some DuPont lines

One 8*8LED lattice

A DS18B20 temperature sensor

3. Learn the connection method of DS18B20 and detect the current temperature.

First, take a look at the meaning of DS18B20 pins, as shown in the figure above:

The corresponding relationship between the pins of TPYBoard and those of DS18B20 is as follows:

TPYBoard DS18B20

-

# 3V3 or any Pin = > VDD

# any Pin = > DO

# GND = > GND

If you still don't understand, just put the pin number on it.

TPYBoard LCD5110

-

3.3v = > VDD

GND = > GND

Y10 = > DO

After connecting to ok, in the source directory of MicroPython, go to the drivers\ onewire\ directory, and then copy the files ds18x20.py and onewire.py in the directory to the root directory of the PYBFLASH disk. Copy the file to safely exit the disk, and then re-access, otherwise can not find the file, you can run the main.py file, print temperature, you can use Putty to see the current temperature.

Main.py source code:

# main.pyimport pybfrom pyb import Pinfrom ds18x20 import DS18X20Pin ("Y11", Pin.OUT_PP). Low () # GNDPin ("Y9", Pin.OUT_PP). High () # VCCpyb.delay (100) DQ=DS18X20 (Pin ('Y10')) # DQwhile True: tem = DQ.read_temp () print (tem) pyb.delay (1000)

4. Light up the 8*8LED lattice

There are two rows of pins behind the lattice, one row begins with 1, that is, 1-8 pins, and the other begins with 9, that is, 9-16 pins. The number in the figure 0 above corresponds to the corresponding number of pins, when the PIN NO of ROW. High level, COL PIN NO. When the power level is low, our LED is all lit. In order to facilitate the operation of rows and columns, we can connect the 8 pins of ROW to the 8 pins of our TPYBoard X1MurX8 Col to our TPYBoard Y1-Y8, so that we can control which pin is lit and off. It is no problem to display any word. Come and try it.

5. The temperature is displayed on the 8*8LED lattice.

After the wiring is successful, we will test the temperature by dividing the function to display ten digits, individual places, decimal points, and the following digits. The code is as follows:

Import pybfrom pyb import Pinfrom ds18x20 import DS18X20x_PIN = [Pin (I, Pin.OUT_PP) for i in ['X1PY (I, Pin.OUT_PP) for i in]] y_PIN = [Pin (I, Pin.OUT_PP) for i in [' Y1MY3]] y_PIN = [Pin (I, Pin.OUT_PP) for i in ['Y1BZ] temp= [' 000000010101010101010101011010110101101011010110101101011010110110110101101101011010110110101101011010110101101011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011010110110110110110110110110110110110110110110110110110110101101011010110101101011010110101101 01110 in range 011110pint 0110pl left_item=left_.split 'flag: for x010value (0) left_ = pl [value] (0) ') right_ = temp [r _ num] right_item=right_.split (' ') li_l=left_ [flag] li_r=right_ [flag] y_PIN [0] .value (int (li_l [: 1])) y_PIN [1] .value (int (li_ l [1: 2])) y_PIN [2] .value (int (li_ l [2: 3])) y_PIN [3] .value (int (li_l [3) ) y_PIN [4] .value (int (li_r [: 1])) y_PIN [5] .value (int (li_ r [1: 2])) y_PIN [6] .value (int (li_ r [2: 3])) y_PIN [7] .value (int (li_ r [3: 4])) xPIN [flag] .value (1) Flag=flag+1 pyb.delay (2) def display (time_ For x in range: for y in range (0110): show (if _ _ name__=='__main__': # time_t=Timer) (4 ~ ~ freqy5) Callback=randSensor) DQ=DS18X20 (Pin ('Y10')) # DQ while 1: tempValue = int (DQ.read_temp ()) print (tempValue) l_n=tempValue//10 r_n=tempValue print (Lindn) print (rhamn) display (60 Renen) for i in x_PIN: i.value (0) above is all the content of the article "how does Python realize temperature Sensor" Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report