Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Raspberry Pi Embedded Projects Hotshot

You're reading from  Raspberry Pi Embedded Projects Hotshot

Product type Book
Published in Feb 2015
Publisher
ISBN-13 9781849696227
Pages 250 pages
Edition 1st Edition
Languages
Concepts

Table of Contents (20) Chapters

Raspberry Pi Mechatronics Projects HOTSHOT
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Hello World A Raspberry WebIDE Example The Arduino Raspberry Pi Interface Christmas Light Sequencer Internet of Things Example – An E-mail Alert Water Fountain Raspberry Pi as a Personal Assistant Raspberry Pi-based Line Following Robot Connect Four Desktop Game using Raspberry Pi The Raspberry Pi-enabled Pet/Wildlife Monitor Raspberry Pi Personal Health Monitor Home Automation using Raspberry Pi Using a Raspberry Pi for Science and Education Tips and Tricks Index

Chapter 3. The Arduino Raspberry Pi Interface

In this project, we will look into interfacing the Raspberry Pi to the Arduino microcontroller development platform. Arduino (www.arduino.cc) is a popular microcontroller platform that is widely used to prototype different projects. We will discuss installation of the Arduino development environment and discuss an example of its usage.

Raspberry Pi and Arduino have become popular platforms among hobbyists, and it is being widely used by people from different backgrounds, including school and university students, artists, and engineers. This project explains how the Raspberry Pi can be used in combination with Arduino.

Note

The Raspberry Pi comes with a GPIO pin set that is quite capable of interfacing and control devices. We would like to discuss the Arduino Raspberry Pi interface because you may have projects that were originally built using an Arduino, especially in scenarios where a remote firmware update needs to be performed on the Arduino...

Mission briefing


In the first part of the project, we will discuss programming the Arduino for the first time, and in the second half, we will look into the control of a Weasley weather clock. We will also look into the Raspberry Pi AlaMode , stackable add-on arduino hardware (http://wyolum.com/projects/alamode/).

Why is it awesome?

Arduino is an open source microcontroller development platform based on the Atmel series of microcontrollers. It has brought engineers, artists, and students to the same table. The programming interface (programs are written in C/C++ usually) is so simple and this was the sole reason that made the platform so popular. Hence, it is widely used for prototyping in product development.

Over the years, there have been several hardware add-ons that aided in hardware development using the Arduino. Some of these add-ons can be stacked on top of the Arduino development platform, and they are commonly referred to as shields. There are shields for medical devices, interfacing...

Installing the Arduino IDE


In this section, we will install the Arduino IDE on the Raspberry Pi.

Prepare for lift off

An Arduino microcontroller development platform (any variant that could be programmed using the Arduino IDE is fine) is absolutely essential for this section of the project.

Engage thrusters

  1. The IDE could be installed by executing the following command in the command line terminal:

    sudo apt-get install arduino
  2. Most Arduino products come with a USB port and are programmed via the USB port (the Arduino enumerates as a serial port device) . It takes a while to download and install the Arduino IDE. Once the installation is finished, we can test the installation by executing the following command:

    arduino
    • The Arduino IDE is shown in the following screenshot:

    The Arduino IDE interface

Objective complete – mini debriefing

Now that we have installed the Arduino IDE, let's move on to the next section and run an example test using the Arduino development platform.

Programming the Arduino using the Raspberry Pi


We will introduce ourselves to the Arduino IDE with an LED blinking example.

Prepare for lift off

There are several examples for the Arduino and it takes less than a minute to execute the first program. Let's get started with the traditional LED blinking example. The LED blinking example can be found at File | Examples | 01 . Basics | Blink.

Engage thrusters

  1. We get started by identifying the Arduino's serial port enumerated on the Raspberry Pi.

  2. The serial port is identified from Tools | Serial Port. Usually there is only one serial port as shown in the following screenshot. If there is more than one serial port device connected, it is recommended that you proceed with caution.

  3. We can program the Arduino by clicking on the Upload button.

    The Arduino IDE interface

Objective complete – mini debriefing

If the Arduino is connected and the serial port was correctly identified, the program should be uploaded successfully.

Sketch uploaded using the Arduino IDE...

Raspberry Pi AlaMode


In this section, we will briefly discuss the Raspberry Pi AlaMode's features and its setup. Raspberry Pi AlaMode (as shown in the following figure) is a stackable Arduino development platform developed specifically for the Raspberry Pi. The board, which is released as open source hardware, is priced at about $45 and also includes a real-time clock and a micro SD card slot for data logging.

Raspberry Pi AlaMode mode stacked on the Raspberry Pi

Prepare for lift off

The attractive feature of the board is that it could be programmed via the Raspberry Pi's UART pins and hence eliminates the need for a USB port. The board could be either powered via the Raspberry Pi or through the Micro B USB port using a wall wart transformer. The product's webpage, http://wyolum.com/projects/alamode/alamode-getting-started/, offers a single step process to start using the board.

Note

The Raspberry Pi AlaMode mode is just one example of the stackable Arduino hardware. There are probably other...

The Weasley weather clock


We will build a Weasley weather clock in this project using an Arduino microcontroller board and the Raspberry Pi. The Weasley Weather clock is inspired by the Weasley clock seen in the Harry Potter series of movies. A Weasley clock is used to identify the current location of a family member of the Weasleys (for example, work, school, and so on) and also the safety of the family member. Mrs. Molly Weasley (the matriarch of the Weasleys) used the Weasley clock to keep tabs on her family and this clock has had its variants over the years. This project happens to be one of them!

The Weasley weather clock is one that displays the current outdoor temperature and the forecast. It also warns us about impending dangers due to conditions such as tornadoes, blizzards, and so on.

A Weasley weather clock built using the Arduino and the Raspberry Pi

Prepare for lift off

The following items (along with their approximate cost) are required to build our Weasley clock:

Controlling the stepper using the Arduino


The part number of the stepper motor used in this example is 28BJY-48 (http://www.adafruit.com/product/858). A stepper motor is a type of motor that is operated by energizing its coils in several steps. The coil energization in several steps enables the stepper to rotate in precise angular steps. This precise movement aids the use of a stepper motor in open loop systems. Since the working principle of a stepper motor is beyond the scope of the book, let's discuss its control technique.

Prepare for lift off

The stepper motor is powered by a common lead connected to the power supply and the other end is connected to a transistor. Since transistors can be used as switches, the leads of the coil can be grounded alternatively. This alternative sequence causes the stepper motor to rotate and the speed of rotation is controlled by introducing a delay in between the coil energization. The minimum delay required between each energization step to make the stepper...

Controlling the RGB LED Strip using the Arduino


We depict the mood of the weather forecast by using RGB LED lighting. We indicate cold weather indications with blue color lighting, fair weather conditions with green lighting, and warm/dangerous weather conditions using red lighting. In this section, we will look into controlling an RGB LED using the Arduino.

The RGB LED strip sold by Adafruit industries (http://www.adafruit.com/products/1004) consumes about 60 mA per segment. It is best recommended to drive the RGB LED strip using a transistor switching circuit. We need to use three transistors for the three colors and it is possible to control each color individually and it is also possible to obtain a combination of colours.

Note

It is possible to produce a secondary color using the RGB combinations. This can be achieved by turning on the RGB segments at the same time and varying the brightness of the primary colors. There are vast resources available for such tips and tricks on the Internet...

I2C Communication using the Arduino (optional)


In this project, there is a 7-Segment display, 8x8 LED matrix, proximity sensor (to determine the home position), and a BlinkM RGB LED that communicates via the I2C interface. We will discuss the application of each component in this project.

Prepare for lift off

The main requirement for this section is the necessary I2C device required to interface with the weather clock.

Engage thrusters

Let us review about the 7-Segment display.

The 7-Segment display

  1. The Adafruit 7-Segment display backpack (reference: the tutorial available at https://learn.adafruit.com/adafruit-led-backpack/0-dot-56-seven-segment-backpack provides instructions on setting up the backpack and testing the backpack with a code sample), which is used to display the current atmospheric temperature obtained via the Raspberry Pi.

  2. Adafruit provides libraries to write to the 7-Segment display. In order to write to the 7-Segment display, we declare a 7-Segment object:

    Adafruit_7segment matrix_7segment...

Serial port communication with the Raspberry Pi


As mentioned earlier, the weather data is obtained by the Raspberry Pi and communicates the data with control characters via the serial port. We will discuss the control signals used in this project.

Engage thrusters

Let's get started by reviewing the Python script used to operate the weather display.

Python program for the Weasley clock

  1. In this section, we will discuss the Python code for the weather clock. The important requirement for this project is the Python weather API. We need to download and install it to get started. If subversion is not installed on the Raspberry Pi, it can be installed using the following command:

    sudo apt-get install subversion
    
  2. Once the installation is complete, the Python weather API repository can be cloned as follows:

    svn checkout http://python-weather-api.googlecode.com/svn/trunk/ python-weather-api-read-only
    
  3. The Python weather API has a Python3 requirement and is installed as follows:

    cd python-weather-api-read...

Mission accomplished


In this project, we discussed interfacing an Arduino with the Raspberry Pi. This was followed by an example of constructing a weather clock. We demonstrated the Arduino as a low-level controller that interfaces actuators, sensors, and display devices while the Raspberry Pi is interfaced with the Internet. I hope you enjoyed the project!

Hotshot challenge


In this example, the city location was hard-coded into the Python script. It is possible to display the weather data based on the zipcode / city location. What could the input device be? How can this be achieved?

lock icon The rest of the chapter is locked
You have been reading a chapter from
Raspberry Pi Embedded Projects Hotshot
Published in: Feb 2015 Publisher: ISBN-13: 9781849696227
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 $15.99/month. Cancel anytime}

Item

Price

...