Table of Contents
Preface xi
Acknowledgments xiii
Introduction xv
1 Getting Started 1
Microcontrollers 1
Development Boards 2
A Tour of an Arduino Uno Board 3
Power Supply 4
Power Connections 4
Analog Inputs 4
Digital Connections 4
Microcontroller 5
Other Components 5
A Tour of a WiFi-Capable Arduino-Compatible 6
The Origins of Arduino 7
Powering Up 8
Installing the Software 8
Uploading Your First Sketch 10
The Arduino Application 14
Conclusion 16
2 C Language Basics 17
Programming 17
What Is a Programming Language? 19
Blink-Again! 24
Variables 26
Experiments in C 27
Numeric Variables and Arithmetic 29
Commands 31
If 31
For 33
While 36
Constants 37
Conclusion 37
3 Functions 39
What Is a Function? 39
Parameters 40
Global, Local, and Static Variables 41
Return Values 44
Other Variable Types 45
Floats 45
Boolean 46
Other Data Types 47
Coding Style 49
Indentation 49
Opening Braces 50
Whitespace 50
Comments 51
Conclusion 52
4 Arrays and Strings 53
Arrays 53
Morse Code SOS Using Arrays 56
String Arrays 57
String Literals 57
String Variables 59
A Morse Code Translator 59
Data 60
Globals and Setup 61
The loop Function 62
The flashSequence Function 64
The flashDotOrDash Function 65
Putting It All Together 66
The String Class 67
Conclusion 67
5 Input and Output 69
Digital Outputs 69
5 V or 3.3 V? 72
Digital Inputs 73
Pull-Up Resistors 73
Internal Pull-Up Resistors 76
Debouncing 77
Analog Outputs 82
Analog Input 84
Conclusion 86
6 Boards 87
Arduino Nano 87
Arduino Pro Mini 89
Breadboard 90
The Boards Manager 91
ESP32 Boards 92
Raspberry Pi Pico 95
BBC micro:bit 96
Adafruit Feather System 98
Conclusion 99
7 Advanced Arduino 101
Random Numbers 101
Math Functions 104
Bit Manipulation 104
Advanced I/O 106
Generating Tones 106
Feeding Shift Registers 108
Interrupts 108
Compile-Time Constants 110
The Arduino Web Editor 111
Conclusion 112
8 Data Storage 113
Large Data Structures 113
Storing Data in Flash Memory 114
EEPROM 116
Storing an int in EEPROM 117
Writing Anything to EEPROM 119
Storing a float in EEPROM 120
Storing a String in EEPROM 121
Clearing the Contents of EEPROM 122
Compression 123
Range Compression 123
Conclusion 124
9 Displays 125
Alphanumeric LCD Displays 126
A USB Message Board 127
Using the Display 129
Other LCD Library Functions 130
OLED Graphic Displays 130
Connecting an OLED Display 131
Software 132
Conclusion 134
10 Arduino Internet of Things Programming 135
Boards for IoT 135
Installing ESP32 into the Arduino IDE 136
Connecting to WiFi 137
Running a Web Server 139
Serving Sensor Readings 141
Serving Sensor Readings-Improved 142
Turning the Built-in LED On and Off from a Web Page 146
Connecting to a Web Service 147
Conclusion 153
Index 155