Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Raspberry Pi Sensors

You're reading from  Raspberry Pi Sensors

Product type Book
Published in Apr 2015
Publisher
ISBN-13 9781784393618
Pages 192 pages
Edition 1st Edition
Languages
Author (1):
Rushi Gajjar Rushi Gajjar
Profile icon Rushi Gajjar
Toc

Table of Contents (16) Chapters close

Raspberry Pi Sensors
Credits
About the Author
Acknowledgements
About the Reviewers
www.PacktPub.com
Preface
1. Meeting Your Buddy – the Raspberry Pi 2. Meeting the World of Electronics 3. Measuring Distance Using Ultrasonic Sensors 4. Monitoring the Atmosphere Using Sensors 5. Using an ADC to Interface any Analog Sensor with the Raspberry Pi 6. Uploading Data Online – Spreadsheets, Mobile, and E-mails 7. Creating an Image Sensor Using a Camera and OpenCV Shopping List Index

python-gpio


The latest distribution of the RasPi comes with python-gpio installed, but this library will be necessary for those who have an old distribution installed. The python-gpio library allows you to easily access and control the GPIO pins while running the Python script. This library can be downloaded from the Python organization's website, but we will install it using the LXTerminal or PuTTY. Let's proceed by downloading the .tar file:

wget https://pypi.python.org/packages/source/R/RPi.GPIO/RPi.GPIO-0.5.7.tar.gz

If you aren't aware, let me tell you that a TAR file is a kind of bundled file used to make the download compact and easy. We need to extract the downloaded file in a directory:

tar -xf RPi.GPIO-0.5.7.tar.gz

Let's rename this folder for ease of use; use this command:

mv RPi.GPIO-0.5.7 python_gpio

Move to the python-gpio directory to install the library using this command:

cd python_gpio

Tip

While writing a command, you can use the Tab key, which provides an autocompletion feature. For example, while writing the cd pyth command, press Tab. This will autocomplete the command, which will save the time spent on long filenames. Pressing the Tab key twice will give you a list of the available commands or filenames.

Now, we will install this library:

sudo python setup.py install

There is a possibility that it gives you a response that the library is already installed with the latest version. After this process, if you want to remove the downloaded file, you can use the rm command and remove it. Finally, one more library that provides support for the Python Serial Peripheral Interface (SPI) protocol on GPIO is spidev. You can install it using the following command. You can refer to the Serial Peripheral Interface section of Chapter 2, Meeting the World of Electronics, to learn more on SPI protocol. We will be using the SPI protocol in Chapter 6, Uploading Data Online – Spreadsheets, Mobile, and E-mails, when we build the sensor station project to send sensor data on web pages.

sudo pip install spidev

Tip

There are many libraries available, but we will install them later in the upcoming chapters, when the need arises. It is simple to install the libraries, why wouldn't it be? Linux rocks!

You have been reading a chapter from
Raspberry Pi Sensors
Published in: Apr 2015 Publisher: ISBN-13: 9781784393618
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 €14.99/month. Cancel anytime