You are on page 1of 16

LAB SHEET

PRACTICAL 1

Objective Navigating the File System


Software Raspberry Pi Shell
Requirement

STEP 1:
Open the Raspberry Pi Shell terminal

STEP 2:

Type in pwd

pi@raspberry:~ $ pwd

And see what is returned


The Output is the current directory that the shell is opened in

STEP 3:

Type in ls

pi@raspberry:~ $ ls

And see what is returned


The Output should be empty, this means that the directory is empty.
STEP 4:

Type in cd Desktop

pi@raspberry:~ $ cd Desktop/

And see what is returned


What should happen is now you are in the Desktop directory

Now type in ls

pi@raspberry:~/Desktop $ ls

And see what is returned is the same as what is the contents of the GUI of the Desktop

STEP 5:

Now we are going to create a New File called NewFile.txt


Type in touch NewFile.txt

pi@raspberry:~/Desktop $ touch NewFile.txt

And see what is returned


What should happen is now NewFile.txt is created

Now type in ls

pi@raspberry:~/Desktop $ ls

And see what is returned is the same as what is the contents of the GUI of the Desktop
STEP 7:

Now we are going to edit the file


Type in nano NewFile.txt

pi@raspberry:~/Desktop $ nano NewFile.txt

Now type anything you want here


Press Ctrl+X when you are done and want to Save, Then press Y and then Press Enter

STEP 8:

Now we are going to delete this file


Type in rm NewFile.txt

pi@raspberry:~/Desktop $ rm NewFile.txt

Now type in ls

pi@raspberry:~/Desktop $ ls

And see if the NewFile.txt has been deleted


PRACTICAL 2

Objective WiringPi Setup and Led Blink


Hardware 1. Raspberry Pi
Requirement 2. Breadboard
3. LED
4. Resistor
5. 2 female-to-male Jumper Wire

STEP 1: Setup As Below


GPIO 17/PIN 11 to Anode of LED (REFER Raspberry Pi Gpio Pins)
GND/PIN 6 to Resistor Cathode of LED

STEP 2:
First we need to download the wiringPi Library on the Raspberry Pi
Open Up Shell terminal
Type in git clone git://git.drogon.net/wiringPi

pi@raspberry:~ $ git clone git://git.drogon.net/wiringPi


Then Wait until it is downloaded
Then type in cd wiringPi
pi@raspberry:~ $ cd wiringPi
Then type in ./build
pi@raspberry:~/wiringPi $ ./build
Wait until it is completed
STEP 3:
Open Up Geany to create a C++ project
Click Menu, then click Programming and then Click Geany

Click On File, Then Click On New

Go to Desktop and Create new Folder


Then Click File, Click Save As
Then Save the file as led.cpp in the new Folder
STEP 4:

#include <stdio.h>
#include <wiringPi.h>

int main(void)
{
printf(“Raspberry Pi Led Control C++\n”);
wiringPiSetupGpio();
int LED = 17;
pinMode(LED, OUTPUT);
for (int x=0; x<5;x++)
{
digitalWrite(LED,HIGH);
delay(500);
digitalWrite(LED,LOW);
delay(500);
}
return 0;
}
Write the C++ source code below:
Once Written Press Ctrl+S to Save

STEP 5:
Press Build, then press Set Build Commands

At Build add the “-l wiringPi” at the end


-l is L NOT ONE

Then Press Ok and press F9 to Build, Press F5 to Execute, wait for the LED to blink 5 times
PRACTICAL 4

Objective Push Button With LED


Hardwar 1. Raspberry Pi
Requirement 2. Breadboard
3. LED
4. Push Button
5. 3 Resistor
6. Jumper Wire

STEP 1: Setup As Below


3.3V/PIN 1 to Resistor of Button (REFER Raspberry Pi Gpio Pins)
GND/PIN 6 to GND of Button and LED(Resistor) Cathode(Breadboard)
GPIO 18/PIN 12 to Resistor of Button
GPIO 17/PIN 11 to ANODE of LED
STEP 2:

Open Geany and Write this Code into Geany

#include <stdio.h>
#include <wiringPi.h>

int main(void)
{
printf(“Raspberry Pi Button Check C++\n”);
wiringPiSetupGpio();
int isButtonPin = 17;
int ledShine = 18;
pinMode(isButtonPin,INPUT);
pinMode(ledShine,OUTPUT);
int prevButton = HIGH, LED =0;
digitalWrite(ledShine,LOW);

for (;;)
{
if (prevButton == HIGH && digitalRead(isButtonPin) == LOW);
{
prevButton = LOW;

if (LED)
{
LED = 0;
digitalWrite(ledShine,LOW);
}
else
{
LED =1;
digitalWrite(ledShine,HIGH);
}
}
else if (prevButton == LOW && digitalRead(isButtonPin) == HIGH)
{
prevButton=HIGH;
}

}
return 0;
}

STEP 3:
Press F9 to Build
Press F5 to Execute and Observe the Shell Terminal
PRACTICAL 5

Objective Push Button With Buzzer


Hardware 1. Raspberry Pi
Requirement 2. Breadboard
3. Buzzer
4. Push Button
5. 3 Resistor
6. Jumper Wire

STEP 1: Setup As Below


Buzzer: + = 5v
- = GND
OUT = 17
3.3V/PIN 1 to Resistor of Button (REFER Raspberry Pi Gpio Pins)
GND/PIN 6 to GND of Button
GPIO 18 to Resistor Button
STEP 2:

Open Geany and Write this Code into Geany

#include <stdio.h>
#include <wiringPi.h>

int main(void)
{
printf(“Raspberry Pi Buzzer Check C++\n”);
wiringPiSetupGpio();
int isButtonPin = 17;
int isBuzzerPin = 18;
pinMode(isButtonPin,INPUT);
pinMode(isBuzzerPin,OUTPUT);
int prevButton = HIGH, Buzzers =0;
digitalWrite(isBuzzerPin,HIGH);

for (;;)
{
if (prevButton == HIGH && digitalRead(isButtonPin) == LOW);
{
prevButton = LOW;

if (Buzzers)
{
Buzzers = 0;
digitalWrite(isBuzzerPin,LOW);
}
else
{
Buzzers =1;
digitalWrite(isBuzzerPin,HIGH);
}
}
else if (prevButton == LOW && digitalRead(isButtonPin) == HIGH)
{
prevButton=HIGH;
}
delay(5);
}
return 0;
}

STEP 3:
Press F9 to Build ->Press F5 to Execute and Observe the Shell Terminal
PRACTICAL 6

Objective Sound Sensor


Hardware 1. Raspberry Pi
Requirement 2. Breadboard
3. Sound Sensor
4. Led
5. Resistor
6. 2 female-to-female Jumper Wire
7. 3 female-to-male Jumper Wire
8. 1 male-to-male Jumper Wire

STEP 1: Setup As Below


3.3V/PIN 1 to VCC of Sound Sensor (REFER Raspberry Pi Gpio Pins)
GND/PIN 6 to GND of IR Sensor and LED(Resistor) Cathode(Breadboard)
GPIO 18/PIN 12 to OUT of Sound Sensor
GPIO 17/PIN 11 to ANODE of LED
STEP 2:

Open Geany and Write this Code into Geany

#include <stdio.h>
#include <wiringPi.h>

int main(void)
{
printf(“Raspberry Pi Sound Check C++\n”);
wiringPiSetupGpio();
int isSoundPin = 18;
int led = 17;
pinMode(isSoundPin,INPUT);
pinMode(led,OUTPUT);
for (int x=0; x<20;x++)
{
if (digitalRead(isSoundPin));
{
printf(“There is NO SOUND!\n”);
digitalWrite(led,LOW);
}
else
{
printf(“There is SOUND!\n”);
digitalWrite(led,HIGH);
}
delay(500);
}
return 0;
}

STEP 3:
Press F9 to Build
Press F5 to Execute
Observe the Shell Terminal
PRACTICAL 7

Objective IR Sensor
Hardwar 1. Raspberry Pi
Requirement 2. Breadboard
3. IR sensor
4. 3 female-to-female Jumper Wire

STEP 1: Setup As Below


5V/PIN 2 to VCC of IR Sensor (REFER Raspberry Pi Gpio Pins)
GND/PIN 6 to GND of IR Sensor
GPIO 18/PIN 12 to OUT of IR Sensor
STEP 2:

Open Geany and Write this Code into Geany

#include <stdio.h>
#include <wiringPi.h>

int main(void)
{
printf(“Raspberry Pi IR Check C++\n”);
wiringPiSetupGpio();
int isObstaclePin = 18;
pinMode(isObstaclePin,INPUT);
for (int x=0; x<10;x++)
{
if (digitalRead(isObstaclePin));
{
printf(“There is NO OBSTACLE!\n”);
}
else
{
printf(“There is OBSTACLE!\n”);
}
delay(500);
}
return 0;
}

STEP 3:
Press F9 to Build
Press F5 to Execute
Observe the Shell Terminal

You might also like