Coding / Programming Videos

Post your favorite coding videos and share them with others!

Raspberry Pi Robot with Live Video Streaming to Computer Wirelessly

Download Video link >



Raspberry Pi Robot with Live Video Streaming to Computer Wirelessly

Components Required:
1) Robot Chassis
2) Motor driver module
3) Li-Po Battery
4) Raspberry Pi 3 Model B
5) Micro SD Card 8gb or greater
6) Power Bank
7) Camera with Raspberry Pi
8) Jumper Cables

Python Code for Raspberry Pi:
# you will have to install following libraries first in your pi for the code to start working like #OpenCV, RPi etc
#import GPIO library
import RPi.GPIO as GPIO
from time import sleep
from picamera import PiCamera
from time import sleep
import cv2
camera = PiCamera()
GPIO.setwarnings(False)
#set GPIO numbering mode and define input and output pins
GPIO.setmode(GPIO.BOARD)
GPIO.setup(31,GPIO.OUT) #Left Motor +
GPIO.setup(33,GPIO.OUT) #Left Motor –
GPIO.setup(35,GPIO.OUT) #Right Motor +
GPIO.setup(37,GPIO.OUT) #Right Motor –
GPIO.setup(18,GPIO.OUT) #for PWM
GPIO.setup(22,GPIO.OUT) #for PWM
#Generating PWM signals
p = GPIO.PWM(18,20)
q = GPIO.PWM(22,20)
p.start(30)
q.start(30)
while True:
camera.capture(‘/home/pi/Desktop/image.jpg’)
frame = cv2.imread(“image.jpg”)
cv2.imshow(“image”,frame)
cv2.waitKey(1)
#moving robot forward for 2 seconds
GPIO.output(31,False)
GPIO.output(33,True)
GPIO.output(35,True)
GPIO.output(37,False)
for k in range(1,8):
camera.capture(‘/home/pi/Desktop/image.jpg’)
frame = cv2.imread(“image.jpg”)
cv2.imshow(“image”,frame)
cv2.waitKey(1)
#Stopping robot for 2 seconds
GPIO.output(31,False)
GPIO.output(33,False)
GPIO.output(35,False)
GPIO.output(37,False)
for k in range(1,8):
camera.capture(‘/home/pi/Desktop/image.jpg’)
frame = cv2.imread(“image.jpg”)
cv2.imshow(“image”,frame)
cv2.waitKey(1)
#moving robot backward for 2 seconds
GPIO.output(33,False)
GPIO.output(31,True)
GPIO.output(37,True)
GPIO.output(35,False)
for k in range(1,8):
camera.capture(‘/home/pi/Desktop/image.jpg’)
frame = cv2.imread(“image.jpg”)
cv2.imshow(“image”,frame)
cv2.waitKey(1)
#Stopping robot for 2 seconds
GPIO.output(31,False)
GPIO.output(33,False)
GPIO.output(35,False)
GPIO.output(37,False)
for k in range(1,8):
camera.capture(‘/home/pi/Desktop/image.jpg’)
frame = cv2.imread(“image.jpg”)
cv2.imshow(“image”,frame)
cv2.waitKey(1)

source

Bookmark(0)
 

 

View Comments source >

Leave a Reply

Please Login to comment
  Subscribe  
Notify of
Translate »