Introduction
In this article, I will show you how to work with Raspberry Pi using Python.
Python is a wonderful and a powerful programming language that's easy to use (Read and Write) with Raspberry Pi.
- Raspberry Pi configure with GPIO library
- 1-Small led
- 1-50 ohm Resisitor
- Some solid core wires
- Bread Board
Let there be light
Before we get around to write the code, let's first get acquainted with the pin numbering of our RPI and create a simple circuit.
- Pin 1 (+3.3v) should go to longer led to the led Pin.
- Attach the shorter led pin to the resistor and finally attach the other end of the resistor to pin-6(GND) on your RPI.
Figure1 - Connection
Controlling the led with our python code
I like to write Python code in IDLE IDE because it comes packaged with Raspbian distribution as it's free and allows to write to our cod a little bit easier than Python command line or a text editor.
- Power on your RPI and boot all the way in the operating system GUI.
- Open the terminal and launch the IDLE IDE.
- Click File > New to open a new window.
Code
- import RPi.GPIO as GPIO
- GPIO.setmode(GPIO.BOARD)
- GPIO.setup(1, GPIO.OUT)
- GPIO.output(1,True)
- Import GPIO library
- Use board pin numbering
- Setup GPIO Pin 1 to OUT
- Turn on GPIO pin 1