I have just started using a servo to drive the front steering of a remote control car frame which i cannibalised. The steering works fine if i start it up and tune it however when i shut down the raspberry pi and then turn it on again the servo goes full blast well out of the range i set up initially (or trys to) and then consequently i think this is causing the internals gears to slip etc because my angles which were set up nicely before are then all wrong again!

Is this something to do witht he raspberry pi's boot method? Is it possible to stop this from happening within the code or will i need to implement some hardware?

update wiring diagram (sorry its a bit messy its only the second i've ever made and i did it quickly) enter image description here

  • Yes. Wiring diagram. Please! Maybe code but like you say it happens before code so that is not the problem. – Piotr Kula Sep 2 '13 at 14:36
  • Thanks for the diagram. First of all it will be a much better idea to power the servos from the power supply. Don't use (or rely) on the Pi. Assume the Pi is on its on breaker and the servos on another one. If you use the Pi it can cause brownouts and reset the Pi. All you need to try is connected a 10k resistor (can be lower or higher anything between 5k to 15k - in this circuit it wont matter- you only tune those for power efficiency with hectic calculations) to GND on each of your OUTPUTS (i assume the Magento links) Then try that and see if it still goes mental on boot?! – Piotr Kula Sep 2 '13 at 20:44
  • Oh and the L293D is your buffer! You don't need any thing else. Just power it directly from source-if your motors can handle 5Volt? Otherwise use a sepearte voltage regualtor. not from the Pi. ANd make sure you got atleast a 2A~3A power supply. Just draw it out on paper first to understand what you need. You can also ask on electronics stack exchange about advise on your circuits! :) – Piotr Kula Sep 2 '13 at 20:48

It does seem like the GPIO pins get set during boot. This is quite a problem as it is not what you would have expected! The problem is that during boot the GPIO pins are floating and pulled down by anything. So they will have "random" or unexpected values and voltages.


First of all the servos should NOT be connected directly to the GPIO. You should be using a buffer of some kind!

You only power up the buffer when you are ready! So during boot it can cycle the GPIO as much as it likes but only after you send an I2C command or something to a separate power control circuit will it power up your buffer.

When I say separate circuit - This might even be a small Arduino that triggers a transition to switch the power on the buffer. Using the GPIO pin to control the power will only result in the same problem unfortunately. You can reliably tell if it won't just cycle.

If you insist on using the GPIO pins then you can solve the problem by adding in a resistor of your own that will control the power to the servos. Put a 10kOhm resistor on the listed PINS below - Do not use other PINS as it won't work because they are pulled HIGH at boot whatever you do to them. This will guarantee LOW at boot time and still allow you to use software to pull it HIGH.


  • 17(GPIO 0)
  • 18(GPIO 1)
  • 21 (GPIO 2)
  • 22 (GPIO 3)
  • 23 (GPIO 4)
  • 24 (GPIO 5)
  • 25 (GPIO 6)
  • 4 (GPIO 7)


  • 17 (GPIO 0)
  • 18 (GPIO 1)
  • 27 (GPIO 2)
  • 22 (GPIO 3)
  • 23 (GPIO 4)
  • 24 (GPIO 5)
  • 25 (GPIO 6)

* Reference

Pull Down resistor

Its only purpose is to keep the PIN low when its in the floating state (not initialised by Pi yet) So the Resistor is connected to PIN and GND. Then your device is connected to PIN as normal. So both Resistor and device are connected to the PIN. But only resistor to GND (So it pulls down the PIN on any stray voltage - And you activate it it will go to 3v3 and the resistor will no longer pull it down but your device will sense the change- This does not affect PWM) This pull down can be on your devices side too)

An easy to follow example.(Ignore the part numbers and pretend that is your Pi pin and the thing-a-ma-jig marked as CCR2 is your servo)

enter image description here

R1 is connected to PIN 1 to pull it down. Pin 1 is also connected to another resistor in series to limit the current for the transistors range. A transistor is a simple gate. If powered on the BASE the gate "connects" COLLECTOR and EMITTER and lets the current flow in the direction of the arrow. In this diagram its a NPN transistor most likely something like a 2N2222 (cheap and cheerful). This is also a very nice way to "BUFFER" your circuits. As you can notice the 7volt supply lights the cathode bulb and goes to GND, without ever reaching your Pi/MCU. The capacitor is not required but it seems to be used here to smooth out (debounce) the switching process) The LED is just coolness.

So your GPIO pins do not drive any heavy loads directly- Doing that can burn out the CHIP or PCB tracks. Instead you supply a voltage with more amps and better copper that will give that burst of energy, while your digital circuit (GPIO and Transistor) control the flow while being protected.

Remember to check if the transistor can handle the load. In most cases if overloaded the transistor will burn out before damaging your digital device.

Pull Up resistor

This resistor is connected to V+ instead of GND and pull the PIN high while floating. This type is not common and only required for specific purposes.

enter image description here

As demonstrated on the Arduino Atmega328. The RESET pin must always be pulled up so that the internal circuit knows it is operating normally. If this pull up drops to the point where the internal circuit thinks its changed from HIGH to LOW (because of battery going flat) that is known as a brown out- and the 328 will reset and behave erratically.

So in this case it is imperative that the RESET pin is always HIGH to indicate normal behaviour.

  • I have had a quick read of the reference, so i add in a resistor in series? Could you just explain how this solves the problem as i only have a basic understanding of electrical circuits (I was hoping to improve that along with my programming and systems knowledge by doing this project) – D Mason Sep 2 '13 at 16:15
  • Just to add i don't insist its just all i have right now, i am looking into the servo board from adafruit – D Mason Sep 2 '13 at 19:25
  • The servo board might already have these pull downs but you need to check, as usually, like with an Arduino pull down resistors are built in to the chip or board. I updated my answer for you! +beer – Piotr Kula Sep 2 '13 at 20:29
  • 1
    AHHH ok i've got you now, Thankyou that all makes much more sense! – D Mason Sep 3 '13 at 10:22
  • 1
    @ChrisStratton could you provide an example diagram explaining your statement (i found the text abit confusing to follow), Also i am awre that using the L293D is overkill but with the current set up it is only driving one DC motor so it is currently underutilised. I have ordered some 10Kohm resistors and some transistors to try out the suggested circuit by ppumkin (hopefully they will arrive today) – D Mason Sep 5 '13 at 10:38

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.