![Master RPI.GPIO](https://cdn.magzter.com/1387539988/1678770230/articles/8Rutehn9H1680529335985/MASTER-RPIGPIO.jpg)
Python and Raspberry Pi go hand in hand. In the early days of the Pi, there was one Python library that dominated the maker and educational scene: RPi.GPIO. It was quickly adopted by Raspberry Pi as the de facto standard means to interact with the GPIO via Python. In this tutorial, we’ll go back to the early days to learn how this communitycreated project can be used with LEDs and buttons. We’ll also talk a little about how RPi.GPIO came to be.
Project 1: Blinking LEDs
The Hello World of hardware hacking is to blink an LED and we continue this great tradition now. This project is useful to debug hardware and software before moving on to more difficult projects. Our goal is to blink an LED 10 times, and with each change of state (LED on, LED off), we print the state to the Python shell. Doing so, we confirm the code is working as it prints the message. If the LED fails to light, we have a hardware issue.
From the main Raspberry Pi menu, go to Programming and select Thonny. We start the code by importing RPi.GPIO and renaming it to GPIO:
import RPi.GPIO as GPIO
Next use the sleep function from the time module. We use this to control how long the LED is on and off:
from time import sleep
Unlike GPIO Zero, RPi.GPIO requires us to specify the GPIO’s pin mapping. The Raspberry Pi Foundation specifies that Broadcom (BCM) mapping is the standard. This makes for a little confusion as the pins are mapped to a non-sequential series of pins. The alternative board uses physical pin mapping. Pin 1 being the top-left pin nearest the microSD slot. Pin 2 is on the next column of pins. We’ll use BCM mapping:
GPIO.setmode(GPIO.BCM)
Denne historien er fra April 2023-utgaven av Linux Format.
Start din 7-dagers gratis prøveperiode på Magzter GOLD for å få tilgang til tusenvis av utvalgte premiumhistorier og 9000+ magasiner og aviser.
Allerede abonnent ? Logg på
Denne historien er fra April 2023-utgaven av Linux Format.
Start din 7-dagers gratis prøveperiode på Magzter GOLD for å få tilgang til tusenvis av utvalgte premiumhistorier og 9000+ magasiner og aviser.
Allerede abonnent? Logg på
![Create your first WebSocket service](https://reseuro.magzter.com/100x125/articles/5276/1248180/0O9EnIuy81680536957346/CREATE-YOUR-FIRST-WEBSOCKET-SERVICE.jpg)
Create your first WebSocket service
Mihalis Tsoukalos explains how to use the Go programming language to work with the WebSocket protocol.
![Fantastic Mr Firefox](https://reseuro.magzter.com/100x125/articles/5276/1248180/cykPj7kU11680536436240/FANTASTIC-MR-FIREFOX.jpg)
Fantastic Mr Firefox
Nick Peers takes a trip down memory lane to reveal the story behind the rise - and slight fall - of Mozilla's popular web browser.
![Set up your terminal and email like it's 1983](https://reseuro.magzter.com/100x125/articles/5276/1248180/VAZbwRiep1680535273421/SET-UP-YOUR-TERMINAL-AND-EMAIL-LIKE-ITS-1983.jpg)
Set up your terminal and email like it's 1983
Jump in the hot terminal time machine with Mats Tage Axelsson who emails from the command line using the latest technology.
![Universal layer text effects with GIMP](https://reseuro.magzter.com/100x125/articles/5276/1248180/7K-VCwiTB1680534818555/UNIVERSAL-LAYER-TEXT-EFFECTS-WITH-GIMP.jpg)
Universal layer text effects with GIMP
Posters use them, films and presentations are hard to imagine without them: text effects. Attract attention with Karsten Günther and GIMP.
![Jump to a federated social network](https://reseuro.magzter.com/100x125/articles/5276/1248180/PC1ABaHtO1680530556699/JUMP-TO-A-FEDERATED-SOCIAL-NETWORK.jpg)
Jump to a federated social network
Nick Peers reveals how you can get up and running with this free, decentralised and non-profit alternative to Twitter.
![Free our SOFTWARE!](https://reseuro.magzter.com/100x125/articles/5276/1248180/w6YpvpcsC1680530070840/FREE-OUR-SOFTWARE.jpg)
Free our SOFTWARE!
Taking anything for granted is dangerous, so Jonni Bidwell and Mike Saunders revisit how the free software movement got started to help free us from proprietary tyranny!
![Master RPI.GPIO](https://reseuro.magzter.com/100x125/articles/5276/1248180/8Rutehn9H1680529335985/MASTER-RPIGPIO.jpg)
Master RPI.GPIO
Les Pounder goes back to the early days of the Raspberry Pi - and his career with this classic library! -
![Waveshare Zero to Pi3](https://reseuro.magzter.com/100x125/articles/5276/1248180/WGSzYfBNe1680529008317/WAVESHARE-ZERO-TO-PI3.jpg)
Waveshare Zero to Pi3
Transform your Pi Zero into a Pi 3, they promised Les Pounder, but it's more like adding on go-faster stripes.
![The Best OPEN SOURCE Software Ever!](https://reseuro.magzter.com/100x125/articles/5276/1248180/2jlRYTgwb1680526563817/THE-BEST-OPEN-SOURCE-SOFTWARE-EVER.jpg)
The Best OPEN SOURCE Software Ever!
In an attempt to trigger controversy, Michael Reed and Neil Mohr unequivocally state these are the greatest free software apps ever. Probably. We’re just trying to be helpful.
![Linux-Mandrake 7](https://reseuro.magzter.com/100x125/articles/5276/1248180/bRg0D4SrQ1680524247505/LINUXMANDRAKE-7.jpg)
Linux-Mandrake 7
Simplicity and a wide range of applications make this a great distribution for all Linux users.