DC Motor & Stepper Motor HAT: stepper not running smoothly

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
EvilGarfield
 
Posts: 8
Joined: Mon Dec 19, 2016 9:35 am

DC Motor & Stepper Motor HAT: stepper not running smoothly

Post by EvilGarfield »

Hello,

I recently bought a DC Motor & Stepper Motor HAT from you and installed (following https://learn.adafruit.com/adafruit-dc- ... l#overview) everything to work with the same model of nema17 stepper motor you have on the website.

After installing the software and finding the right pairs of wires, I tried the stepperTest.py file. The motor turns in one directection and then the other as expected but the rotation is very slow and jerky as if the motor was going forward 2 steps and 1 back constantly. When the program uses Single steps the motor going back is almost visible. The movement when using Microsteps is seem smoother but I can still feel the motor blocking from time to time. I also tried sapping the cable pairs around to no avail.

I changed the number of steps in each direction, tried with the function oneStep(direction, step-style) in a loop and tried with an other motor but the result is always the same. Moreover, increasing the RMP with setSpeed has no visible effect. Whatever the value, the motor turns at a speed of a few rotations per minute in singlestep mode.

Does anyone have any experience with this issue? Do you think it is a code issue? Or is the HAT simply too limited to use a stepper motor efficiently?

Sorry if this has been asked before. I searched the web but could not find a solution to my problem.

EDIT: If i set the speed to 255 and do a simple while loop with the one step function:

Code: Select all

while(True)
    myStepper.oneStep(Adafruit_MotorHAT.FORWARD, Adafruit_MotorHAT.SINGLE)
The motor moves randomly back and forth with no apparent logic as when and why it reverses direction

User avatar
adafruit_support_bill
 
Posts: 88087
Joined: Sat Feb 07, 2009 10:11 am

Re: DC Motor & Stepper Motor HAT: stepper not running smooth

Post by adafruit_support_bill »

The SINGLE step mode is the weakest and roughest of the stepping modes and more prone to skipping steps.

What are you using to power the motor?

User avatar
EvilGarfield
 
Posts: 8
Joined: Mon Dec 19, 2016 9:35 am

Re: DC Motor & Stepper Motor HAT: stepper not running smooth

Post by EvilGarfield »

Hi Bill,

Thank you for your reply. I am using a 12V 2,24A power supply.
I know that single is not the most precise. I can use microstep and then it runs a bit smoother (still not perfect) but the fastest rotation I get is 1-2 RPMs.
I noticed that when I start the script the motor changes direction several times during 4-5s and then chooses one direction and keeps it but it is still vibrating a lot and not turning very smooth. Could this be linked to the baudrate settings of my pi?

User avatar
adafruit_support_bill
 
Posts: 88087
Joined: Sat Feb 07, 2009 10:11 am

Re: DC Motor & Stepper Motor HAT: stepper not running smooth

Post by adafruit_support_bill »

Do you have a link to the specifications for the motor you are using? The NEMA 17 designation only specifies the location of the bolt-holes on the faceplate. There can be major differences in electrical characteristics between different NEMA 17 motors.

Also, please post the code you are using.

User avatar
EvilGarfield
 
Posts: 8
Joined: Mon Dec 19, 2016 9:35 am

Re: DC Motor & Stepper Motor HAT: stepper not running smooth

Post by EvilGarfield »

The motor I am using is this one
I read on the forums that the HAT was designed for motors with a high phase resistance. And the specs on this one is the same as the one you have here

The first code I used was

Code: Select all

#!/usr/bin/python
#import Adafruit_MotorHAT, Adafruit_DCMotor, Adafruit_Stepper
from Adafruit_MotorHAT import Adafruit_MotorHAT, Adafruit_DCMotor, Adafruit_StepperMotor

import time
import atexit

# create a default object, no changes to I2C address or frequency
mh = Adafruit_MotorHAT()

# recommended for auto-disabling motors on shutdown!
def turnOffMotors():
    mh.getMotor(1).run(Adafruit_MotorHAT.RELEASE)
    mh.getMotor(2).run(Adafruit_MotorHAT.RELEASE)
    mh.getMotor(3).run(Adafruit_MotorHAT.RELEASE)
    mh.getMotor(4).run(Adafruit_MotorHAT.RELEASE)

atexit.register(turnOffMotors)

myStepper = mh.getStepper(200, 1)      # 200 steps/rev, motor port #1
myStepper.setSpeed(255)          # 30 RPM

while (True):
    print("Single coil steps")
    myStepper.step(100, Adafruit_MotorHAT.BACKWARD,  Adafruit_MotorHAT.SINGLE)
    myStepper.step(100, Adafruit_MotorHAT.BACKWARD, Adafruit_MotorHAT.SINGLE)

    print("Double coil steps")
    myStepper.step(100, Adafruit_MotorHAT.FORWARD,  Adafruit_MotorHAT.DOUBLE)
    myStepper.step(100, Adafruit_MotorHAT.BACKWARD, Adafruit_MotorHAT.DOUBLE)

    print("Interleaved coil steps")
    myStepper.step(100, Adafruit_MotorHAT.FORWARD,  Adafruit_MotorHAT.INTERLEAVE)
    myStepper.step(100, Adafruit_MotorHAT.BACKWARD, Adafruit_MotorHAT.INTERLEAVE)

    print("Microsteps")
    myStepper.step(100, Adafruit_MotorHAT.FORWARD,  Adafruit_MotorHAT.MICROSTEP)
    myStepper.step(100, Adafruit_MotorHAT.BACKWARD, Adafruit_MotorHAT.MICROSTEP)
And then I changed it to

Code: Select all

#!/usr/bin/python
#import Adafruit_MotorHAT, Adafruit_DCMotor, Adafruit_Stepper
from Adafruit_MotorHAT import Adafruit_MotorHAT, Adafruit_DCMotor, Adafruit_StepperMotor

import time
import atexit

# create a default object, no changes to I2C address or frequency
mh = Adafruit_MotorHAT()

# recommended for auto-disabling motors on shutdown!
def turnOffMotors():
    mh.getMotor(1).run(Adafruit_MotorHAT.RELEASE)
    mh.getMotor(2).run(Adafruit_MotorHAT.RELEASE)
    mh.getMotor(3).run(Adafruit_MotorHAT.RELEASE)
    mh.getMotor(4).run(Adafruit_MotorHAT.RELEASE)

atexit.register(turnOffMotors)

myStepper = mh.getStepper(200, 1)      # 200 steps/rev, motor port #1
myStepper.setSpeed(255)          # 30 RPM

while (True):
    myStepper.oneStep(Adafruit_MotorHAT.BACKWARD, Adafruit_MotorHAT.DOUBLE)
As as sidenote, what effective speed can I expect from such a motor/HAT combination?

User avatar
adafruit_support_bill
 
Posts: 88087
Joined: Sat Feb 07, 2009 10:11 am

Re: DC Motor & Stepper Motor HAT: stepper not running smooth

Post by adafruit_support_bill »

Code: Select all

myStepper.setSpeed(255)          # 30 RPM
This may be your problem. The maximum speed achievable on a Pi depends somewhat on what else is running on it. But the theoretical maximum using the default i2c bus speed is about 50 RPM. It is possible to increase the speed of the i2c bus.

http://raspberrypi.stackexchange.com/qu ... an-i2c-bus

User avatar
EvilGarfield
 
Posts: 8
Joined: Mon Dec 19, 2016 9:35 am

Re: DC Motor & Stepper Motor HAT: stepper not running smooth

Post by EvilGarfield »

Thank you again for your help!
The thing is, even when decreasing this value to below 30, the motion is the same. This option doesn't seem to have any effect. If the value is 1, 30 or 255, my motor behaves the same.

I modified my config.txt to a higher baudrate as explained in your link but when I check it using

Code: Select all

  sudo cat /sys/module/i2c_bcm2708/parameters/baudrate 
I get 0. I'm kind of confused. Sorry for all those questions, I'm new to this.

User avatar
adafruit_support_bill
 
Posts: 88087
Joined: Sat Feb 07, 2009 10:11 am

Re: DC Motor & Stepper Motor HAT: stepper not running smooth

Post by adafruit_support_bill »

If you post some photos showing your soldering and connections to the HAT we can take a look for any problems there.

Pi internals are not my forte, but there may be differences for the version of Linux you are running. If you search "raspberry pi change i2c baud rate" you can probably find the right command for the version you are running.

User avatar
EvilGarfield
 
Posts: 8
Joined: Mon Dec 19, 2016 9:35 am

Re: DC Motor & Stepper Motor HAT: stepper not running smooth

Post by EvilGarfield »

Good morning!

Here are the pictures of my soldering. I tested the connections and all of them have a < 30 ohm resistance. Also, I tried my motor with both ports and the result is the same.

I will check this baudrate thing and see if it fixes the problem.
Attachments
Motor wires connection
Motor wires connection
_DSC0110.jpg (530.49 KiB) Viewed 2331 times
Bottom soldegrin
Bottom soldegrin
_DSC0107.jpg (427.76 KiB) Viewed 2331 times
top soldering
top soldering
_DSC0108.jpg (370.27 KiB) Viewed 2331 times

User avatar
EvilGarfield
 
Posts: 8
Joined: Mon Dec 19, 2016 9:35 am

Re: DC Motor & Stepper Motor HAT: stepper not running smooth

Post by EvilGarfield »

Ok I got it to work by increasing the baudrate of my I2C ports to 400 KHz. Thanks a lot Bill ;)

The only thing now is that the motor start spinning at a certain speed for like 2-3s and then slows down for the rest of the command. Any idea where this could come from?

User avatar
adafruit_support_bill
 
Posts: 88087
Joined: Sat Feb 07, 2009 10:11 am

Re: DC Motor & Stepper Motor HAT: stepper not running smooth

Post by adafruit_support_bill »

You are running on Linux, so timing is not guaranteed. Your motor control process is going to be sharing the processor with whatever else is running on the Pi. If possible, shut down some of the other processes and services and see how that affects your motor.

User avatar
MVkit
 
Posts: 1
Joined: Fri Jan 27, 2017 10:41 am

Re: DC Motor & Stepper Motor HAT: stepper not running smooth

Post by MVkit »

Hello i've got the same problem as mentioned at the top. I tried the board with the Raspberry Pi 3 with 4.4.44 Kernel Version. The solution above doesn't work for me. It seems that I can not set the I2C baudrate correctly. Could you please tell me how you did this?

I added the following lines in /boot/config.txt

Code: Select all

dtparam=i2c_arm_baudrate=400000
But

Code: Select all

sudo cat /sys/module/i2c_bcm2708/parameters/baudrate
tells 0.
My osciloscope says it's at 5kHz for SCL.

I also tried two different Motor Hats with two different Raspberry Pi 3 and an Arduino Uno and different Motors (DC and stepper, NEMA 11 and 17).
Here's the motor datasheet https://www.pololu.com/file/download/SY ... e_id=0J686

User avatar
shmulyeng
 
Posts: 2
Joined: Mon Oct 23, 2017 4:40 pm

Re: DC Motor & Stepper Motor HAT: stepper not running smooth

Post by shmulyeng »

Have either of you solved this problem? I'm experiencing the same issue.

User avatar
chenp
 
Posts: 1
Joined: Mon Jan 29, 2018 4:14 pm

Re: DC Motor & Stepper Motor HAT: stepper not running smooth

Post by chenp »

I realise its a while ago this was posted, but have been experiencing similar issues - the motor was drawing c. 2.5A with no load on and using the "standard" 30rpm setting in the example code. This was on a nominal 12V 5A psu so "should" have the power. I swapped today for a lower power motor which is drawing only about 0.5A and it seems to run smoothly. I'm not sure if the issue is the PSU or the motor - but worth considering if you are getting unexpected results.

User avatar
shmulyeng
 
Posts: 2
Joined: Mon Oct 23, 2017 4:40 pm

Re: DC Motor & Stepper Motor HAT: stepper not running smooth

Post by shmulyeng »

Unfortunately that's not an option for me. I need the power of the higher voltage motor.

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”