DIY Tip: How to Set Up Your Raspberry Pi

DIY Tip: How to Set Up Your Raspberry Pi

Figure 8: LED On


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
  • Keyboard
  • Mouse
  • Monitor
  • LED
  • Resistor
  • Breadboard
  • Jumper Wires
  • Computer w/ Internet connection

Table of Contents

  1. Setting Up Your Raspberry Pi
    1. Downloading NOOBs
    2. Formatting Micro SD Card (Optional)
    3. First Boot and Installing Raspbian
  2. Building the Circuit
  3. Flashing the LED
    1. Writing the Script
    2. Running the Script
  4. Appendix: (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: 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.

DIY 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.

raspberry-pi Fig2 NOOBS Initialization Screen

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:

Figure 5: Fritzing Schematic

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:

Once you’ve updated RPi.GPIO, you will make a Python script file. I named mine “LED_blink,” but feel to give it another name. To create the file, type the following in the command line:

This will take you to a new window for script editing. Copy the script I’ve placed in the appendix into the editor and save the file.

Figure 6: Running the Script from Command Line

Now type the following command (Figure 6: Running the Script from Command Line):

Your LED should now flash off (Figure 6: LED Off) and on (Figure 7: LED On) every second. To stop running the script, press “CTRL + C” on your keyboard.

Congrats! Your Raspberry Pi is set up and running. You can now use it for running scripts or other applications.

Figure 7: LED Off

Figure 8: LED On

4) Appendix: (Python Script)

  1. import RPi.GPIO as GPIO
  2. import time
  3. LedPin = 11 # pin11
  4. def setup():
  5. GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location
  6. GPIO.setup(LedPin, GPIO.OUT) # Set LedPin’s mode is output
  7. GPIO.output(LedPin, GPIO.HIGH) # Set LedPin high(+3.3V) to turn on led
  8. def blink():
  9. while True:
  10. GPIO.output(LedPin, GPIO.HIGH) # led on
  11. time.sleep(1)
  12. GPIO.output(LedPin, GPIO.LOW) # led off
  13. time.sleep(1)
  14. def destroy():
  15. GPIO.output(LedPin, GPIO.LOW) # led off
  16. GPIO.cleanup() # Release resource
  17. if __name__ == ‘__main__’: # Program start from here
  18. setup()
  19. try:
  20. blink()
  21. except KeyboardInterrupt: # When ‘Ctrl+C’ is pressed, the child program destroy() will be executed.
  22. destroy()