Lecture 17 - RPi II
Lecture 17 - RPi II
Working on Raspberry Pi
boards II
Operating Pi in headless mode
▪ Connecting a monitor is not always feasible.
▪ Problem: How can Pi receive digital data that uses 5V as logic high?
https://projects.raspberrypi.org/en/projects/physical-computing/12
Connecting an ultrasonic distance sensor
▪ An ultrasonic distance sensor sends out pulses of (inaudible) ultrasound
and detects the echo that is sent back when the sound bounces off a
nearby object.
▪ It then uses the speed of sound to calculate the distance from the
object. Speed of sound in air is 343 m/s
▪ For Python code, gpiozero library takes care of all workflow, including
▪ Sending a pulse via Trigger pin
▪ Detecting the echo signal on Echo pin
▪ Converting echo time to distance
https://www.instructables.com/DC-Motor-Control-With-Raspberry-Pi-and-L293D/
Circuit with L293D driver
https://theorycircuit.com/raspberry-pi/coding-raspberry-pi-interface-dc-motor/
Motor interfacing code
▪ Once again, gpiozero library provides very helpful abstractions.
camera = PiCamera()
# Take a picture
camera.capture('hello.jpg')
Access camera through code
Capturing videos
camera = PiCamera()
camera.start_recording('myvideo.mp4', format='h264')
time.sleep(10) # make a 10-second video
camera.stop_recording()
Access camera through code
Storing captures directly to a server. Use standard sockets API.
camera = PiCamera()