Using the GPIO

Gert’s video on Wednesday explaining how to fix up your own ribbon cable with a press connector (much cheaper and easier to source than buying a finished one in the shops) got a lot of people asking for more information on using the Raspberry Pi’s GPIO (general purpose input/output) pins. So here’s another video from our friend RaspberryPi Beginners – he has a whole YouTube channel full of these tutorials, and they’re very helpful – showing you what’s what.

56 comments

Avatar

There is also a very good article in issue 2 of the Magpi Magazine http://www.themagpi.com/ called In Control.

Avatar

It’s handy having both resources. Some people prefer to learn from videos, others from something on paper. We aim to please all comers!

Avatar

Indeed, just suggesting an additional source of info on GPIO.

Avatar

Oh absolutely – no crit intended. We think the MagPi’s resources are fantastic.

Avatar

Thanks for the link to MagPi. I prefer my video without legacy browser plugins.

Avatar

Sorry to be off topic, but is anyone else having a problem with the videos on the main website? Every time a new video is posted, the video on the main site is always “Boreatton Robotics Team Discusses the Raspberry Pi.” It’s a rather nice video and all, but I do like to be in on the new stuff! In writing this comment, I found that if I click on the actual post, I can see the video just fine. However, I’d still like to know if this is a problem with my browser or the website. Thanks for everything Liz!

Avatar

Have you tried clearing your browser cache?

Avatar

Yep, that did it. I really thought I had done that, and I feel pretty silly now… Thanks though! To the Robotics Team: I won’t forget about you even though I don’t see your video in every post anymore.

Avatar

I get that occasionally too. No idea why, so I just use the same “fix” that you do :) (i.e. view just the post itself)

Avatar

Patrick, that problem has always been here with WordPress. The easiest way around it is to get off the front page and into the article itself by clicking on the “NN replies” link. Then you’ll find that video links display the correct video for the article.

I’m not really sure why the site is still using WordPress to blog now that we have decent quality forum software running. These news announcements could easily be done in a News or Announcements section of the forum. It would make them more easily searchable too, as well as consigning the WordPress bugs to the mists of time.

Avatar

Excellent. Thanks.

Avatar

You can save typing / copy-and-pate but simply using ./ to end you mv statement if you’re in the directory you want to mv something to.

sudo mv /var/tmp/RPi.GPIO-0.2.0.tar.gz ./

Avatar

Any reason why everything is being done as root (via sudo) with a umask of 0 (so everything is world-writeable)?
For a teaching device, teaching security and responsibility is also a good idea.
Time to get away form the “everyone can modify everything” Microsoft philosophy, which leads to so many viruses.

Avatar

Or you could save one more keystroke on that as well:

sudo mv /var/tmp/RPi.GPIO-0.2.0.tar.gz .

:)

Avatar

Controlling IO with Python? really!

Avatar

The video was quite helpful!

It’s a bit too bad raspi uses 3.3v logics for the GPIO pins instead of the more common (or is it?) 5v logic used by Atmel and PIC. Nothing an array of simple 1 cent transistors and an octal buffer or two can’t fix, though!

I must say it’s also too bad that there is no I2S available on the GPIO pins. There’s plenty of I2C DACs to fill in the niche, and HDMI can also be used as a source for raw audio streams! I can only imagine the GPIO pins being hugely fast on raspberry pi. The SD-card is also directly connected to the GPIO pins without any logic circuits in between. In other words; using an IO line should be okay for turning it into a sort of “software I2S”. I haven’t tried this, yet..

Pypi!

Avatar

If you use HC logic components 3,3V isn’t a problem. And in that video AFAIK Gert mentioned the I2C bus, didn’t he?

Avatar

I2C and I2S are two different things I’m afraid.

Avatar

My apologies; I2c (pronounced I-squared-C) is a protocol for serial data connections

I2S (I-squared-S) is a protocol specifically designed to carry raw PCM audio data.

Both protocols are used for digital-to-analogue converters, though I2S is sometimes preferred because (especially older) DACs only support I2s. In any other application, I2C is usually superior that it is bidirectional as opposed to I2s being unidirectional.

I’m not sure I2C is actually fast enough to carry anything higher than 44.1khz at 16bit stereo, though. It’s quite a lot of data. Not that it’s really necessary, though I’m just saying 5.1 surround is probably too much data for i2c

Avatar

In fact 5V is not at all common any more. You will find that no new logic uses 5V everybody uses max 3V3, the unfortunate exception being the Arduino series**. As I am working in the mobile world we see there that 1.8V I/O is getting more and more common. It is expected that other logic will slowly follow.
I suspect the Arduino is running of 5V because that is where you can run them at their maximum speed of 20MHz. At 3V3 you are not supposed to go above ~11MHz.

Avatar

What on earth is 3V3?
I know 5V is 5 Volts & 3V is 3 Volts is but what is 3V3?

I see it referenced everywhere but haven’t seen it explained.

Avatar

3V3 = 3.3V because a decimal point is so small and could easily be missed it has become a convention to use the unit as the seperator. You will also see resistors refered to as 8K2 meaning 8.2K ohm.

Avatar

Oh my how simple, I should have just assumed that :)
cheers.

Avatar

Hi Gerd,

great stuff!
Sadly i can’t check out because my Pi wasn’t delivered until today :-/
Q: Why did the push button pull the port to Vcc and a restor to GND? I think the usual way is vice-versa. I know that Atmel-MCU and other MCU’scan switch a pull-up resistor to Vcc by setting a flag. Isn’t is possible on a Pi? Not a big drawback i think, but makes the R’s obsolete.

And i think you should teach the newbies that on a cp-command a target “dot” will use the source-filename for the target-filename. That won’t overburden someone.

But again, i appreciate that kind of developement!

Tod ziens
Max

Avatar

There are no options in the python library to switch on the internal pull-up/down resistors in the Bradcom chip. That is why it is necessary to use a resistor in the circuit.

Avatar

I’d like to know where to get the IDC single socket patch leads featured in the video – they don’t seem to be on the Maplin website (or RS, Rapid, CPC). Any ideas anyone?

Avatar

I also have been looking for those for ages! Recently Gordon send me this link:
http://www.skpang.co.uk/catalog/jumper-wires-kit-100mm-ff-50pcs-p-380.html
They have all types, male-male, female-female and male-female.

Avatar

Just to clarify something the ones Gert has linked to there are the female-female, the one used in the video are male-famale that are these ones http://www.skpang.co.uk/catalog/jumper-wires-premium-150mm-mf-pack-of-10-p-909.html

Avatar

Looks like he was also using skpangs breadboard case, mine arrived yesterday and it make “hardware hacking” the Pi a doddle.

http://www.skpang.co.uk/catalog/starter-kit-for-raspberry-pi-b-p-1107.html?zenid=s969fmn4ktnqh72fadm6si8tj6

Avatar

It is a really nice case. I use one too. putting a ribbon connector on would be a smart thing – have to see if if I have an old one kicking about to cut up.

Avatar

At 4:24, he says the TXD/RXD are for a RS232 cable. Do those pins use positive and negative voltages specified in RS232, or plain TTL levels (so an adapter is required for true RS232 levels) ?

Avatar

No all pins on the GPIO header on the Raspberry Pi use 3.3V logic, I think what he meant to say is TXD/RXD are serial connectors. To use them with true RS422 or RS232 would require a level convertor.

Avatar

It uses 3.3v. I think SparkFun has a converter breakout board though.

Avatar

Hi,

It looks like a good video series, to inspire others to start interfacing.

A few minor comments, it would be good to see programming directly on the PI. Several times sudo is not needed for the command being typed. For the spreadsheet, why not wrap the lookup in a library which includes a C header file or similar. In this manner one can hide the mapping rather than carry the spreadsheet around.

Presumably the device permissions could be set to allow non-root users to control the GPIO port?

Thanks and best regards,

Will

Avatar

Would it be possible to use the GPIO to have a temperature probe hooked up (for home brewing) and then have the pi log the temperature in intervals?

Cheers!

Avatar

Yes, you have a number of options, the raspberry Pi does not have any analogue connections on the GPIO so it is a little more involved than just attaching a thermister to a pin. You can use one of the digital thermometer IC’s that will talk to the Pi over a serial connection such as 1-Wire, I2C or SPI, or you can use an Analogue to Digital convertor.

Avatar

This would be one of those applications where an arduino is more suited, I believe. With its 10bit ADC, an arduino can easily measure temperature fairly accurately with a temperature probe (or even more if necessary). Using an arduino SD-card reader, the data can be written to an sd-card in whatever way you see suit!

Avatar

Like this one? [url=http://www.flickr.com/photos/davidmam/7351822700/][img]http://farm8.staticflickr.com/7243/7351822700_52e2d3ed6b_z.jpg[/img][/url]
[url=http://www.flickr.com/photos/davidmam/7351822700/]Raspberry Pi thermometer[/url] by [url=http://www.flickr.com/people/davidmam/]davidmamartin[/url], on Flickr- I’ve been able to add a few more DS18B20 thermometers onto this without any problem on a few tens of meters of cable. Use the quick-2-wire setup, connect the GPIO7 to the data pin, bridge the data and 3V3 lines with a 4K7 resistor and you are good to go. I must write this up somewhere.

Avatar

Q1: Does the available gpio of the raspberry pi support PWM?
Q2: Can I power the raspberry pi just by connecting it to the powered usb hub that I use to on the raspberry pi to expand its usb ports?

Avatar

Yes there is a single GPIO pin that has native PWM support it is Pin 12.

You can power the Pi from the same USB hub providing the USB ports can supply the required power, some are limited to 500mA.

Avatar

Thank you very much for the quick answer!!!! It seems I have to connect it with the arduino.

Avatar

Thanks to this video and it’s helpful links, I was able to setup a similar board and create a python program that tells me how the MtGox Bitcoin Market is doing at a glance.

Green LED is flashing: Market is at it’s highest (Time to SELL!!!)
Green LED is solid: Market is above average
Yellow LED is solid: Market is below average but above lows
Red LED is flashing: Market is at it’s lowest point (Time to Buy Buy Buy!!!)

Avatar

Why did you not just a 26 pin IDC connecter it would have been so much neater. This is what was used as the printer port connector on the old BBC model B.

Avatar

Yes that is the case i used. I need to get a ribbon cable so I can put the lid back on

Avatar

Hi,

I’m very new to electronics and want to build a circuit with some protection for the pi. I can see myself ending up with a tragic mess and given the lead time to get a replacement pi it would be a very sad story in deed.

Does anyone know of a circuit design that I can use to create a buffer between my circuit and the pi that is not too complex but will stop me from breaking the pi?

Thanks for any help here.

Jason

Avatar

While surfing I have come across these addon boards that protect the RPi. I have no experience, just passing on URLs for reference.
I think this is basic protection:
http://www.thebox.myzen.co.uk/Raspberry/Buffer_Board.html
And this is more advanced:
http://www.raspberrypi.org/archives/411

Avatar

perfect for making a fully automated and voice controlled room

Avatar

I wrote a script to full step a stepper motor with my raspberry pi http://youtu.be/5mFdZ9tP6D4?hd=1
I have two complaints about using the python library.
1.) Only controlling one GPIO pin at a time rather then using a lookup table and setting all pins at once.
2.) Python 2.6.6 does not support argparse so I can pass arguments using the command line to control speed, direction, and or number of rotations etc.

In my video I am stepping slow to show the steps clearly in the video. If I reduce the sleep time between steps to sleep(.125) the motor spins fast with fluid like motion.

Avatar

Hi there out of inetrest how would the pi benefit me as a developer of c++ python and ajax.
Just out of interest because I am going to buy one since I have been doing very many development prodjects and would like the most simplest machine to modify and also control external things with it.

Avatar

Hi,
how about publishing the nice sheet shown at min 3:00?
would make a nice, important looking poster on my bulletin board ;)
Need not be in Excel format, ODS is also sufficient.

(written with my lousy school english and google-translate ;))

Greets from Hannover, Germany

Avatar

ok – just watched the video again on Youtube – and saw the description with the link ……

Avatar

Is it possible to power the Raspberry PI using a GPIO board as a 5v power source? Any special precautions, e.g. detecting if the board is being powered through USB already?

Avatar

GPIO is a great thing. Imagine things you can do with this! Add sensors and monitor things, control things. This is awesome.

Avatar

YouTube?!! Damn it. YouTube means Flash and I don’t do deprecated software – especially not on a tablet device. Any chance you can host these video on Vimeo?

Leave a Comment

Comments are closed