Book Image

Raspberry Pi Home Automation with Arduino - Second Edition

By : Andrew K. Dennis
Book Image

Raspberry Pi Home Automation with Arduino - Second Edition

By: Andrew K. Dennis

Overview of this book

Table of Contents (16 chapters)
Raspberry Pi Home Automation with Arduino Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
4
Temperature Storage – Setting Up a Database to Store Your Results
Index

History and background of the Arduino


One of the most popular open-hardware products to have hit the market is the Arduino platform. Developed in Italy by Massimo Banzi and David Cuartielles in 2005, Arduino is an open-hardware technology coupled with a programming language and an Integrated Development Environment (IDE) based on the open source wiring software.

The Arduino platform allows the user to create custom hardware and applications that control it via its namesake programming language. Cheap and easy to use, Arduino is an alternative to expensive programmable cards and closed commercial systems. Therefore, it helped pave the way for home enthusiasts to build their own home automation projects.

Currently, there are several board models in the market with a wide range of sizes and components; for example, the Lily Pad allows enthusiasts to attach an Arduino board to clothing for textile-based electronic projects. These boards support a wide range of shields—Arduino-compatible electronic boards that can be plugged into it and expand its functionality. One particular extension has been the introduction of Ethernet shields and wireless XBee devices that allow communication with home networks and the Web. What makes Arduino suitable for amateur enthusiasts is that little or no knowledge of how electronic components are soldered is required to use its prebuilt shields. As the user becomes more comfortable with the technology, they can progress to building their own projects using the numerous kits and sensors available on the market.

This easy adoption has helped contribute to a number of websites and books dedicated to home automation projects that use this technology.

Throughout the following chapters, you will explore the use of Arduino alongside the Raspberry Pi. For the projects in this book, we recommend using the Uno board pictured as follows:

Note

You can read more about Arduino products at http://arduino.cc/en/Products.Compare.

Next, we shall look at the Raspberry Pi to Arduino connection bridge, a method of connecting your Arduino shields to your Raspberry Pi.

Raspberry Pi to Arduino shield connection bridge

For two of the projects in this book, we will be using the Raspberry Pi to Arduino shield connection bridge. This is produced by Cooking Hacks, an offshoot of the Libelium wireless communications company based in Spain.

Note

Their website can be found at http://www.cooking-hacks.com.

By connecting this device to our Raspberry Pi, we get to reuse our Arduino shields and components, and get the power and storage of the Raspberry Pi running behind it. This opens up many options for complex home automation projects that may need to host databases or run memory-intensive software.

The Cooking Hacks shield is connected to the Raspberry Pi's General Purpose Input/Output (GPIO) pins. With the inclusion of the arduPi software, you will be able to communicate between your electronic devices, the Raspberry Pi's operating system, and web-based projects.

The Cooking Hacks shield should look like this:

Image courtesy: Cooking Hacks

A wide range of Arduino shields can be used with the connection bridge. At the time of writing this book, the Arduino shield connection bridge was available for €40.

Note

Many of these shields can be found on the Arduino website at http://arduino.cc/en/Main/Products.

The shields specifications can be also be found at http://www.cooking-hacks.com/documentation/tutorials/raspberry-pi-to-arduino-shields-connection-bridge.

By learning to use this shield, you will discover how you can extend the functionality of your Raspberry Pi so that it can mimic the Arduino microcontroller and reuse components from other Arduino projects that you may have attempted in the past or will build in the future.

Soldering

Soldering is the process of attaching electronic components using a heated metal filler (the solder), in order to allow electrical current to flow between them.

At this point, it is worth mentioning that practicing some soldering before you start building the projects in this book is worth the effort, but not strictly necessary. If you are a novice, do not worry because there will be minimal soldering.

Also, if you have any old PC hardware sitting around, such as a graphics card that is no longer in use, you can practice desoldering and resoldering the components until you become comfortable with the process. This will also help you to get used to the soldering iron and desoldering tool.

Creating software for the Arduino

After you have set up the Arduino microcontroller and Arduino shield, and plugged it into the Raspberry Pi, you will probably be wondering how to interact with it. After all, it has sensors and LEDs, but these are nothing without applications to control them in a meaningful manner.

There are many software languages available for building projects with, but we are interested in the Arduino programming language, C++, Python, SQL, and HTSQL.

  • The Arduino programming language is a subset of C++ and provides us with a tool to program the Arduino microcontroller, Arduino-compatible shields, and the components connected to them. One benefit of using this technology is that there is a wealth of programs and libraries online that can be used for future projects. You will be using this language in the Arduino IDE and on the Raspberry Pi to write the core applications that will be reading data from sensors attached to your projects.

  • The next language that we will be using is Python. Python is a high-level programming language developed in the late 1980s by Guido Van Rossum named after the popular comedy show Monty Python's Flying Circus. This language allows you to build web and database applications that can be used to process the output of Arduino programs. We will be using Python to build a web application that can process data sent to it and then insert it via SQL into a SQLite3 database.

  • We will also be using SQL to build the database that our Python script connects to. In conjunction with the SQLite database management system, we will construct a repository to store some of the results from our projects, for example temperature data.

  • Besides these languages, we will also be using Hyper Text Structured Query Language (HTSQL) to provide a web interface to our database that is easy to access via the web browser and query via HTTP.

Now that we have looked at our tools to build home automation systems, the Raspberry Pi and Arduino, let's look at what home automation is.