EasyManua.ls Logo

Raspberry Pi B User Manual

Raspberry Pi B
2 pages
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #2 background imageLoading...
Page #2 background image
Controlling the GPIO in python
You can simulate and test these commands without a RPi on create.withcode.uk
Import the GPIO module
Youll need to do this once at the start of your code so
that you can use the GPIO module to access the inputs
and outputs.
Setup inputs and outputs
All I/O pins are set to be inputs unless you write code to make them outputs.
This example sets the RPi to use physical pin
numbering then sets physical pin 3 to be an output.
Change GPIO.BOARD to GPIO.BCM if you want BCM pin numbering instead of physical pin numbering
Change GPIO.OUT to GPIO.IN if you want to set a pin back to being an input
Reading inputs and setting outputs
The time module is useful for adding delays to
pause your program
Weve set up physical pin 3 (BCM2) as an
output and physical pin 5 (BCM 3) as an input:
GPIO.output sends a value to an output pin
time.sleep(1) pauses the program for 1
second
GPIO.input reads a value from an input pin
You can run this code online with a simulated Raspberry Pi here;
https://create.withcode.uk/python/A3
Question and Answer IconNeed help?

Do you have a question about the Raspberry Pi B and is the answer not in the manual?

Raspberry Pi B Specifications

General IconGeneral
GPUBroadcom VideoCore IV
RAM512 MB
Audio Outputs3.5 mm jack, HDMI
GPIO26-pin header
Power5 V via Micro USB or GPIO header
ProcessorBroadcom BCM2835
CPU700 MHz ARM1176JZF-S core
USB Ports2
Video OutputsHDMI, Composite RCA (PAL and NTSC)
StorageSD card
Ethernet10/100 Mbit/s

Summary

Raspberry Pi GPIO Fundamentals

GPIO Pin Types and Functions

Details GPIO pins as power or I/O, explaining input and output capabilities.

GPIO Pin Numbering Conventions

Explains the physical and BCM numbering systems used for GPIO pins.

Critical GPIO Connection Safety

Provides essential warnings for connecting to GPIO pins to prevent RPi damage.

Controlling GPIO with Python

Importing the RPi.GPIO Module

Shows how to import the necessary RPi.GPIO library for Python control.

Configuring GPIO Pins

Explains setting pin numbering modes and configuring pins as inputs or outputs.

Reading and Writing GPIO States

Demonstrates Python code for reading digital inputs and setting digital outputs with timing.

Related product manuals