Difference between revisions of "Digital Electronics (USIU)"

From Raspberry Pi Min-Grant project
Jump to: navigation, search
(Created page with "== Digital Electronics == === Study of Logic Gates – AND, OR, NOT, NAND, NOR, XOR === LABORATORY 1 ===== EXPLORING RASPBERRY PI ===== ======  Pre-Lab Exercise 1:&nb...")
 
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
== Digital Electronics ==
 
== Digital Electronics ==
  
=== Study of Logic Gates – AND, OR, NOT, NAND, NOR, XOR ===
+
=== Study of Logic Gates – AND, OR, NOT ===
  
LABORATORY 1
+
====== In-Lab Exercise 1: Realizing a AND gate ======
  
===== EXPLORING RASPBERRY PI =====
+
*'''Step 1  Connect the Circuit as shown in the image below'''
  
======  Pre-Lab Exercise 1:  Installing OS on Raspberry PI ======
+
[[File:Lab1-1.png|RTENOTITLE]]
  
The RPI will not boot up without an SD Card that is properly formatted to contain a suitable boot loader and operating system.
+
*'''Step 2'''  load the python code into your favorite code editor and copy paste the following code and save it as buttonpressed.py
  
The distribution we have chosen to run in this lab and subsequent labs is called Raspbian.
+
In our case we used the command line and opened the nano editor and added the following code
  
We will use NOOBS operating system installer to install Raspbian
+
<span style="font-family:courier new,courier,monospace">'''#''nano buttonpressed.py'''''</span>
  
#Using a computer with an SD card reader, visit the&nbsp;raspberry pi official downloads&nbsp;page.
+
''import RPi.GPIO as GPIO''
  
http://raspberry.kenet.or.ke/images/5/59/Noobs1.png
+
''import time''
  
[https://www.raspberrypi.org/downloads/ https://www.raspberrypi.org/downloads/]
+
''#import random''
  
#Click on the <code>download ZIP</code> button under ‘NOOBS (offline and network install)’, and select a folder to save it to.
+
''GPIO.setmode(GPIO.BCM)''
#Extract the files from the zip.
 
#Click on the <code>download ZIP</code> button under ‘NOOBS (offline and network install)’, and select a folder to save it to.
 
#Extract the files from the zip.
 
  
====== Preparing SD card on Linux/Windows Platforms ======
+
''GPIO.setup(6,GPIO.IN,pull_up_down = GPIO.PUD_UP)''
<ol style="list-style-type:upper-alpha;">
 
<li>'''Preparing SD card on Linux/Windows Platforms'''</li>
 
</ol>
 
  
On windows format your SD card before copying the NOOBS files onto it.
+
''while True:''
  
#You will need a 4GB or larger card. You will need a 4GB or larger card. NOOBS holds the various distros and support files for the “recovery” process. Basically, the installer lives on the card
+
''&nbsp;&nbsp; input = GPIO.input(6)&nbsp;&nbsp;''
#Go to the SD Association’s website&nbsp;and download SD Formatter 4.0 for Windows<br/>([https://www.sdcard.org/downloads/formatter_4/ https://www.sdcard.org/downloads/formatter_4/])
 
#Follow the instructions to install the software.
 
#Insert your SD card into the computer or SD card reader and make a note of the drive letter allocated to it.
 
#In SD Formatter software, select the drive letter for your SD card and format it.
 
  
'''Copy and Paste the NOOBS files'''
+
''&nbsp;&nbsp; if input == False:''
  
#Once your SD card has been formatted, copy all the files in the extracted NOOBS folder and paste them onto the SD card drive.
+
''&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print ("Button Pressed")''
#When this process has finished, safely remove the SD card and insert it into your Raspberry Pi.
+
 
 +
''&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; time.sleep(0.2)''&nbsp;&nbsp;
 +
 
 +
 
 +
 
 +
====== In-Lab Exercise 2: Realizing a OR gate ======
 +
 
 +
*'''Step 1'''&nbsp; Connect the Circuit as shown in the image below
 +
 
 +
[[File:Lab1-2.png|RTENOTITLE]]
 +
 
 +
*'''Step 2'''&nbsp; load the python code into your favorite code editor and copy paste the following code and save it as LightsOn.py
 +
*In our case we used the command line and opened the nano editor and added the following code
 +
 
 +
<span style="font-family:courier new,courier,monospace">#nano LightsOn.py</span>
 +
 
 +
''import RPi.GPIO as GPIO''
 +
 
 +
''import time''
 +
 
 +
''GPIO.setmode(GPIO.BCM)''
 +
 
 +
''GPIO.setwarnings(False)''
 +
 
 +
''led = 4''
 +
 
 +
''GPIO.setup(led, GPIO.OUT)''
 +
 
 +
''GPIO.output(led,1)''
 +
 
 +
''time.sleep(0.5)''
 +
 
 +
''GPIO.output(led, 0)''
 +
 
 +
''time.sleep(0.05)''
 +
 
 +
 
 +
 
 +
====== In-Lab Exercise 3: Realizing a NOT gate ======
 +
 
 +
*'''Step 1'''&nbsp; Connect the Circuit as shown in the image below
 +
 
 +
[[File:Lab1-3.png|RTENOTITLE]]
 +
 
 +
*'''Step 2'''&nbsp; load the python code into your favorite code editor and copy paste the following code and save it as SwitchLightsOn.py
 +
 
 +
In our case we used the command line and opened the nano editor and added the following code
 +
 
 +
<span style="font-family:courier new,courier,monospace">'''#nano SwitchLightsOn.py'''</span>
 +
 
 +
''import RPi.GPIO as GPIO''
 +
 
 +
''import time''
 +
 
 +
''GPIO.setmode(GPIO.BCM)''
 +
 
 +
''GPIO.setup(6,GPIO.IN,pull_up_down = GPIO.PUD_UP)''
 +
 
 +
''led = 4''
 +
 
 +
''GPIO.setup(led, GPIO.OUT)''
 +
 
 +
''while True:''
 +
 
 +
''&nbsp;&nbsp; input = GPIO.input(6)''
 +
 
 +
''&nbsp;&nbsp; if input == False:''
 +
 
 +
''&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print ("Button Pressed")''
 +
 
 +
''&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; time.sleep(0.2)''
 +
 
 +
''&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GPIO.output(led,1)''
 +
 
 +
''&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; time.sleep(0.5)''
 +
 
 +
''&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GPIO.output(led, 0)''
 +
 
 +
''&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; time.sleep(0.05)''
  
&nbsp;
 
<ol style="list-style-type:upper-alpha;">
 
<li>'''&nbsp;Format the SD card on the Linux Platform'''</li>
 
</ol>
 
  
'''On linux the following assumes you have root/administrator privileges'''
 
  
#First we need to download the ISO from the downloads page<br/>([https://www.raspberrypi.org/downloads/ https://www.raspberrypi.org/downloads/])<br/>Select an OS either Raspbian, UBUNTU mate or Snappy UBUNTU core
+
====== In-Lab Experiment 1: Realizing AND gate ======
#Find the device, assuming your system is different to mine. The easiest way is to run the following:
 
  
'''''#fdisk -l'''''
+
'''<u>Wire up the circuit as shown in Figure</u>'''
  
(This command lists all the mounted and unmounted devices on your computer.)
+
#'''Edit the Program shown in the following (python) code&nbsp; below'''<br/>'''(Note: In python the spacing/indentation of the code is important to the code)'''
  
#Once you have identified your device and the partition enter the following command that will format the SDcard
+
[[File:Lab1-4.png|RTENOTITLE]]
  
'''''#dd if=/downloads/raspbian.img of/=sdb bs=512 conv=noerror,sync'''''
+
''import RPi.GPIO as GPIO<br/>import time<br/>GPIO.setmode(GPIO.BCM)<br/>GPIO.setup(6, GPIO.IN, pull_up_down = GPIO.PUD_UP)''
  
#When this process has finished, safely remove the SD card and insert it into your Raspberry Pi and boot it.
+
''GPIO.setup(26, GPIO.IN, pull_up_down = GPIO.PUD_UP)''
  
====== Installing OS ======
+
''GPIO.setup(16, GPIO.OUT)<br/>a = 0<br/>b = 0''
  
'''Noobs installer First boot'''
+
''print "\n2 Input AND Gate"''
  
#Plug in your keyboard, mouse and monitor cables.
+
''print "\n"''
#Now plug in the USB power cable to your Pi.
 
#Your Raspberry Pi will boot, and a window will appear with a list of different operating systems that you can install. We recommend that you use Raspbian – tick the box next to Raspbian and click on <code>Install</code>.
 
  
http://raspberry.kenet.or.ke/images/0/05/Noobsinstall2.png
+
''print "A | B | AB"''
  
#Raspbian will then run through its installation process. Note this can take a while.
+
''print "----------"''
#When the install process has completed, the Raspberry Pi configuration menu (raspi-config) will load. Here you are able to set the time and date for your region and enable a Raspberry Pi camera board, or even create users. You can exit this menu by using Tab on your keyboard to move to <code>Finish</code>.
 
  
'''<u>Logging in with Default username and password</u>'''
+
''print "1 | 1 | 1"''
  
The OS will boot to command line where you will need to enter the default username and password
+
''print "1 | 0 | 0"''
  
*The default login for Raspbian OS<br/>Username: <code>pi</code> with the<br/>Password: <code>raspberry</code>
+
''print "0 | 1 | 0"''
  
'''<u>Loading the graphical user interface</u>'''
+
''print "0 | 0 | 0"''
  
To load the graphical user interface type<br/>'''''#'''''<code>'''''startx'''''</code>
+
''print "\n"''
  
 
&nbsp;
 
&nbsp;
  
====== Pre-Lab Exercise 2:Connecting Pi to the Internet ======
+
''while True:''
 +
 
 +
''&nbsp;&nbsp;&nbsp; button1 = GPIO.input(6)''
 +
 
 +
''&nbsp;&nbsp;&nbsp; button2 = GPIO.input(26)''
 +
 
 +
''&nbsp;&nbsp;&nbsp; if button1 == False:''
 +
 
 +
''&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a = 1''
 +
 
 +
''&nbsp;&nbsp;&nbsp; if button2 == False:''
 +
 
 +
''&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b = 1''
 +
 
 +
''&nbsp;&nbsp;&nbsp; if (a == 1) and (b == 1):''
 +
 
 +
''&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GPIO.output(16, 1)''
 +
 
 +
''&nbsp;&nbsp;&nbsp; else:''
 +
 
 +
''&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GPIO.output(16, 0)''
  
#WiFi Configuration
+
''&nbsp;&nbsp;&nbsp; time.sleep(1)''
#Using the command line
+
 
##LAN Configuration
+
''&nbsp;&nbsp;&nbsp; a = 0''
###DHCP Configuration
+
 
###Static configuration
+
''&nbsp;&nbsp;&nbsp; b = 0''
 +
 
 +
&nbsp;
  
====== Pre-Lab Exercise 3:&nbsp; Installing Applications on PI ======
+
#'''Run the Program and Observe LED when'''
  
#– Updating System
+
*'''Switch A is pressed'''
##Installing the Python Package Manager(PIP)
+
*'''Switch B is pressed'''
##Installing GPIO Library
+
*'''When Both Switch A and B are pressed'''
#In-Lab Exercises
+
*'''Both Switches A and B are processed simultaneous'''
##In-Lab Exercise 1: Realizing a AND gate
 
###Wire up the circuit
 
###&nbsp;&nbsp;Edit the Program
 
##In-Lab Exercise 2: Realizing a OR gate
 
##In-Lab Exercise 3: Realizing a NOT gate
 

Latest revision as of 22:18, 28 July 2015

Digital Electronics

Study of Logic Gates – AND, OR, NOT

In-Lab Exercise 1: Realizing a AND gate
  • Step 1  Connect the Circuit as shown in the image below

RTENOTITLE

  • Step 2  load the python code into your favorite code editor and copy paste the following code and save it as buttonpressed.py

In our case we used the command line and opened the nano editor and added the following code

#nano buttonpressed.py

import RPi.GPIO as GPIO

import time

#import random

GPIO.setmode(GPIO.BCM)

GPIO.setup(6,GPIO.IN,pull_up_down = GPIO.PUD_UP)

while True:

   input = GPIO.input(6)  

   if input == False:

       print ("Button Pressed")

       time.sleep(0.2)  


In-Lab Exercise 2: Realizing a OR gate
  • Step 1  Connect the Circuit as shown in the image below

RTENOTITLE

  • Step 2  load the python code into your favorite code editor and copy paste the following code and save it as LightsOn.py
  • In our case we used the command line and opened the nano editor and added the following code

#nano LightsOn.py

import RPi.GPIO as GPIO

import time

GPIO.setmode(GPIO.BCM)

GPIO.setwarnings(False)

led = 4

GPIO.setup(led, GPIO.OUT)

GPIO.output(led,1)

time.sleep(0.5)

GPIO.output(led, 0)

time.sleep(0.05)


In-Lab Exercise 3: Realizing a NOT gate
  • Step 1  Connect the Circuit as shown in the image below

RTENOTITLE

  • Step 2  load the python code into your favorite code editor and copy paste the following code and save it as SwitchLightsOn.py

In our case we used the command line and opened the nano editor and added the following code

#nano SwitchLightsOn.py

import RPi.GPIO as GPIO

import time

GPIO.setmode(GPIO.BCM)

GPIO.setup(6,GPIO.IN,pull_up_down = GPIO.PUD_UP)

led = 4

GPIO.setup(led, GPIO.OUT)

while True:

   input = GPIO.input(6)

   if input == False:

       print ("Button Pressed")

       time.sleep(0.2)

       GPIO.output(led,1)

       time.sleep(0.5)

       GPIO.output(led, 0)

       time.sleep(0.05)


In-Lab Experiment 1: Realizing AND gate

Wire up the circuit as shown in Figure

  1. Edit the Program shown in the following (python) code  below
    (Note: In python the spacing/indentation of the code is important to the code)

RTENOTITLE

import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(6, GPIO.IN, pull_up_down = GPIO.PUD_UP)

GPIO.setup(26, GPIO.IN, pull_up_down = GPIO.PUD_UP)

GPIO.setup(16, GPIO.OUT)
a = 0
b = 0

print "\n2 Input AND Gate"

print "\n"

print "A | B | AB"

print "----------"

print "1 | 1 | 1"

print "1 | 0 | 0"

print "0 | 1 | 0"

print "0 | 0 | 0"

print "\n"

 

while True:

    button1 = GPIO.input(6)

    button2 = GPIO.input(26)

    if button1 == False:

        a = 1

    if button2 == False:

       b = 1

    if (a == 1) and (b == 1):

       GPIO.output(16, 1)

    else:

        GPIO.output(16, 0)

    time.sleep(1)

    a = 0

    b = 0

 

  1. Run the Program and Observe LED when
  • Switch A is pressed
  • Switch B is pressed
  • When Both Switch A and B are pressed
  • Both Switches A and B are processed simultaneous