Professional Documents
Culture Documents
Name:UNSA JAN
CMS ID: 033-19-0048
Semester: VII
Required Components:
1. Raspberry Pi
2. Micro SD card
3. USB Card reader
4. HDMI Cable
5. Monitor with HDMI port
6. Keyboard
7. Mouse
8. USB-Micro USB cable
9. Mobile Robot Chassis with motors
10. Battery
11. Motor Driver circuit board
12. LED and a resistor
13. Connecting wires
1. Download NOOBs (New Out Of the Box Software) an straightforward way to install an
operating system on Pi from https://www.raspberrypi.org/downloads/noobs/.
2. Insert the USB card reader (with SD card) in the USB port of the PC.
3. Copy extracted contents of “NOOB.zip” file on SD card.
4. Insert the SD card in Raspberry Pi.
5. Connect HDMI cable between a monitor and the Raspberry Pi. Also connect a mouse and
keyboard with the Pi.
6. Power on Pi using USB-Micro USB cable.
7. Follow the installation process on Monitor to install the Raspbian OS.
Accessing GPIOs:
In order to access (read/write) GPIOs we ned to write a program file in Python within the Raspberry
and execute it. Perform following steps to make an LED blink using Raspberry Pi.
1. Turn on the Raspberry Pi and make a connection with an LED as shown in figure.
Note that the Anode of the LED is connected with Pin no. 8 through a resistor.
2. Create a new file on Desktop with name “LED_blink.py”
3. Copy and Paste following code in the file.
4. Open terminal and write this command “chmod +x /Desktop/LED_blink.py”
This make the file executable.
5. Run this command on terminal. “./Desktop/LED_blink.py”
________________________________________________________________________________
import RPi.GPIO as GPIO # Import Raspberry Pi GPIO library
from time import sleep # Import the sleep function from the time module
GPIO.setwarnings(False) # Ignore warning for now
GPIO.setmode(GPIO.BOARD) # Use physical pin numbering
GPIO.setup(12, GPIO.OUT, initial=GPIO.LOW) # Set pin 12 to be an output pin and set initial
value to low (off)
#U-Turn
El.ChangeDutyCycle(25)
Er.ChangeDutyCycle(100)
GPIO.output(10, GPIO.HIGH);
GPIO.output(12, GPIO.LOW);
GPIO.output(22, GPIO.HIGH);
GPIO.output(16, GPIO.LOW);
sleep(2)
2. Make the robot move forward for 2 seconds and then make a random radial turn slowly.
Code
import RPi.GPIO as GPIO # Import Raspberry Pi GPIO library
import random
#from time import sleep Import the sleep function from the time module
GPIO.setwarnings(False)# ignore warning for now
num = random.randint(0,9)
print(num)
#Random Right
if num<=5:
print('Random RIGHT')
El.ChangeDutyCycle(30)
GPIO.output(10, GPIO.LOW);
GPIO.output(12, GPIO.LOW);
sleep(2)
#Random Left
if num>=6:
print('Random LEFT')
Er.ChangeDutyCycle(30)
sleep(2)
3. Make the robot move forward for 2 seconds and then make a random axial turn slowly.
Code
import RPi.GPIO as GPIO # Import Raspberry Pi GPIO library
import random
#from time import sleep Import the sleep function from the time module
GPIO.setwarnings(False)# ignore warning for now
num = random.randint(0,9)
print(num)
El.ChangeDutyCycle(30)
Er.ChangeDutyCycle(30)
Note: Use H-Bridge to interface Pi GPIOs with the robot chassis motors. Raspberry Pi 4 has
different GPIO configuration than Pi 3. Please refer Raspberry Pi 4 manual for Pin configuration.
Rubrics for Lab Task Assessment
80% 20 % 100 %