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.
Please select an option to see content specific to your location and shop online.
当社のウェブサイトでは、分析目的でまた広告をパーソナライズし、検索または注文を行う際に、より優れたサービスをお客様に提供するためにクッキーおよび同様の技術を使用しています。 当社のクッキーポリシーをご一読いただき、クッキー設定を変更することができます。 それ以外の場合は、Cookie を使用して問題ないものと判断します。