Gigiux
Posts: 28
Joined: Wed Apr 10, 2019 7:28 pm

Problem running ULN2003 on Pi3

Sun Aug 11, 2019 8:36 am

Hello,
I have the Amzdeal Stepper Motor 1.5A 42NCM and a ULN2003 controller. I connected PIN 2 (5V) to + and PIN 6 (GRN) to - of ULN2003. I plugged the cable between the ULN2003 and the motor as in this pic:
20190811_100557.jpg
PICT
20190811_100557.jpg (127.98 KiB) Viewed 526 times
I ran the file:

Code: Select all

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)

in_1_pin = 17
in_2_pin = 18
in_3_pin = 27
in_4_pin = 22

GPIO.setup(in_1_pin, GPIO.OUT)
GPIO.setup(in_2_pin, GPIO.OUT)
GPIO.setup(in_3_pin, GPIO.OUT)
GPIO.setup(in_4_pin, GPIO.OUT)

period = 0.02
steps = 100

def step_fwd(steps, period):
	for i in range(0, steps):
		set_coils(1,0,0,1)
		time.sleep(period)
		set_coils(1,0,1,0)
		time.sleep(period)
		set_coils(0,1,1,0)
		time.sleep(period)
		set_coils(0,1,0,1)
		time.sleep(period)

def step_rev(steps, period):
	for i in range(0, steps):
		set_coils(0,1,0,1)
		time.sleep(period)
		set_coils(0,1,1,0)
		time.sleep(period)
		set_coils(1,0,1,0)
		time.sleep(period)
		set_coils(1,0,0,1)
		time.sleep(period)

def set_coils(in1, in2, in3, in4):
	GPIO.output(in_1_pin, in1)
	GPIO.output(in_2_pin, in2)
	GPIO.output(in_3_pin, in3)
	GPIO.output(in_4_pin, in4)

print("running forward 100 steps")
step_fwd(steps, period)
print("running reverse 100 steps")
step_rev(steps, period)
GPIO.cleanup()
The lights of the ULN2003 lit up, so they must receive the commands but nothing happens.

So my questions:
- are the cable between ULN2003 and the motor correctly placed? (while the white end of the cable fits properly on the motor, the black end that i suppose goes into the controller, is loose and have 4 pins whereas the slot has 5)
- why the motor was dead? is there not enough voltage?

pcmanbob
Posts: 6652
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Problem running ULN2003 on Pi3

Sun Aug 11, 2019 9:48 am

A ULN2003 can only be used to drive 5 wire unipolar stepper motor, your stepper motor is a 4 wire bipolar stepper motor so it will not work.

also the ULN2003 is only rated for 500mA and your motor needs 1.5A so if it had tried to drive you motor it would have burnt out due to the overload.

you need to look for a stepper motor drive for you particular motor if you look up the manufacture they often supply driver boards as well as the motors.

You can also drive 4 wire stepper motors using an L298N if your motor runs at 12V

And lastly even if your motor is 5v rated you will not be able to power it from the 5v pin on the pi it will required its own power supply.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Gigiux
Posts: 28
Joined: Wed Apr 10, 2019 7:28 pm

Re: Problem running ULN2003 on Pi3

Sun Aug 11, 2019 3:20 pm

Thank you, it makes sense. I also tried the 28BYJ-48 motor that was shipped with the ULN2003; in this case, the motor makes some CLICKING but does not move. Would the controller 42NCM be a better choice? How do I power the motor with some batteries if the connection is via the 5 PIN plug?
Is there a good tutorial on how to run the stepper motors (particularly the 42NCM)? On google there are only few scripts that talks about the PINs but not all these other things such as powering (they say simply to use the PI 5V PIN).

pcmanbob
Posts: 6652
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Problem running ULN2003 on Pi3

Sun Aug 11, 2019 3:30 pm

If you look at the ULN2003 board there should be a jumper on there that will allow you to provide power to the motor via another supply.

I have no idea about the other driver board as you have not provided a link to it .

If your smaller 5 wire stepper motor is not turning that you may have the wrong step sequence or timing in your code , I will post some code when I get a chance that may help.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

pcmanbob
Posts: 6652
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Problem running ULN2003 on Pi3

Mon Aug 12, 2019 12:41 am

Here's a typical ULN2003 board showing you were to connect your power for the motor to.

Image
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

pcmanbob
Posts: 6652
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Problem running ULN2003 on Pi3

Mon Aug 12, 2019 2:13 pm

Try this code with your 5 wire 28BYJ-48 motor, I think it has the correct sequence for driving your motor.

Code: Select all

import RPi.GPIO as GPIO
import time
# uln2803A and 6 wire stepper motor
# Variables

delay = 0.005
steps = 100

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

# Enable pins for IN1-4 to control step sequence

coil_A_1_pin = 17
coil_A_2_pin = 18
coil_B_1_pin = 27
coil_B_2_pin = 22

# Set pin states


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)

# output pin order list


pinList = [
    [1,0,0,0],
    [1,1,0,0],
    [0,1,0,0],
    [0,1,1,0],
    [0,0,1,0],
    [0,0,1,1],
    [0,0,0,1],
    [1,0,0,1]
]
c = 0 # count for pinlist

# Function for step sequence

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)

# loop through step sequence based on number of steps
time.sleep (2)
print "go forward"
for i in range(0, steps):

    c = c + 1
    if c == 8:
        c = 0
    print i, c, pinList [c]
    setStep(*pinList [c])
    time.sleep(delay)

print "stop"

time.sleep (3)
# Reverse previous step sequence to reverse motor direction
print "go reverse"

# loop through step sequence based on number of steps

for i in range(0, steps):

    c = c -1
    if c == -1:
        c = 7
    print i, c, pinList [c]
    setStep(*pinList [c])
    time.sleep(delay)
        
print "stop"        
print "motor free"
setStep(0,0,0,0)      
        
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Gigiux
Posts: 28
Joined: Wed Apr 10, 2019 7:28 pm

Re: Problem running ULN2003 on Pi3

Tue Aug 13, 2019 4:46 pm

I tried but nothing happened. Actually, before all the four leds of the controller were flashing, now only the first. This is the configuration of the board:
20190812_210112.jpg
20190812_210112.jpg (157.76 KiB) Viewed 418 times
I am using the 28BYJ-48 to be sure it should work. Looks to me that the 5V pin is connected to the + pin of the controller (orange cable) and the ground to the - pin (yellow pin)...

pcmanbob
Posts: 6652
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Problem running ULN2003 on Pi3

Tue Aug 13, 2019 6:05 pm

What happens if you run your original code do all 4 LED's work then , I don't see why my code should not work its using the same gpio pins as yours.

In your picture I can't see were the leads are connected on the driver board, but you can really get them wrong , the power connection looks ok it should work and drive the LED's without the motor connected.

Edit.

Tested your posted code and my posted code on a pi with 4 LED's connected to the correct gpio and both produce an output on all 4 LED's.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Gigiux
Posts: 28
Joined: Wed Apr 10, 2019 7:28 pm

Re: Problem running ULN2003 on Pi3

Wed Aug 14, 2019 9:05 pm

Hi, it turned out I must have damaged the controller when running the 42NCM motor: by using a spare ULN2003 controller, the small motor worked. I can't use the ULN2003 on the 42NCM.

pcmanbob
Posts: 6652
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Problem running ULN2003 on Pi3

Thu Aug 15, 2019 11:01 am

Exactly what I said in one of my earlier posts
pcmanbob wrote:
Sun Aug 11, 2019 9:48 am
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Gigiux
Posts: 28
Joined: Wed Apr 10, 2019 7:28 pm

Re: Problem running ULN2003 on Pi3

Sat Aug 17, 2019 6:44 am

yep!

Return to “Beginners”