Here’s a neat trick to impress your friends at parties. Control your LEDs via the GPIO pins with nothing more than your trusty Raspberry Pi. It’s pretty easy to do if you’re in the know. So we thought we’d let you in on the secret. And help you to see the light.
The main thing is to figure out how to program the GPIO pins on the Raspberry Pi as digital outputs. It’s these pins that will control your LEDs plus a seven segment LED display.
All set? Let’s go…
Your Pi has a few General Purpose Input Output (GPIO) pins which can be programmed as DIGITAL inputs or outputs. Digital inputs and outputs can only ever be “ON” (digital state “1”) or “OFF” (digital state “0”).
You’ll find the GPIO pins tucked away at one corner of your Pi:
You’ll have 40 pins in all, and they’re used for a ton of stuff. You don’t have to know what they all do, but you do have to note how they’re numbered.
As ever, we’ve split the exercises into 3 steps of increasing complexity.
We start off by checking out the integrated development environment as well as basic Python by entering commands at the Python prompt. We’ll also look at “user privileges” under Linux (really, it’s beyond the scope of this exercise, but what the heck).
On to step 2… and here we’ll show you how to create a file containing a set of Python commands, saving the file as a “computer program” and then “running” it. On the way we’ll explore compiler warning and error messages – and just how useful they really are.
Finally, we’ll see how to open and edit a file, plus how to re-use Python code. Here we’ll also look at adding comments to code to make it more user friendly, and we’ll finish by showing you how to assign values to variables.
We created these exercises using a Raspberry Pi Model B with a 26 Way GPIO Pin header. Newer models have a 40 Way GPIO header, but the first 26 pins ae the same.
Now check out these exercises and our Raspberry Pi Setup guides. And with a little help from us, you’ll soon see the light.
Notre site Web utilise des cookies et des technologies similaires pour vous fournir un meilleur service lorsque vous effectuez une recherche et passez une commande, à des fins d'analyse ou pour personnaliser nos publicités. Vous pouvez modifier vos paramètres de cookies en lisant notre politique en matière de cookie. Faute de quoi, nous considérerons que vous acceptez notre utilisation des cookies.
Please select an option to see content specific to your location and shop online.