stavím Plotter na platformě RPI 2. Použil jsem tyto moduly - https://tutorials-raspberrypi.com/how-t ... -uln2003a/ . Problém je, že nastavené kroky v kódu motor neroztočí. Diody na modulu blikají, ozýva se rachot, ale motor se neotočí.
Bipolar_Stepper_Motor_Class
Kód: Vybrať všetko
import RPi.GPIO as GPIO
import time
#sequence for a1, b2, a2, b1
#phase_seq=[[0,0,1,1],[1,0,0,1],[1,1,0,0],[0,1,1,0]];
phase_seq=[[0,0,0,1],[0,0,1,1],[0,0,1,0],[0,1,1,0],[0,1,0,0],[1,1,0,0],[1,0,0,0],[1,0,0,1]];
#full step sequence. maximum torqu
#phase_seq=[[1,0,1,0],[0,1,0,1],[1,0,1,0],[0,1,0,1]]
#half-step sequence. double resolution. But the torque of the stepper motor is not constant
num_phase=len(phase_seq);
class Bipolar_Stepper_Motor:
phase=0;
dir=0;
position=0;
def __init__(self,a1,a2,b1,b2):
#initial a Bipolar_Stepper_Moter objects by assigning the pins
GPIO.setmode(GPIO.BOARD);
self.a1=a1;
self.a2=a2;
self.b1=b1;
self.b2=b2;
GPIO.setup(self.a1,GPIO.OUT);
GPIO.setup(self.a2,GPIO.OUT);
GPIO.setup(self.b1,GPIO.OUT);
GPIO.setup(self.b2,GPIO.OUT);
self.phase=0;
self.dir=0;
self.position=0;
def move(self, dir, steps, delay=0.2):
for _ in range(steps):
next_phase=(self.phase+dir) % num_phase;
GPIO.output(self.a1,phase_seq[next_phase][0]);
GPIO.output(self.b2,phase_seq[next_phase][1]);
GPIO.output(self.a2,phase_seq[next_phase][2]);
GPIO.output(self.b1,phase_seq[next_phase][3]);
self.phase=next_phase;
self.dir=dir;
self.position+=dir;
time.sleep(delay);
def unhold(self):
GPIO.output(self.a1,0);
GPIO.output(self.a2,0);
GPIO.output(self.b1,0);
GPIO.output(self.b2,0);
Kód: Vybrať všetko
################################################################################################
# #
# linear motion #
# Xiang Zhai, May 2, 2013 #
# zxzhaixiang at gmail.com #
# For instruction on how to build the laser engraver and operate the codes, please visit #
# funofdiy.blogspot.com #
# #
################################################################################################
import RPi.GPIO as GPIO
from Bipolar_Stepper_Motor_Class import Bipolar_Stepper_Motor
import time
from numpy import pi, sin, cos, sqrt, arccos, arcsin
GPIO.setmode(GPIO.BOARD)
M=Bipolar_Stepper_Motor(29,31,33,37);
speed=200; #step/sec
try:
for i in range(30):
print "Move to %s .." % ((i+1)*1000);
M.move(-1,1000,1.0/speed);
except KeyboardInterrupt:
pass
M.unhold();
GPIO.cleanup();
Mezitím když jsem zkoušel jednoduchý samostatný skript kde jsem použil [1,0,0,0,] [0,1,0,0] [0,0,1,0] [0,0,0,1] Tak se vše točilo. Proc ovšem tyto sekvence nefungují v tomto kódu zaboha nevidím. Neví někdo co je špatně? Díky