Skip to content

SimpleStepper Board with Dual H-Bridge chip

Yuichi TAMIYA Fablab Kannai, Yokohama, JAPAN

alt text

History

Moduler Things BootCamp
Waag2023
BootCamp
Leon2024
BootCamp
Norway2026
alt text alt text alt text alt text

Board

alt text alt text
alt text alt text alt text
Milling(Outline&Holes)
alt text
Engrave(Traces)
Xtool F2 Ultra
alt text

BOM

Item Qty
Xiao RP2040 1
DRV8421A Dual H-Bridge Stepper Driver 1
100uF 1
0.1uF 1
Pinheaders 2+

Firmware

simple_stepper.ino.uf2 from Quentin's WS in FAB25

Code

Python

Downlad from here

.
└── code
    └── python
        ├── __pycache__
           ├── cobs_usb_serial.cpython-312.pyc
           ├── cobs_usb_serial.cpython-313.pyc
           ├── motor.cpython-312.pyc
           └── motor.cpython-313.pyc
        ├── cobs_usb_serial.py
        ├── main_test_gantry.py
        ├── main_test.py
        ├── motor.py
        └── two_axis.py

Serial port

% ls /dev/tty.*
/dev/tty.usbmodem101

main_test.py

import motor
import time
import random


def goto(m: motor.Motor, x, vel, accel):
    # print(m.get_states())
    m.set_target_position(x, vel, accel)

    # print(m.get_states())
    # ... wait while not at point:
    while True:
        states = m.get_states()

        # print(states["position"])
        # if states['is_moving'] == 0:
        if not states["is_moving"]:
            break
        # if abs(states["position"] - x) <= 0.01:
        #     break


def goto_all(m1: motor.Motor, m2: motor.Motor, x1, x2, vel, accel):
    m1.set_target_position(x1, vel, accel)
    m2.set_target_position(x2, vel, accel)

    # ... wait while not at point:
    done = False
    while not done:
        states1 = m1.get_states()
        states2 = m2.get_states()
        done = states1['is_moving'] == 0 and states2['is_moving'] == 0


def main():
    # change to the correct serial port
    # m = motor.Motor("COM47")
    # Use /dev/cu.* instead of /dev/tty.* for USB serial devices on macOS.
    # /dev/cu.* is non-blocking and safer for direct communication with Arduino.
    m = motor.Motor("COM47") # ============================== here

    # turns/sec
    vel = 5
    # turns/sec²
    acc = 30

    # 200 steps per turn
    steps_per_unit = 200
    # 30% current
    current = 0.3

    m.set_steps_per_unit(steps_per_unit)
    m.set_current(current)

    goto(m, 2.0, vel, acc)
    time.sleep(0.2)
    goto(m, 0.0, vel, acc)

    m.set_current(0)


if __name__ == "__main__":
    main()

Result

% python3 main_test.py

video

Note

The code is designed for Python >= 3.10
Dependencies:

pyserial >= 3.4
cobs >= 1.1