Raspberry Pi is a series of single-board computers used by DIYers, hobbyists, and students. The series was founded to promote computer science education around the world. The difference between Arduino and Raspberry Pi is Arduinos are microcontroller-based boards while Raspberry Pi boards are microprocessor-based and run an operating system (OS). In this tutorial I am going to show you how to set up your Raspberry Pi by booting an OS disk image. I will then demonstrate using the GPIO to flash an LED ON and OFF every second.
Estimated Time to Complete: 45min.-1hr.
Parts and Equipment Needed
Raspberry Pi 3 Model B
Micro SD Card
Micro USB Cable
Computer w/ Internet connection
Table of Contents
Setting Up Your Raspberry Pi
Formatting Micro SD Card (Optional)
First Boot and Installing Raspbian
Building the Circuit
Flashing the LED
Writing the Script
Running the Script
Appendix: LED_flash.py (Python Script)
1) Setting Up Your Raspberry Pi: Downloading NOOBS
As I stated in the overview, Raspberry Pis are microcomputers that run an operating system. In this tutorial, I will show you how to install the OS Raspbian. Raspbian is a Linux-based OS and is the supported OS of the Raspberry community.
The first step is to download the latest version of NOOBS (New Out Of Box Software) from here: https://www.raspberrypi.org/downloads/noobs/. NOOBS is an OS installer and is used to install different OSs on your Raspberry Pi.
Note: If the micro SD card you purchased has NOOBS pre-installed you can skip this and the next step.
If your micro SD card is new you may need to format it. You can do this with SD Card Formatter 4.0. This step is optional.
Once NOOBS is installed and your SD card is formatted, you can copy all the extracted NOOBS files to the SD card. Make sure you copy all the files within the folder and don’t just copy the folder itself, otherwise NOOBS will not boot. Remove the SD card from your computer and insert it into your Raspberry Pi.
Figure 1: Raspberry Pi
You are now ready to boot your Raspberry Pi for the first time. Connect your keyboard, mouse, and monitor to your Raspberry Pi (Figure 1: Raspberry Pi). Plug in your USB cable to apply power to your Raspberry Pi; your Pi will boot and a window will appear (Figure 2: NOOBS Initialization Screen). This will list all the different OSs that you can install. Since we want to install Raspbian Lite, check the box to select Raspbian Lite and then click “Install” (Figure 3: OS Install Selection (NOOBS)). NOOBS will now install Raspbian Lite. Be patient; it may take 10-20 minutes.
After the install you will be asked to login. The default login for Raspbian is username: pi, password: raspberry. NOTE: When typing the password, you will not see characters typed out. The remaining directions in this tutorial use the command line.
Figure 2: NOOBS Initialization Screen
Figure 3: OS Install Selection (NOOBS)
Figure 4: NOOBS Installing Raspbian Lite
2) Building the Circuit
The circuit we are building is simple. I am using a breadboard to make the circuit; feel free to the solder the components together or to make a shield out of a protoboard for your Raspberry Pi. I like to make Fritzing schematics of my circuits before building them (Figure 5: Fritzing Schematic). Fritzing is an open-source schematic capture and PCB routing software. If you wish to download Fritzing, it is here: http://fritzing.org/home/.
The LED and resistor should be connected in series between Pin 11 (GPIO17) and Pin 25 (Ground). The resistor is there to limit current through the LED and should be sized accordingly depending on your LED to prevent burning it out. Remember the longer lead on the LED is positive and should be connected to Pin 11.
3) Writing the Code
To flash the LED we are going to write and run a Python script. Python is an interpreted program language. I am not going to go into the details of Python in this tutorial, however I will show you how to write a script in Python on your Raspberry Pi and then run the script. You can then use this knowledge to write other scripts in Python and utilize the GPIO on the Raspberry Pi. Make sure your Raspberry Pi is connected to the Internet before moving on.
The first step is to make sure you have the latest version of RPi.GPIO. RPi.GPIO is a Python library that is used to control Raspberry Pi GPIO pins. To update to the latest version, type the following two commands in the command line: