|Think about Loose Coupling|
Re^2: Using a controllerless servo on the Raspberry Pi with Perlby afoken (Abbot)
|on Jul 12, 2017 at 19:40 UTC||Need Help??|
powering an inductive load from the pi directly can cause a voltage spike to flow back on the 5v rail
Use of decoupling capacitors can negate such problems
You are mixing up two things there.
Decoupling capacitors are required to keep the supply voltage stable when lots of transistors inside the controller switch simultanously and parasitic capacitors inside the controller are forced to change their charge. The PCB tracks to the supply pins behave like a resistor or inductor, so even a very good, nearly ideal power supply simply can not keep the voltage at the supply pins constant. The decoupling capacitors can, because their track to the supply pins is extremely short. As a welcome side-effect, the decoupling capacitors also short high frequency noise to ground.
Inductive loads switched to DC suppiles create a more or less large voltage spike with reversed polarity. This voltage is usually large enough to kill nearby semiconductors, typically the switching transistor. To get rid of the voltage, connect a fast diode in parallel to the inductive load, but with reversed polarity. This is commonly called a flyback diode. While the load is powered, the diode is passive. Because the voltage spike has reversed polarity, the diode becomes conductive and shorts out the voltage from the load, converting the energy to heat in the diode and the load's wire. The remaining circuit sees a reverse voltage of about 0.7 V across the load that does not harm usual Si semiconductors.
Another thing: Yes, the I/O pins of AVR microcontrollers have a significant capability to sink and source current. The ATmega328 (datasheet), commonly found on Arduino boards, can sink and source at least 20 mA @ 5 V, 10 mA @ 3 V, abs. max. 40 mA (see datasheet page 365 and following). But the total current must not exceed 100 mA per port, and it must not exceed 200 mA total. Other AVR processors have very similar ratings, and I would expect similar performance from PIC chips. But for anything but a simple LED or a TTL/CMOS compatible input, I would use a driver transistor. I/O pins also have a pair of diodes (see page 97), but those diodes are just clamping diodes that prevent killing the controller by ESD. They are not designed to discharge an inductive load.
Oh, and don't expect other, younger microcontrollers to have similar driving capabilities. Let's look at the SAM4S series (datasheet), an ARM Cortex M4 with a lot of peripherals, more I/Os, more flash, more RAM, and faster than AVRs. The I/O pins can sink and source max. 2 mA (see page 1143), a few pins can sink and source 4 mA, and only two pins can sink and source 30 mA. Abs. max. total current is 100 mA for 64 pin devices, 150 mA for 100 pin devices. All of that at an I/O voltage of 3.3 V typ. Other ARM-based microcontrollers have similar limits. They can directly drive a low-current LED, or CMOS compatible logic inputs, but for everything else, you need a driver transistor.
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)