C++ is the language Arduino programs are written in, or more precisely a C++ with scaffolding around it (the Wiring dialect), where two functions, setup() and loop(), frame the whole of the code. Mastering its building blocks is what separates copying an example from writing your own program. This page is the step-by-step learning hub for the language on the embedded side: from the first program that compiles through to control structures, every sub-page comes with code to read and exercises to work through. The same language programs the ESP32, the Teensy and the other boards of the Arduino framework. This path therefore serves them all.

Learning path

To be followed in order: each step assumes the one before it.

  1. How a program runs — the compile → upload → run cycle, and the minimum code that compiles;
  2. The structure of a program — preprocessor, #include, #define, global variables, setup(), loop(), functions;
  3. Typing variables — picking the right type, and what it costs in memory;
  4. Local and global variables — scope, and what survives from one pass of the loop to the next;
  5. Conditions — if / else, switch, comparison and logical operators;
  6. Loops — for, while, do…while: which one to choose;
  7. Reading and understanding errors — decoding the compiler’s messages to get yourself unstuck;
  8. Reading a program you did not write — getting into unfamiliar code, and the language mechanisms that come back from one example to the next.

Once these blocks are in place, the question becomes how to structure the code: see non-blocking programming, state machines and the overall shaping of the firmware. And for the MicroPython path, the same apprenticeship in the language exists as a twin: The MicroPython language.

See also