Simple GPIO testing board


65 posts   Page 1 of 3   1, 2, 3
by RaspberryPiBeginners » Sun Jun 17, 2012 9:59 pm
So i need some help from some electronics peoples, I've got the breadboard working and I want to free it up to try some new stuff, however I want to be able to go back to it quickly and not have to re-wire it.

So I'm going to get the board made into a PCB, if it works I might make a few with all the parts soldered and sell them (at cost price) if anyone is interested.

If anyone who has skills in electronics can help me that would be great in checking my work.

Image
Click here for my unofficial YouTube Channel > http://goo.gl/oFYBD
User avatar
Posts: 203
Joined: Fri May 11, 2012 6:54 am
Location: Soham, Cambridgeshire
by rockhawk » Sun Jun 17, 2012 11:31 pm
Don't think I really count as an "electronics person", but a couple of thoughts from me anyway.

* When you say +5v, I think you mean +3.3v. You shouldn't connect the GPIOs to 5v.
* Bring all the pins out 0.1" apart so you can solder a standard header on.
* If you route the trace from S1 to +3.3v under R2 you can do it with only 1 layer
* I would source the current from GPIO for the LEDs rather than sink it (I don't know if there's a reason sinking might be better for the hardware - but on the software side setting high for on makes more sense to me).
Find Iridium Rising, our 3D space combat game, on the Pi Store!
Posts: 54
Joined: Thu Feb 09, 2012 9:24 pm
by domesday » Mon Jun 18, 2012 12:17 am
Unless you want to do it for the experience of having a PCB made you might as well just get a couple of spare breadboards they are only about £2.50 each.
Posts: 256
Joined: Fri Oct 21, 2011 5:53 pm
Location: UK
by RaspberryPiBeginners » Mon Jun 18, 2012 8:14 am
Yeah i could get another bread board but i wanna play with some soldering again. Does any know if this is correct or not.
Click here for my unofficial YouTube Channel > http://goo.gl/oFYBD
User avatar
Posts: 203
Joined: Fri May 11, 2012 6:54 am
Location: Soham, Cambridgeshire
by domesday » Mon Jun 18, 2012 9:24 am
Yes it would appear to be ok, as rockhawk says you need the 3.3V line not 5V.

However there is a significant problem with your design that could result in a fried Raspberry Pi, your switches are connected to the Vcc and there is no resistor preventing a complete short of the GPIO pin to the 3.3V. If someone makes the mistake of setting one of those GPIOs as an output and it is low the GPIO will be destroyed as more current than can be handled will flow when the switch is pressed.
Posts: 256
Joined: Fri Oct 21, 2011 5:53 pm
Location: UK
by RaspberryPiBeginners » Mon Jun 18, 2012 9:29 am
domesday wrote:Yes it would appear to be ok, as rockhawk says you need the 3.3V line not 5V.

However there is a significant problem with your design that could result in a fried Raspberry Pi, your switches are connected to the Vcc and there is no resistor preventing a complete short of the GPIO pin to the 3.3V. If someone makes the mistake of setting one of those GPIOs as an output and it is low the GPIO will be destroyed as more current than can be handled will flow when the switch is pressed.


Really i got this diagram from another side, do you mean on the Breadbord or the pcb or both.
Click here for my unofficial YouTube Channel > http://goo.gl/oFYBD
User avatar
Posts: 203
Joined: Fri May 11, 2012 6:54 am
Location: Soham, Cambridgeshire
by rurwin » Mon Jun 18, 2012 9:41 am
do you mean on the Breadbord or the pcb or both.

He means both. Put something like a 2.2K resistor between the switch and the power.

Rather than getting a PCB made, why not just use something like Veroboard 01-0171? You can take your breadboard circut over onto that almost unchanged. The only difference from breadboard is that the power buses are not there. You could modify the breadboard circuit to not use them and then copy it directly to Veroboard.

Radio Shack might do one with power buses too, but their online catalogue is rubbish so I can't be sure. (I find their quality is lower than Vero; the copper tends to come away from the board easier).
User avatar
Moderator
Moderator
Posts: 2890
Joined: Mon Jan 09, 2012 3:16 pm
by RaspberryPiBeginners » Mon Jun 18, 2012 10:22 am
How about this

Image
Click here for my unofficial YouTube Channel > http://goo.gl/oFYBD
User avatar
Posts: 203
Joined: Fri May 11, 2012 6:54 am
Location: Soham, Cambridgeshire
by domesday » Mon Jun 18, 2012 10:33 am
What value are your pull down resistors ?
Posts: 256
Joined: Fri Oct 21, 2011 5:53 pm
Location: UK
by RaspberryPiBeginners » Mon Jun 18, 2012 10:58 am
2.2k like you said :)

The reason i want to create a PCB is because these are awesome. I've got a couple of project ideas that i want to ultimately build into a case and these looks really good.
Image
Click here for my unofficial YouTube Channel > http://goo.gl/oFYBD
User avatar
Posts: 203
Joined: Fri May 11, 2012 6:54 am
Location: Soham, Cambridgeshire
by domesday » Mon Jun 18, 2012 11:09 am
No I'm asking the value of the resistors that you are using as pull-down connected to the 0V rail, are they 10K ?
Posts: 256
Joined: Fri Oct 21, 2011 5:53 pm
Location: UK
by RaspberryPiBeginners » Mon Jun 18, 2012 11:11 am
Oh yes sorry they are 10K
Click here for my unofficial YouTube Channel > http://goo.gl/oFYBD
User avatar
Posts: 203
Joined: Fri May 11, 2012 6:54 am
Location: Soham, Cambridgeshire
by rurwin » Mon Jun 18, 2012 11:40 am
GPIO internal pull-ups are 60k, pull-downs are 10k, current-restricting resistors are 2.2k.

That seems right to me.

@RaspberryPiBeginners, those are some nice prices and a neat looking PCB. It's still three or four time the price of Veroboard, or ten-twenty times when you take account that you wont use a whole strip. But it is a nice feeling to hold a PCB that you've deigned yourself.

And yes, your modifications are correct.

But I note that the connections to the switches are not the same in your schematic and on the breadboard. Does the top left pin connect to the bottom left pin inside the switch? I assume it must, since you short them out on the breadboard anyway.
User avatar
Moderator
Moderator
Posts: 2890
Joined: Mon Jan 09, 2012 3:16 pm
by RaspberryPiBeginners » Mon Jun 18, 2012 12:05 pm
Thank you guys for your feedback it's really great to have help from everyone.

They are actually
270
10k
and the newly added to the diagram 2.2k

I still have 2 outstanding questions.

1. Why cant I use the 5V supply? I've seen lots of people using it and I use it without issue.
2. Can I use the 5V line if i just protect it better? The 3v3 supply is really weak and doesn't really light up the LEDs much.
Click here for my unofficial YouTube Channel > http://goo.gl/oFYBD
User avatar
Posts: 203
Joined: Fri May 11, 2012 6:54 am
Location: Soham, Cambridgeshire
by rurwin » Mon Jun 18, 2012 1:00 pm
The GPIO inputs can not handle 5V, which is a problem on those switches.

If you must use 5V, although there is no reason you should, then those 2.2K resistors should be 6.8k I'm surprised you haven't blown the GPIO pins already by running with no resistor at all.

The LEDs drop 1.8 volts, so the outputs wont see a dangerous voltage, The 270 ohm resistors let 11mA flow, and that is rather high.

But having 5V around is just asking for trouble. You only have to accidentally touch the wrong thing with a wire, or make a mistake wiring up and you will instantly lose a GPIO pin permenantly. A transistor is the fastest fuse known to mankind. I would strongly recommend that you switch to using 3.3V, since it will affect nothing in your circuit. The LEDs will be a little dimmer. You could lower the value of those 270ohm resistors by anything up to half, which will get you back to the same brightness.
User avatar
Moderator
Moderator
Posts: 2890
Joined: Mon Jan 09, 2012 3:16 pm
by Grumpy Mike » Mon Jun 18, 2012 2:02 pm
Personally I am not a great fan of pull down resistors for switches. I think you are much better off using a pull up resistor, either internal or external and connecting the switch between input and ground.
This is my take on inputs, written from mainly an Arduino viewpoint but the principals still apply
http://www.thebox.myzen.co.uk/Tutorial/Inputs.html

As it is a 3V3 chip then of course you must pull up to that voltage and not 5V.

There is then a problem if you have a switch from ground to the input if you accidentally make that pin into an output and press the button. So two thing going wrong. Then you will be driving a logic one into ground. In a lot of electronics while this is wrong you tend not to kill the device, where as driving a logic zero to the supply will.

However, as we are not allowed to see the real data sheet it is hard to say how delicate this chip actually is. My preferred solution for input protection is a 3V3 zener diode across the input and then a series resistor of about 330R before the user accessing connection. This will work not only to protect the pin as an input but will also serve as an anti short measure for the output, limiting the current to 10mA. As a bonus you can then also connect LEDs directly to this output and ground.

If you then want to power an LED using current sinking from 5V you will have a minimum 1.7V across the LED at all times and that might not be enough to completely turn it off. However the current through the output pin in these circumstances will be about 15mA which is acceptable.

For driving a higher voltage or higher current loads buffers of some sort must be used.
User avatar
Posts: 748
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
by RaspberryPiBeginners » Mon Jun 18, 2012 3:28 pm
Thanks for the details guys. It's really tricky knowing where to go with this stuff.

Going back to the original question does this look better? I know it's a bit of a crummy layout but i can tidy it up later if the logic is correct.

Image
Click here for my unofficial YouTube Channel > http://goo.gl/oFYBD
User avatar
Posts: 203
Joined: Fri May 11, 2012 6:54 am
Location: Soham, Cambridgeshire
by domesday » Mon Jun 18, 2012 4:03 pm
I appreciate you are just beginning to learn these things (we all have to start somewhere) but your approach is somewhat trial and error and it sounds like you will need to learn a bit more about electronics.

As a general rule your trigger Voltage for an input should always be less than or equal to the operating Voltage (Vcc) of the device. In this case the Pi is running at 3.3V, other common Voltages are 1.8V and 5V. The trouble is a lot of the information you read will be based on 5V logic as used on the Arduino so will not be correct for the Pi. Even worse is a lot of the information you will find will be wrong, the internet is full of misinformation. Take your video for example, it is great effort but without the current limiting resistors that you now have in this revised version has the potential to lead people who don't know any better to break their Pi. As the foundation posted a link to it then people will assume it is correct. So much of what you have seen on-line will have been made by people like you who are just figuring things out for themselves and have made mistakes along the way, so it is good that you are asking for help in the forum. Perhaps a follow up video with the corrections would be a plan ;)

The two main things you will need to get used to using so as to select the right resistors is Ohms Law, that is the VIR Triangle you can work out http://www.sengpielaudio.com/calculator-ohmslaw.htm and how a Voltage Divider (Potential Divider) works so you can make sure that the combination of your pull-up/down resistors meet the minimum voltage required to make a high state.

I know it is a bit boring and perhaps a bit intimidating at first but the maths is an essential part to successful circuit design.
Posts: 256
Joined: Fri Oct 21, 2011 5:53 pm
Location: UK
by RaspberryPiBeginners » Mon Jun 18, 2012 4:29 pm
Again thanks for the reply,

I've already amened my "downloadable package diagram" to swap to the 3v3 from the 5v, so a little safer, and I can amend it again with the extra resistors as below if you agree it is now correct & Safe.

Image

It's really hard to get this kind of stuff right, you read someone's work that ....works. It doesn't blow up your Pi so happy days right?

I've done all that ohms laws stuff at school but that was 15 years ago, I've looked into some local electronics courses to refresh my knowingly.
Click here for my unofficial YouTube Channel > http://goo.gl/oFYBD
User avatar
Posts: 203
Joined: Fri May 11, 2012 6:54 am
Location: Soham, Cambridgeshire
by gordon@drogon.net » Mon Jun 18, 2012 6:59 pm
RaspberryPiBeginners wrote:Again thanks for the reply,

I've already amened my "downloadable package diagram" to swap to the 3v3 from the 5v, so a little safer, and I can amend it again with the extra resistors as below if you agree it is now correct & Safe.

Image

It's really hard to get this kind of stuff right, you read someone's work that ....works. It doesn't blow up your Pi so happy days right?

I've done all that ohms laws stuff at school but that was 15 years ago, I've looked into some local electronics courses to refresh my knowingly.


You don't actually need to use the resistors on the buttons at all. If you arrange the buttons to short the gpio pin to ground, then you enable the internal pull-up resistor on the pin then it'll work just fine (actually one of the ways it's intended to work to minimise external components. See for example page 2 of the circuit diagram near the SD card - there is a signal indicating SD present which simply shorts a pin to ground - internally the pull-up will be enabled and it saves an external resistor).

However, should you accidentally configure the pin to an output, set it high, and push the button, then you do run the risk of breaking that pin, or possibly the chip, however I have (accidentally) run LEDs directly without the limiting resistor with no short-term ill effects, but I'd really not recomend trying it!

And even if you can't set the internal pull-ups (don't know of the /sys/class stuff allows it - I put it into wiringPi), then if you use the 2 I2C pins, (GPIO 0 and 1), they have on-board pull-ups - so just connect a switch from these to ground, make sure they're programmed as inputs and off you go.

I'm using 330 ohms to drive LEDs, but 270 isn't much different.

A mod to my temp/rh sensor test bed to add a button - no resistor as I've actvated the interal pull-up. Normally displays temperature, but I can push the button and it displays the RH.

Image
Temperature is in binary (20C)
Image
Relative humidity (also binary: 70%)

-Gordon
--
Gordons projects: https://projects.drogon.net/
User avatar
Posts: 1421
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
by RaspberryPiBeginners » Mon Jun 18, 2012 8:03 pm
Gordon you say

If you arrange the buttons to short the gpio pin to ground, then you enable the internal pull-up resistor on the pin then it'll work just fine


This is what I've done right?

I'm planning on creating a new video with an updated/safer board layout and also adding a web interface for control. I want to ensure it's 100% correct before I put it out there again.

Thanks again everyone, is it correct yet...my board that is?
Click here for my unofficial YouTube Channel > http://goo.gl/oFYBD
User avatar
Posts: 203
Joined: Fri May 11, 2012 6:54 am
Location: Soham, Cambridgeshire
by domesday » Mon Jun 18, 2012 8:23 pm
Sorry to say I think Gordon is confusing the issue a bit as he is suggesting you don't need pull-up/down resistors but as there is no way to set them in python at the moment that isn't particularly practical, so I would leave them on there. He is apparently also not allowing for the possibility of someone setting a GPIO as an output by mistake, so I would stick with what you have as it is the easiest and safest way to do it for use with python.
Posts: 256
Joined: Fri Oct 21, 2011 5:53 pm
Location: UK
by gordon@drogon.net » Mon Jun 18, 2012 8:27 pm
RaspberryPiBeginners wrote:Gordon you say

If you arrange the buttons to short the gpio pin to ground, then you enable the internal pull-up resistor on the pin then it'll work just fine


This is what I've done right?


It's not wrong, however...

In the image above, you have 2 resistors per button -

+3.3v - Button - GPIO - 10K - 0V

So this is biasing the input pin to ground, and will connect it to +3.3 when the button is pushed. (well, to 2.75V which will register as "high").

You can optimise this in 2 ways. The first is to just use one resistor like this:

+3.3 - 10K resistor - GPIO - button - 0V

That way it will bias the input high and take it to 0V when you push the button. The logic input is the other way round, (ie. read 1 when open, 0 when pushed) but we can fix that in software.

The 2nd way to optimise it is to know that the BCM chip has internal resistors that you can configure in software. So if you configure an internal resisor to connect the pin to +3.3v then all you need is:

GPIO - button - 0V

and it works like the method above, but with no resistors.

RaspberryPiBeginners wrote:I'm planning on creating a new video with an updated/safer board layout and also adding a web interface for control. I want to ensure it's 100% correct before I put it out there again.

Thanks again everyone, is it correct yet...my board that is?


Your circuit will work - no question about that, but is it "optimal", and does it really matter if it's optimal or not?

It is "safe" in that if you accidentally program the pin as output and set it high, then it's not going to do much, button pressed or not, but if you were making a million of them and could save a penny a resistor, then ...

I also notice in the picture, your using GPIO 0 and GPIO 1 for the button inputs. I'm suspecting you really mean BCM_GPIO 17 and BCM_GPIO 18 as 0 and 1 are the I2C pins and these already have 1.8K resistors to +3.3V.

In my infinite wisdom, I renumbered the GPIO pins in my wiringPi code to be more Arduino Like and got whinged at, but for Arduino users it makes more sense than the "native" GPIO numbering does. What doesn't help is that the original drawing of the GPIO on the wiki refered to them as starting at zero too... Just stick to pictures, that's what I reckon ;-)


-Gordon
--
Gordons projects: https://projects.drogon.net/
User avatar
Posts: 1421
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
by RaspberryPiBeginners » Mon Jun 18, 2012 8:31 pm
OK again 100% thank you for you advice.

Is this below correct? LOL I think i owe you guys a beer,

Image
Click here for my unofficial YouTube Channel > http://goo.gl/oFYBD
User avatar
Posts: 203
Joined: Fri May 11, 2012 6:54 am
Location: Soham, Cambridgeshire
by gordon@drogon.net » Mon Jun 18, 2012 8:35 pm
domesday wrote:Sorry to say I think Gordon is confusing the issue a bit as he is suggesting you don't need pull-up/down resistors but as there is no way to set them in python at the moment that isn't particularly practical, so I would leave them on there. He is apparently also not allowing for the possibility of someone setting a GPIO as an output by mistake, so I would stick with what you have as it is the easiest and safest way to do it for use with python.


You can't do that in Python? Oh. I'm sure that'll be changed though - it's fairly funadamental thing to do in the world of microcontrollers and the BCM chip supports both pull-up and pull-downs...

(And you can always fetch my wiringPi software which has a command-line program that'll do it for you ;-)

As for not allowing the possibility of setting a GPIO to output by mistake... I would suggest you re-read my post. I was quite clear on it, and there is a circuit that does just that on the Pi itself... This is not an uncommon thing to do in the world of microcontrollers. Such optimisations are made all the time, so it's good to be aware of it. One mmap, and wrong location written to as root and the possibility of frying your Pi even with nothing connected to the GPIO is > 0.

Fortunately GPIO pins are normally set to inputs at reset time...



-Gordon
--
Gordons projects: https://projects.drogon.net/
User avatar
Posts: 1421
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK