Kickstart Raspberry Pi With Python


In this article, I will show you how to work with Raspberry Pi using Python. Python is a wonderful and powerful programming language that's easy to use (Read and Write) with Raspberry Pi.
What you will need
  • Raspberry Pi configure with GPIO library
  • 1-Small led
  • 1-50 ohm Resistor
  • 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 us 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.
  1. import RPi.GPIO as GPIO  
  2. GPIO.setmode(GPIO.BOARD)  
  3. GPIO.setup(1, GPIO.OUT)  
  4. GPIO.output(1,True)   
  1. Import GPIO library
  2. Use board pin numbering
  3. Setup GPIO Pin 1 to OUT
  4. Turn on GPIO pin 1