Difference between revisions of "Digital Electronics (USIU)"

From Raspberry Pi Min-Grant project
Jump to: navigation, search
 
(5 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 ===
  
#In-Lab Exercise 1: Realizing a AND gate
+
====== In-Lab Exercise 1: Realizing a AND gate ======
#In-Lab Exercise 2: Realizing a OR gate
+
 
#In-Lab Exercise 3: Realizing a NOT gate
+
*'''Step 1  Connect the Circuit as shown in the image below'''
 +
 
 +
[[File:Lab1-1.png|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
 +
 
 +
<span style="font-family:courier new,courier,monospace">'''#''nano buttonpressed.py'''''</span>
 +
 
 +
''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:''
 +
 
 +
''&nbsp;&nbsp; input = GPIO.input(6)&nbsp;&nbsp;''
 +
 
 +
''&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;
 +
 
 +
 
 +
 
 +
====== 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)''
 +
 
 +
 
 +
 
 +
====== In-Lab Experiment 1: Realizing AND gate ======
 +
 
 +
'''<u>Wire up the circuit as shown in Figure</u>'''
 +
 
 +
#'''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)'''
 +
 
 +
[[File:Lab1-4.png|RTENOTITLE]]
 +
 
 +
''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)''
 +
 
 +
''GPIO.setup(26, GPIO.IN, pull_up_down = GPIO.PUD_UP)''
 +
 
 +
''GPIO.setup(16, GPIO.OUT)<br/>a = 0<br/>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"''
 +
 
 +
&nbsp;
 +
 
 +
''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)''
 +
 
 +
''&nbsp;&nbsp;&nbsp; time.sleep(1)''
 +
 
 +
''&nbsp;&nbsp;&nbsp; a = 0''
 +
 
 +
''&nbsp;&nbsp;&nbsp; b = 0''
 +
 
 +
&nbsp;
 +
 
 +
#'''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'''

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