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.

  • what is the expected RPM with this? myStepper.setSpeed(60) – jsotola Feb 13 at 6:03
  • Expected speed would be 60 RPM. However, when it's set to 60, the RPM measured based on time per step is somewhere around 16 when the baudrate is 100Kbps, and 30 when the baudrate is 400Kbps. Also, my teammate tested multiple RPM values, and the measured RPM does not vary linearly with what we put in setSpeed()--it looks kind of logarithmic and seems to top out around 20 RPM (with baudrate 100Kbps). – otolithic Feb 14 at 14:23
  • Just as an update: I tried this on an Arduino Genuino with Adafruit MotorShield v2.3 and got a similar result (nonlinearly varying actual RPM compared to set RPM). I'm going to try a DRV-8825 driver instead. – otolithic Feb 15 at 16:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.