RE: Motor Bridge Cape and BBGW

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
silver2row
 
Posts: 180
Joined: Sat Jan 30, 2016 3:42 pm

RE: Motor Bridge Cape and BBGW

Post by silver2row »

Hello,

I have the Motor Bridge Cape controlling two stepper motors and some screw slides. It is neat but I want to learn more on programing in the BBGW and Python3 environment while using my board.

...

Would the Adafruit_BBIO library help me at all during the programming of this Cape while using two stepper motors.

Anyway, here is some fun source to review. If you have any pointers, please add some context:

Code: Select all

def StepperMotorATest():
    motor.StepperMotorAInit()
    if a == 22 or a == 1:
        motor.StepperMotorAMove(-1000, 1000)
        time.sleep(2)
        motor.StepperMotorAMove(1000, 1000)
        time.sleep(2)
    elif a == 45 or a <= 0:
        motor.StepperMotorAMove(-4500, 1000)
        time.sleep(2)
        motor.StepperMotorAMove(4500, 1000)
        time.sleep(2)
    else:
        motor.StepperMotorAMove(500, 1000)
        time.sleep(2)
        motor.StepperMotorAMove(-500, 1000)
        time.sleep(2)
    #motor.StepperMotorAMove(-4500, 1000)
    #time.sleep(4)
    #motor.StepperMotorAMove(4500, 1000)
    #time.sleep(4)
 
def StepperMotorBTest():
    motor.StepperMotorBInit()
    if b == 45 or b == 1:
        motor.StepperMotorBMove(4500, 1000)
        time.sleep(2)
        motor.StepperMotorBMove(-4500, 1000)
        time.sleep(2)
    elif b == 22 or b <= 0:
        motor.StepperMotorBMove(-1000, 1000)
        time.sleep(2)
        motor.StepperMotorBMove(1000, 1000)
        time.sleep(2)
    else:
        pass
    #motor.StepperMotorBMove(4500, 1000)
    #time.sleep(4)
    #motor.StepperMotorBMove(-4500, 1000)
    #time.sleep(4)
 
try:
 
    if __name__=="__main__":
        motor = MotorBridge.MotorBridgeCape()
        while True:
            StepperMotorATest()
            StepperMotorBTest()
 
except KeyboardInterrupt:
    print("Making Headway?")
Does that make any sense to anyone?

Seth

P.S. Please reply with any recommendations you have on how to spiff up the source.

User avatar
drewfustini
 
Posts: 944
Joined: Sat Dec 26, 2015 1:19 pm

Re: RE: Motor Bridge Cape and BBGW

Post by drewfustini »

what happens when you run this current code?

User avatar
silver2row
 
Posts: 180
Joined: Sat Jan 30, 2016 3:42 pm

Re: RE: Motor Bridge Cape and BBGW

Post by silver2row »

Hello,

I changed everything after posting. I think I am making some headway on understanding functions in Python a bit better.

Seth

P.S. I will post the source and let you know what the source does in a bit.

User avatar
silver2row
 
Posts: 180
Joined: Sat Jan 30, 2016 3:42 pm

Re: RE: Motor Bridge Cape and BBGW

Post by silver2row »

Hello,

This is it for now:

Code: Select all

# /*
 # * StepperOne.py
 # * This is a test code  for BBG/BBB motor bridge cape Stepper Motor
 # *
 # * Copyright (c) 2015 seeed technology inc.
 # * Author      : Jiankai Li
 # * Create Time:  Nov 2015
 # * Change Log : Updates and extra ideas performed by Seth Oct. 2020
 # *
 # * The MIT License (MIT)
 # *
 # * Permission is hereby granted, free of charge, to any person obtaining a copy
 # * of this software and associated documentation files (the "Software"), to deal
 # * in the Software without restriction, including without limitation the rights
 # * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 # * copies of the Software, and to permit persons to whom the Software is
 # * furnished to do so, subject to the following conditions:
 # *
 # * The above copyright notice and this permission notice shall be included in
 # * all copies or substantial portions of the Software.
 # *
 # */


import MotorBridge
import time

def StepperMotorATest(after, afterOne, afterTwo):
    motor.StepperMotorAInit()
    after = motor.StepperMotorAMove(3000, 1000)
    time.sleep(2)
    print (f"I used this many steps to get here ".format(after))

    afterOne = motor.StepperMotorAMove(-2000, 1000)
    time.sleep(2)
    print (f"I used this many steps this time to move to this point ".format(afterOne))

    afterTwo = motor.StepperMotorAMove(-1000, 1000)
    time.sleep(3)
    print (f"I am attempting another rendition of movement! ".format(afterTwo))
	
	#def StepperMotorBTest():
    #motor.StepperMotorBInit()

try:

    if __name__=="__main__":
        motor = MotorBridge.MotorBridgeCape()
        while True:
            after = StepperMotorATest(1, 1, 1)
            afterOne = StepperMotorATest(1, 1, 1)
            afterTwo = StepperMotorATest(1, 1, 1)
            #StepperMotorBTest()

except KeyboardInterrupt:
    print("Making Headway?")
Okay...this is the updated source. This makes one stepper motor listen to the commands in the source one by one until I exit the program with Control-C.

...

The block on the slide, which is attached to the screw, moves positive 3000 steps in 1000 microseconds between the steps (I think) and the other movements are in reverse for -2000 steps and then another -1000 steps to complete the source. This repeats until it is completed by my Control-C command.

Seth

P.S. Does this sound correct?

Locked
Please be positive and constructive with your questions and comments.

Return to “Beagle Bone & Adafruit Beagle Bone products”