<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Python | DXSdata</title>
	<atom:link href="https://www.dxsdata.com/category/python/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dxsdata.com</link>
	<description>Software &#124; Network &#124; Administration</description>
	<lastBuildDate>Mon, 14 Nov 2016 15:27:37 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>

<image>
	<url>https://www.dxsdata.com/wp-content/uploads/2023/08/cropped-logo-32x32.jpg</url>
	<title>Python | DXSdata</title>
	<link>https://www.dxsdata.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>[:de]Bipolaren 4-PIN Schrittmotor mit Raspberry Pi und Motortreiber steuern[:en]Controlling a 4-Pin bipolar stepper motor with Raspberry Pi and motor shield[:]</title>
		<link>https://www.dxsdata.com/2016/11/controlling-a-4-pin-bipolar-stepper-motor-with-raspberry-pi-and-motor-shield/</link>
					<comments>https://www.dxsdata.com/2016/11/controlling-a-4-pin-bipolar-stepper-motor-with-raspberry-pi-and-motor-shield/#comments</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Mon, 14 Nov 2016 15:27:37 +0000</pubDate>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Home Automation]]></category>
		<category><![CDATA[Python]]></category>
		<guid isPermaLink="false">http://www.dxsdata.com/?p=1293</guid>

					<description><![CDATA[[:en]This tutorial gives you a quick and simple idea how to control a stepper motor via Raspberry Pi and a Python script. Parts Raspberry Pi 3 Deek-Robot Stepper Motor Shield v1 (includes an L293D motor driver) Nema 17 stepper motor, Type 42HS34-1334-04LA (4-pin, bipolar) Connection between motor and shield Red: A- Green: A+ Yellow: B- [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>[:en]This tutorial gives you a quick and simple idea how to control a stepper motor via Raspberry Pi and a Python script.</p>
<h3>Parts</h3>
<ul>
<li><a href="https://www.raspberrypi.org/">Raspberry Pi 3</a></li>
<li><a href="http://www.deek-robot.com/productshow.asp?id=17&amp;small=4">Deek-Robot Stepper Motor Shield v1 </a>(includes an L293D motor driver)</li>
<li><a href="https://www.aliexpress.com/item/3D-printer-linear-stepper-motor-42mm-NEMA17-screw-rod-stepper-motor-Tr8-pitch2mm-lead-screw-linear/32550028445.html">Nema 17 stepper motor, Type </a><span style="font-family: Arial;">42HS34-1334-04LA (4-pin, bipolar)</span></li>
</ul>
<h3>Connection between motor and shield</h3>
<ul>
<li>Red: A-</li>
<li>Green: A+</li>
<li>Yellow: B-</li>
<li>Blue: B+</li>
</ul>
<p>Red+Green and Yellow+Blue are one phase each, in this case (4-pin bipolar motor) it does not matter if you swap Red with Green or Yellow with Blue.</p>
<p>&nbsp;</p>
<h3>Connection between shield and RPi</h3>
<ul>
<li>5V+ (VCC): Pin 2</li>
<li>GND: Pin 6</li>
<li>IN1: Pin 12</li>
<li>IN2: Pin 16</li>
<li>IN3: Pin 18</li>
<li>IN4: Pin 22</li>
<li>VIN: <del>Pin 4</del> (not needed; or separate power source)</li>
<li>GND (near VIN): <del>Pin 10</del> (not needed; or separate power source)</li>
</ul>
<p>For INx, you can of course choose other GPIO ports on your RPi, but you have to fit the script.</p>
<h3>Python Script</h3>
<p>&nbsp;</p>
<pre class="lang:python decode:true">import RPi.GPIO as GPIO
import time

# Variables

delay = 0.0055
steps = 500

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

# Enable pins for IN1-4 to control step sequence

coil_A_1_pin = 18
coil_A_2_pin = 23
coil_B_1_pin = 24
coil_B_2_pin = 25

# Set pin states

GPIO.setup(coil_A_1_pin, GPIO.OUT)
GPIO.setup(coil_A_2_pin, GPIO.OUT)
GPIO.setup(coil_B_1_pin, GPIO.OUT)
GPIO.setup(coil_B_2_pin, GPIO.OUT)


# Function for step sequence

def setStep(w1, w2, w3, w4):
  GPIO.output(coil_A_1_pin, w1)
  GPIO.output(coil_A_2_pin, w2)
  GPIO.output(coil_B_1_pin, w3)
  GPIO.output(coil_B_2_pin, w4)

# loop through step sequence based on number of steps

for i in range(0, steps):
    setStep(1,0,1,0)
    time.sleep(delay)
    setStep(0,1,1,0)
    time.sleep(delay)
    setStep(0,1,0,1)
    time.sleep(delay)
    setStep(1,0,0,1)
    time.sleep(delay)

# Reverse previous step sequence to reverse motor direction

for i in range(0, steps):
    setStep(1,0,0,1)
    time.sleep(delay)
    setStep(0,1,0,1)
    time.sleep(delay)
    setStep(0,1,1,0)
    time.sleep(delay)
    setStep(1,0,1,0)
    time.sleep(delay)
</pre>
<h3>Pictures</h3>
<h3><a href="https://www.dxsdata.com/wp-content/uploads/2016/11/20161114_155915.jpg" rel="attachment wp-att-1294"><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-1294" src="https://www.dxsdata.com/wp-content/uploads/2016/11/20161114_155915-300x169.jpg" alt="raspberry pi with stepper motor and shield 2" width="300" height="169" /></a></h3>
<h3><a href="https://www.dxsdata.com/wp-content/uploads/2016/11/20161114_155839.jpg" rel="attachment wp-att-1295"><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-1295" src="https://www.dxsdata.com/wp-content/uploads/2016/11/20161114_155839-300x169.jpg" alt="raspberry pi with stepper motor and shield 1" width="300" height="169" /></a></h3>
<p>&nbsp;</p>
<h3>Important</h3>
<p>In general, I highly recommend to only power the shield (especially the motor) when it is needed, not all the time. The motor takes about 0,5A even when idle, and the L293D chip gets quite hot.</p>
<p>So use a switch etc. for the power line, or maybe use <a href="http://electronics.stackexchange.com/questions/108686/what-h-bridge-drivers-are-preferred-for-applications-controlling-a-low-voltage-m">another driver chip</a>.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>References:</p>
<p>https://www.raspberrypi.org/forums/viewtopic.php?f=49&#038;t=55580</p>
<p>http://www.elektronx.de/tutorials/schrittmotorsteuerung-mit-dem-raspberry-pi/</p>
<p>&nbsp;[:]</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dxsdata.com/2016/11/controlling-a-4-pin-bipolar-stepper-motor-with-raspberry-pi-and-motor-shield/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
