Raspberry Pi Lab

Tag: GPIO

RPi GPIO Setup Script

by on Jan.02, 2014, under Code, Installation

I figure I’ll be setting up and re-setting up RPi units for the forseeable future, so I converted my last post on installing the Python libraries for the GPIO into a Bash script.

Copy and paste the code to a text file in your home directory and make sure it is executable with ‘chmod +x filename’. ┬áThen cd into your home directory and ‘./filename’ to run the script.

Here is the code…

#!/bin/bash

#####################################
# Setup the Raspberry Pi GPIO       #
# Script:  R00t  root@bjbranson.com #
# Version: 1 January 2014  V1.0     #
#                                   #
# Change Log: V1.0  Initial Script  #
#                                   #
#####################################

#########################
# CONFIGURATION SECTION #
#########################
mydir=$HOME/RPiDev

######################################
# Make sure the repository source is #
# up-to-date.                        #
######################################
echo '[I] Updating repository sources. Be Patient!'
sudo apt-get -qq update

#######################################
# Make sure the git utility is both   #
# installed and at the latest version #
#######################################
echo "[I] Verifying latest version of 'git' is installed."
sudo apt-get -y -q install git

#######################################
# Download the AdaFruit Rapberry Pi   #
# Python development libraries then   #
# list the directory to show that the #
# files were successfully downloaded  #
#######################################
if [ -d "$mydir" ]; then
   echo '[W] Specified download directory already exists.'
   echo '[I] Download of AdaFruit Python libraries skipped.'
else
   echo '[I] Downloading Python libraries from AdaFruit.'
   mkdir $mydir
   cd $mydir
   git clone http://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code.git
   cd $mydir/Adafruit-Raspberry-Pi-Python-Code
   ls
fi

#########################################
# Download and install Python libraries #
# for controlling the RPi's GPIO        #
#########################################
echo '[I] Installing Python Dev libraries for the RPi GPIO'
sudo apt-get -y -q install python-dev
sudo apt-get -y -q install python-rpi.gpio
sudo apt-get -y -q install python-pip


#################
## END OF FILE ##
#################

 

Leave a Comment :, , , , , , , , more...

Archives

All entries, chronologically...

Our Partners

Please take a minute to visit our partners

Looking for something?

Search the Site

If you can't find what you are looking for, please leave a comment somewhere, subscribe to our feed and hopefully your question will be answered shortly, so please visit again!