I'm trying to drive some stepper motors using a Raspberry Pi 3 B V1.2 and an Adafruit Stepper Motor HAT v0.1 and am having trouble setting them to the speed I want. The motors have a step angle of 1.8 degrees, so 200 steps per revolution.
A teammate and I have written a python program using the Adafruit_MotorHAT library in which the speed in RPM is set using
myStepper.setSpeed(60) (for example). However, when we test the rpm both manually with a timer and within the program itself using
time.time() before and after the call to move the motor, the measured RPM is consistently much lower than what we are aiming for.
What is causing this discrepancy? We believe the problem may be with the I2C bus communication between the Pi and the HAT, as this can be measured within the program even when the power source is disconnected from the motors, and changing the baudrate to 400000 (from 100000) improves the accuracy slightly. I've also seen around that other operations occurring on the Pi may be causing clock stretching, but I don't know what those operations could be since this is the only thing we're running.
Do we need to change drivers, or even switch from Raspberry Pi to an Arduino or something? Let me know if any additional information is needed.