1

I'm working on a project and unfortunately my DC motor is not working. I wired it like this, am using a brand-new motor (SP BN2A in this document, I scavenged it from a bidet I had at home), powering the whole system with a DC power supply so I can control the voltage exactly, using Raspberry Pi as the controller and using the following code:

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)

enable_pin = 5
coil_A_1_pin = 26
coil_A_2_pin = 19
coil_B_1_pin = 6
coil_B_2_pin = 13

GPIO.setup(enable_pin, GPIO.OUT)
GPIO.setup(coil_A_1_pin, GPIO.OUT)
GPIO.setup(coil_A_2_pin, GPIO.OUT)
GPIO.setup(coil_B_1_pin, GPIO.OUT)
GPIO.setup(coil_B_2_pin, GPIO.OUT)

GPIO.output(enable_pin, 1)

def forward(delay, steps):  
  for i in range(0, steps):
    setStep(1, 0, 1, 0)
    time.sleep(delay)
    setStep(0, 1, 1, 0)
    time.sleep(delay)
    setStep(0, 1, 0, 1)
    time.sleep(delay)
    setStep(1, 0, 0, 1)
    time.sleep(delay)

def backwards(delay, steps):  
  for i in range(0, steps):
    setStep(1, 0, 0, 1)
    time.sleep(delay)
    setStep(0, 1, 0, 1)
    time.sleep(delay)
    setStep(0, 1, 1, 0)
    time.sleep(delay)
    setStep(1, 0, 1, 0)
    time.sleep(delay)


def setStep(w1, w2, w3, w4):
  GPIO.output(coil_A_1_pin, w1)
  GPIO.output(coil_A_2_pin, w2)
  GPIO.output(coil_B_1_pin, w3)
  GPIO.output(coil_B_2_pin, w4)

while True:
  delay = raw_input("Delay between steps (milliseconds)?")
  steps = raw_input("How many steps forward? ")
  forward(int(delay) / 1000.0, int(steps))
  steps = raw_input("How many steps backwards? ")
  backwards(int(delay) / 1000.0, int(steps))

The motor vibrates and heats up when I power the system and run the code, but doesn't spin. What part of my system is wrong? Is it the hardware of the motor, the wiring, the code, the power supply, or something else?

Thanks, all help is appreciated.

NeonCop
  • 43
  • 1
  • 8
  • Breadboard graphics.... really... not going there – Trevor_G Jul 14 '17 at 17:26
  • how would you prefer I format it? It's no big deal I can redo it in 5 minutes... I'm new to this EE thing so I'm not sure about standards and stuff like that – NeonCop Jul 14 '17 at 17:29
  • @NeonCop Adding a circuit diagram to your question would be best - you have shown us a wiring diagram, which is not the same thing. – Andrew Morton Jul 14 '17 at 17:37
  • @AndrewMorton Is there any software that you would recommend? Also how would I put a Raspberry Pi or motion sensor into the circuit diagram it's not as easy as a motor or a battery. – NeonCop Jul 14 '17 at 17:56
  • There is a button in the question editor which will let you create a circuit diagram. For a RPi, you only need to indicate the connections to/from it. Or you can use a pencil and paper and add a photo to your question, but that is not the preferred method. – Andrew Morton Jul 14 '17 at 18:04
  • It might be this: https://electronics.stackexchange.com/questions/108686/what-h-bridge-drivers-are-preferred-for-applications-controlling-a-low-voltage-m and please note that running from a puny 9 volt battery (as shown in your cartoon) will not work either. – Andy aka Jul 14 '17 at 18:14
  • I'm not a Raspberry guy, but I notoce your forward and backwards functions have int for arguments. Does this mean your delay gets truncated to zero? – John Birckhead Jul 14 '17 at 18:20
  • @Andyaka That's a smart idea, but I actually think that the L293D is designed to handle specificlaly the voltage of my motor (12V), so I don't think it's a problem with the voltage being too low. Also, my battery is actually 12V I'm using a DC power supply. – NeonCop Jul 14 '17 at 18:55
  • @JohnBirckhead you're right, the input it asks for is in ms, and since i usually go with between 1-5 it might be setting it to 0. Wouldn't that just make the motor spin continuously though? – NeonCop Jul 14 '17 at 18:56
  • For a stepper motor, remember that the rotor mass has inertia. You must accelerate the mass by applying torque sufficient to overcome the inertia and get the motor moving and then there must be enough time to get it to the next position. If you step too quickly, you will move only slightly, falling back, to the original position, which would give you the described symptom. In your code, if you enter a value larger than 1000, you will have a step time of one second, and the motor will move (albeit slowly) if this is your problem. – John Birckhead Jul 16 '17 at 15:55

1 Answers1

1

Finally figured it out! I substituted the unipolar motor for a bipolar one, and the whole system worked perfectly as is! To use the unipolar motor, it is necessary to use a motor-driving IC specifically for the unipolar motor, and the L293D does not accomplish the task.

NeonCop
  • 43
  • 1
  • 8