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 the rotation Button to Control offline swing by MicroPython

2025-03-26 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 to achieve MicroPython to control offline swing by rotating button". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to achieve MicroPython to control offline swing by rotating button" can help you solve the problem.

First, the purpose of the experiment:

Learn the method of extending the simple Icano interface in the PC system

Learn TurnipBit splicing programming

Understand how the steering gear works

Learn how to connect the TurnipBit expansion board steering gear and rotary button

Second, the required original devices:

TurnipBit together

TurnioBit expansion board

Some DuPont lines

One usb cable

One steering gear.

Rotate a button

Third, the experimental principle:

1. Composition and parameters of steering gear

Steering gear, also known as servo motor, is a kind of electromechanical structure with closed-loop control system. The steering gear is mainly composed of shell, circuit board, non-core motor, gear and position detector. Its working principle is that the controller sends PWM (Pulse width Modulation) signal to the steering gear, calculates the rotation direction after IC processing on the circuit board, then drives the core-less motor to rotate, transmits the power to the swing arm through the deceleration gear, and returns the position signal from the position detector (potentiometer) to judge whether it has reached the set position. Generally, the steering gear can only rotate 180 degrees.

Wiring of steering gear

The steering gear has three wires, brown for the ground, red for the power supply, and orange for the signal line, but for different brands of steering gear, the color of the line may be different.

Control principle of steering gear

The rotation angle of the steering gear is realized by adjusting the duty cycle of the PWM (pulse width modulation) signal.

Duty cycle:

1. Refers to the ratio of time taken up by a high level in a cycle.

two。 The ratio of the duration of the positive pulse to the total period of the pulse. For example, the duty cycle of the pulse sequence with a positive pulse width of 1 μ s and a signal period of 10 μ s is 0.1. That is, the width of the pulse divided by the period of the pulse is called duty cycle. The period of standard PWM (pulse width modulation) signal is fixed as 20ms (50Hz). Theoretically, the pulse width distribution should be between 1ms and 2ms, but in fact, the pulse width can be between 0.5ms and 2.5ms, and the pulse width corresponds to the steering gear rotation angle 0 °~ 180 °.

4. Connection method:

The TurnipBit expansion board corresponds to the LED interface as follows:

5. Source code:

From microbit import * #-# github: https://github.com/microbit-playground/microbit-servo-class#------------class Servo: def _ _ init__ (self, pin, freq=50, min_us=600, max_us=2400 Angle=180): self.min_us = min_us self.max_us = max_us self.us = 0 self.freq = freq self.angle = angle self.analog_period = 0 self.pin = pin analog_period = round ((1/self.freq) * 1000) # hertz to miliseconds self.pin.set_analog_period (analog_period) def write_us (self Us): us = min (self.max_us, max (self.min_us, us)) duty = round (us * 1024 * self.freq / / 1000000) self.pin.write_analog (duty) self.pin.write_digital (0) # turn the pin off def write_angle (self Degrees=None): degrees= degrees% 360 total_range = self.max_us-self.min_us us = self.min_us + total_range * degrees / / self.angle self.write_us (us) sv1 = Servo (pin1) temp=0while True: # read the value passed in by the rotation button Range 2: 1023 read_val=pin0.read_analog () # steering gear rotates 180 degrees and divides 1023 into 180 parts, which is about 5.67 angle=round (read_val/5.67) if (tempwise angle): temp=angle sv1.write_angle (angle) sleep (60). This is the end of the introduction on "how MicroPython realizes the rotation button to control offline swing". Thank you for 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