Professional Documents
Culture Documents
Required components
1. Raspberry Pi
2. Micro SD card (Raspbian OS Pre-installed)
3. HDMI Cable
4. Monitor with HDMI port
5. Keyboard
6. Mouse
7. USB-Micro USB cable
8. Mobile Robot Chassis with motors
9. Battery
10. Motor Driver circuit board
11. Connecting wires
12. Laptop/Mobile phone
There could be many reasons to access your Raspberry Pi remotely, without connecting any
monitor and peripheral device (i.e., keyboard, mouse). For example if Raspberry Pi is embedded in
a robot, from where it is not possible to connect monitor to it. Or you may want to view some
information from Pi or any process running on it from elsewhere/remotely. Or your not present at
physical location of your Raspberry Pi, or you do not have any other monitor to connect with Pi.
For all of these reasons you need to access your Pi remotely using another
Desktop/Pi/Laptop/Phone.
Pi can be accessed several ways on Local network and over the internet. The remote connection can
also be made using Remote desktop (using VNC or RDP) protocol or just remote terminal (using
SSH). In this lab we will be working remote terminal access of Raspberry Pi on a local network.
In order to access your Raspberry Pi remotely, you need to get familiarise yourself with following
terms.
Pi Username & Password: Username and password is used to access Super User control of
the Pi. This is need when you need to install/remove any software/library or access your Pi
remotely. Default username and password is “pi” and “raspberry” respectively. You can change
your password by typing following commands on the terminal;
>passwd
>(Your current password i.e., raspberry)
>(Your new password)
>(Confirm your new password)
>hostname -I
SSH (Secure Shell): You can access the command line (terminal) of a Raspberry Pi remotely
from another computer or device on the same network using SSH. The Raspberry Pi will act as a
remote device and you can connect to it using a client on another machine on same network. Figure
1 shows a laptop connected to a Pi through SSH and Wi-Fi router.
Is is possible that SSH is not enabled on your Raspberry Pi. In that case, raspi-config command can
be used in the terminal in order to enable it:
1. Enter sudoraspi-config in a terminal window
2. Select Interfacing Options
3. Navigate to and select SSH
4. Choose Yes
5. Select Ok
6. Choose Finish
Practice Tasks:
1. Write a program to control an LED remotely.
Code
2. Connect a USB camera with the Pi and watch live video transmission remotely.
Code
import io
import picamera
import logging
import socketserver
PAGE="""\
<html>
<head>
</head>
<body>
</body>
</html>
"""
class StreamingOutput(object):
def __init__(self):
self.frame = None
self.buffer = io.BytesIO()
self.condition = Condition()
if buf.startswith(b'\xff\xd8'):
self.buffer.truncate()
with self.condition:
self.frame = self.buffer.getvalue()
self.condition.notify_all()
self.buffer.seek(0)
return self.buffer.write(buf)
class StreamingHandler(server.BaseHTTPRequestHandler):
def do_GET(self):
if self.path == '/':
self.send_response(301)
self.send_header('Location', '/index.html')
self.end_headers()
content = PAGE.encode('utf-8')
self.send_response(200)
self.send_header('Content-Type', 'text/html')
self.send_header('Content-Length', len(content))
self.end_headers()
self.wfile.write(content)
self.send_response(200)
self.send_header('Age', 0)
self.send_header('Pragma', 'no-cache')
self.send_header('Content-Type', 'multipart/x-mixed-
replace; boundary=FRAME')
self.end_headers()
try:
while True:
with output.condition:
output.condition.wait()
frame = output.frame
self.wfile.write(b'--FRAME\r\n')
self.send_header('Content-Type', 'image/jpeg')
self.send_header('Content-Length', len(frame))
self.end_headers()
self.wfile.write(frame)
self.wfile.write(b'\r\n')
except Exception as e:
logging.warning(
self.client_address, str(e))
else:
self.send_error(404)
self.end_headers()
class StreamingServer(socketserver.ThreadingMixIn,
server.HTTPServer):
allow_reuse_address = True
daemon_threads = True
output = StreamingOutput()
#camera.rotation = 90
camera.start_recording(output, format='mjpeg')
try:
server.serve_forever()
finally:
camera.stop_recording()
Exercise Task: Write program(s) to access sensor data on your remote terminal.
Code
# distance sensor
TRIG = 23
ECHO = 24
trigger = gpiozero.OutputDevice(TRIG)
echo = gpiozero.DigitalInputDevice(ECHO)
time.sleep(0.00001)
trigger.off()
round_distance = round(distance,2)
# Display the distance
80% 20 % 100 %