Micropython turnipbit automatic Curtain simulation system

Source: Internet
Author: User

Today we continue to study turnipbit This board function, this experiment inspiration is not I think out of, the office is shady, morning noon can not see the sun, sit opposite colleague every four o'clock in the afternoon, all to pull the curtains, I can feel the sun straight sun his eyes, (squint squint). So I thought of this.

Required Devices:

Üturnipbit Development Board 1 pieces

ü Download Data Cable 1 article

ü Miniature Stepper Motor (28BYJ-48) One

ü Stepper Motor Drive Plate (ULN2003APG) 1 block

ü Photosensitive sensor One

Üturnipbit Expansion Board 1 blocks

ü 1 computers connected to the network

ü Online visual programmer

Http://turnipbit.com/PythonEditor/editor.html

Introduction of Stepper motor

This experiment uses the 28byj-48 four-phase eight beats the motor, the voltage dc5v~12v.

Meaning of the 24byj48 name:

24: Motor diameter 24mm

B: Stepping motor in the pinyin first letter of the word

Y: the pinyin initials of permanent characters

J: reduced pinyin first letter of deceleration

48: Four-Phase 8-Step

Stepping motor is an open-loop control motor which transforms electric pulse signal into angular displacement or line displacement, and is the main executing element in modern Digital program control system, which is widely used. In the case of non-overloading, the speed of the motor, the position of the stop only depends on the frequency of the pulse signal and the number of pulses, and is not affected by the load changes, when the stepper driver receives a pulse signal, it will drive the stepper motor in the direction set to rotate a fixed angle, called "Step Angle", Its rotation is run at a fixed angle step-by-step. The angular displacement can be controlled by controlling the number of pulses to achieve accurate positioning, and the speed and acceleration of motor rotation can be controlled by controlling the pulse frequency to achieve the purpose of speed regulation.

Driving principle

When the continuous transmission of control pulses to the motor, the motor will continue to rotate. Each pulse signal corresponding to the stepper motor of a phase or two-phase winding power state change once, corresponding to the rotor will be turned over a certain angle (step angle). When the power state changes to complete a cycle, the rotor turns over a pitch.

Four-phase stepper motors can operate in different power modes, common power-on mode:

Four-shot (single-phase winding power): A-b-c-d-a ...

Double four-shot (dual-phase winding power): Ab-bc-cd-da-ab-...

Eight beats: a-ab-b-bc-c-cd-d-da-a ...

Connection of the device

1, the stepper motor white connector inserted into the driver plate corresponding to the chair.

2, turnipbit corresponding to insert expansion board, remember with LED lights and the side of the key to the expansion board with the side of the pin.

3. Connect the drive board to the Turnipbit expansion board. The wiring diagram is as follows:

Turnipbit Expansion Board

ULN2003APG Drive Board

P5

IN1

P8

IN2

P11

IN3

P12

IN4

+ +

5V Positive

GND

Negative

4. Connect the photosensitive sensor with the Turnipbit expansion board. The wiring diagram is as follows:

Turnipbit Expansion Board

Photosensitive sensor

3.3V

Vcc

GND

GND

P0

AO

Start programming

The previous tutorial has been to use drag-and-drop visualization programming, which allows you to quickly get started with a zero-based partner, but in a real project or work, you're going to hit the code directly. Today, let's introduce another function of turnipbit visual programmer-code programming. (actually this plug-in programming is too troublesome)

It's easy to see that the programmer's interface is the first thing that opens the editor.

5.4.2, the next use of code to achieve the control of stepper motor and lighting data acquisition.

ü When the light becomes weak, the stepper motor rotates clockwise for one week, simulating the operation of closing the curtain;

ü When the light becomes stronger, the stepper motor rotates counterclockwise for a week, simulating the operation of opening the curtain;

Complete the source code:

# Add Python code here from microbit Import * Pin_all=[pin5,pin8,pin11,pin12] #转速 (ms) The higher the speed the slower the minimum value 1.8msspeed=5 steper_round=512 #转动一圈 (360 degree) period angle_per_round=steper_round/360 #转动1度的周期 isopen=false# indicates the state of the curtain True: On False: Turns off def steperwritedata (  Data): Count=0 for I in Data:pin_all[count].write_digital (i) count+=1def Steperfrontturn (): Global Speed Steperwritedata ([1,1,0,0]) sleep (speed) steperwritedata ([0,1,1,0]) sleep (speed) Steperwritedata       ([0,0,1,1]) sleep (speed) steperwritedata ([1,0,0,1]) the Sleep (speed) def steperbackturn (): Global speed Steperwritedata ([1,1,0,0]) sleep (speed) steperwritedata ([1,0,0,1]) sleep (speed) Steperwritedata ([0, 0,1,1]) sleep (speed) steperwritedata ([0,1,1,0]) sleep (speed) def steperstop (): Steperwritedata ([0,0,0,0]) d EF Steperrun (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_an Alog () #读取光敏传感器传递过来的模拟量数据 #数值越大说明光照度越小 if Light>400:if isopen:isopen=false steperru   N ( -360) #光照小于设定的值, close the curtains else:if isopen==false:isopen=true steperrun (#光照大于设定的值), open the curtains

  

Micropython turnipbit automatic Curtain simulation system

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.