SlideShare a Scribd company logo
IoT For Data Science and
Analytics
"Anything that can be connected, will be connected"
Sourav Tripathy
Syllabus
2
IOT FOR DATA SCIENCE AND ANALYTICS
Module 5
3
Raspberry Pi
Introduction to Raspberry Pi
About Raspberry Pi board
Hardware layout
Operating Systems on Raspberry Pi
Configuring Raspberry Pi
Configuring Raspberry Pi with Python
Wireless temperature monitoring system using Pi
DS18B20 Temperature Sensor
Connecting Raspberry Pi via SSH
Accessing temperature from DS18B20 sensors
Remote Access to Raspberry Pi
4
Introduction to Raspberry Pi
Raspberry Pi is defined as a minicomputer the size of a credit card that is interoperable with
any input and output hardware device like a monitor, a television, a mouse, or a keyboard –
effectively converting the set-up into a full-fledged PC at a low cost.
•Affordable: Prices start as low as $5 for the Raspberry Pi Pico and increase depending on
model and capabilities.
•Compact: Pocket-sized design (typically around the size of a credit card) makes it portable
and convenient.
•Powerful: Can handle diverse tasks with processors ranging from single-core to quad-core
and RAM from 256MB to 8GB.
•Versatile: Offers various input/output ports, including HDMI, USB, and GPIO pins for
connecting to different devices and sensors.
•Open-source: Supported by a large and active community and runs on open-source
operating systems like Raspberry Pi OS (based on Linux).
https://www.raspberrypi.com/documentation/computers/getting-started.html#setting-up-your-
raspberry-pi
5
Raspberry Pi and Arduino Difference
6
Feature Raspberry Pi Arduino
Type of device Microcomputer Microcontroller
Processing power More powerful Less powerful
Operating system
Runs a full operating system, such as
Raspberry Pi OS or Ubuntu
Doesn't run an operating system
Programming language Python, Java, C++, Scratch C++
Connectivity Wi-Fi, Bluetooth, Ethernet Limited to USB
Cost More expensive Less expensive
Complexity More complex to set up and use Simpler to set up and use
Best for
Complex projects that require multitasking
and internet connectivity
Simple projects that require controlling
hardware
Raspberry Pi and Arduino Difference
7
•Processing power: Raspberry Pi has a more powerful processor, which means it can handle more
complex tasks, such as running multiple programs at the same time or processing large amounts of
data. Arduino has a simpler processor, which is better suited for smaller, more focused tasks.
•Operating system: Raspberry Pi runs a full operating system, which gives you more flexibility and
control over your projects. Arduino doesn't run an operating system, so you have less control over
how it works.
•Programming language: Raspberry Pi can be programmed in a variety of languages, including
Python, Java, and C++. Arduino can only be programmed in C++.
•Connectivity: Raspberry Pi has built-in Wi-Fi, Bluetooth, and Ethernet connectivity, which makes it
easy to connect to the internet and other devices. Arduino typically only has USB connectivity.
•Cost: Raspberry Pi is more expensive than Arduino. However, it is also more powerful and
versatile.
•Complexity: Raspberry Pi is more complex to set up and use than Arduino. This is because it runs
an operating system and has more features. However, there are many resources available to help
you get started with Raspberry Pi.
•Best for: Raspberry Pi is best for complex projects that require multitasking and internet
Raspberry Pi board : Hardware layout
8
Raspberry Pi board : Hardware layout
9
https://www.youtube.com/watch?v=oWxeoU9v3K8
http://meseec.ce.rit.edu/551-projects/spring2017/2-3.pdf
Raspberry Pi board : Hardware layout
10
System on a Chip (SoC):
This is the brain of the Raspberry Pi, integrating the Central Processing Unit
(CPU), Graphics Processing Unit (GPU), and Random Access Memory (RAM)
onto a single chip. Different models boast varying processing power and graphics
capabilities
Storage:
The Raspberry Pi relies on a microSD card for storing its operating system
and files. Choose a high-quality card with sufficient capacity for your needs,
as it plays a crucial role in performance and data safety
Power Supply:
A stable power supply is vital for smooth operation. Most models require a Micro
USB or USB-C power supply that can deliver at least 2.5 amps of current. Choose
a reliable power adapter to avoid any hiccups.
Input/Output (I/O) Ports:
•HDMI: for connecting to a monitor or TV
•USB: for connecting peripherals like keyboards, mice, and external storage
•Ethernet: for wired network connection
•3.5mm jack: for audio output
•MicroSD card slot: for storage expansion
Raspberry Pi board : Hardware layout
11
General-Purpose Input/Output (GPIO) Pins:
These 40 pins on the Raspberry Pi's header offer immense flexibility. You can connect various
sensors, actuators, and other devices to interact with the physical world, enabling exciting projects like
robotics, home automation, and more.
3V3 3.3 volts
Anything connected to these pins will
always get 3.3V of power
5V 5 volts
Anything connected to these pins will
always get 5V of power
GND ground Zero volts, used to complete a circuit
GP2 GPIO pin 2
These pins are for general-purpose use and
can be configured as input or output pins
ID_SC/ID_SD/DNC Special purpose pins
Operating Systems on Raspberry Pi
Raspberry PI needs optimized OS suitable to run on Raspberry Pi hardware.
Raspberry Pi OS (formerly Raspbian)
The official and most popular choice, based on Debian Linux. Beginner-friendly with a
desktop environment and pre-installed software. Available in 32-bit and 64-bit versions.
Ubuntu Core
Another Linux-based option, lightweight and focused on security and minimal resource usage.
Ideal for Internet of Things (IoT) projects and headless servers.
LibreELEC and OSMC
These media center distributions turn your Pi into a dedicated streaming device, supporting
popular services like Netflix, Kodi, and Plex.
12
Raspberry Pi OS
Beginner-friendly: Raspberry Pi OS boasts a familiar desktop interface with pre-installed
software for everyday tasks like browsing the web, watching videos, editing documents, and
coding. You don't need prior Linux experience to get started
•Lightweight and efficient: Optimized for Raspberry Pi's hardware, the OS runs smoothly
even on models with limited resources, making it ideal for resource-intensive projects like
robotics or IoT applications.
•Highly customizable: With access to the vast Debian package repository, you can install
countless software applications to tailor the OS to your specific needs and interests.
•Educational focus: Raspberry Pi OS includes educational software like Scratch and
Python, making it a fantastic platform for learning programming and electronics.
•Community-driven: A vibrant community of Raspberry Pi enthusiasts and developers
provides extensive support and resources, ensuring you're never alone in your Raspberry Pi
journey.
https://en.wikipedia.org/wiki/Raspberry_Pi_OS
13
Configuring Raspberry Pi
Pre-requisites
• Power Supply
• microSD Card
• Keyboard / Mouse
• TV/Monitor Screen
Steps
• Setup SD Card and install OS
• Connect Raspberry Pi
• Powerup
• Finish Installation
https://projects.raspberrypi.org/en/projects/raspberry-pi-setting-up
14
Programming Raspberry Pi with Python
15
https://realpython.com/python-raspberry-pi/
• Python comes preinstalled on Raspbian
• The Raspbian operating system comes with several preinstalled Python IDEs that you can use to write
can use to write your programs. One of these IDEs is Mu. It can be found in the main menu:
menu:
Raspberry Pi Icon → Programming → Mu
Steps
1.Open Mu by going to Raspberry Pi Icon → Programming → Mu.
2.Click New in the menu bar to create an empty file.
3.Click Save in the menu bar.
4.Navigate to the /home/pi directory in the directory dropdown.
5.Click the Create New Folder icon in the top-right corner.
6.Name this new directory python-projects and hit Enter.
7.Click Cancel to close.
Wireless temperature monitoring system using Pi
16
DS18B20 Temperature Sensor
17
No: Pin Name Description
1 Ground Connect to the ground of the circuit
2 Vcc Powers the Sensor, can be 3.3V or 5V
3 Data This pin gives output the temperature value which
can be read using 1-wire method
ConnectingRaspberryPi via SSH
• Enable SSH on Raspberry Pi
•Connecting via SSH
• Find out IP Address
• hostname -I
• ssh username@IPAddress
https://raspberrypi-guide.github.io/networking/connecting-via-ssh
18
AccessingtemperaturefromDS18B20sensors
19
import os
import glob
import time
os.system('modprobe w1-gpio')
os.system('modprobe w1-therm')
base_dir = '/sys/bus/w1/devices/'
device_folder = glob.glob(base_dir + '28*')[0]
device_file = device_folder + '/w1_slave'
def read_temp_raw():
f = open(device_file, 'r')
lines = f.readlines()
f.close()
return lines
def read_temp():
lines = read_temp_raw()
while lines[0].strip()[-3:] != 'YES':
time.sleep(0.2)
lines = read_temp_raw()
equals_pos = lines[1].find('t=')
if equals_pos != -1:
temp_string = lines[1][equals_pos+2:]
temp_c = float(temp_string) / 1000.0
temp_f = temp_c * 9.0 / 5.0 + 32.0
return temp_c, temp_f
while True:
print(read_temp())
time.sleep(1)
Load the following kernel modules (w1-gpio and w1-therm) to interface with
the DS18B20 sensor via one-wire communication protocol.
The function read_temp_raw() gets the temperature readings from
the w1_slave file (that’s the place where those are stored). This function opens
the w1_slave file, reads its contents line by line, and then returns a list containing the
lines.
Reads the actual data
RemoteAccesstoRaspberryPi
20
Enable Remote Access:
•SSH (Secure Shell): This is the most common method for command-line access. It's typically enabled by default in
Raspberry Pi OS.
• To verify, open a terminal and type sudo raspi-config.
• Navigate to "Interfacing Options" > "SSH" and enable it if necessary.
•VNC (Virtual Network Computing): This allows for full graphical desktop access remotely.
• Go to "Menu" > "Preferences" > "Raspberry Pi Configuration" > "Interfaces" and enable VNC.
• Set a password for VNC access.
2. Find Your Raspberry Pi's IP Address:
•Open a terminal and type hostname -I to display its IP address on your local network.
•Note this address for connecting from other devices.
3. Choose Your Remote Access Method:
A. SSH (Command-Line Access):
•From a Linux or macOS computer: Open a terminal and type ssh pi@<IP_address> (replace <IP_address> with your
Pi's actual IP).
•From a Windows computer: Use an SSH client like PuTTY.
B. VNC (Graphical Desktop Access):
•Install a VNC viewer app on your device (e.g., VNC Viewer, RealVNC Viewer).
•Enter your Pi's IP address and VNC password when prompted.
C. Third-Party Remote Access Solutions:
•Chrome Remote Desktop: Simple setup for remote desktop access from anywhere (requires a Google account).
•TeamViewer: Versatile option for both desktop and command-line access, often used for professional support.

More Related Content

PPTX
해시암호와 비밀번호 - 9th KUSISWALL
PPT
Rasp berry Pi
PPTX
Raspberry pi complete setup
PDF
CNIT 126: 10: Kernel Debugging with WinDbg
PDF
Rust for professionals.pdf
PPT
Rasberry pi
PDF
Session1-Introduce Http-HTTP Security headers
PDF
What are Hadoop Components? Hadoop Ecosystem and Architecture | Edureka
해시암호와 비밀번호 - 9th KUSISWALL
Rasp berry Pi
Raspberry pi complete setup
CNIT 126: 10: Kernel Debugging with WinDbg
Rust for professionals.pdf
Rasberry pi
Session1-Introduce Http-HTTP Security headers
What are Hadoop Components? Hadoop Ecosystem and Architecture | Edureka

Similar to IoT for data science Module 5 - Raspberry Pi.pptx (20)

PPTX
IOT notes ....,.........
PPTX
Raspberry pi
PPTX
Raspberry Pi ppt.pptx
PPTX
Raspberry Pi ppt.pptx
PPTX
Up and running with Raspberry Pi
PDF
5 IOT MODULE 5 RaspberryPi Programming using Python.pdf
PPTX
Raspberry pi. mini computer networks science ppt
PPTX
Lecture 8
PDF
My presentation raspberry pi
PPTX
Raspberry-Pi, Developing on Raspberry Pi, Difference between Arduino & Raspbe...
PPTX
RaspberryPi & Python Workshop Day - 01.pptx
PPTX
Unit 6 - PART2.pptx
PDF
Raspberry pi overview
PDF
Raspberry pi Board Hardware & Software Setup
PPTX
Introduction to raspberry pi
PPTX
Raspberry Pi Free Session - 20_09_2014
PPTX
Raspberry Pi Session - 22_11_2014
PPTX
Raspberry Pi (Introduction)
PPTX
IoT Levels of AUtomation-case study topic
PDF
Introduction aboout raspberry PI
IOT notes ....,.........
Raspberry pi
Raspberry Pi ppt.pptx
Raspberry Pi ppt.pptx
Up and running with Raspberry Pi
5 IOT MODULE 5 RaspberryPi Programming using Python.pdf
Raspberry pi. mini computer networks science ppt
Lecture 8
My presentation raspberry pi
Raspberry-Pi, Developing on Raspberry Pi, Difference between Arduino & Raspbe...
RaspberryPi & Python Workshop Day - 01.pptx
Unit 6 - PART2.pptx
Raspberry pi overview
Raspberry pi Board Hardware & Software Setup
Introduction to raspberry pi
Raspberry Pi Free Session - 20_09_2014
Raspberry Pi Session - 22_11_2014
Raspberry Pi (Introduction)
IoT Levels of AUtomation-case study topic
Introduction aboout raspberry PI
Ad

Recently uploaded (20)

PPTX
IBA_Chapter_11_Slides_Final_Accessible.pptx
PDF
Galatica Smart Energy Infrastructure Startup Pitch Deck
PDF
168300704-gasification-ppt.pdfhghhhsjsjhsuxush
PDF
Clinical guidelines as a resource for EBP(1).pdf
PPTX
IB Computer Science - Internal Assessment.pptx
PPTX
Acceptance and paychological effects of mandatory extra coach I classes.pptx
PPTX
Supervised vs unsupervised machine learning algorithms
PPTX
1_Introduction to advance data techniques.pptx
PPTX
Business Ppt On Nestle.pptx huunnnhhgfvu
PPTX
05. PRACTICAL GUIDE TO MICROSOFT EXCEL.pptx
PPTX
oil_refinery_comprehensive_20250804084928 (1).pptx
PDF
TRAFFIC-MANAGEMENT-AND-ACCIDENT-INVESTIGATION-WITH-DRIVING-PDF-FILE.pdf
PDF
BF and FI - Blockchain, fintech and Financial Innovation Lesson 2.pdf
PPTX
MODULE 8 - DISASTER risk PREPAREDNESS.pptx
PPT
Chapter 3 METAL JOINING.pptnnnnnnnnnnnnn
PPTX
advance b rammar.pptxfdgdfgdfsgdfgsdgfdfgdfgsdfgdfgdfg
PPTX
Introduction-to-Cloud-ComputingFinal.pptx
PPTX
Moving the Public Sector (Government) to a Digital Adoption
PPTX
ALIMENTARY AND BILIARY CONDITIONS 3-1.pptx
PPT
Reliability_Chapter_ presentation 1221.5784
IBA_Chapter_11_Slides_Final_Accessible.pptx
Galatica Smart Energy Infrastructure Startup Pitch Deck
168300704-gasification-ppt.pdfhghhhsjsjhsuxush
Clinical guidelines as a resource for EBP(1).pdf
IB Computer Science - Internal Assessment.pptx
Acceptance and paychological effects of mandatory extra coach I classes.pptx
Supervised vs unsupervised machine learning algorithms
1_Introduction to advance data techniques.pptx
Business Ppt On Nestle.pptx huunnnhhgfvu
05. PRACTICAL GUIDE TO MICROSOFT EXCEL.pptx
oil_refinery_comprehensive_20250804084928 (1).pptx
TRAFFIC-MANAGEMENT-AND-ACCIDENT-INVESTIGATION-WITH-DRIVING-PDF-FILE.pdf
BF and FI - Blockchain, fintech and Financial Innovation Lesson 2.pdf
MODULE 8 - DISASTER risk PREPAREDNESS.pptx
Chapter 3 METAL JOINING.pptnnnnnnnnnnnnn
advance b rammar.pptxfdgdfgdfsgdfgsdgfdfgdfgsdfgdfgdfg
Introduction-to-Cloud-ComputingFinal.pptx
Moving the Public Sector (Government) to a Digital Adoption
ALIMENTARY AND BILIARY CONDITIONS 3-1.pptx
Reliability_Chapter_ presentation 1221.5784
Ad

IoT for data science Module 5 - Raspberry Pi.pptx

  • 1. IoT For Data Science and Analytics "Anything that can be connected, will be connected" Sourav Tripathy
  • 3. IOT FOR DATA SCIENCE AND ANALYTICS Module 5 3
  • 4. Raspberry Pi Introduction to Raspberry Pi About Raspberry Pi board Hardware layout Operating Systems on Raspberry Pi Configuring Raspberry Pi Configuring Raspberry Pi with Python Wireless temperature monitoring system using Pi DS18B20 Temperature Sensor Connecting Raspberry Pi via SSH Accessing temperature from DS18B20 sensors Remote Access to Raspberry Pi 4
  • 5. Introduction to Raspberry Pi Raspberry Pi is defined as a minicomputer the size of a credit card that is interoperable with any input and output hardware device like a monitor, a television, a mouse, or a keyboard – effectively converting the set-up into a full-fledged PC at a low cost. •Affordable: Prices start as low as $5 for the Raspberry Pi Pico and increase depending on model and capabilities. •Compact: Pocket-sized design (typically around the size of a credit card) makes it portable and convenient. •Powerful: Can handle diverse tasks with processors ranging from single-core to quad-core and RAM from 256MB to 8GB. •Versatile: Offers various input/output ports, including HDMI, USB, and GPIO pins for connecting to different devices and sensors. •Open-source: Supported by a large and active community and runs on open-source operating systems like Raspberry Pi OS (based on Linux). https://www.raspberrypi.com/documentation/computers/getting-started.html#setting-up-your- raspberry-pi 5
  • 6. Raspberry Pi and Arduino Difference 6 Feature Raspberry Pi Arduino Type of device Microcomputer Microcontroller Processing power More powerful Less powerful Operating system Runs a full operating system, such as Raspberry Pi OS or Ubuntu Doesn't run an operating system Programming language Python, Java, C++, Scratch C++ Connectivity Wi-Fi, Bluetooth, Ethernet Limited to USB Cost More expensive Less expensive Complexity More complex to set up and use Simpler to set up and use Best for Complex projects that require multitasking and internet connectivity Simple projects that require controlling hardware
  • 7. Raspberry Pi and Arduino Difference 7 •Processing power: Raspberry Pi has a more powerful processor, which means it can handle more complex tasks, such as running multiple programs at the same time or processing large amounts of data. Arduino has a simpler processor, which is better suited for smaller, more focused tasks. •Operating system: Raspberry Pi runs a full operating system, which gives you more flexibility and control over your projects. Arduino doesn't run an operating system, so you have less control over how it works. •Programming language: Raspberry Pi can be programmed in a variety of languages, including Python, Java, and C++. Arduino can only be programmed in C++. •Connectivity: Raspberry Pi has built-in Wi-Fi, Bluetooth, and Ethernet connectivity, which makes it easy to connect to the internet and other devices. Arduino typically only has USB connectivity. •Cost: Raspberry Pi is more expensive than Arduino. However, it is also more powerful and versatile. •Complexity: Raspberry Pi is more complex to set up and use than Arduino. This is because it runs an operating system and has more features. However, there are many resources available to help you get started with Raspberry Pi. •Best for: Raspberry Pi is best for complex projects that require multitasking and internet
  • 8. Raspberry Pi board : Hardware layout 8
  • 9. Raspberry Pi board : Hardware layout 9 https://www.youtube.com/watch?v=oWxeoU9v3K8 http://meseec.ce.rit.edu/551-projects/spring2017/2-3.pdf
  • 10. Raspberry Pi board : Hardware layout 10 System on a Chip (SoC): This is the brain of the Raspberry Pi, integrating the Central Processing Unit (CPU), Graphics Processing Unit (GPU), and Random Access Memory (RAM) onto a single chip. Different models boast varying processing power and graphics capabilities Storage: The Raspberry Pi relies on a microSD card for storing its operating system and files. Choose a high-quality card with sufficient capacity for your needs, as it plays a crucial role in performance and data safety Power Supply: A stable power supply is vital for smooth operation. Most models require a Micro USB or USB-C power supply that can deliver at least 2.5 amps of current. Choose a reliable power adapter to avoid any hiccups. Input/Output (I/O) Ports: •HDMI: for connecting to a monitor or TV •USB: for connecting peripherals like keyboards, mice, and external storage •Ethernet: for wired network connection •3.5mm jack: for audio output •MicroSD card slot: for storage expansion
  • 11. Raspberry Pi board : Hardware layout 11 General-Purpose Input/Output (GPIO) Pins: These 40 pins on the Raspberry Pi's header offer immense flexibility. You can connect various sensors, actuators, and other devices to interact with the physical world, enabling exciting projects like robotics, home automation, and more. 3V3 3.3 volts Anything connected to these pins will always get 3.3V of power 5V 5 volts Anything connected to these pins will always get 5V of power GND ground Zero volts, used to complete a circuit GP2 GPIO pin 2 These pins are for general-purpose use and can be configured as input or output pins ID_SC/ID_SD/DNC Special purpose pins
  • 12. Operating Systems on Raspberry Pi Raspberry PI needs optimized OS suitable to run on Raspberry Pi hardware. Raspberry Pi OS (formerly Raspbian) The official and most popular choice, based on Debian Linux. Beginner-friendly with a desktop environment and pre-installed software. Available in 32-bit and 64-bit versions. Ubuntu Core Another Linux-based option, lightweight and focused on security and minimal resource usage. Ideal for Internet of Things (IoT) projects and headless servers. LibreELEC and OSMC These media center distributions turn your Pi into a dedicated streaming device, supporting popular services like Netflix, Kodi, and Plex. 12
  • 13. Raspberry Pi OS Beginner-friendly: Raspberry Pi OS boasts a familiar desktop interface with pre-installed software for everyday tasks like browsing the web, watching videos, editing documents, and coding. You don't need prior Linux experience to get started •Lightweight and efficient: Optimized for Raspberry Pi's hardware, the OS runs smoothly even on models with limited resources, making it ideal for resource-intensive projects like robotics or IoT applications. •Highly customizable: With access to the vast Debian package repository, you can install countless software applications to tailor the OS to your specific needs and interests. •Educational focus: Raspberry Pi OS includes educational software like Scratch and Python, making it a fantastic platform for learning programming and electronics. •Community-driven: A vibrant community of Raspberry Pi enthusiasts and developers provides extensive support and resources, ensuring you're never alone in your Raspberry Pi journey. https://en.wikipedia.org/wiki/Raspberry_Pi_OS 13
  • 14. Configuring Raspberry Pi Pre-requisites • Power Supply • microSD Card • Keyboard / Mouse • TV/Monitor Screen Steps • Setup SD Card and install OS • Connect Raspberry Pi • Powerup • Finish Installation https://projects.raspberrypi.org/en/projects/raspberry-pi-setting-up 14
  • 15. Programming Raspberry Pi with Python 15 https://realpython.com/python-raspberry-pi/ • Python comes preinstalled on Raspbian • The Raspbian operating system comes with several preinstalled Python IDEs that you can use to write can use to write your programs. One of these IDEs is Mu. It can be found in the main menu: menu: Raspberry Pi Icon → Programming → Mu Steps 1.Open Mu by going to Raspberry Pi Icon → Programming → Mu. 2.Click New in the menu bar to create an empty file. 3.Click Save in the menu bar. 4.Navigate to the /home/pi directory in the directory dropdown. 5.Click the Create New Folder icon in the top-right corner. 6.Name this new directory python-projects and hit Enter. 7.Click Cancel to close.
  • 16. Wireless temperature monitoring system using Pi 16
  • 17. DS18B20 Temperature Sensor 17 No: Pin Name Description 1 Ground Connect to the ground of the circuit 2 Vcc Powers the Sensor, can be 3.3V or 5V 3 Data This pin gives output the temperature value which can be read using 1-wire method
  • 18. ConnectingRaspberryPi via SSH • Enable SSH on Raspberry Pi •Connecting via SSH • Find out IP Address • hostname -I • ssh username@IPAddress https://raspberrypi-guide.github.io/networking/connecting-via-ssh 18
  • 19. AccessingtemperaturefromDS18B20sensors 19 import os import glob import time os.system('modprobe w1-gpio') os.system('modprobe w1-therm') base_dir = '/sys/bus/w1/devices/' device_folder = glob.glob(base_dir + '28*')[0] device_file = device_folder + '/w1_slave' def read_temp_raw(): f = open(device_file, 'r') lines = f.readlines() f.close() return lines def read_temp(): lines = read_temp_raw() while lines[0].strip()[-3:] != 'YES': time.sleep(0.2) lines = read_temp_raw() equals_pos = lines[1].find('t=') if equals_pos != -1: temp_string = lines[1][equals_pos+2:] temp_c = float(temp_string) / 1000.0 temp_f = temp_c * 9.0 / 5.0 + 32.0 return temp_c, temp_f while True: print(read_temp()) time.sleep(1) Load the following kernel modules (w1-gpio and w1-therm) to interface with the DS18B20 sensor via one-wire communication protocol. The function read_temp_raw() gets the temperature readings from the w1_slave file (that’s the place where those are stored). This function opens the w1_slave file, reads its contents line by line, and then returns a list containing the lines. Reads the actual data
  • 20. RemoteAccesstoRaspberryPi 20 Enable Remote Access: •SSH (Secure Shell): This is the most common method for command-line access. It's typically enabled by default in Raspberry Pi OS. • To verify, open a terminal and type sudo raspi-config. • Navigate to "Interfacing Options" > "SSH" and enable it if necessary. •VNC (Virtual Network Computing): This allows for full graphical desktop access remotely. • Go to "Menu" > "Preferences" > "Raspberry Pi Configuration" > "Interfaces" and enable VNC. • Set a password for VNC access. 2. Find Your Raspberry Pi's IP Address: •Open a terminal and type hostname -I to display its IP address on your local network. •Note this address for connecting from other devices. 3. Choose Your Remote Access Method: A. SSH (Command-Line Access): •From a Linux or macOS computer: Open a terminal and type ssh pi@<IP_address> (replace <IP_address> with your Pi's actual IP). •From a Windows computer: Use an SSH client like PuTTY. B. VNC (Graphical Desktop Access): •Install a VNC viewer app on your device (e.g., VNC Viewer, RealVNC Viewer). •Enter your Pi's IP address and VNC password when prompted. C. Third-Party Remote Access Solutions: •Chrome Remote Desktop: Simple setup for remote desktop access from anywhere (requires a Google account). •TeamViewer: Versatile option for both desktop and command-line access, often used for professional support.