0

I'm new to electronics and have run into a problem while trying to hook up my micro-servo to my Pi.

I have a Rapsberry Pi model 3 B, a breadboard, a 6V power supply, and a TowerPro MG90S micro servo.

The way I have everything wired is as followed:

  • The battery supply is connected to the right side power rails, the black goes negative, the red to positive.

  • The micro servo gets connected with the black wire going to negative, middle wire (orange/red) to positive, and the yellow wire goes directly to pin 11 (6th row, first pin) on my pi.

  • Lastly, the ground pin on the pi (row 3, pin 2) is hooked up to negative on the right side of the power rail.

The code I'm using to test it I found online:

import RPi.GPIO as GPIO

import time

GPIO.setmode(GPIO.BOARD)

pin_number = 11
GPIO.setup(pin_number, GPIO.OUT)

frequency_hertz = 50
pwm = GPIO.PWM(pin_number, frequency_hertz)


left_position = 0.40
right_position = 2.5
middle_position = (right_position - left_position) / 2 + left_position


positionList = [left_position, middle_position, right_position, middle_position]


ms_per_cycle = 1000 / frequency_hertz

for i in range(3):
        for position in positionList:
                duty_cycle_percentage = position * 100 / ms_per_cycle
                print("Position: " + str(position))
                print("Duty Cycle: " + str(duty_cycle_percentage))
                print("")
                pwm.start(duty_cycle_percentage)
                time.sleep(.5)

pwm.stop()


GPIO.cleanup()

When I run this, nothing happens. I don't know if the pi is faulty, the servo is, or something might be wired incorrectly.

2
  • Try adding a transistor to the signal wire on the servo. Commented Mar 27, 2018 at 22:16
  • Please make a wiring diagram/schematic. Commented Mar 28, 2018 at 8:02

1 Answer 1

1

See https://pinout.xyz/ for the pin out of the Pi's 40-pin expansion header.

I'm assuming you have connected the servo control wire to GPIO 17. I'm further assuming you have connected a Pi ground to the servo ground.

To see if your servo works enter the following commands.

sudo pigpiod # start the pigpio daemon

pigs s 17 1000 # send 1000 micro pulses to servo
pigs s 17 1500 # send 1500 micro pulses to servo
pigs s 17 2000 # send 2000 micro pulses to servo
7
  • Yes, that all seems correct. It doesn't seem to respond to any of those commands. I almost wonder if the battery is not working correctly, but I don't have a volt meter to test it.
    – Astrum
    Commented Mar 27, 2018 at 21:38
  • Forget the battery. Power the servo from the Pi's 5V rail. That should supply more than enough for a 9g servo or two or three.
    – joan
    Commented Mar 27, 2018 at 21:42
  • Unfortunately that didn't work either. I rebooted my pi and tried again, no luck.
    – Astrum
    Commented Mar 27, 2018 at 21:58
  • You need to add a photo of your connections. There is very little to go wrong with a servo.
    – joan
    Commented Mar 27, 2018 at 22:00
  • 1
    @mrSidX There are two hardware PWM channels connected to GPIO 12/13/18/19 on the expansion header. pigs/pigpiod uses hardware timed PWM on any of GPIO 0-31 which is fine for servos/ESCs.
    – joan
    Commented Mar 28, 2018 at 7:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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