-1

I am trying to control some 5v stepper motor driver inputs using GPIO. I found this helpful tutorial and was able to get it working (scroll to the last post where he's got it rigged up to a breadboard with transistors, etc, with pictures):

https://www.raspberrypi.org/forums/viewtopic.php?t=106916

However-- I don't understand WHY it works. Or at least, I think I might, but my recollection of NPN transistors is that the collector is always set to ground and the switch helps complete the circuit. Like, using an LED on the collector with a 5v supply and using the 3.3v supply on the base, it allow sthe LED to turn on by giving access to ground when turned 'on' by the GPIO.

However, when you connect 5v from the RPi to the + leads on the motor controller, and then use the transistor as a switch to the negative side, I'm having trouble figuring out how that is the same thing-- is the circuit inside the stepper motor basically like an LED in that all we are doing is supplying access to ground to get them to turn on?

edit: to clarify

Is this correct: versus using the 3.3v GPIO pins to control the + inputs of the stepper motor directly and connecting the - inputs to ground, since it has insufficient voltage, instead we are using the constant 5v source from the pi and controlling the switch on the negative side, supplying access to ground to complete the circuit by using GPIO pins as a switch to a transistor?

  • 2
    This appears to be a general electronics question. The Pi is irrelevant. – joan Sep 30 '19 at 20:00
  • Perhaps you're right, but the pi is not irrelevant-- from an applied perspective, this is one of the only ways to control a 5v input using the pi's 3.3v GPIO pins without an external power source or relay. People searching for this exact problem will find this and hopefully, it will help them. I am just trying to understand if I have the science right so I don't blow up my Pi. Thanks. – Hodor Sep 30 '19 at 20:08
  • Not only is this question off topic; the suggested circuit connects the GPIO directly to a transistor base, effectively shorting the GPIO. The alternative (a PNP transistor) is even worse - it connects the 5V to a GPIO and would short the 5V supply! Both risk damage to the Pi. See elinux.org/RPi_GPIO_Interface_Circuits#Using_an_NPN_transistor for a proper circuit. – Milliways Oct 1 '19 at 1:17
  • @Hodor, your using Rpi GPIO pins to drive 5V stepper motor driver is OK but need to be very careful of not to carelessly connect 5V power to Rpi GPIO pins. I see your are using NPN BJT such as 2N2222 to prevent this over voltage. But EE guys usually use opto-isolation modules to reduce noise step up and shift up logical levels. Optoisolation is very important, because back EMF and EMI always jumps back to Rpi, possibly freeze it or fry it. Perhaps I can search my junk box for a old stepper motor driver and share my stepper motor toys with you. – tlfong01 Oct 1 '19 at 1:19
  • @Hodor, your use of the verb "amplify" to describe your NPN BJT operation is a bit misleading. NPN BJT such as 2N2222 can either do "amplification" or "switching". In your particular case, it is sort of switching, but mainly "level shifting". You need to go to electronics tutorials, as recommended by >Fred below, to get a solid foundation on NPN BJT for amplification and switching, use of pull up resistors and so on. Happy learning and cheers. – tlfong01 Oct 1 '19 at 1:29
1

is the circuit inside the stepper motor basically like an LED in that all we are doing is supplying access to ground to get them to turn on?

Yes. In an NPN transistor current flows from the collector, through the base into the emitter, i.e. it acts as a sink. In your circuit then, +5V from the Pi flows through the stepper motor controller, through the transistor, through to ground. The current only flows when the base is activated.

A simple explanation of NPN transistors. A bit more detailed explanation of NPN transistors.

| improve this answer | |
  • 1
    Your references are very good. I always refer newbies and professionals to "Electronics Tutorials". The good thing about "Electronics Tutorials" is that they are very comprehensive, and from basic to advanced, so newbies can start from beginning. or jump around. I myself from time to time visited their site to update/upgrade EE knowledge/skills. I also often go there to clarify confusing things. For example, I never understand why use "phasor" to represent AC signals, and why use the mysterious operator “j", and constant "e", which are used in very basic capacitor circuits. – tlfong01 Oct 1 '19 at 1:14

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