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 DIY ultrasonic rangefinder with python

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article mainly introduces the relevant knowledge of "how python realizes DIY ultrasonic rangefinder". The editor shows you the operation process through the actual case, the operation method is simple, fast and practical. I hope this article "how to realize DIY ultrasonic rangefinder with python" can help you solve the problem.

1. Experimental purpose

1. Learn to extend the simple Icano in PC system. The method of the interface.

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

3. Learn the ranging principle of ultrasonic module.

4. Learn the method of LCD5110 wiring

5. Learn TPYboard to control ultrasonic module distance measurement. (radish programming education tpyboard. Com)

two。 Required components

An ultrasonic module

TPYBoard board

One 5110LCD display screen

A data line

Some DuPont lines

3. Working principle of ultrasonic module

(1) using IO port TRIG to trigger ranging, to send a signal to the high level of at least 10us.

(2) the module automatically sends 8 square waves of 40khz and automatically detects whether there is a signal return.

(3) when a signal is returned, a high level is output through the IO port ECHO. The duration of the high level is the time from the emission to the return of the ultrasonic wave. Test distance = (high level time * speed of sound (340M/S)) / 2.

The following figure wiring, VCC for 5V power supply, GND for the ground wire, TRIG trigger control signal input, ECHO echo signal output and other four interface terminals. (radish programming education tpyboard. Com)

4. Control 5110 display screen to display 6x8 characters

Let's take a look at the meaning of LCD5110 stitches (note: LCD5110 stitches are a little different)

The pins of TPYBoard correspond to the pins of 5110 as follows:

TPYBoard LCD5110 memo

-

# any Pin = > RST Reset pin (0=reset, 1=normal)

# any Pin = > CE Chip Enable (0=listen for input, 1=ignore input)

# any Pin = > DC Data/Command (0=commands, 1=data)

# MOSI = > DIN data flow (Master out, Slave in)

# SCK = > CLK SPI clock

# 3V3 or any Pin = > VCC 3.3V logic voltage (0=off, 1=on)

# any Pin = > LIGHT Light (0=on, 1=off)

# GND = > GND

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

TPYBoard LCD5110 memo

-

Y10 = > RST Reset pin (0=reset, 1=normal)

Y11 = > CE Chip Enable (0=listen for input, 1=ignore input)

Y9 = > DC Data/Command (0=commands, 1=data)

X8 = > DIN data flow (Master out, Slave in)

X6 = > CLK SPI clock

VCC

Y12 = > LIGHT Light (0=on, 1=off)

GND

After connecting the ok, and import the font.py file and upcd8544.py file, write main.py to display the measured distance on the 5110 display screen, run main.py on the ok. (font.py and upcd8544.py can be downloaded from the official website and will eventually be told the download address). (radish programming education tpyboard. Com)

5. source code

Import pybfrom pyb import Pinfrom pyb import Timerimport upcd8544from machine import SPI,PinTrig = Pin ('X2mom pin. OUTZPP) Echo = Pin (' X1FLTZN Pin.IN) num=0flag=0run=1def start (t): global flag global num if (flag==0): num=0 else: num=num+1def stop (t): global run if (run==0): run=1start1=Timer (1m freqstores 10000 call callbacks start) stop1=Timer (4m freqcards 2 Callback=stop) while True: if (run==1): SPI = pyb.SPI (1) # DIN= > X8 MOS DIN= CLK = > X6-SCK # DIN= > SPI (1). MOSI 'X8' data flow (Master out) Slave in) # CLK = > SPI (1). SCK 'X6' SPI clock RST = pyb.Pin (' Y10') CE = pyb.Pin ('Y11') DC = pyb.Pin (' Y9') LIGHT = pyb.Pin ('Y12') lcd_5110 = upcd8544.PCD8544 (SPI, RST, CE, DC LIGHT) Trig.value (1) pyb.udelay (100) Trig.value (0) while (Echo.value () = = 0): Trig.value (1) pyb.udelay (100) Trig.value (0) flag=0 if (Echo.value () = = 1): flag=1 while (Echo.value ( ) = = 1): flag=1 if (numb num:' 0): # print ('num:' Num) distance=num/10000*34000/2 print ('Distance') print (distance,'cm') lcd_5110.lcd_write_string (' Distance',0,0) lcd_5110.lcd_write_string (str (distance), 6) lcd_5110.lcd_write_string ('cm',58,1) lcd_5110.lcd_write_string (' This is a test of Distance') Flag=0 run=0 's introduction on "how to realize DIY ultrasonic rangefinder by python" ends here. Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

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