0

Raspberry Pi 3 stepper motor release
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Re: Raspberry Pi 3 stepper motor release

by Skydromer on Tue Jul 30, 2019 8:38 am

ok yeah it was the GPIO mode.

In the end the new library is to rought and not precisely enought, even with time.sleep().

Now i got a new question. Is it possible to modify the old library to let me use release.


sorry for so much trouble and posts

Skydromer
 
Posts: 23
Joined: Thu Jul 18, 2019 2:56 am

Re: Raspberry Pi 3 stepper motor release

by adafruit_support_carter on Tue Jul 30, 2019 12:19 pm

The old library repo is there if you want to fork and modify the code:
https://github.com/adafruit/Adafruit-Mo ... on-Library

In the end the new library is to rought and not precisely enought, even with time.sleep().

Can you elaborate on this. Is the motor not turning smoothly? Did you try tweaking the value of the delay?

adafruit_support_carter
 
Posts: 12968
Joined: Tue Nov 29, 2016 2:45 pm

Re: Raspberry Pi 3 stepper motor release

by Skydromer on Tue Jul 30, 2019 4:12 pm

Thanks i will look at it tomorrow and hopefully i can get where i want to :D



i have a little switch which is pushed once in a revolution of a rotating table. Just the command kit.stepper.onestep() is enough that this switch wont be registered when pushed. Even if i place the same or lower speed on the motor it wont be registered. But in the old library it is fin and get registered. Additonaly i dont get any issues with stuttering stepper motors at higher speed then used with the new library.


Hope my english is good enough to understand everything.

Skydromer
 
Posts: 23
Joined: Thu Jul 18, 2019 2:56 am

Re: Raspberry Pi 3 stepper motor release

by Skydromer on Mon Aug 05, 2019 4:57 am

Code: Select all | TOGGLE FULL SIZE
import time

from Adafruit_MotorHAT.Adafruit_PWM_Servo_Driver import PWM


class Adafruit_StepperMotor:
    MICROSTEPS = 8
    MICROSTEP_CURVE = [0, 50, 98, 142, 180, 212, 236, 250, 255]

    #MICROSTEPS = 16
    # a sinusoidal curve NOT LINEAR!
    #MICROSTEP_CURVE = [0, 25, 50, 74, 98, 120, 141, 162, 180, 197, 212, 225, 236, 244, 250, 253, 255]

    def __init__(self, controller, num, steps=200):
        self.MC = controller
        self.revsteps = steps
        self.motornum = num
        self.sec_per_step = 0.1
        self.steppingcounter = 0
        self.currentstep = 0

        num -= 1

        if (num == 0):
            self.PWMA = 8
            self.AIN2 = 9
            self.AIN1 = 10
            self.PWMB = 13
            self.BIN2 = 12
            self.BIN1 = 11
        elif (num == 1):
            self.PWMA = 2
            self.AIN2 = 3
            self.AIN1 = 4
            self.PWMB = 7
            self.BIN2 = 6
            self.BIN1 = 5
        else:
            raise NameError('MotorHAT Stepper must be between 1 and 2 inclusive')

    def setSpeed(self, rpm):
        self.sec_per_step = 60.0 / (self.revsteps * rpm)
        self.steppingcounter = 0

    def oneStep(self, dir, style):
        pwm_a = pwm_b = 255

        # first determine what sort of stepping procedure we're up to
        if (style == Adafruit_MotorHAT.SINGLE):
            if ((self.currentstep//(self.MICROSTEPS//2)) % 2):
                # we're at an odd step, weird
                if (dir == Adafruit_MotorHAT.FORWARD):
                    self.currentstep += self.MICROSTEPS//2
                else:
                    self.currentstep -= self.MICROSTEPS//2
            else:
                # go to next even step
                if (dir == Adafruit_MotorHAT.FORWARD):
                    self.currentstep += self.MICROSTEPS
                else:
                    self.currentstep -= self.MICROSTEPS
        if (style == Adafruit_MotorHAT.DOUBLE):
            if not (self.currentstep//(self.MICROSTEPS//2) % 2):
                # we're at an even step, weird
                if (dir == Adafruit_MotorHAT.FORWARD):
                    self.currentstep += self.MICROSTEPS//2
                else:
                    self.currentstep -= self.MICROSTEPS//2
            else:
                # go to next odd step
                if (dir == Adafruit_MotorHAT.FORWARD):
                    self.currentstep += self.MICROSTEPS
                else:
                    self.currentstep -= self.MICROSTEPS
        if (style == Adafruit_MotorHAT.INTERLEAVE):
            if (dir == Adafruit_MotorHAT.FORWARD):
                self.currentstep += self.MICROSTEPS//2
            else:
                self.currentstep -= self.MICROSTEPS//2

        if (style == Adafruit_MotorHAT.RELEASE):
            if (dir == Adafruit_MotorHAT.FORWARD):
                self.MC.setPin(self.AIN1pin, self.LOW)
                self.MC.setPin(self.AIN2pin, self.LOW)
                self.MC.setPin(self.BIN1pin, self.LOW)
                self.MC.setPin(self.BIN2pin, self.LOW)
                self.MC.setPWM(self.PWMApin, 0)
                self.MC.setPWM(self.PWMBpin, 0)

        if (style == Adafruit_MotorHAT.MICROSTEP):
            if (dir == Adafruit_MotorHAT.FORWARD):
                self.currentstep += 1
            else:
                self.currentstep -= 1

                # go to next 'step' and wrap around
                self.currentstep += self.MICROSTEPS * 4
                self.currentstep %= self.MICROSTEPS * 4

            pwm_a = pwm_b = 0
            if (self.currentstep >= 0) and (self.currentstep < self.MICROSTEPS):
                pwm_a = self.MICROSTEP_CURVE[self.MICROSTEPS - self.currentstep]
                pwm_b = self.MICROSTEP_CURVE[self.currentstep]
            elif (self.currentstep >= self.MICROSTEPS) and (self.currentstep < self.MICROSTEPS*2):
                pwm_a = self.MICROSTEP_CURVE[self.currentstep - self.MICROSTEPS]
                pwm_b = self.MICROSTEP_CURVE[self.MICROSTEPS*2 - self.currentstep]
            elif (self.currentstep >= self.MICROSTEPS*2) and (self.currentstep < self.MICROSTEPS*3):
                pwm_a = self.MICROSTEP_CURVE[self.MICROSTEPS*3 - self.currentstep]
                pwm_b = self.MICROSTEP_CURVE[self.currentstep - self.MICROSTEPS*2]
            elif (self.currentstep >= self.MICROSTEPS*3) and (self.currentstep < self.MICROSTEPS*4):
                pwm_a = self.MICROSTEP_CURVE[self.currentstep - self.MICROSTEPS*3]
                pwm_b = self.MICROSTEP_CURVE[self.MICROSTEPS*4 - self.currentstep]


        # go to next 'step' and wrap around
        self.currentstep += self.MICROSTEPS * 4
        self.currentstep %= self.MICROSTEPS * 4

        # only really used for microstepping, otherwise always on!
        self.MC._pwm.setPWM(self.PWMA, 0, pwm_a*16)
        self.MC._pwm.setPWM(self.PWMB, 0, pwm_b*16)

        # set up coil energizing!
        coils = [0, 0, 0, 0]

        if (style == Adafruit_MotorHAT.MICROSTEP):
            if (self.currentstep >= 0) and (self.currentstep < self.MICROSTEPS):
                coils = [1, 1, 0, 0]
            elif (self.currentstep >= self.MICROSTEPS) and (self.currentstep < self.MICROSTEPS*2):
                coils = [0, 1, 1, 0]
            elif (self.currentstep >= self.MICROSTEPS*2) and (self.currentstep < self.MICROSTEPS*3):
                coils = [0, 0, 1, 1]
            elif (self.currentstep >= self.MICROSTEPS*3) and (self.currentstep < self.MICROSTEPS*4):
                coils = [1, 0, 0, 1]
        else:
            step2coils = [     [1, 0, 0, 0],
                [1, 1, 0, 0],
                [0, 1, 0, 0],
                [0, 1, 1, 0],
                [0, 0, 1, 0],
                [0, 0, 1, 1],
                [0, 0, 0, 1],
                [1, 0, 0, 1] ]
            coils = step2coils[self.currentstep//(self.MICROSTEPS//2)]

        #print "coils state = " + str(coils)
        self.MC.setPin(self.AIN2, coils[0])
        self.MC.setPin(self.BIN1, coils[1])
        self.MC.setPin(self.AIN1, coils[2])
        self.MC.setPin(self.BIN2, coils[3])

        return self.currentstep

    def release(self):
        self.MC.setPin(self.AIN1pin, self.LOW)
        self.MC.setPin(self.AIN2pin, self.LOW)
        self.MC.setPin(self.BIN1pin, self.LOW)
        self.MC.setPin(self.BIN2pin, self.LOW)
        self.MC.setPWM(self.PWMApin, 0)
        self.MC.setPWM(self.PWMBpin, 0)

    def step(self, steps, direction, stepstyle):
        s_per_s = self.sec_per_step
        lateststep = 0

        if (stepstyle == Adafruit_MotorHAT.INTERLEAVE):
            s_per_s = s_per_s / 2.0
        if (stepstyle == Adafruit_MotorHAT.MICROSTEP):
            s_per_s /= self.MICROSTEPS
            steps *= self.MICROSTEPS

        print("{} sec per step".format(s_per_s))

        for s in range(steps):
            lateststep = self.oneStep(direction, stepstyle)
            time.sleep(s_per_s)

        if (stepstyle == Adafruit_MotorHAT.MICROSTEP):
            # this is an edge case, if we are in between full steps, lets just keep going
            # so we end on a full step
            while (lateststep != 0) and (lateststep != self.MICROSTEPS):
                lateststep = self.oneStep(direction, stepstyle)
                time.sleep(s_per_s)

class Adafruit_DCMotor:
    def __init__(self, controller, num):
        self.MC = controller
        self.motornum = num
        pwm = in1 = in2 = 0

        if (num == 0):
                 pwm = 8
                 in2 = 9
                 in1 = 10
        elif (num == 1):
                 pwm = 13
                 in2 = 12
                 in1 = 11
        elif (num == 2):
                 pwm = 2
                 in2 = 3
                 in1 = 4
        elif (num == 3):
                 pwm = 7
                 in2 = 6
                 in1 = 5
        else:
            raise NameError('MotorHAT Motor must be between 1 and 4 inclusive')
        self.PWMpin = pwm
        self.IN1pin = in1
        self.IN2pin = in2

    def run(self, command):
        if not self.MC:
            return
        if (command == Adafruit_MotorHAT.FORWARD):
            self.MC.setPin(self.IN2pin, 0)
            self.MC.setPin(self.IN1pin, 1)
        if (command == Adafruit_MotorHAT.BACKWARD):
            self.MC.setPin(self.IN1pin, 0)
            self.MC.setPin(self.IN2pin, 1)
        if (command == Adafruit_MotorHAT.RELEASE):
            self.MC.setPin(self.IN1pin, 0)
            self.MC.setPin(self.IN2pin, 0)
    def setSpeed(self, speed):
        if (speed < 0):
            speed = 0
        if (speed > 255):
            speed = 255
        self.MC._pwm.setPWM(self.PWMpin, 0, speed*16)


class Adafruit_MotorHAT:
    FORWARD = 1
    BACKWARD = 2
    BRAKE = 3
    RELEASE = 4

    SINGLE = 1
    DOUBLE = 2
    INTERLEAVE = 3
    MICROSTEP = 4

    def __init__(self, addr = 0x60, freq = 1600, i2c=None, i2c_bus=None):
        self._frequency = freq
        self.motors = [ Adafruit_DCMotor(self, m) for m in range(4) ]
        self.steppers = [ Adafruit_StepperMotor(self, 1), Adafruit_StepperMotor(self, 2) ]
        self._pwm = PWM(addr, debug=False, i2c=i2c, i2c_bus=i2c_bus)
        self._pwm.setPWMFreq(self._frequency)

    def setPin(self, pin, value):
        if (pin < 0) or (pin > 15):
            raise NameError('PWM pin must be between 0 and 15 inclusive')
        if (value != 0) and (value != 1):
            raise NameError('Pin value must be 0 or 1!')
        if (value == 0):
            self._pwm.setPWM(pin, 0, 4096)
        if (value == 1):
            self._pwm.setPWM(pin, 4096, 0)

    def getStepper(self, steps, num):
        if (num < 1) or (num > 2):
            raise NameError('MotorHAT Stepper must be between 1 and 2 inclusive')
        return self.steppers[num-1]

    def getMotor(self, num):
        if (num < 1) or (num > 4):
            raise NameError('MotorHAT Motor must be between 1 and 4 inclusive')
        return self.motors[num-1]


This what i have done now.
I added those sections in.
Code: Select all | TOGGLE FULL SIZE
        if (style == Adafruit_MotorHAT.RELEASE):
            if (dir == Adafruit_MotorHAT.FORWARD):
                self.MC.setPin(self.AIN1pin, self.LOW)
                self.MC.setPin(self.AIN2pin, self.LOW)
                self.MC.setPin(self.BIN1pin, self.LOW)
                self.MC.setPin(self.BIN2pin, self.LOW)
                self.MC.setPWM(self.PWMApin, 0)
                self.MC.setPWM(self.PWMBpin, 0)


    def release(self):
        self.MC.setPin(self.AIN1pin, self.LOW)
        self.MC.setPin(self.AIN2pin, self.LOW)
        self.MC.setPin(self.BIN1pin, self.LOW)
        self.MC.setPin(self.BIN2pin, self.LOW)
        self.MC.setPWM(self.PWMApin, 0)
        self.MC.setPWM(self.PWMBpin, 0)


But when i use release i got an Attribute error.
With Adafruit_MotorHAT.RELEASE the stepper is giving a high frequenz sound after work is done.
With both function i do not get any of what i wanted.

Do you see any mistakes i may have build here

Skydromer
 
Posts: 23
Joined: Thu Jul 18, 2019 2:56 am

Re: Raspberry Pi 3 stepper motor release

by adafruit_support_carter on Mon Aug 05, 2019 12:22 pm

i have a little switch which is pushed once in a revolution of a rotating table. Just the command kit.stepper.onestep() is enough that this switch wont be registered when pushed.

Can you post a photo of this hardware. It's not clear what is happening and if this is step resolution issue or step speed issue. Or something else.

adafruit_support_carter
 
Posts: 12968
Joined: Tue Nov 29, 2016 2:45 pm

Re: Raspberry Pi 3 stepper motor release

by Skydromer on Mon Aug 05, 2019 2:30 pm

Adafruit_support_carter for your efforts but i will focus on rewriting parts of the old library.

Skydromer
 
Posts: 23
Joined: Thu Jul 18, 2019 2:56 am

Re: Raspberry Pi 3 stepper motor release

by Skydromer on Wed Aug 07, 2019 2:04 am

thanks *



But do you know anything about my newest issues?

Skydromer
 
Posts: 23
Joined: Thu Jul 18, 2019 2:56 am

Re: Raspberry Pi 3 stepper motor release

by adafruit_support_carter on Wed Aug 07, 2019 3:26 pm

Can you restate what the newest issues are?

adafruit_support_carter
 
Posts: 12968
Joined: Tue Nov 29, 2016 2:45 pm

Re: Raspberry Pi 3 stepper motor release

by Skydromer on Thu Aug 08, 2019 12:53 am

Skydromer wrote:
Code: Select all | TOGGLE FULL SIZE
import time

from Adafruit_MotorHAT.Adafruit_PWM_Servo_Driver import PWM


class Adafruit_StepperMotor:
    MICROSTEPS = 8
    MICROSTEP_CURVE = [0, 50, 98, 142, 180, 212, 236, 250, 255]

    #MICROSTEPS = 16
    # a sinusoidal curve NOT LINEAR!
    #MICROSTEP_CURVE = [0, 25, 50, 74, 98, 120, 141, 162, 180, 197, 212, 225, 236, 244, 250, 253, 255]

    def __init__(self, controller, num, steps=200):
        self.MC = controller
        self.revsteps = steps
        self.motornum = num
        self.sec_per_step = 0.1
        self.steppingcounter = 0
        self.currentstep = 0

        num -= 1

        if (num == 0):
            self.PWMA = 8
            self.AIN2 = 9
            self.AIN1 = 10
            self.PWMB = 13
            self.BIN2 = 12
            self.BIN1 = 11
        elif (num == 1):
            self.PWMA = 2
            self.AIN2 = 3
            self.AIN1 = 4
            self.PWMB = 7
            self.BIN2 = 6
            self.BIN1 = 5
        else:
            raise NameError('MotorHAT Stepper must be between 1 and 2 inclusive')

    def setSpeed(self, rpm):
        self.sec_per_step = 60.0 / (self.revsteps * rpm)
        self.steppingcounter = 0

    def oneStep(self, dir, style):
        pwm_a = pwm_b = 255

        # first determine what sort of stepping procedure we're up to
        if (style == Adafruit_MotorHAT.SINGLE):
            if ((self.currentstep//(self.MICROSTEPS//2)) % 2):
                # we're at an odd step, weird
                if (dir == Adafruit_MotorHAT.FORWARD):
                    self.currentstep += self.MICROSTEPS//2
                else:
                    self.currentstep -= self.MICROSTEPS//2
            else:
                # go to next even step
                if (dir == Adafruit_MotorHAT.FORWARD):
                    self.currentstep += self.MICROSTEPS
                else:
                    self.currentstep -= self.MICROSTEPS
        if (style == Adafruit_MotorHAT.DOUBLE):
            if not (self.currentstep//(self.MICROSTEPS//2) % 2):
                # we're at an even step, weird
                if (dir == Adafruit_MotorHAT.FORWARD):
                    self.currentstep += self.MICROSTEPS//2
                else:
                    self.currentstep -= self.MICROSTEPS//2
            else:
                # go to next odd step
                if (dir == Adafruit_MotorHAT.FORWARD):
                    self.currentstep += self.MICROSTEPS
                else:
                    self.currentstep -= self.MICROSTEPS
        if (style == Adafruit_MotorHAT.INTERLEAVE):
            if (dir == Adafruit_MotorHAT.FORWARD):
                self.currentstep += self.MICROSTEPS//2
            else:
                self.currentstep -= self.MICROSTEPS//2

        if (style == Adafruit_MotorHAT.RELEASE):
            if (dir == Adafruit_MotorHAT.FORWARD):
                self.MC.setPin(self.AIN1pin, self.LOW)
                self.MC.setPin(self.AIN2pin, self.LOW)
                self.MC.setPin(self.BIN1pin, self.LOW)
                self.MC.setPin(self.BIN2pin, self.LOW)
                self.MC.setPWM(self.PWMApin, 0)
                self.MC.setPWM(self.PWMBpin, 0)

        if (style == Adafruit_MotorHAT.MICROSTEP):
            if (dir == Adafruit_MotorHAT.FORWARD):
                self.currentstep += 1
            else:
                self.currentstep -= 1

                # go to next 'step' and wrap around
                self.currentstep += self.MICROSTEPS * 4
                self.currentstep %= self.MICROSTEPS * 4

            pwm_a = pwm_b = 0
            if (self.currentstep >= 0) and (self.currentstep < self.MICROSTEPS):
                pwm_a = self.MICROSTEP_CURVE[self.MICROSTEPS - self.currentstep]
                pwm_b = self.MICROSTEP_CURVE[self.currentstep]
            elif (self.currentstep >= self.MICROSTEPS) and (self.currentstep < self.MICROSTEPS*2):
                pwm_a = self.MICROSTEP_CURVE[self.currentstep - self.MICROSTEPS]
                pwm_b = self.MICROSTEP_CURVE[self.MICROSTEPS*2 - self.currentstep]
            elif (self.currentstep >= self.MICROSTEPS*2) and (self.currentstep < self.MICROSTEPS*3):
                pwm_a = self.MICROSTEP_CURVE[self.MICROSTEPS*3 - self.currentstep]
                pwm_b = self.MICROSTEP_CURVE[self.currentstep - self.MICROSTEPS*2]
            elif (self.currentstep >= self.MICROSTEPS*3) and (self.currentstep < self.MICROSTEPS*4):
                pwm_a = self.MICROSTEP_CURVE[self.currentstep - self.MICROSTEPS*3]
                pwm_b = self.MICROSTEP_CURVE[self.MICROSTEPS*4 - self.currentstep]


        # go to next 'step' and wrap around
        self.currentstep += self.MICROSTEPS * 4
        self.currentstep %= self.MICROSTEPS * 4

        # only really used for microstepping, otherwise always on!
        self.MC._pwm.setPWM(self.PWMA, 0, pwm_a*16)
        self.MC._pwm.setPWM(self.PWMB, 0, pwm_b*16)

        # set up coil energizing!
        coils = [0, 0, 0, 0]

        if (style == Adafruit_MotorHAT.MICROSTEP):
            if (self.currentstep >= 0) and (self.currentstep < self.MICROSTEPS):
                coils = [1, 1, 0, 0]
            elif (self.currentstep >= self.MICROSTEPS) and (self.currentstep < self.MICROSTEPS*2):
                coils = [0, 1, 1, 0]
            elif (self.currentstep >= self.MICROSTEPS*2) and (self.currentstep < self.MICROSTEPS*3):
                coils = [0, 0, 1, 1]
            elif (self.currentstep >= self.MICROSTEPS*3) and (self.currentstep < self.MICROSTEPS*4):
                coils = [1, 0, 0, 1]
        else:
            step2coils = [     [1, 0, 0, 0],
                [1, 1, 0, 0],
                [0, 1, 0, 0],
                [0, 1, 1, 0],
                [0, 0, 1, 0],
                [0, 0, 1, 1],
                [0, 0, 0, 1],
                [1, 0, 0, 1] ]
            coils = step2coils[self.currentstep//(self.MICROSTEPS//2)]

        #print "coils state = " + str(coils)
        self.MC.setPin(self.AIN2, coils[0])
        self.MC.setPin(self.BIN1, coils[1])
        self.MC.setPin(self.AIN1, coils[2])
        self.MC.setPin(self.BIN2, coils[3])

        return self.currentstep

    def release(self):
        self.MC.setPin(self.AIN1pin, self.LOW)
        self.MC.setPin(self.AIN2pin, self.LOW)
        self.MC.setPin(self.BIN1pin, self.LOW)
        self.MC.setPin(self.BIN2pin, self.LOW)
        self.MC.setPWM(self.PWMApin, 0)
        self.MC.setPWM(self.PWMBpin, 0)

    def step(self, steps, direction, stepstyle):
        s_per_s = self.sec_per_step
        lateststep = 0

        if (stepstyle == Adafruit_MotorHAT.INTERLEAVE):
            s_per_s = s_per_s / 2.0
        if (stepstyle == Adafruit_MotorHAT.MICROSTEP):
            s_per_s /= self.MICROSTEPS
            steps *= self.MICROSTEPS

        print("{} sec per step".format(s_per_s))

        for s in range(steps):
            lateststep = self.oneStep(direction, stepstyle)
            time.sleep(s_per_s)

        if (stepstyle == Adafruit_MotorHAT.MICROSTEP):
            # this is an edge case, if we are in between full steps, lets just keep going
            # so we end on a full step
            while (lateststep != 0) and (lateststep != self.MICROSTEPS):
                lateststep = self.oneStep(direction, stepstyle)
                time.sleep(s_per_s)

class Adafruit_DCMotor:
    def __init__(self, controller, num):
        self.MC = controller
        self.motornum = num
        pwm = in1 = in2 = 0

        if (num == 0):
                 pwm = 8
                 in2 = 9
                 in1 = 10
        elif (num == 1):
                 pwm = 13
                 in2 = 12
                 in1 = 11
        elif (num == 2):
                 pwm = 2
                 in2 = 3
                 in1 = 4
        elif (num == 3):
                 pwm = 7
                 in2 = 6
                 in1 = 5
        else:
            raise NameError('MotorHAT Motor must be between 1 and 4 inclusive')
        self.PWMpin = pwm
        self.IN1pin = in1
        self.IN2pin = in2

    def run(self, command):
        if not self.MC:
            return
        if (command == Adafruit_MotorHAT.FORWARD):
            self.MC.setPin(self.IN2pin, 0)
            self.MC.setPin(self.IN1pin, 1)
        if (command == Adafruit_MotorHAT.BACKWARD):
            self.MC.setPin(self.IN1pin, 0)
            self.MC.setPin(self.IN2pin, 1)
        if (command == Adafruit_MotorHAT.RELEASE):
            self.MC.setPin(self.IN1pin, 0)
            self.MC.setPin(self.IN2pin, 0)
    def setSpeed(self, speed):
        if (speed < 0):
            speed = 0
        if (speed > 255):
            speed = 255
        self.MC._pwm.setPWM(self.PWMpin, 0, speed*16)


class Adafruit_MotorHAT:
    FORWARD = 1
    BACKWARD = 2
    BRAKE = 3
    RELEASE = 4

    SINGLE = 1
    DOUBLE = 2
    INTERLEAVE = 3
    MICROSTEP = 4

    def __init__(self, addr = 0x60, freq = 1600, i2c=None, i2c_bus=None):
        self._frequency = freq
        self.motors = [ Adafruit_DCMotor(self, m) for m in range(4) ]
        self.steppers = [ Adafruit_StepperMotor(self, 1), Adafruit_StepperMotor(self, 2) ]
        self._pwm = PWM(addr, debug=False, i2c=i2c, i2c_bus=i2c_bus)
        self._pwm.setPWMFreq(self._frequency)

    def setPin(self, pin, value):
        if (pin < 0) or (pin > 15):
            raise NameError('PWM pin must be between 0 and 15 inclusive')
        if (value != 0) and (value != 1):
            raise NameError('Pin value must be 0 or 1!')
        if (value == 0):
            self._pwm.setPWM(pin, 0, 4096)
        if (value == 1):
            self._pwm.setPWM(pin, 4096, 0)

    def getStepper(self, steps, num):
        if (num < 1) or (num > 2):
            raise NameError('MotorHAT Stepper must be between 1 and 2 inclusive')
        return self.steppers[num-1]

    def getMotor(self, num):
        if (num < 1) or (num > 4):
            raise NameError('MotorHAT Motor must be between 1 and 4 inclusive')
        return self.motors[num-1]


This what i have done now.
I added those sections in.
Code: Select all | TOGGLE FULL SIZE
        if (style == Adafruit_MotorHAT.RELEASE):
            if (dir == Adafruit_MotorHAT.FORWARD):
                self.MC.setPin(self.AIN1pin, self.LOW)
                self.MC.setPin(self.AIN2pin, self.LOW)
                self.MC.setPin(self.BIN1pin, self.LOW)
                self.MC.setPin(self.BIN2pin, self.LOW)
                self.MC.setPWM(self.PWMApin, 0)
                self.MC.setPWM(self.PWMBpin, 0)


    def release(self):
        self.MC.setPin(self.AIN1pin, self.LOW)
        self.MC.setPin(self.AIN2pin, self.LOW)
        self.MC.setPin(self.BIN1pin, self.LOW)
        self.MC.setPin(self.BIN2pin, self.LOW)
        self.MC.setPWM(self.PWMApin, 0)
        self.MC.setPWM(self.PWMBpin, 0)


But when i use release i got an Attribute error.
With Adafruit_MotorHAT.RELEASE the stepper is giving a high frequenz sound after work is done.
With both function i do not get any of what i wanted.

Do you see any mistakes i may have build here


This it is. By adding those section the stepper motor is howl or python is responding with not attribute found in this class.

Skydromer
 
Posts: 23
Joined: Thu Jul 18, 2019 2:56 am

Re: Raspberry Pi 3 stepper motor release

by adafruit_support_carter on Thu Aug 08, 2019 11:05 am

It may be how you are calling it? What line of code is giving you the attribute error?

In general, it would be best to move to the newer driver which is the one we are going to be supporting.
https://github.com/adafruit/Adafruit_Ci ... n_MotorKit

adafruit_support_carter
 
Posts: 12968
Joined: Tue Nov 29, 2016 2:45 pm

Re: Raspberry Pi 3 stepper motor release

by Skydromer on Thu Aug 08, 2019 2:21 pm

the attribute error is coming from

def release(self):


I know but somehow the new does fit as well as the old does.

Skydromer
 
Posts: 23
Joined: Thu Jul 18, 2019 2:56 am

Re: Raspberry Pi 3 stepper motor release

by adafruit_support_carter on Thu Aug 08, 2019 3:09 pm

I don't see how the function def could lead to the attribute error. In general, you can take and modify the old code as much as you want, but support is limited.

The new library is the one we are currently maintaining. If it doesn't work, you can open issues and we can work them.
https://github.com/adafruit/Adafruit_Ci ... Kit/issues

adafruit_support_carter
 
Posts: 12968
Joined: Tue Nov 29, 2016 2:45 pm

Re: Raspberry Pi 3 stepper motor release

by Skydromer on Fri Aug 09, 2019 1:57 am

adafruit_support_carter wrote:I don't see how the function def could lead to the attribute error. In general, you can take and modify the old code as much as you want, but support is limited.


That is what i dont understand ^^'.
Or did i added the wrong file somehow or need to change every file?

Skydromer
 
Posts: 23
Joined: Thu Jul 18, 2019 2:56 am

Re: Raspberry Pi 3 stepper motor release

by adafruit_support_carter on Fri Aug 09, 2019 12:05 pm

In general, you should grab all the files for the old library.

adafruit_support_carter
 
Posts: 12968
Joined: Tue Nov 29, 2016 2:45 pm

Re: Raspberry Pi 3 stepper motor release

by Skydromer on Wed Aug 14, 2019 1:30 am

I think i i got the problem. I use 2 different kinds of Stepper motor. One got 4 and ther other 6 wire. Just the one with 6 wire is noise with the release. Any idear why this might be. Otherwise i have to investigate more.

Skydromer
 
Posts: 23
Joined: Thu Jul 18, 2019 2:56 am

Please be positive and constructive with your questions and comments.