Chapter 1. Introduction

The Arduino and Raspberry Pi make it easier than ever for a hobbyist to get into the world of electronics. Perhaps you want to set up a DIY home automation system so that you can control your lights and heating over your WiFi network, or simply control some motors. 

This book will show you how to use the popular Raspberry Pi and Arduino platforms so that your Pi or Arduino can make and control movement, light, and sound.

Arduino and Pi

Although the Arduino and Raspberry Pi are both small, credit card–sized circuit boards, they are actually quite different devices. The Arduino is a very simple microcontroller board that does not run an operating system of any sort, whereas the Raspberry Pi is a tiny computer that runs Linux and also happens to be able to interface to external electronics.

Raspberry Pi

If you are new to electronics, but comfortable using computers, then the Raspberry Pi is going to be the more familiar device. The Raspberry Pi (Figure 1-1) really is a very small version of a regular computer running Linux. It has USB ports for you to attach a keyboard and mouse as well as HDMI video output to connect to a monitor or TV and audio output.

Figure 1-1. A Raspberry Pi 2

The Raspberry Pi has an Ethernet port to connect it to your network and will also accept USB WiFi adapters. Power is supplied to the Raspberry Pi using a microUSB socket.

A microSD card is used for storage rather than a conventional disk drive. This card contains both the operating system and all your documents and programs.

The Raspberry Pi was created in the UK, primarily to serve as a low-cost computer to help with teaching computer basics, particularly Python programming, to school kids. In fact, the name Pi is said to be derived from the Py of Python.

A few things set the Raspberry Pi apart from a regular desktop or laptop computer running Linux:

  • It costs just $40 (a cut-down Raspberry Pi called the model A+ is also available for a lower price and the model zero for an even lower price).
  • It uses under 5 watts of power.
  • The Raspberry Pi has a double row of general-purpose input/output (GPIO) pins that allow you to connect electronics directly to it (the pins can be seen in the upper-left part of Figure 1-1. From these pins, you can control LEDs, displays, motors, and all the different types of output devices that you will work with later in this book. 

In addition, the Raspberry Pi can also be connected to the Internet using WiFi or a LAN cable, making it suitable for Internet of Things projects (Chapter 16).

The specs for the Raspberry Pi 2 (the latest and best version at the time of writing) are as follows:

  • ARM v7 900 MHz quad-core processor 
  • 1 GB DDR2 memory
  • 10.100 BaseT Ethernet
  • 4 USB 2.0 ports
  • HDMI video out
  • Camera interface socket
  • 40-pin GPIO header (all pins operate at 3.3V)

If you are new to Raspberry Pi, there is a primer to get you up and running with the hardware and also the Python programming language in Chapter 3.

Arduino

There is quite a wide range of different Arduino models available. This book concentrates on the most widely used and popular Arduino model, the Arduino Uno (Figure 1-2). The Arduino is a little cheaper than a Raspberry Pi—you can purchase an Arduino Uno for around $25.

Figure 1-2. An Arduino Uno Revision 3

If you are accustomed to working on a regular computer, the Arduino’s specifications will probably seem grossly inadequate. It has just 34 KB of memory (of various types). That means that the Raspberry Pi has roughly 30,000 times as much memory, without even including the flash memory of the Pi’s SD card! What’s more, the Arduino Uno has a processor clocked at just 16MHz. You cannot attach a keyboard, mouse, or monitor to the Arduino, and it does not run an operating system.

You may wonder how this little device can actually do anything useful. The secret to the Arduino’s usefulness lies in its very simplicity. There is no operating system to boot up, or other interfaces that you may not need in a project that would simply add cost and consume power.

Whereas the Raspberry Pi is a general computer, the Arduino concentrates on doing one thing well—connecting to and controlling electronics.

To program an Arduino, you need a regular computer (you can even use a Raspberry Pi if you want). On the computer you choose, you’ll need to run an integrated development environment (IDE), which allows you to write a program to be downloaded to the built-in flash memory on the Arduino.

The Arduino can only run one program at a time, and once it is programmed, it will remember that program and automatically run it as soon as it is powered up.

Arduinos are designed to accept shields, which are boards that plug on top of the Arduino’s input/output sockets and add extra hardware features, such as various types of display, as well as Ethernet and WiFi adapters. 

You program an Arduino using the C programming language (you can find out more about programming and using an Arduino in Chapter 2).

Choosing a Device: Arduino or Pi?

One of the reasons this book explains how to connect electronics to both Arduino and Raspberry Pi is that some projects are better suited to a Raspberry Pi and some to an Arduino. Other boards that lie in between these extremes are generally close enough to either an Arduino or Raspberry Pi that this book will be of use in working out how to use them.

When embarking on a new project, my rule of thumb is to use an Arduino by default. However, if the project has one of the following requirements, then a Raspberry Pi is probably a better choice:

  • Internet or network connectivity
  • The need for a large screen
  • The need to attach keyboard and mouse
  • The need for USB peripherals such as a web cam

With some effort and expense it’s possible to expand the Arduino with shields to cover most of the preceding requirements. However, it will be harder to get everything working if you go this route, as none of these are native features of the Arduino in the same way as they are for the Pi.

Good reasons for using an Arduino over a Raspberry Pi include the following:

Cost
An Arduino Uno is cheaper than a Raspberry Pi 2.
Startup time
An Arduino does not need to wait while an operating system boots up. There is a small delay of about a second while it checks to see if a new program is being uploaded and then it’s up and running.
Reliability
An Arduino is intrinsically a much simpler and tougher device than a Raspberry Pi and doesn’t have the overhead of an operating system.
Power consumption
An Arduino uses about 1/10th of the power of a Raspberry Pi. If you need a battery- or solar-powered solution, then the Arduino is a better choice.
GPIO output current
A Raspberry Pi’s GPIO pin should only be used to supply a maximum of around 16 mA. On the other hand, an Arduino pin is rated at 40 mA. So, in some cases, you can connect something (say a bright LED) to an Arduino directly, in a way that you couldn’t with a Raspberry Pi.

The Arduino and the Raspberry Pi both are great devices to base a project on, and to some extent, the choice of which device to use will also be a matter of personal preference.

One important thing to remember when attaching external electronics to a Raspberry Pi is that it operates at 3.3V, rather than the 5V of Arduino. Connecting 5V to one of the Raspberry Pi’s GPIO pins is likely to damage or destroy the GPIO pin or even the whole Raspberry Pi.

Alternatives

The Arduino Uno and Raspberry Pi sit at each end of the range of devices that can be used to control things. As you might expect, the market has produced a whole host of other devices that sit in between these two extremes, in some cases trying to give the best of both worlds.

New devices are popping up all the time. The open source nature of Arduino has led to lots of variations on it, with designs for specific niches, such as controlling drones or interfacing to wireless sensors.

Figure 1-3 shows a spread of some of the most popular devices in this area.

Figure 1-3. Embedded platforms

Below the Arduino Uno, both in price and performance, is the Adafruit Trinket. This interesting board only has a few GPIO pins, but is otherwise fairly Arduino compatible. It’s worth considering for a project that may just have one or two inputs or outputs.

There is a middle ground of products comprising the Arduino Yun, Intel Edison, and Photon that all have built-in WiFi capabilities and are intended for use with Internet of Things (IoT) projects (see Chapter 16). Of these, the Photon probably represents the best value. All three of these devices are programmed using Arduino C, so what you learn about using the Arduino will also apply to these boards. 

The BeagleBone Black is very similar in concept to the Raspberry Pi. It too is a single-board computer and although the current BeagleBone Black version has fallen behind the Raspberry Pi 2 in terms of raw power, the BeagleBone Black does have some advantages over the Raspberry Pi. It has more GPIO pins and also has some pins that can act as analog inputs, a feature lacking in the Raspberry Pi 2. The BeagleBone Black can either be programmed in Python, in a similar way to the Raspberry Pi, or in JavaScript.

Summary

This chapter provided a brief introduction to the Arduino and the Raspberry Pi. We discussed the advantages and disadvantages that each of these boards offer, and also looked at some alternatives. The next two chapters will get you started with using and programming the Arduino and then the Raspberry Pi.  

If you have used Arduino and Raspberry Pi before, you might like to jump ahead to  Chapter 4 and use the Arduino and Raspberry Pi to Make some Action! You can always return to Chapter 2 and Chapter 3 if you need to.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset