I finally tried Raspberry Pi Pico, and I was shocked. Writing hardware logic in Python is the simplest prototyping method, period. Now, details. To test the MicroPython I came up with a project I saw implemented on Arduino – a stepper motor controlled with a thumb stick.
I did a shallow googling and implemented everything using the code (plus a 3rd-party module stepper
):
from machine import Pin, ADC
import stepper
import utime
xAxis = ADC(Pin(27))
yAxis = ADC(Pin(26))
button = Pin(16,Pin.IN, Pin.PULL_UP)
# Define the stepper motor pins
IN1 = 21
IN2 = 20
IN3 = 19
IN4 = 18
# Initialize the stepper motor
stepper_motor = stepper.HalfStepMotor.frompins(IN1, IN2, IN3, IN4)
# Set the current position as position 0
stepper_motor.reset()
while True:
xValue = xAxis.read_u16()
buttonValue = button.value()
if xValue <= 600:
print("Moving left")
stepper_motor.step(-100)
elif xValue >= 60000:
print("Moving right")
stepper_motor.step(100)
It is insane! Without thinking much, I’ve 3d-printed 3 parts and added the stepper to my rEmotion project.
I am impressed. The MCU now is part of my daily tools!