Arduino Programming Techniques

Jump to navigation Jump to search


Arduino Programming Techniques Course

This is a course Ronen Shouker (talk) 11:45, 23 August 2016 (UTC) is planning to give starting at the end of October 2016

Many people working with Arduino (or other MCUs from the Arduino IDE) don't realise it, but they are actually programming in C++. C++ can give you power to do many thing: The "C" part gives you power over the bits and bytes. The "++" part gives you object oriented powers. As a former C++ programmer for many years, Ronen will introduce you to some of those things, with emphasis for programing Arduino and other MCUs.

What is this good for?

  • You will have powers to create more complex functionality in code with good structure and increased flexibility.
  • In many cases people who write libraries for hardware modules are makers like you, they wrote it for their need, but you may need to adjust the code to suite yours.
  • Reuse code you find, for more that one hardware module of the same type.
  • Interface with hardware you have no code for.

The course is not intended as a comprehensive C++ course, but gives you some of the basics you can utilize in your Arduino/MCU projects.

Intended Audience

The course is for people who already fiddled with the Arduino, and its programming.


The course will be passed on to you as a series of frontal lectures, that will be given usually on every other Monday at Google's Tel Aviv Campus, so that the TAMI space will not be clogged up. For the examples and exercises you will either need:

  • To come to TAMI and use the pre-prepared kits for them.
  • Get the parts and do the exercises at home. Part List

Ronen will be on most Wednesday evenings at TAMI, so you can come with your questions, and get some help.

The lectures will be in English, unless everyone attending is comfortable with Hebrew.


Topic 1: Preliminaries

  • Basic types
  • Casting
  • typedef
  • Structures
  • Functions
    • Passing parameters by reference.
    • Pointers (in brief)
    • The anomaly of arrays in C/C++

Topic 2: The Object Oriented Advantage

  • Classes intro.
  • Structuring existing code around classes, and using multiple instances. Using example for code for encoder.
  • Virtual functions and inheritance for “callbacks” implementing it for the encoder.
  • Passing object vs. object references in C++.
  • Bird-eye view of some object oriented design possibilities.

Topic 3: Concurrency of operations

  • The problem with delay and blocking operations
    • The multi-threaded approach (with FreeRTOS.)
      • The problem with freeRTOS for arduino.
      • Protecting from inconsistent situation: Mutexes.
      • Avoiding dead locks.
    • Under the hood of multi-threading
      • Structure of memory: stack
      • context switching
  • The asynchronous approach.
    • Introduction: Registering callbacks
    • Using member variables instead of automatic variables.
    • Breaking down simple operations.
    • Breaking down loops.

Topic 4: Bits and Bytes

  • Intro: Representation of stuff in memory.
  • Memory and pointers
    • Structure of memory: program memory area, global variable memory area, stack (review), heap.
  • Pointers
    • Pointer arithmetic and sizeof,
    • Pointers and arrays.
    • memcpy() and memmove()
  • Bits
    • Bitwise operations.
    • Bit shifting