In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 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 Python realizes the relevant knowledge of DIY automatic curtain simulation system. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's learn about it.
I. preparatory work
ü TurnipBit development board
Download a data line
A miniature stepper motor (28BYJ-48)
A stepper motor drive board (ULN2003APG)
A light-sensitive sensor
ü TurnipBit expansion board
A computer connected to the network
ü online visual programmer
Introduction of stepper motor
This experiment uses 28BYJ-48 four-phase eight-beat motor, voltage DC5V~12V.
The meaning of the 24BYJ48 name:
24: motor outside diameter 24mm
B: the pinyin initials of step characters in stepper motors
Y: the pinyin initials of permanent characters in permanent magnets
J: the first letter of the decelerated Pinyin
48: four phases and eight steps
Physical drawing
working principle
Stepper motor is an open-loop control motor which converts electric pulse signal into angular displacement or linear displacement. it is the main executive component of modern digital program control system and is widely used. In the case of non-overload, the speed and stop position of the motor only depend on the frequency and number of pulses of the pulse signal, but are not affected by the change of the load. When the stepper driver receives a pulse signal, it drives the stepper motor to turn a fixed angle in the set direction, which is called "step angle". Its rotation runs step by step at a fixed angle. The angular displacement can be controlled by controlling the number of pulses to achieve the purpose of accurate positioning; at the same time, the speed and acceleration of motor rotation can be controlled by controlling pulse frequency, so as to achieve the purpose of speed regulation.
28BYJ-48 stepper motor parameter table
The start frequency in the above table is ≥ 550P.P.S (pulses per second), which means that in order to start normally, a single-chip microcomputer is required to give at least 550stepping pulses per second. Then the duration of each beat is 1S/550 ≈ 1.8ms, so the rate of controlling the beat refresh should be about 1.8ms.
Driving principle
When the control pulse is continuously sent to the motor, the motor will continue to rotate. When each pulse signal changes the power-up state of a phase or two-phase winding of the stepper motor, the corresponding rotor will turn over a certain angle (step angle). When the change of the electrified state completes a cycle, the rotor turns over a tooth pitch.
The four-phase stepper motor can operate in different power-up modes, and the common power-up modes are:
Four beats (single-phase winding electrified): A-B-C-D-A …
Double quadruple beat (two-phase winding electrified): AB-BC-CD-DA-AB-...
Eight beats: A-AB-B-BC-C-CD-D-DA-A...
III. Connection of devices
1. Insert the white connector of the stepper motor into the seat corresponding to the driving plate.
2. TurnipBit is inserted into the expansion board. Remember that the side with LED lights and buttons faces the side with pins on the expansion board.
3. Connect the drive board with the TurnipBit expansion board. The wiring diagram is as follows:
4. Connect the photosensitive sensor with the TurnipBit expansion board. The wiring diagram is as follows:
Start programming
1. The previous tutorials have always used drag-and-drop visual programming, which can quickly get you started with a zero-foundation partner, but you still have to hit the code directly in the actual project or work. Today I'm going to introduce you to another feature of TurnipBit's visual programmer-code programming.
For those of you who have seen programming before, it is not difficult to find that when you open the editor, the first thing you enter is the code programmer interface. As shown below:
2. Then use the code to realize the control of the stepper motor and the collection of illumination data.
When the light becomes weak, the stepper motor rotates clockwise to simulate the operation of closing the curtains
When the light becomes stronger, the stepper motor rotates counterclockwise to simulate the operation of opening the curtains
Complete the source code:
# add the Python code from microbit import * Pin_All= [pin5,pin8,pin11] here Pin12] # the larger the speed (ms), the slower the speed is, the minimum 1.8msspeed=5STEPER_ROUND=512 # the period ANGLE_PER_ROUND=STEPER_ROUND/360 of one turn (360C) # the period isOpen=False# of one degree of rotation represents the state of the curtain True: open False: close def SteperWriteData (data): count=0 for i in data: Pin_ all [count]. Write _ digital (I) count+=1def SteperFrontTurn (): global speed SteperWriteData ([1LJ 1) 0mem0]) sleep (speed) SteperWriteData ([0meme 1mine1mine0]) sleep (speed) SteperWriteData ([0mai 0lce1]) sleep (speed) SteperWriteData ([1LJ 0lce1]) sleep (speed) def SteperBackTurn (): global speed SteperWriteData ([1MJ 0MJ 0]) sleep (speed) SteperWriteData ([1MJ 0mil 1]) sleep (speed) SteperWriteData ([0MJ 01J 1]) sleep (speed) SteperWriteData ([0LJ 1]) 1 sleep (speed) def SteperStop (): SteperWriteData (angle): global ANGLE_PER_ROUND val=ANGLE_PER_ROUND*abs (angle) if (angle > 0): for i in range (0 Val): SteperFrontTurn () else: for i in range (0) Val): SteperBackTurn () SteperStop () while True: light=pin0.read_analog () # read the analog data transmitted by the photosensitive sensor # the larger the value, the smaller the illuminance if light > 400: if isOpen: isOpen=False SteperRun (- 360) # Illumination is less than the set value Close the curtains else: if isOpen==False: isOpen=True SteperRun (360) # Illumination is greater than the set value, open the curtains above is "Python how to achieve DIY automatic curtain simulation system" all the content of this article, 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.