Arduino has become the standard microcontroller used by makers, artists, and educators due to its ease of use, low cost, and plethora of interface boards (shields). Plug-in shields can be attached to the basic board, extending the Arduino into the Internet, robotic, and home automation realms. As well as official Arduino hardware, the many types of Arduino-compatible boards that can be programmed from the Arduino IDE mean that you can find a board that suits your project’s requirements and cost constraints.
Simple Arduino projects are easy to make. As soon as you start to stray into territory not covered by the introductory texts, however, you’ll find that things can rapidly become confusing and frustrating as complexity—the enemy of all programmers—rears its ugly head.
This book is designed as a companion and sequel to the very successful book Programming Arduino: Getting Started with Sketches. Although this book includes a brief recap of basic Arduino programming, it leads the reader through the more advanced aspects of Arduino programming. Specifically, this book will help you with:
• Working effectively with minimal memory
• Doing more than one thing at a time, without the luxury of multithreading
• Setting up the Arduino IDE to use “Arduino-compatible” boards
• Using hardware and timer interrupts
• Maximizing performance
• Minimizing power consumption
• Interfacing with different types of serial busses (I2C, 1-Wire, SPI, and serial)
• USB programming
• Network programming
• Digital Signal Processing (DSP)
The book includes some 75 example sketches, which are all open source and available from the book’s web page at http://simonmonk.org/nextsteps2. Follow the link to the pages for this book where you will be able to download the code as well as an up-to-date list of errata for the book.
This book is primarily about software. So, for most of the examples, all you really need is an Arduino (or compatible board) and an LED or multimeter. Having said that, if you do have other Arduino shields, these will come in handy. You will also need an Ethernet or WiFi shield for Chapter 12. Throughout the book, several different types of module are used to illustrate different interfaces.
Although the book is mostly concerned with the Arduino Uno (the most commonly used Arduino board), it also covers other special-purpose Arduinos as well as some of the most popular Arduino-compatible boards.
The Appendix at the end of this book lists possible suppliers for these parts.
Each of the chapters deals with a specific topic relating to Arduino programming. Apart from Chapter 1, which is a recap and overview of Arduino basics, the remaining chapters can be accessed pretty much in any order you like.
Following is a description of each chapter:
1. “Programming Arduino” This chapter contains a summary of Arduino programming. It is a primer for those needing to get up to speed quickly with basic Arduino.
2. “Under the Hood” In this chapter, we take a peek under the hood at how the Arduino software works and where it came from.
3. “When Is an Arduino Not an Arduino?” The word “Arduino” has come to mean a lot more than just the standard Arduino boards. In this chapter you will learn how to use Arduino-compatible boards with the Arduino IDE.
4. “Interrupts and Timers” Novices often steer clear of using interrupts. They shouldn’t, however, as they can be handy on occasion and are not difficult to code for. Although there are some pitfalls, this chapter tells you what you need to be aware of.
5. “Making Arduino Faster” Arduinos have low-speed, low-power processors and sometimes you need to squeeze every ounce of juice out of them. For example, the built-in digitalWrite function is safe and easy to use, but is not very efficient, especially when setting multiple outputs at the same time. In this chapter, you look at ways to exceed this performance and learn about other techniques for writing time-efficient sketches.
6. “Low-Power Arduino” When you want to run your Arduino on batteries or solar, then you need to look at minimizing power consumption. In addition to optimizing the hardware design, you can also set up the code to reduce the Arduino’s energy use.
7. “Memory” In this chapter, we look at minimizing memory usage and the benefits and dangers associated with using memory dynamically within your sketches.
8. “Interfacing with Arduino” This chapter explains the theory behind interfacing with microcontrollers that you will need to understand when working with I2C, SPI, and UART serial.
9. “Using I2C” The Arduino’s I2C interface can greatly simplify talking to modules and components, reducing the number of interface pins you need to use. This chapter describes how I2C works and how to use it.
10. “Interfacing with 1-Wire Devices” This chapter focuses on 1-Wire bus devices such as Dallas Semiconductor’s range of temperature sensors, which are extremely popular for use with the Arduino. You learn how the bus works and how to use it.
11. “Interfacing with SPI Devices” Yet another interface standard used with the Arduino is SPI. This chapter explores how it works and how to use it.
12. “Serial UART Programming” Serial communications, either through USB or the Arduino’s Rx and Tx pins, provide a great way to exchange data between peripherals and other Arduinos. In this chapter, you learn how to use serial.
13. “USB Programming” This chapter looks at various aspects of using the Arduino with USB. You’ll learn about the keyboard and mouse emulation features provided by the Arduino Leonardo and also the reverse process of allowing a USB keyboard or mouse to be connected to a suitably equipped Arduino.
14. “Network and Internet of Things Programming” The Arduino is a common component in the Internet of Things. In this chapter, you’ll learn how to program Arduino and Arduino-compatibles for use in network settings and for the Internet of Things.
15. “Digital Signal Processing” The Arduino is capable of fairly rudimentary signal processing. This chapter discusses a variety of techniques, from filtering a signal from an analog input using software rather than external electronics to calculating the relative magnitude of various frequencies in a signal using the Fast Fourier Transform.
16. “Managing with One Process” Programmers coming to Arduino from a background of programming large systems often signal the lack of multithreading and concurrency in Arduino as some kind of deficiency. In this chapter, I try to set the record straight and show how to embrace the single-thread model of embedded systems.
17. “Writing Libraries” Sooner or later, you will make something really good that you think other people could use. This is the time to wrap up the code in a library and release it to the world. This chapter shows you how.
This book is supported by a page on the author’s website (http://simonmonk.org/nextsteps2/) and a GitHub repository containing all the examples (https://github.com/simonmonk/nextsteps2). Follow the link for this book, and you will find all the source code, as well as other resources such as errata.