Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Getting Started with Python for the Internet of Things

You're reading from   Getting Started with Python for the Internet of Things Leverage the full potential of Python to prototype and build IoT projects using the Raspberry Pi

Arrow left icon
Product type Course
Published in Feb 2019
Publisher
ISBN-13 9781838555795
Length 732 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (5):
Arrow left icon
Tim Cox Tim Cox
Author Profile Icon Tim Cox
Tim Cox
Prof. Diwakar Vaish Prof. Diwakar Vaish
Author Profile Icon Prof. Diwakar Vaish
Prof. Diwakar Vaish
Sai Yamanoor Sai Yamanoor
Author Profile Icon Sai Yamanoor
Sai Yamanoor
Steven Lawrence Fernandes Steven Lawrence Fernandes
Author Profile Icon Steven Lawrence Fernandes
Steven Lawrence Fernandes
Srihari Yamanoor Srihari Yamanoor
Author Profile Icon Srihari Yamanoor
Srihari Yamanoor
+1 more Show less
Arrow right icon
View More author details
Toc

Table of Contents (37) Chapters Close

Title Page
Copyright and Credits
About Packt
Contributors
Preface
1. Getting Started with a Raspberry Pi 3 Computer FREE CHAPTER 2. Dividing Text Data and Building Text Classifiers 3. Using Python for Automation and Productivity 4. Predicting Sentiments in Words 5. Detecting Edges and Contours in Images 6. Building Face Detector and Face Recognition Applications 7. Using Python to Drive Hardware 8. Sensing and Displaying Real-World Data 9. Building Neural Network Modules for Optical Character Recognition 10. Arithmetic Operations, Loops, and Blinky Lights 11. Conditional Statements, Functions, and Lists 12. Communication Interfaces 13. Data Types and Object-Oriented Programming in Python 14. File I/O and Python Utilities 15. Requests and Web Frameworks 16. Awesome Things You Could Develop Using Python 17. Robotics 101 18. Using GPIOs as Input 19. Making a Gardener Robot 20. Basics of Motors 21. Bluetooth-Controlled Robotic Car 22. Sensor Interface for Obstacle Avoidance 23. Making Your Own Area Scanner 24. Basic Switching 25. Recognizing Humans with Jarvis 26. Making Jarvis IoT Enabled 27. Giving Voice to Jarvis 28. Gesture Recognition 29. Machine Learning 30. Making a Robotic Arm 1. Other Books You May Enjoy Index

Connecting remotely to Raspberry Pi over the network using VNC


Often, it is preferable to remotely connect to and control Raspberry Pi across the network, for instance, using a laptop or desktop computer as a screen and keyboard, or while Raspberry Pi is connected elsewhere, perhaps even connected to some hardware it needs to be close to.

VNC is just one way in which you can remotely connect to Raspberry Pi. It will create a new desktop session that will be controlled and accessed remotely. The VNC session here is separate from the one that may be active on Raspberry Pi's display.

Getting ready

Ensure that your Raspberry Pi is powered up and connected to the internet. We will use the internet connection to install a program using apt-get. This is a program that allows us to find and install applications directly from the official repositories.

How to do it...

  1. First, we need to install the TightVNC server on Raspberry Pi with the following commands. It is advisable to run an update command first to get the latest version of the package you want to install, as follows:
sudo apt-get updatesudo apt-get install tightvncserver
  1. Accept the prompt to install and wait until it completes. To start a session, use the following command:
vncserver :1
  1. The first time you run this, it will ask you to enter a password (of no more than eight characters) to access the desktop (you will use this when you connect from your computer).

The following message should confirm that a new desktop session has been started:

New 'X' desktop is raspberrypi:1

If you do not already know the IP address of Raspberry Pi, use hostname -I and take note of it.

Next, we need to run a VNC client. VNC Viewer is suitable program, which is available at http://www.realvnc.com/ and should work on Windows, Linux, and OS X.

When you run VNC Viewer, you will be prompted for the Server address and Encryption type. Use the IP address of your Raspberry Pi with :1. That is, for the IP address 192.168.1.69, use the 192.168.1.69:1 address.

You can leave the Encryption type as Off or Automatic.

Depending on your network, you may be able to use the hostname; the default is raspberrypi, that is raspberrypi:1.

You may have a warning about not having connected to the computer before or having no encryption. You should enable encryption if you are using a public network or if you are performing connections over the internet (to stop others from being able to intercept your data).

There's more...

You can add options to the command line to specify the resolution and also the color depth of the display. The higher the resolution and color depth (can be adjusted to use 8-bits to 32-bits per pixel to provide low or high color detail), the more data has to be transferred through the network link. If you find the refresh rate a little slow, try reducing these numbers as follows:

vncserver :1 -geometry 1280x780 -depth 24

To allow the VNC server to start automatically when you switch on, you can add the vncserver command to .bash_profile (this is executed each time Raspberry Pi starts).

Use the nano editor as follows (the -c option allows the line numbers to be displayed):

sudo nano -c ~/.bash_profile

Add the following line to the end of the file:

vncserver :1

The next time you power up, you should be able to remotely connect using VNC from another computer.

You have been reading a chapter from
Getting Started with Python for the Internet of Things
Published in: Feb 2019
Publisher:
ISBN-13: 9781838555795
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image