Jonathan Dreyer




Arduino-Stepper Motor with Python Control

Overview

These instructions are for building a Arduino controlled stepper motor with a Python interface.

Required Hardware

Required Software

Hardware Setup

Connect the Arduino, motor driver, and motor as seen below.

Schematic

Software Setup

Using the Arduino software upload ArduinoStepperControl.ino to Arduino.

Copy InstrumentControl.py to the /lib/pythonX.Y/site-packages directory

Copy the contents of serialArduino.zip to the /lib/pythonX.Y/site-packages/ directory

Example

#Load communication module
>>> import InstrumentControl
Loading InstrumentControl v1.2
#Change 'COM5' to the Arduino COM port.
>>> Stepper=InstrumentControl.StepperMotor('COM5')
StepperMotor: Serial Communication Open
#Get the version of ArduinoStepperControl software
>>> Stepper.GetVersion()
'5.00'
#Set position of motor
>>> Stepper.SetPosition(1,1,1000)
1000
>>> Stepper.SetPosition(1,1,2000)
2000
#Ask Arduino for motor position
>>> Stepper.GetPosition()
'2000'
>>> Stepper.SetPosition(1,1,1000)
1000
>>> Stepper.SetPosition(1,1,0)
0
>>> Stepper.GetPosition()
'0'
>>> Stepper.SetPosition(1,1,837)
837
>>> Stepper.GetPosition()
'837'
#Close the serial session between the computer and Arduino
>>> Stepper.CloseSerial()
StepperMotor: Serial Communication Closed
#Reopen serial session.
>>> Stepper=InstrumentControl.StepperMotor('COM5')
StepperMotor: Serial Communication Open
#Note that Arduino remembers the motor position
>>> Stepper.GetPosition()
'837'
>>> Stepper.SetPosition(1,1,0)
0
>>> Stepper.CloseSerial()
StepperMotor: Serial Communication Closed
>>>

 

 

 

(c) jdreyer 2014