jtloper1
Posts: 10
Joined: Tue Jan 20, 2015 11:37 pm

Stepper motor jerky rotation & hum

Sun Mar 04, 2018 10:58 pm

I'm trying to build an automated cat food dispenser. All I need to do is turn the handle of a gumball machine one revolution to dispense a serving on a schedule.

I'm using a pi B+, L298N motor driver & a 28BYGH301 bipolar stepper. I have been following this tutorial.
viewtopic.php?f=49&t=55580
I have been unable to find documentation on the pinout of the motor. The 4pin connector has pins 1 & 4 designated. pin 1 is black, 2 is green, 3 red, 4 blue. Pin 1 is connected to in1 on the L298N, pin 2 in2, pin3 in3, pin 4 in4. This pinout yields the jerky rotation. When using different pin configurations (the guess & check troubleshooting method) the motor just hums.

After the program finishes execution the motor just hums. I surmise that the coils are still energized after the program completes. Rebooting the pi stops the hum. I need a more elegant solution.

So, I would like to a get a complete non jerky rotation & B, stop that hum.
Picture of setup: http://jeffloper.me/20180304_140631/

Video of symptoms: http://jeffloper.me/20180304_140938/

Suggestions?

User avatar
joan
Posts: 14960
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Stepper motor jerky rotation & hum

Sun Mar 04, 2018 11:28 pm

The following script will try each of the 16 possibilities.

Edit the gpios = [7, 8, 9, 10] line to reflect the (Broadcom numbering scheme) GPIO you are using.

See if one gives a smooth rotation.

Code: Select all

#!/usr/bin/env python

# permute_stepper.py
# 2014-10-06
# Public Domain

import time
import itertools

import pigpio # http://abyz.co.uk/rpi/pigpio/python.html

class stepper:
   """
   A class to pulse a stepper.
   """

   def __init__(self, pi, g1, g2, g3, g4):
      """
      """
      self.pi = pi
      self.g1 = g1
      self.g2 = g2
      self.g3 = g3
      self.g4 = g4

      self.all = (1<<g1 | 1<<g2 | 1<<g3 | 1<<g4)

      self.pos = 0

      pi.set_mode(g1, pigpio.OUTPUT)
      pi.set_mode(g2, pigpio.OUTPUT)
      pi.set_mode(g3, pigpio.OUTPUT)
      pi.set_mode(g4, pigpio.OUTPUT)

   def move(self):
      pos = self.pos 
      if pos < 0:
         pos = 7
      elif pos > 7:
         pos = 0
      self.pos = pos

      if   pos == 0: on = (1<<self.g4)
      elif pos == 1: on = (1<<self.g3 | 1<<self.g4)
      elif pos == 2: on = (1<<self.g3)
      elif pos == 3: on = (1<<self.g2 | 1<<self.g3)
      elif pos == 4: on = (1<<self.g2)
      elif pos == 5: on = (1<<self.g1 | 1<<self.g2)
      elif pos == 6: on = (1<<self.g1)
      else:          on = (1<<self.g1 | 1<<self.g4)

      off = on ^ self.all

      self.pi.clear_bank_1(off)
      self.pi.set_bank_1(on)

   def forward(self):
      self.pos += 1
      self.move()

   def backward(self):
      self.pos -= 1
      self.move()

   def stop(self):
      self.pi.clear_bank_1(self.all)

# Permutes the gpio assignments to find ones which successfully
# drive a stepper.  The stepper should move clockwise then
# anti-clockwise for DELAY seconds.

DELAY=3

gpios = [7, 8, 9, 10] # Set the gpios being used here.

pi=pigpio.pi()

if not pi.connected:
   exit(0)

try:
   for x in itertools.permutations(gpios):

      s = stepper(pi, x[0], x[1], x[2], x[3])

      print("Trying {}".format(x))

      stop = time.time() + DELAY
      while time.time() < stop:
         s.forward()
         time.sleep(0.0001)

      stop = time.time() + DELAY
      while time.time() < stop:
         s.backward()
         time.sleep(0.0001)

except KeyboardInterrupt:
   pass

s.stop()

pi.stop()

jtloper1
Posts: 10
Joined: Tue Jan 20, 2015 11:37 pm

Re: Stepper motor jerky rotation & hum

Sun Mar 04, 2018 11:49 pm

Thanks!

Return to “Beginners”