Reader small image

You're reading from  Raspberry Pi Computer Architecture Essentials

Product typeBook
Published inMar 2016
Reading LevelIntermediate
Publisher
ISBN-139781784397975
Edition1st Edition
Languages
Right arrow
Authors (2):
Andrew K. Dennis
Andrew K. Dennis
author image
Andrew K. Dennis

Andrew K. Dennis is a full stack and cybersecurity architect with over 17 years' experience who currently works for Modus Create in Reston, VA. He holds two undergraduate degrees in software engineering and creative computing and a master's degree in information security. Andy has worked in the US, Canada, and the UK in software engineering, e-learning, data science, and cybersecurity across his career, and has written four books on IoT, the Raspberry Pi, and supercomputing. His interests range from the application of pataphysics in computing to security threat modeling. Andy lives in New England and is an organizer of Security BSides CT.
Read more about Andrew K. Dennis

View More author details
Right arrow

Chapter 10. Integrating with Third-Party Microcontrollers

In this chapter, we will explore how we can integrate third-party microcontrollers into a project using the Raspberry Pi. This allows us to then build a variety of projects, from home automation to robotics. Here, we will bring together some of the skills we have learned over the previous chapters. In this chapter we will cover the following topics:

  • The Genuino/Arduino microcontroller

  • Setting up the Arduino software

  • Working with the serial and I2C pins we enabled earlier in the book

  • Communicating between devices using Python and the Arduino programming language

For the projects in this chapter you will need the following components:

  • Genuino/Arduino Uno

  • USB cable

  • 1.6 and 3.3 Ohm resistors

  • Wires and breadboard

  • Ethernet shield (optional if you wish to try out the Arduino web server examples)

We have chosen the Ardunio Uno microcontroller as it is popular, cheap and versatile. Next, we will look at it in more detail.

Genuino/Arduino microcontroller


Genuino/Arduino is a range of open source microcontrollers developed by Massimo Banzi in Italy during the early 2000s. They have been geared toward students and the open source hardware hacking community. With products ranging from wearable microcontrollers to the wireless Arduino Yun, the range of projects available to enthusiasts is only limited by the imagination.

In the US, the product is branded with the Arduino name. Outside of the US you will see the Genuino branding. This is due to an ongoing legal dispute over the copyright outside of the US. You can read more about this at http://makezine.com/2015/05/16/arduino-adafruit-manufacturing-genuino/.

The full range of boards can be found at the official Arduino website at https://www.arduino.cc/en/Main/GenuinoBrand.

Software developed for Arduino is done via a free programming development environment. The Arduino sketch programming language was based upon the open source Wiring platform. You can read more...

Setting up the Arduino software


Our first task will be to install a copy of the Arduino IDE (Integrated Development Environment) on our Raspberry Pi. The Arduino IDE is where we will write sketches—these are Arduino programs. The IDE also allows us to upload the code directly to the Arduino Uno.

The software can be found at the official Arduino website: http://arduino.cc/en/main/software

The installation instructions cover a variety of operating systems, including Linux, Mac OSX, and Windows. For the Raspberry Pi you will want the Linux instructions.

You can, of course, install the IDE onto a separate computer and use this for updating the Arduino if you wish.

The following section will provide a quick overview of the Linux installation process.

Installing the IDE on your Raspberry Pi 2

To install the IDE directly onto your Raspberry Pi 2, you can use the terminal.

  1. Open a new command line, or via your SSH connection run the following command:

    sudo apt-get install arduino
    
  2. Accept any prompts displayed...

Integration with Arduino


As you may remember, we enabled the serial port on the Raspberry Pi earlier. We are now going to install a Python library called PySerial that allows us to communicate via Python.

This can be installed via apt-get:

sudo apt-get install python-serial

Tip

If you already have the latest version of the library, you will see this message:

python-serial is already the newest version.

Once you have this installed you can read more about the library at the PySerial website: https://pythonhosted.org/pyserial/.

Before we start writing applications with PySerial, we need to know where our Arduino is connected. You may have noticed that this information was provided in the Arduino IDE when you selected the serial port. If you used a different machine to write the sketch, however, there is a method we can use to find out where it is plugged in.

Start by running the following command:

ls /dev/tty*

This will output a list to your screen. Currently, the Arduino Uno isn't connected,...

Summary


This concludes our chapter on working with the Raspberry Pi 2 and the Arduino microcontroller.

Here, we learned how we could communicate over USB, GPIO, and I2C. This brought together some of the tasks we performed in earlier chapters.

Next is the final chapter of the book! Here we will build a project that uses some of the skills you have learned so far. You'll test your experience of working with GPIO pins, the Python programming language, and web development. Finally, you'll be presented with some ideas on how to expand your project further.

So let's get started.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Raspberry Pi Computer Architecture Essentials
Published in: Mar 2016Publisher: ISBN-13: 9781784397975
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.
undefined
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

Authors (2)

author image
Andrew K. Dennis

Andrew K. Dennis is a full stack and cybersecurity architect with over 17 years' experience who currently works for Modus Create in Reston, VA. He holds two undergraduate degrees in software engineering and creative computing and a master's degree in information security. Andy has worked in the US, Canada, and the UK in software engineering, e-learning, data science, and cybersecurity across his career, and has written four books on IoT, the Raspberry Pi, and supercomputing. His interests range from the application of pataphysics in computing to security threat modeling. Andy lives in New England and is an organizer of Security BSides CT.
Read more about Andrew K. Dennis