IOT Journal C
IOT Journal C
Practical No: 01 A
Source Code:
import RPi.GPIO as a
a.setmode(a.BOARD)
ledPin = 11
a.setup(ledPin, a.OUT)
a.output(ledPin, False)
try:
while True:
a.output(ledPin, True)
print("LED ON")
sleep(1)
a.output(ledPin, False)
print("LED OFF")
sleep(1)
finally:
a.output(ledPin, False)
a.cleanup()
Requirement:
Hardware Connectivity:
OUTPUT:
Practical No: 01 B
Source Code:
import RPi.GPIO as b
b.setmode(b.BOARD)
b.setup(11,b.ouput)
b.setup(13,b.ouput)
b.setup(15,b.output)
for i in range(10):
b.output(11,True)
print("ON")
sleep(2)
b.ouput(11,False)
print("OFF")
sleep(2)
b.output(13,True)
print("ON")
b.ouput(13,False)
print("OFF")
sleep(2)
b.output(15,True)
print("ON")
sleep(2)
b.ouput(15,False)
print("OFF")
sleep(2)
print("DONE")
b.cleanup()
Requirement:
Hardware Connectivity:
OUTPUT:
Practical No: 02
Raspberry Pi.
Source Code:
import sys
import time
import datetime
import RPi.GPIO as a
import tm1637
Display = tm1637.TM1637(23,24,tm1637.BRIGHT_TYPICAL)
Display.Clear()
Display.SetBrightnes(1)
while(True):
now = datetime.datetime.now()
hour = now.hour
minute = now.minute
second = now.second
Display.Show(currenttime)
time.sleep(1)
Requirement:
Hardware Connectivity:
1. Connect your 4 digit 7 segment display with Raspberry Pi's GPIO Pins.
Other Requirement:
1. Now to download libraries, open Web Browser on your Raspberry Pi and log on to the
following link: https://github.com/timwaizenegger/raspberrypi-examples/tree/master/actor-led-
7segment-4numbers . Click on the actor-led-7segment-4numbers.zip folder and Now click on
Download Button to download the file.
2. Now on your rpi move to /home/pi/Downloads/ location to find the zip file downloaded.
3. Unzip the file and try to execute the different example codes present in that folder in Python
Idle.
4. create a new file, write the code given below and save it in the same folder
Source Code:
camera = PiCamera()
camera.start_preview()
sleep(2)
camera.capture('/home/pi/Pictures/newImage.jpg')
camera.stop_preview()
Requirement :
Hardware Connectivity:
# sudo raspi-config
3.Go to Interface Option and enable Camera and I2C option.then click on Done option.
# sudo reboot
OUTPUT:
Commands:
# ls /dev/ttyUSB*
3. To install gpsd, make sure your Pi has an Internet connection and run the following
commands:
4. You will need to enable the gpsd systemd service by running the following commands:
# gpsd
# gpsmon
cgps which gives a less detailed, but still quite nice output
# cgps -s
Requirement:
1. GPS module.
Hardware Connectivity :
1. Connect the VCC Pin of GPS Module to 3.3V Pin of USB to TTL converter
2. Connect the GND Pin of GPS Module to GND Pin of USB to TTL converter
5. Lastly connect the USB to TTL converter to USB port of Raspberry Pi.
Source Code:
1.For Writing
import RPi.GPIO as b
reader = SimpleMFRC522()
try:
reader.write(text)
print("Written")
finally:
b.cleanup()
2. For Reading
import RPi.GPIO as b
reader = SimpleMFRC522()
try:
print(text)
finally:
b.cleanup()
Requirement:
Hardware Connectivity:
SDA 24
SCK 23
MOSI 19
MISO 21
GND 6
RST 22
3.3V 1
1. To enable P4 SPI :
# sudo raspi-config
# sudo reboot
4. To update
Source Code:
import time,datetime
import RPi.GPIO as b
import telepot
LED1=31
LED2=33
LED3=35
LED4=37
now=datetime.datetime.now()
b.setmode(b.BOARD)
b.setwarnings(False)
b.setup(LED1,b.OUT)
b.output(LED1,0)
b.setup(LED2,b.OUT)
b.output(LED2,0)
b.output(LED3,0)
b.setup(LED4,b.OUT)
b.output(LED4,0)
def action(msg):
chat_id=msg['chat']['id']
command=msg['text']
if 'on' in command:
message="on"
if 'LED1' in command:
message=message+"LED1"
b.output(LED1,1)
if 'LED2' in command:
message=message+"LED2"
b.output(LED2,1)
if 'LED3' in command:
message=message+"LED3"
b.output(LED3,1)
if 'LED4' in command:
message=message+"LED4"
if 'all' in command:
message=message+"all"
b.output(LED1,1)
b.output(LED2,1)
b.output(LED3,1)
b.output(LED4,1)
message=message+"light(s)"
telegram_bot.sendMessage(chat_id,message)
if 'off' in command:
message="off"
if 'LED1' in command:
message=message+"LED1"
b.output(LED1,0)
if 'LED2' in command:
message=message+"LED2"
b.output(LED2,0)
if 'LED3' in command:
message=message+"LED3"
b.output(LED3,0)
if 'LED4' in command:
message=message+"LED4"
b.output(LED4,0)
message=message+"all"
b.output(LED1,0)
b.output(LED2,0)
b.output(LED3,0)
b.output(LED4,0)
message=message+"light(s)"
telegram_bot.sendMessage(chat_id,message)
16 pt
telegram_bot=telepot.Bot('6489494048:AAEPlW7QpyIW_ne8KNr1UvILgw2jkANvens')
print(telegram_bot.getMe())
MessageLoop(telegram_bot,action).run_as_thread()
while 1:
time.sleep(10)
Requirement:
Other Requirement:
Practical No: 07
Commands:
1.Installation of WebIOPi:
To update the raspberry Pi below commands and then reboot the RPi:
2. sudo reboot
2. Now download the latest version of WebIOPi from the following link on your raspberry
pi:
http://webiopi.trouch.com/DOWNLOADS.html
cd /home/pi/Downloads/
4. extract the file and adapt x.y.z with the version you download:
2. cd WebIOPi-x.y.z
5. Below commands are used to install patch while still in the WebIOPi directory, run:
1. wget https://raw.githubusercontent.com/doublebind/raspi/master/webiopi-pi2bplus.patch
1. sudo ./setup.sh
For instance, to start with verbose output and the default config file:
/etc/webiopi/config.
7.NOTE:
You can also start/stop the background service, the configuration will be loaded from
/etc/webiopi/config.
8. Ip address
username: webiopi
password: raspberry
Requirement:
Hardware Connectivity:
Other Requirement:
1. To update the raspberry Pi below commands and then reboot the RPi:
3. #sudo reboot
2. Now download the latest version of WebIOPi from the following link on your raspberry
pi:
http://webiopi.trouch.com/DOWNLOADS.html
OUTPUT: