0

I am trying to drive a stepper motor with circuitpython 7.3.3 on a esp32 s2 with a A4988 stepper motor driver board. I have been fiddling for a while now. Since adafruit does not carry the A4988 boards there is no example code to start from on there pages, so I ended up trying to modify a piece of micropython code from TechToTinker.

https://techtotinker.blogspot.com/2021/05/036-micropython-technotes-stepper-motor.html%5B/url%5D

Unfortunately I can't seem to make the most basics of code to work and get the stepper to move.

import time
import board
from digitalio import DigitalInOut, Direction, Pull

dir_1 = DigitalInOut(board.IO1) 
dir_1.direction = Direction.OUTPUT
step_1 = DigitalInOut(board.IO2) 
step_1.direction = Direction.OUTPUT

def rotate(angle=0, rotation='cw'):
    if rotation == 'cw':
        dir_1.value(0)
        for i in range(0, 200, 1):
            step_1.value(1)  # one step
            time.sleep(0.5)
            step_1.value(0)   
            time.sleep(0.5)
    if rotation == 'ccw':
        dir_1.value(1)
        for i in range(200-1, -1, -1):
            step_1.value(1)  
            time.sleep(0.5)
            step_1.value(0)  
            time.sleep(0.5)

With the following lines of codes I should be able to test the stepper using the REPL:

rotate(360, 'cw')
rotate(360, 'ccw')

I checked the above code with mu and corrected all the found (style) error's, still when I run it I get the following error.

Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'rotate' is not defined.

A google search gave me an ansers like:

It looks like a variable named 'python' is used which is not present at the given scope during execution[/quote], Unfortunately I can't do much with that, as far as I understand I am not doing that, so if I am, I have no idea how I am doing that, additionally I thought to have defined 'rotate'.

I tried the following to get some use out of the stepper:

I searched the adafruit site for relevant example code.
I searched the adafruit forum for similar issues but found only topics on arduino boards.
I searched the net for similar pieces of ciruit/micropython code to use with the A4988 board.
I finally tried to write, modify code myself, from relevant code from whichI tried to solve all errors.
I googled the final additional error but did not understand what I found.

0 Answers0