SlideShare a Scribd company logo
USTF
COLLEGE OF ENGINEERING & INFORMATION TECHNOLOGY
210400 ENGINEERING TRAINING I (INTERNAL TRAINING)
MICROCONTROLLERS ( RASPBERRY PI)
A microcontroller (sometimes abbreviated µC, uC or MCU) is a small computer on a single integrated
circuit containing a processor core, memory, and programmable input/output peripherals. Program
memory in the form of NOR flash or OTP ROM is also often included on chip, as well as a typically small
amount of RAM. Microcontrollers are designed for embedded applications, in contrast to the
microprocessors used in personal computers or other general purpose applications.
RASPBERRYPI
The Raspberry Pi is a low-cost credit-card sized single-board computer. The Raspberry Pi was created
in the UK by the Raspberry Pi Foundation. The Raspberry Pi Foundation's goal is to "advance the education
of adults and children, particularly in the field of computers, computer science and related subjects."
Many people have used the Raspberry Pi to make things like cameras, gaming machines, robots, web
servers and media centres.
VERSIONS
There are a few different versions of the Raspberry Pi, each made for different uses. All of the current
versions use a microSD card for the operating system and file storage. They are powered by a micro-USB
port, have one HDMI port, one audio/video jack socket, and a 40-pin GPIO connector. This is a list of the
current versions of the Raspberry Pi and their features.
• Model A+: The Model A+ is cheaper, smaller and has fewer connectors than the other versions
of the Raspberry Pi. It is made for use in small, low-power projects. It features a single-core
700 MHz ARM processor, 256MBs of RAM and one USB port.
• Model B+: The Model B+ is more expensive than the Model A+ and has more connectors and
RAM. It features a single-core 700 MHz ARM processor, 512MBs of RAM, four USB ports and
one Ethernet port.
• Raspberry Pi 2, Model B: The Raspberry Pi 2 Model B is more expensive than the other
versions of the Raspberry Pi and has much more RAM and a much faster processor. It features
a quad-core 900MHz ARM processor, 1GB of RAM, four USB ports and one Ethernet port.
FEATURES
• The Raspberry Pi uses the ARM processor architecture, which is also used by most modern
mobile phones.
• The Raspberry Pi can use the Linux operating system, or RISC OS, instead of Microsoft Windows
or Mac OS X like most computers.
• The Raspberry Pi operating system can be installed using NOOBS (recommended), or by directly
installing an operating system.
UNIX BASICS
LISTING FILES AND DIRECTORIES
ls (list)
When you first login, your current working directory is your home directory. Your home
directory has the same name as your user-name, for example, ee91ab, and it is where
your personal files and subdirectories are saved.
To find out what is in your home directory, type
The ls command ( lowercase L and lowercase S ) lists the contents of your current working
directory.
% ls
There may be no files visible in your home directory, in which case, the UNIX prompt will be
returned. Alternatively, there may already be some files inserted by the System
Administrator when your account was created.
ls does not, in fact, cause all the files in your home directory to be listed, but only those
ones whose name does not begin with a dot (.) Files beginning with a dot (.) are known as
hidden files and usually contain important program configuration information. They are
hidden because you should not change them unless you are very familiar with UNIX!!!
To list all files in your home directory including those whose names begin with a dot, type
As you can see, ls -a lists files that are normally hidden.
ls is an example of a command which can take options: -a is an example of an option. The
options change the behaviour of the command. There are online manual pages that tell you
which options a particular command can take, and how each option modifies the behaviour
of the command.
MAKING DIRECTORIES
% ls -a
mkdir (make directory)
We will now make a subdirectory in your home directory to hold the files you will be creating
and using in the course of this tutorial. To make a subdirectory called unixstuff in your
current working directory type
To see the directory you have just created, type
CHANGING TO A DIFFERENT DIRECTORY
cd (change directory)
The command cd directory means change the current working directory to 'directory'. The
current working directory may be thought of as the directory you are in, i.e. your current
position in the file-system tree.
To change to the directory you have just made, type
Type ls to see the contents (which should be empty)
THE DIRECTORIES . AND ..
Still in the unixstuff directory, type
As you can see, in the unixstuff directory (and in all other directories), there are two
special directories called (.) and (..)
THE CURRENT DIRECTORY (.)
In UNIX, (.) means the current directory, so typing
% mkdir unixstuff
% ls
% cd unixstuff
% ls -a
means stay where you are (the unixstuff directory).
This may not seem very useful at first, but using (.) as the name of the current directory will
save a lot of typing, as we shall see later in the tutorial.
THE PARENT DIRECTORY (..)
(..) means the parent of the current directory, so typing
will take you one directory up the hierarchy (back to your home directory). Try it now.
Note: typing cd with no argument always returns you to your home directory. This is very
useful if you are lost in the file system.
PATHNAMES
pwd (print working directory)
Pathnames enable you to work out where you are in relation to the whole file-system. For
example, to find out the absolute pathname of your home-directory, type cd to get back to
your home-directory and then type
The full pathname will look something like this -
which means that ee51vn (your home directory) is in the sub-directory ug1 (the group
directory),which in turn is located in the its sub-directory, which is in the home sub-
directory, which is in the top-level root directory called " / " .
% cd .
NOTE: there is a space between cd and the dot
% cd ..
% pwd
/home/its/ug1/ee51vn
COPYING FILES
cp (copy)
cp file1 file2 is the command which makes a copy of file1 in the current working
directory and calls it file2
What we are going to do now, is to take a file stored in an open access area of the file
system, and use the cp command to copy it to your unixstuff directory.
First, cd to your unixstuff directory.
Then at the UNIX prompt, type,
The above command means copy the file science.txt to the current directory, keeping the
name the same.
% cd ~/unixstuff
% cp /vol/ee/ee-info/Teaching/Unix/science.txt .
Note: Don't forget the dot . at the end. Remember, in UNIX, the dot means the current
directory.
MOVING FILES
mv (move)
mv file1 file2 moves (or renames) file1 to file2
To move a file from one place to another, use the mv command. This has the effect of
moving rather than copying the file, so you end up with only one file rather than two.
It can also be used to rename a file, by moving the file to the same directory, but giving it a
different name.
We are now going to move the file science.bak to your backup directory.
First, change directories to your unixstuff directory (can you remember how?). Then, inside
the unixstuff directory, type
Type ls and ls backups to see if it has worked.
REMOVING FILES AND DIRECTORIES
rm (remove), rmdir (remove directory)
To delete (remove) a file, use the rm command. As an example, we are going to create a
copy of the science.txt file then delete it.
Inside your unixstuff directory, type
(Note: The directory /vol/ee/ee-info/Teaching/Unix/ is an area to which everyone in
the school has read and copy access. If you are from outside the University, you can grab a
copy of the file here. Use 'File/Save As..' from the menu bar to save it into your unixstuff
directory.)
% mv science.bak backups/.
% cp science.txt tempfile.txt
% ls
You can use the rmdir command to remove a directory (make sure it is empty first). Try to
remove the backups directory. You will not be able to since UNIX will not let you remove a
non-empty directory.
RASPBERRY PI: PYTHON SCRIPTING THE GPIO
by scottkildall
The GPIO: General Purpose Input/Output lets you interface your Raspberry Pi with the outside world,
making it a powerful interactive device for just $40-$50.
This Instructable will show you how to install the GPIO package on your Raspberry Pi and how to wire
up a simple push button circuit with an LED.
I use the command-line and Python for this, no web
browser or GUI.
Before you do this Instructable, make sure you have your Raspberry Pi ready for action. My Ultimate
Raspberry Pi Configuration Guide covers how to do this in detail.
You will want to have an internet connection to download the packages and probably use ssh.
STEP 1: GATHER YOUR COMPONENTS
% rm tempfile.txt
% ls
Microcontrollers programming Raspberry Pi
Components
* Raspberry Pi
* Cobbler breakout board with cable — you can order this from Adafruit for $8.
* Breadboard
* Wires — breadboard or otherwise
* standard LED
* 270 Ohm resistor
* 1K resistor
* 10K resistor
* Push button
* USB power for RPI (not pictured)
* Monitor + keyboard (not pictured)
Tools
* wire-stripper
* small diagonal snips
* multimeter for checking continuity
STEP 2: ASSEMBLE YOUR CIRCUIT
We will have a simple push button that will turn an LED on when the button is pressed and off when it is
released. I know, it's not super-exciting, but think of this as a building block for digital input and
output.
Here is the schematic and breadboard diagram.
The LED is straightforward: 270 Ohm resistor is needed to light up the LED from a 3.3V input.
The concept is simple: the LED is an output of pin 4 and the button is an input of pin 22. The button
circuit has a pull-down resistor. Pin 22 will be pulled down to zero through the 10K resistor when the button is
inactive. When it gets pressed, the 3.3V power from the Raspberry Pi goes into thepin 22
input, bypassing the 10K resistor.
Without the 10K resistor, you'll have a floating input and will get erratic behavior in your code. The 1K
resistor protects the Raspberry Pi from too much current.
STEP 3: PUTTING IT ON THE BREADBOARD
After doing the wiring diagram in Fritzing, I laid out the components on a real breadboard. Strip the
wires and use the diagonal snips for a clean-looking breadboard.
This is what it looks like with the Cobbler breakout board before I attach the ribbon cable to the Pi.
Even with a simple circuit like this, double-check your components to make sure you're not shorting
your circuit or anything else like that.
STEP 4: CONNECT TO THE PI
Usethe breakout cable and connect the cobbler to your Raspberry Pi.
You will want to be connected to the internet to download the latest packages via Wifi or an Ethernet
cable.
Power up your Raspberry Pi.
STEP 5: INSTALL THE GPIO PACKAGE
The Raspberry Pi GPIO libraries may come with the latest versions of Wheezy, but maybe not.
Just in case, I suggest installing them again, which involves first installing the Python Development toolkit
that RPi.GPIO uses and then the GPIO package itself.
Type in
Then, for the GPIO libraries:
If asked for confirmation on either of these, press Y
You'll get the usual Linux garble like this. In my case, the Python development tools were not installed but
GPIO was.
STEP 6: BLINK AN LED IN PYTHON
sudo apt-get install python-dev
sudo apt-get install python-rpi.gpio
sudo nano gpio_blink.py
sudo python gpio_blink.py
At this point, I run the Raspberry Pi from my monitor with a keyboard plugged in — I usually do the package
updates from ssh. On the command line, create a new python script by invoking nano.
And enter in this script. The advantage with using ssh is that you can just copy-and-paste the script.
Alternatively, I have this on a GitHub repository.
# gpio_blink.py
# by Scott Kildall (www.kildall.com)
# LED is on pin 4, use a 270 Ohm resistor to ground
import RPi.GPIO as GPIO
import time
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.OUT)
state = True
# endless loop, on/off for 1 second while
True:
GPIO.output(4,True)
time.sleep(1)
GPIO.output(4,False)
time.sleep(1)
Ctrl-X, Y to save the file.
Now run the script:
Note: you have to invoke sudo — root access for the GPIO library.
sudo nano gpio_blink.py
You should have a blinking LED on your circuit. We're not using the switch at all at this point.
CTRL-C TO EXIT THE SCRIPT
how it works
- Pin 4 is an input pin. We alternate between high (True) and low (False) for 1 second at a time.
- I turn warnings off because I was getting errors in my script because the GPIO wasn't properly closed (this
shouldn't matter and I found it an annoyance).
- Setting the mode to BCM means that the pin numbers etched on the Raspberry Cobbler match the ones
that you are using in your code.
STEP 7: PYTHON SCRIPT FOR SWITCH-ACTIVATED LED
Now, we'll try adding a switch, using the same circuit. Type in:
You can also refer to the GitHub repository, if need be.
# gpio_swtich.py
# by Scott Kildall (www.kildall.com)
# LED is on pin 4, use a 270 Ohm reistor to ground
# Switch is on pin 22, use a pull-down resistor (10K) to ground
import RPi.GPIO as GPIO
import time
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.OUT)
GPIO.setup(22,GPIO.IN)
# input of the switch will change the state of the LED while True:
GPIO.output(4,GPIO.input(22))
time.sleep(0.05)
CNTL-X, Y TO SAVE THE FILE
sudo python gpio_switch.py
(note the indentations af
Now run the script:
If you press the switch, the LED should turn on and when you let it go, it should turn off. Congratulations,
you have an input and output into your Raspberry Pi.
how it works
This is like the previous script, except that we are designating Pin 22 as an input pin. We set the output of
Pin 4 to match the input of Pin 22. When Pin 22 goes high, so does Pin 4. The time.sleep(0.05) is there to
account for any debouncing in the button.
REFERENCES:
- https://simple.wikipedia.org/wiki/Raspberry_Pi
- A computer that is all on a single printed circuit board with no removable parts or external
parts needed to work.
- The Raspberry Pi Foundation, "About Us". Retrieved on 21 July 2015
- NOOBS stands for New Out Of Box Software. There are several choices of operating system available,
including Arch Linux, OpenELEC (media center), Pidora (Fedora Linux remix), raspbmc (media
center), Raspbian (recommended), and RISC OS (non-linux).
- http://www.ee.surrey.ac.uk/Teaching/Unix/
http://www.instructables.com/id/Raspberry-Pi-Python-scripting-the-GPIO/
Pre-Session Home Work
- DESCRIBE PIC 16F877, ARDUINO UNO, AND RASPBERRY PI 3 MODEL B IN YOUR OWN
WORDS CONSIDERING THE COST, HARDWARE, AND CAPABILITIES.
………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
- What is the difference between Microprocessors and Microcontrollers and is Raspberry Pi
considered one of the two types or something else?
………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
- What operating systems could be installed on the Raspberry Pi and what are they used for?
………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
Prepared by Musaab Hasan
http://musaab.info
- Unlike Windows OS, LINUX OS has a different directory structure as shown below.
Explain what each of the directories is used for.
………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
- Complete the following table according to the date of release of Raspberry Pi (0, 1, 2, 3).
Raspberry
Pi Version
Cost RAM Size Processor
Speed
Bluetooth
Version
Wi-Fi
Version
Built-in
Connections

More Related Content

PPT
Edubooktraining
PPTX
Raspberry pi introduction
PPTX
Unix operating system architecture with file structure
PPTX
Unix Administration
PDF
Linux basic
PPSX
Unix environment [autosaved]
PPTX
Introduction to Unix
Edubooktraining
Raspberry pi introduction
Unix operating system architecture with file structure
Unix Administration
Linux basic
Unix environment [autosaved]
Introduction to Unix

What's hot (20)

PPTX
Linux Command Suumary
ODP
PPTX
Introduction to Linux
PDF
PPTX
Ubuntu File System
PDF
Linux Getting Started
DOC
84640411 study-of-unix-os
ODP
Linux Introduction (Commands)
PDF
Part 2 of 'Introduction to Linux for bioinformatics': Installing software
PDF
Browsing The Source Code of Linux Packages
PPTX
Unix OS & Commands
PPTX
PPTX
PPT
Linuxppt
PPTX
Unix Operating System
DOCX
Introduction to unix
PDF
Linux Practical Manual
PDF
Techbuddy: Introduction to Linux session
PDF
Basics of Linux Commands, Git and Github
PDF
Linux intro 1 definitions
Linux Command Suumary
Introduction to Linux
Ubuntu File System
Linux Getting Started
84640411 study-of-unix-os
Linux Introduction (Commands)
Part 2 of 'Introduction to Linux for bioinformatics': Installing software
Browsing The Source Code of Linux Packages
Unix OS & Commands
Linuxppt
Unix Operating System
Introduction to unix
Linux Practical Manual
Techbuddy: Introduction to Linux session
Basics of Linux Commands, Git and Github
Linux intro 1 definitions
Ad

Similar to Microcontrollers programming Raspberry Pi (20)

PPT
Basics of unix
PDF
linux.pdf
PDF
Linux Tutorial with commands to use while learning
ODP
PPT
Shell_Scripting.ppt
ODP
ODP
ODP
Linuxppt
PPT
Tutorial 2
PDF
beginner.en.print
PDF
beginner.en.print
PDF
beginner.en.print
ODP
Nguyễn Vũ Hưng: Basic Linux Power Tools
PPT
Karkha unix shell scritping
PPTX
linux system administration for system admin jobs
PDF
Operating system lab manual
ODP
Linux introduction-commands2338
ODP
Linux introduction-commands2338
PDF
Linux Notes-1.pdf
Basics of unix
linux.pdf
Linux Tutorial with commands to use while learning
Shell_Scripting.ppt
Linuxppt
Tutorial 2
beginner.en.print
beginner.en.print
beginner.en.print
Nguyễn Vũ Hưng: Basic Linux Power Tools
Karkha unix shell scritping
linux system administration for system admin jobs
Operating system lab manual
Linux introduction-commands2338
Linux introduction-commands2338
Linux Notes-1.pdf
Ad

More from MUSAAB HASAN (14)

PDF
Communication & switching networks lab manual
PPTX
Instruction manual for E Archiving
PPTX
Instruction manual for E Archiving
PDF
A Security Study for Smart Metering Systems
PDF
Engineering design via autocad
PDF
Android Applications development Using APP inventor
PDF
Engineering Design vis Microsoft Visio
PDF
Using PCB wizard for PCB implementation
PDF
PC techniques software and Hardware
PDF
Datasheets & Searching information
PDF
Lab 1 Bag & Tag (cyber forensics)
PDF
Cyber forensics lab 4
PDF
Cyber forensics Lab
PDF
2016 ieee uae_student_day_sep_description_aau-dec-01-2015
Communication & switching networks lab manual
Instruction manual for E Archiving
Instruction manual for E Archiving
A Security Study for Smart Metering Systems
Engineering design via autocad
Android Applications development Using APP inventor
Engineering Design vis Microsoft Visio
Using PCB wizard for PCB implementation
PC techniques software and Hardware
Datasheets & Searching information
Lab 1 Bag & Tag (cyber forensics)
Cyber forensics lab 4
Cyber forensics Lab
2016 ieee uae_student_day_sep_description_aau-dec-01-2015

Recently uploaded (20)

PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Cell Structure & Organelles in detailed.
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
01-Introduction-to-Information-Management.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Cell Types and Its function , kingdom of life
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Cell Structure & Organelles in detailed.
102 student loan defaulters named and shamed – Is someone you know on the list?
Abdominal Access Techniques with Prof. Dr. R K Mishra
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
01-Introduction-to-Information-Management.pdf
O7-L3 Supply Chain Operations - ICLT Program
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Cell Types and Its function , kingdom of life
O5-L3 Freight Transport Ops (International) V1.pdf
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
A systematic review of self-coping strategies used by university students to ...
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Supply Chain Operations Speaking Notes -ICLT Program
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
human mycosis Human fungal infections are called human mycosis..pptx
Final Presentation General Medicine 03-08-2024.pptx
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf

Microcontrollers programming Raspberry Pi

  • 1. USTF COLLEGE OF ENGINEERING & INFORMATION TECHNOLOGY 210400 ENGINEERING TRAINING I (INTERNAL TRAINING) MICROCONTROLLERS ( RASPBERRY PI) A microcontroller (sometimes abbreviated µC, uC or MCU) is a small computer on a single integrated circuit containing a processor core, memory, and programmable input/output peripherals. Program memory in the form of NOR flash or OTP ROM is also often included on chip, as well as a typically small amount of RAM. Microcontrollers are designed for embedded applications, in contrast to the microprocessors used in personal computers or other general purpose applications. RASPBERRYPI The Raspberry Pi is a low-cost credit-card sized single-board computer. The Raspberry Pi was created in the UK by the Raspberry Pi Foundation. The Raspberry Pi Foundation's goal is to "advance the education of adults and children, particularly in the field of computers, computer science and related subjects." Many people have used the Raspberry Pi to make things like cameras, gaming machines, robots, web servers and media centres. VERSIONS There are a few different versions of the Raspberry Pi, each made for different uses. All of the current versions use a microSD card for the operating system and file storage. They are powered by a micro-USB port, have one HDMI port, one audio/video jack socket, and a 40-pin GPIO connector. This is a list of the current versions of the Raspberry Pi and their features. • Model A+: The Model A+ is cheaper, smaller and has fewer connectors than the other versions of the Raspberry Pi. It is made for use in small, low-power projects. It features a single-core 700 MHz ARM processor, 256MBs of RAM and one USB port. • Model B+: The Model B+ is more expensive than the Model A+ and has more connectors and RAM. It features a single-core 700 MHz ARM processor, 512MBs of RAM, four USB ports and one Ethernet port. • Raspberry Pi 2, Model B: The Raspberry Pi 2 Model B is more expensive than the other versions of the Raspberry Pi and has much more RAM and a much faster processor. It features a quad-core 900MHz ARM processor, 1GB of RAM, four USB ports and one Ethernet port.
  • 2. FEATURES • The Raspberry Pi uses the ARM processor architecture, which is also used by most modern mobile phones. • The Raspberry Pi can use the Linux operating system, or RISC OS, instead of Microsoft Windows or Mac OS X like most computers. • The Raspberry Pi operating system can be installed using NOOBS (recommended), or by directly installing an operating system. UNIX BASICS LISTING FILES AND DIRECTORIES ls (list) When you first login, your current working directory is your home directory. Your home directory has the same name as your user-name, for example, ee91ab, and it is where your personal files and subdirectories are saved. To find out what is in your home directory, type The ls command ( lowercase L and lowercase S ) lists the contents of your current working directory. % ls
  • 3. There may be no files visible in your home directory, in which case, the UNIX prompt will be returned. Alternatively, there may already be some files inserted by the System Administrator when your account was created. ls does not, in fact, cause all the files in your home directory to be listed, but only those ones whose name does not begin with a dot (.) Files beginning with a dot (.) are known as hidden files and usually contain important program configuration information. They are hidden because you should not change them unless you are very familiar with UNIX!!! To list all files in your home directory including those whose names begin with a dot, type As you can see, ls -a lists files that are normally hidden. ls is an example of a command which can take options: -a is an example of an option. The options change the behaviour of the command. There are online manual pages that tell you which options a particular command can take, and how each option modifies the behaviour of the command. MAKING DIRECTORIES % ls -a
  • 4. mkdir (make directory) We will now make a subdirectory in your home directory to hold the files you will be creating and using in the course of this tutorial. To make a subdirectory called unixstuff in your current working directory type To see the directory you have just created, type CHANGING TO A DIFFERENT DIRECTORY cd (change directory) The command cd directory means change the current working directory to 'directory'. The current working directory may be thought of as the directory you are in, i.e. your current position in the file-system tree. To change to the directory you have just made, type Type ls to see the contents (which should be empty) THE DIRECTORIES . AND .. Still in the unixstuff directory, type As you can see, in the unixstuff directory (and in all other directories), there are two special directories called (.) and (..) THE CURRENT DIRECTORY (.) In UNIX, (.) means the current directory, so typing % mkdir unixstuff % ls % cd unixstuff % ls -a
  • 5. means stay where you are (the unixstuff directory). This may not seem very useful at first, but using (.) as the name of the current directory will save a lot of typing, as we shall see later in the tutorial. THE PARENT DIRECTORY (..) (..) means the parent of the current directory, so typing will take you one directory up the hierarchy (back to your home directory). Try it now. Note: typing cd with no argument always returns you to your home directory. This is very useful if you are lost in the file system. PATHNAMES pwd (print working directory) Pathnames enable you to work out where you are in relation to the whole file-system. For example, to find out the absolute pathname of your home-directory, type cd to get back to your home-directory and then type The full pathname will look something like this - which means that ee51vn (your home directory) is in the sub-directory ug1 (the group directory),which in turn is located in the its sub-directory, which is in the home sub- directory, which is in the top-level root directory called " / " . % cd . NOTE: there is a space between cd and the dot % cd .. % pwd /home/its/ug1/ee51vn
  • 6. COPYING FILES cp (copy) cp file1 file2 is the command which makes a copy of file1 in the current working directory and calls it file2 What we are going to do now, is to take a file stored in an open access area of the file system, and use the cp command to copy it to your unixstuff directory. First, cd to your unixstuff directory. Then at the UNIX prompt, type, The above command means copy the file science.txt to the current directory, keeping the name the same. % cd ~/unixstuff % cp /vol/ee/ee-info/Teaching/Unix/science.txt . Note: Don't forget the dot . at the end. Remember, in UNIX, the dot means the current directory.
  • 7. MOVING FILES mv (move) mv file1 file2 moves (or renames) file1 to file2 To move a file from one place to another, use the mv command. This has the effect of moving rather than copying the file, so you end up with only one file rather than two. It can also be used to rename a file, by moving the file to the same directory, but giving it a different name. We are now going to move the file science.bak to your backup directory. First, change directories to your unixstuff directory (can you remember how?). Then, inside the unixstuff directory, type Type ls and ls backups to see if it has worked. REMOVING FILES AND DIRECTORIES rm (remove), rmdir (remove directory) To delete (remove) a file, use the rm command. As an example, we are going to create a copy of the science.txt file then delete it. Inside your unixstuff directory, type (Note: The directory /vol/ee/ee-info/Teaching/Unix/ is an area to which everyone in the school has read and copy access. If you are from outside the University, you can grab a copy of the file here. Use 'File/Save As..' from the menu bar to save it into your unixstuff directory.) % mv science.bak backups/. % cp science.txt tempfile.txt % ls
  • 8. You can use the rmdir command to remove a directory (make sure it is empty first). Try to remove the backups directory. You will not be able to since UNIX will not let you remove a non-empty directory. RASPBERRY PI: PYTHON SCRIPTING THE GPIO by scottkildall The GPIO: General Purpose Input/Output lets you interface your Raspberry Pi with the outside world, making it a powerful interactive device for just $40-$50. This Instructable will show you how to install the GPIO package on your Raspberry Pi and how to wire up a simple push button circuit with an LED. I use the command-line and Python for this, no web browser or GUI. Before you do this Instructable, make sure you have your Raspberry Pi ready for action. My Ultimate Raspberry Pi Configuration Guide covers how to do this in detail. You will want to have an internet connection to download the packages and probably use ssh. STEP 1: GATHER YOUR COMPONENTS % rm tempfile.txt % ls
  • 10. Components * Raspberry Pi * Cobbler breakout board with cable — you can order this from Adafruit for $8. * Breadboard * Wires — breadboard or otherwise * standard LED * 270 Ohm resistor * 1K resistor * 10K resistor * Push button * USB power for RPI (not pictured) * Monitor + keyboard (not pictured) Tools * wire-stripper * small diagonal snips * multimeter for checking continuity STEP 2: ASSEMBLE YOUR CIRCUIT
  • 11. We will have a simple push button that will turn an LED on when the button is pressed and off when it is released. I know, it's not super-exciting, but think of this as a building block for digital input and output. Here is the schematic and breadboard diagram. The LED is straightforward: 270 Ohm resistor is needed to light up the LED from a 3.3V input. The concept is simple: the LED is an output of pin 4 and the button is an input of pin 22. The button circuit has a pull-down resistor. Pin 22 will be pulled down to zero through the 10K resistor when the button is inactive. When it gets pressed, the 3.3V power from the Raspberry Pi goes into thepin 22 input, bypassing the 10K resistor. Without the 10K resistor, you'll have a floating input and will get erratic behavior in your code. The 1K resistor protects the Raspberry Pi from too much current. STEP 3: PUTTING IT ON THE BREADBOARD
  • 12. After doing the wiring diagram in Fritzing, I laid out the components on a real breadboard. Strip the wires and use the diagonal snips for a clean-looking breadboard. This is what it looks like with the Cobbler breakout board before I attach the ribbon cable to the Pi. Even with a simple circuit like this, double-check your components to make sure you're not shorting your circuit or anything else like that. STEP 4: CONNECT TO THE PI Usethe breakout cable and connect the cobbler to your Raspberry Pi. You will want to be connected to the internet to download the latest packages via Wifi or an Ethernet cable. Power up your Raspberry Pi. STEP 5: INSTALL THE GPIO PACKAGE
  • 13. The Raspberry Pi GPIO libraries may come with the latest versions of Wheezy, but maybe not. Just in case, I suggest installing them again, which involves first installing the Python Development toolkit that RPi.GPIO uses and then the GPIO package itself. Type in Then, for the GPIO libraries: If asked for confirmation on either of these, press Y You'll get the usual Linux garble like this. In my case, the Python development tools were not installed but GPIO was. STEP 6: BLINK AN LED IN PYTHON sudo apt-get install python-dev sudo apt-get install python-rpi.gpio
  • 14. sudo nano gpio_blink.py sudo python gpio_blink.py At this point, I run the Raspberry Pi from my monitor with a keyboard plugged in — I usually do the package updates from ssh. On the command line, create a new python script by invoking nano. And enter in this script. The advantage with using ssh is that you can just copy-and-paste the script. Alternatively, I have this on a GitHub repository. # gpio_blink.py # by Scott Kildall (www.kildall.com) # LED is on pin 4, use a 270 Ohm resistor to ground import RPi.GPIO as GPIO import time GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(4, GPIO.OUT) state = True # endless loop, on/off for 1 second while True: GPIO.output(4,True) time.sleep(1) GPIO.output(4,False) time.sleep(1) Ctrl-X, Y to save the file. Now run the script:
  • 15. Note: you have to invoke sudo — root access for the GPIO library.
  • 16. sudo nano gpio_blink.py You should have a blinking LED on your circuit. We're not using the switch at all at this point. CTRL-C TO EXIT THE SCRIPT how it works - Pin 4 is an input pin. We alternate between high (True) and low (False) for 1 second at a time. - I turn warnings off because I was getting errors in my script because the GPIO wasn't properly closed (this shouldn't matter and I found it an annoyance). - Setting the mode to BCM means that the pin numbers etched on the Raspberry Cobbler match the ones that you are using in your code. STEP 7: PYTHON SCRIPT FOR SWITCH-ACTIVATED LED Now, we'll try adding a switch, using the same circuit. Type in: You can also refer to the GitHub repository, if need be. # gpio_swtich.py # by Scott Kildall (www.kildall.com) # LED is on pin 4, use a 270 Ohm reistor to ground # Switch is on pin 22, use a pull-down resistor (10K) to ground import RPi.GPIO as GPIO import time GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(4, GPIO.OUT) GPIO.setup(22,GPIO.IN) # input of the switch will change the state of the LED while True: GPIO.output(4,GPIO.input(22)) time.sleep(0.05)
  • 17. CNTL-X, Y TO SAVE THE FILE
  • 18. sudo python gpio_switch.py (note the indentations af Now run the script: If you press the switch, the LED should turn on and when you let it go, it should turn off. Congratulations, you have an input and output into your Raspberry Pi. how it works This is like the previous script, except that we are designating Pin 22 as an input pin. We set the output of Pin 4 to match the input of Pin 22. When Pin 22 goes high, so does Pin 4. The time.sleep(0.05) is there to account for any debouncing in the button. REFERENCES: - https://simple.wikipedia.org/wiki/Raspberry_Pi - A computer that is all on a single printed circuit board with no removable parts or external parts needed to work. - The Raspberry Pi Foundation, "About Us". Retrieved on 21 July 2015 - NOOBS stands for New Out Of Box Software. There are several choices of operating system available, including Arch Linux, OpenELEC (media center), Pidora (Fedora Linux remix), raspbmc (media center), Raspbian (recommended), and RISC OS (non-linux). - http://www.ee.surrey.ac.uk/Teaching/Unix/ http://www.instructables.com/id/Raspberry-Pi-Python-scripting-the-GPIO/
  • 19. Pre-Session Home Work - DESCRIBE PIC 16F877, ARDUINO UNO, AND RASPBERRY PI 3 MODEL B IN YOUR OWN WORDS CONSIDERING THE COST, HARDWARE, AND CAPABILITIES. ……………………………………………………………………………………………………………… ……………………………………………………………………………………………………………… ……………………………………………………………………………………………………………… ……………………………………………………………………………………………………………… ……………………………………………………………………………………………………………… ……………………………………………………………………………………………………………… ……………………………………………………………………………………………………………… ……………………………………………………………………………………………………………… - What is the difference between Microprocessors and Microcontrollers and is Raspberry Pi considered one of the two types or something else? ……………………………………………………………………………………………………………… ……………………………………………………………………………………………………………… ……………………………………………………………………………………………………………… ……………………………………………………………………………………………………………… ……………………………………………………………………………………………………………… ……………………………………………………………………………………………………………… ……………………………………………………………………………………………………………… ……………………………………………………………………………………………………………… - What operating systems could be installed on the Raspberry Pi and what are they used for? ……………………………………………………………………………………………………………… ……………………………………………………………………………………………………………… ……………………………………………………………………………………………………………… ……………………………………………………………………………………………………………… ……………………………………………………………………………………………………………… ……………………………………………………………………………………………………………… ……………………………………………………………………………………………………………… ………………………………………………………………………………………………………………
  • 20. Prepared by Musaab Hasan http://musaab.info - Unlike Windows OS, LINUX OS has a different directory structure as shown below. Explain what each of the directories is used for. ……………………………………………………………………………………………………………… ……………………………………………………………………………………………………………… ……………………………………………………………………………………………………………… ……………………………………………………………………………………………………………… ……………………………………………………………………………………………………………… ……………………………………………………………………………………………………………… ……………………………………………………………………………………………………………… ……………………………………………………………………………………………………………… - Complete the following table according to the date of release of Raspberry Pi (0, 1, 2, 3). Raspberry Pi Version Cost RAM Size Processor Speed Bluetooth Version Wi-Fi Version Built-in Connections