Raspberry Pi breakout board - Did I do it right? - Page 1
Forum section: electronics / projects

author: ryanmills
author_rank: Unknown
timestamp: October 03, 2019, 11:44:40 pm
content: Mostly a lurker here just learning as I go. I'm working on a controller for a simple arcade style game. The controller is basically a breakout board for a Raspberry Pi 4. I have found some conflicting information on driving an NPN with a Pi GPIO and selecting a correct base resistor. For the NPN and LEDs under "LED Tree" I could be driving most of them at once I wanted to keep the draw as low as possible on the 3v output of the Pi. The NPN's are driving either a single or dual super bright 10mm LED. The current limiting resistor for the LED will likely change because the LEDs are going into a light pipe but are likely still too bright. Not sure if the 10k base resistor is too high? The NPN is a MMBT3904-TP. And im giving the NPN a hFE of 150 to 200 based on the datasheet curve and draw I'm expecting.If anyone has a moment I could use a sanity check just to see if anything looks grossly out of place or wrong. Note the isolation on the on the distance sensor input is because its over a very long run of a wire and I have had issues in the past. Just want to be safe. The SSR used is overkill but I have hundreds of them on hand. I don't have a lot of experience with this so any suggestions for improvements are welcome.

author: jhpadjustable
author_rank: Frequent Contributor
timestamp: October 04, 2019, 01:27:11 am
content: Curves aren't really guarantees, so I pulled up my datasheet for Fairchild/ON Semi 3904s, which claims the dc current gain at 10mA and 1.0V Vce is at least 100. ON doesn't mention gain bins, so I'll go with the worst case of 100. 3.3 - 0.65 - 0.05V of fudge for rounding = 2.6V / 10k = 260µA * 100 = 26mA Ic. With a 10mA load, you could double the base resistor, if you really wanted to, and if you aren't one of those people who keeps a reel of 10k resistors around in case of emergency like I do, and you don't want to leave margin for later adjustment.Personally, I'd use a MOSFET. Curves aren't really guarantees, but with a small, common MOSFET like the 2N7002, typically you could pass up to (approximately) 60mA at 25°C with essentially zero static gate current. According tosome random bloke on Stack Exchange, pi GPIO output current should be limited to no more than 16mA instantaneous current per pin, so 3.3 / 0.016 = 206 ohms gate resistance, in isolation. However, total GPIO output current should also be limited to no more than 50mA in total, including your optoisolators and everything else, so, just in case you switch all those LEDs on or off at once, I'd limit all the gate/GPIO currents to 1mA peak by placing 3.3k resistors in series with all those gates. The 165ns RC time constant is negligible in the case of visual LEDs.

author: teksturi
author_rank: Regular Contributor
timestamp: October 04, 2019, 04:39:43 am
content: You must have 4k monitor because this is wild to look with 13" HD screenI have to zoom in and zoom out or take the time to scroll to next part. Maybe you could tider this design a lot. Now one title letter is even bigger than resistor. Also normally inputs are left and outputs are in right. So try that and you see how much better schematic will look. Example move solenoids outputs right part of schematic and rotate them so gpio input is left and connector is faced right. Try to fit everything in space between J1 - Raspberry connector. Also name that connector also.Why do you need so expensive ssr to basically just level shift 5v to 3.3v? It is also kinda of expensive. Same thing with relay driver. Can't you just use transistor or mosfet to drive.Good in this schematic is that you have good titles in every sections. Nice divisions to sections. Gnd are always down. Good job.These are just small things and you can make or not make these. I'm no expert ether and I have made my knowledge with Youtube. I have watched Robert Feranec videos and of course Daves videos.

author: ryanmills
author_rank: Unknown
timestamp: October 04, 2019, 05:32:22 am
content: Quote from: jhpadjustable on October 04, 2019, 01:27:11 amThank you, I'm open to any ideas to improve the design. To clarify are you saying add 3.3ks on all the GPIO's like the opto's? And I will have to take a peek at MOSFET's. I still have time to make chances. I just went with the NPN because I had seen it implemented that way in a relay board I had lying around.Quote from: teksturi on October 04, 2019, 04:39:43 amHa, sorry I knew the comment about size was coming. I am on very large screens and did not want to post multiple photos nor mash it all too close. I will try to scale it a bit better next time.SSR's are just because I have a ton left over. But it is a little more than a level shift. The Pi has a max of 50ma and a max of 18ma per GPIO. Also on the input I have had issues with long runs of wire basically acting like antennas. But those SSR's are seriously overkill and will be replaced with something more appropriate once the prototype works.And thank you for the pointers on the layout. I agree I should have ordered the input and outputs differently. I was just watching dave's hour and half schematic fix to see any little things I might be doing wrong.

author: jhpadjustable
author_rank: Frequent Contributor
timestamp: October 04, 2019, 07:47:12 am
content: Quote from: ryanmills on October 04, 2019, 05:32:22 amKeep in mind the concept of margin. Avoid running components at 100% power when you can. Here, that means to avoid getting close to the 16/50 output limits. I'd opt for 1/30 mainly because SoC GPIOs are on the delicate side and I don't want to get into the weeds on advanced GPIO configuration like drive strengths. I'm sure Adafruit has written a ton on the subject of care and feeding of GPIOs, in case you want something to binge-read this weekend.The 3.3k only applies to the gates of the MOSFETs. The NPN transistors are fine with 10k resistors on the base. Both need current limiters on their control terminals, but for different reasons. The LED outputs are good enough as drawn.Oh, and one more thing: put diodes across your mechanical relay coils (in reverse, cathode goes to + side) to keep the turn-off current spikes down. Then it will be safe to replace the SSRs with transistors just like you did for the LEDs. In that case, reduce their base resistor just as you and I calculated before.

author: teksturi
author_rank: Regular Contributor
timestamp: October 04, 2019, 02:41:59 pm
content: Quote from: ryanmills on October 04, 2019, 05:32:22 amThis step is important even if you have big monitor. When you build your prototype it will be more convenient to print A4 papers.QuoteYes that is problem. You can check this posthttps://electronics.stackexchange.com/a/49825You should but some filtering for 5v output also. If you can choose cable with shielding and twisted pairs.

author: rstofer
author_rank: Super Contributor
timestamp: October 04, 2019, 03:47:46 pm
content: The other day I did a little MATLAB thing for analyzing the base resistor of a simple transistor inverter.https://www.eevblog.com/forum/beginners/question-on-npn-logic-inverter-from-textbook/msg2718816/#msg2718816In the case of an LED, instead of a single 8.2k resistor like the example above, you have a VF(forward voltage drop) plus a ballast resistor.Code:[font=courier]format shortEngformat compactVcc = 12.0 % all values assumedVpin = 3.0 % RPi Output Voltage On PinVceSat = 0.2 % Transistor Saturation VoltageVb = 0.7 % Transistor Base VoltagehFE = 40 % Transistor DC Current GainVf = 2.0 % LED Forward Voltage DropIf = 0.020 % LED current (20 mA)% calculate LED bias resistor given Vf, If and various voltagesRled = (Vcc - Vf - VceSat) / If% calculate transistor base resistorIbase = If / hFERbase = (Vpin - Vb) / IbaseAnd the results are:Code:[font=courier]Vcc =12.0000e+000Vpin =3.0000e+000VceSat =200.0000e-003Vb =700.0000e-003hFE =40.0000e+000Vf =2.0000e+000If =20.0000e-003Rled =490.0000e+000Ibase =500.0000e-006Rbase =4.6000e+003I realize that NONE of these numbers is correct for your project. But the formulas are given and you can substitute as required. Or, post the right numbers and a readable drawing.The pin current is the same as the base current or only 500 uA in this example. Note that I assumed the pin voltage would really only get to 3.0V, not 3.3V. You can make some measurements if you want to improve the estimate.The code above will run on Octave and it's free!

author: ryanmills
author_rank: Unknown
timestamp: October 04, 2019, 08:47:35 pm
content: OK I made most of the recommended changes. Added a diode to the relay coils and I swapped the NPN for N channel MOSFET's, specifically the BSS138LT3G Datasheet:https://www.onsemi.com/pub/Collateral/BSS138LT1-D.PDFIf I'm reading the datasheet correct the Vgs is 0.85v to 1.5v. I assume it's just basic ohms law to figure out the correct resistor but I'm not sure what values I should be using to determine that?Condensed the schematic as much as I could without going to multiple sheets. Sorry, I know its still a too big.

author: rstofer
author_rank: Super Contributor
timestamp: October 04, 2019, 10:17:45 pm
content: Without actual datasheets for things like the LEDs, it is hard to tell what's going to happen.For the linked datasheet, Vf (forward voltage) averages around 3.2V. As a result, two LEDs in series won't work because the forward voltage drop (the voltage at which you get usable light) of the two LEDs is more than VccIn the case of a single LED running at 80 mA, you need the resistor to drop 5.0V - 3.2V or 1.8V. R = E / I or 1.8V/0.08 = 22.5 Ohms .https://cdn.sparkfun.com/datasheets/Components/General/YSL-R1042WC-D15.pdfAs to the SSRs, Vf = 1.14V and If = 3 mA. I don't know what kind of led is in series but it you wanted it as a low intensity indicator, say 10 mA, there would be no problem. Guessing that Vf of the LED is 1.8V then the total voltage is 1.14 + 1.8 or 2.94V The resistor would be (3.3-2.94)/0.01 or 36 Ohms. If the LED is high intensity I don't think the circuit will work, too much current for the SSR. Actually, I'm not keen on the fact that there is so little headroom and the resistor is so small. If Vf of the LED gets much higher, you will run out of 3.3V and the resistor will get stupid small. I would try to avoid that.Indicators don't need high intensity, you could probably drop If to 5 mA (much closer to what the SSR needs) and not notice the difference. Or, move the indicator LED to the 12V side and just wire it in parallel with the SSR and use a resistor based on 12V. A 510 Ohm resistor will give 20 mA running through an LED with Vf of 1.8V. R = (12 - Vf) / If if you want to change the numbers. Recalculate the SSR resistor as (3.3-1.14)/0.003 or 633 Ohms.https://media.digikey.com/pdf/Data%20Sheets/Panasonic%20Electric%20Works%20PDFs/AQW,AQY280,282,284.pdfI would encourage you to use information from actual datasheets for the exact parts you intend to use.Another example might be the MOSFETs. Are you sure they will turn on with 3.3V?I missed the link to the MOSFET datasheet. They should work fine.

author: jhpadjustable
author_rank: Frequent Contributor
timestamp: October 05, 2019, 12:29:44 am
content: Quote from: ryanmills on October 04, 2019, 08:47:35 pmA bipolar transistor is a current-controlled current source, whose control terminal behaves as one leg of a diode. A MOSFET is a voltage-controlled resistor whose control terminal behaves as one leg of a capacitor (see C(iss) under Dynamic Characteristics in your datasheet). A capacitor approximates a short circuit at the instant a voltage step is applied, such as the (ideal) rising and falling transitions of your control signals. On the other end of the control wire, the maximum current spec for the I/O ports is 16mA per pin. You must limit the per-pin current to less than that value at any instant, and good engineering practice is not to approach that limit any closer than necessary. Because there are several outputs and a total limit of 50mA for all outputs, and owing to an abundance of caution and the potential grief of blowing an I/O on a dev board, it's preferred to limit the current sourced/sunk by the port closer to like (pulls number out of air) 1mA per pin. Your I/O supply voltage is 3.3V, of course. So choose the gate resistor for 1mA at 3.3V to limit current into/out of the gate and its attached I/O pin at the instant the ouput level changes.As a footnote, for a tiny capacitor like the BSS138's gate, these gate current calculations are more fiddling than strictly necessary. You could just throw in a 100 ohm to 1k resistor and move on. Power MOSFETs switching larger currents demand these and other considerations, so consider it good practice for later.The series resistors for the LEDs are even less critical and can be chosen empirically to give the desired brightness.