I'm newbie in electronics. I'm joining RPi's world through a starter learning kit but there's a wiring incongruity in DC Motor lesson:

In the 1st image there's only RPi's 3.3V power. In the 2nd image there's a breadboard power supply module. The lesson says that L9110 needs a +5V power supply.

enter image description here enter image description here

When I run the code below, the LED lights and the buttons work, but the motor doesn't work

#!/usr/bin/env python
import RPi.GPIO as GPIO
import time

STATUS_LED         = 10

BTN_RUN_STOP       = 11

MotorPin_A         = 16
MotorPin_B         = 18

g_sta =  1
g_dir =  1
speed = 50

pwm_B = 0

def motorStop():
    GPIO.output(MotorPin_A, GPIO.HIGH)
    GPIO.output(MotorPin_B, GPIO.LOW)

def setup():
    GPIO.setup(STATUS_LED, GPIO.OUT)   # pin mode --- output
    GPIO.setup(BTN_RUN_STOP, GPIO.IN, pull_up_down=GPIO.PUD_UP)  # set pin mode as input, and pull it to high level.
    GPIO.setup(BTN_DIRECTION, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.setup(MotorPin_A, GPIO.OUT)
    GPIO.setup(MotorPin_B, GPIO.OUT)
    global pwm_B
    pwm_B = GPIO.PWM(MotorPin_B, 2000) # create pwm and set frequece to 2KHz

def motor(status, direction, speed):
    global pwm_B
    if status == 1:  # run
        GPIO.output(STATUS_LED, GPIO.LOW) # led on
        if direction == 1:
            GPIO.output(MotorPin_A, GPIO.HIGH)
            GPIO.output(MotorPin_A, GPIO.LOW)
    else:  # stop
        GPIO.output(STATUS_LED, GPIO.HIGH) # led off

def btnScan():
    global g_sta
    global g_dir
    global speed
    if GPIO.input(BTN_RUN_STOP) == GPIO.LOW:
        if GPIO.input(BTN_RUN_STOP) == GPIO.LOW:
            g_sta = not g_sta
            print 'g_sta = %d', g_sta
        while not GPIO.input(BTN_RUN_STOP):
        if GPIO.input(BTN_DIRECTION) == GPIO.LOW:
            g_dir = not g_dir
            print 'g_dir = %d', g_dir
        while not GPIO.input(BTN_DIRECTION):
        if GPIO.input(BTN_SPEED_INCREASE) == GPIO.LOW:
            speed += 1
            if speed > 100:
                speed = 100
            print 'speed = %d', speed
        while not GPIO.input(BTN_SPEED_INCREASE):
        if GPIO.input(BTN_SPEED_DECREASE) == GPIO.LOW:
            speed -= 1
            if speed < 0:
                speed = 0
            print 'speed = %d', speed
        while not GPIO.input(BTN_SPEED_DECREASE):

def loop():
    while True:
#       print 'test....2...'
#       print 'test....3...'
        global g_sta
        global g_dir 
        global speed
        motor(g_sta, g_dir, speed)

def destroy():
    GPIO.cleanup()             # Release resource

if __name__ == '__main__':     # Program start from here
    except KeyboardInterrupt:

enter image description here

I don't have another power supply for the breadboard power supply module, it accepts a DC 6.5V-12V input voltage and outputs 700mA (Max) current.

Can I feed it with the laptop's USB? If I feed it with a 12V power supply, which maximum current must output? Can I use RPi's 2nd pin?

What can I do?

  • 1
    I don't know how you expect it to work; the only connection to the Pi power is the LED. NOTE it is unadvisable to attempt to power a motor from the Pi unless it uses little current - also connecting ANY inductive load to an electronic circuit without a flyback diode is dangerous. Your questions are unclear. The diagrams and text are inconsistent. – Milliways Feb 3 '18 at 3:10
  • 1
    Yeah, its unclear how the L9110 is being powered. The fritzig diagram shows it as not being wired to 5V at all and the two pictures are such a mess I have no idea where the wires are going. As Milliways said, typically you would have a fly back diode in the circuit to save your RPi from the inductive load but you don't need that here as the L9110 already has those built in. I'd be checking your wiring with a volt meter to confirm you have power and gnd where you think you should. – Chef Flambe Feb 3 '18 at 4:17

You do not want to power the motor directly from the Raspberry Pi. I'm surprised that your attempt at it hasn't destroyed the Pi already.

The L9110 chip datasheet states that the L9110 Vcc (input power) can be from 2.5V to 12V. The +5 volt specified input is probably because the motor can't take a high voltage.

You should not use USB to directly drive a motor.

One way to power this is to get a 6v battery pack (4 AA batteries - non-rechargeable - would do) and connect it like the breadboard power supply is connected.

Another way would be to use the breadboard power supply and power that with a 9V battery pack (6 AA batteries).

Happy Making!

  • As you suggest to use batteries, I'd like to power both RPi and motor with a rechargeable and scalable battery, because I'd like to start a modular project, adding motors and other components, but I don't know how to size the battery. Can you direct me to how do you do this? – Miky Feb 3 '18 at 5:11
  • I suggested non-rechargeable batteries because they are nominally 1.5v per cell. This makes it easier to calculate the voltages. NiMH rechargeable batteries have a nominal charge of 1.2v per cell. So to power the breadboard supply, I would suggest using again a 6 cell pack, with a nominal voltage of 8.2v. It would be cheaper to just get a power supply that plugs into the wall. I doubt that you'd need more than a 1-amp supply, but a more powerful supply would be better and more useful in the future. I use a 12v/5amp supply from Adafruit.com. – NomadMaker Feb 3 '18 at 16:52
  • and what about a power bank? is rechargeable and maybe I can use a battery monitor to shutdown the pi safely before battery dies. With which specifications should I look for it? – Miky Feb 3 '18 at 17:18
  • I do not like using a power bank for a Raspberry Pi because a normal USB port is required to only supply 0.5 amps. I have a wall supply, also bought from Adafruit, which supplies 5 volts at 5 amps. For a robot I use a LiPo battery and use a board to drop the power efficiently down to 5 volts. For other things, like Arduinos, a power bank is fine. – NomadMaker Feb 3 '18 at 22:07

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.