Difference between revisions of "Stepper Motor and ULN2003"

From Sketching with Hardware at LMU Wiki
Jump to navigation Jump to search
Line 40: Line 40:
 
from machine import Pin
 
from machine import Pin
  
 +
# for the ESP8266
 +
# In1 = Pin(2,Pin.OUT) # IN1-> GPIO2
 +
# In2 = Pin(0,Pin.OUT) # IN1-> GPIO0
 +
# In3 = Pin(4,Pin.OUT) # IN1-> GPIO4
 +
# In4 = Pin(5,Pin.OUT) # IN1-> GPIO5
 +
 +
# for ESP32
 
In1 = Pin(32,Pin.OUT)
 
In1 = Pin(32,Pin.OUT)
 
In2 = Pin(33,Pin.OUT)
 
In2 = Pin(33,Pin.OUT)
Line 53: Line 60:
 
s1.step(509)
 
s1.step(509)
 
</syntaxhighlight>
 
</syntaxhighlight>
 
 
 
  
 
= Related Tutorial Videos =
 
= Related Tutorial Videos =
 
<youtube>PEKjvD1uQe4</youtube>
 
<youtube>PEKjvD1uQe4</youtube>

Revision as of 00:22, 22 December 2020

IMPORTANT

In many computers the current is not enough to drive the servo!!!

If it does not work, keeps disconnecting, or rebooting the ESP the power is not sufficent and you need an extra power supply.

Description

A stepper motor is a motor where the turning can be controlled in steps.

Our motor has about 508 steps for 360° (the motor itself has 64 steps but there is a gear train on top)

more details:

Stepper.JPG Stepper03.JPG

ULN2003 driver module.

Stepper02.JPG

How to connect it electrically

Stepper-c.JPG

Stepper-cables01.JPG Stepper-cable02.JPG

Required Module and Files

How to control it in MicroPython

 1 import Stepper
 2 from machine import Pin
 3 
 4 # for the ESP8266 
 5 # In1 = Pin(2,Pin.OUT) # IN1-> GPIO2 
 6 # In2 = Pin(0,Pin.OUT) # IN1-> GPIO0 
 7 # In3 = Pin(4,Pin.OUT) # IN1-> GPIO4 
 8 # In4 = Pin(5,Pin.OUT) # IN1-> GPIO5 
 9 
10 # for ESP32
11 In1 = Pin(32,Pin.OUT)
12 In2 = Pin(33,Pin.OUT)
13 In3 = Pin(25,Pin.OUT)
14 In4 = Pin(26,Pin.OUT)
15 
16 s1 = Stepper.create(In1,In2,In3,In4, delay=10)
17 
18 s1.step(509,-1)
19 
20 s1 = Stepper.create(In1,In2,In3,In4, delay=1)
21 
22 s1.step(509)

Related Tutorial Videos