Arduino Software Internals

The Arduino platform does a great job of abstracting the hardware and software so that makers can focus on the task at hand such as blinking an LED or moving a servo.

But there are times when you need to look inside to gain understanding, support a new board, customise the build process or fix a bug. And this is where Norman Dunbar’s book comes in useful.

Arduino Software Internals focuses on the AVR family of microcontrollers that are most commonly found in Arduino boards and more specifically the ATmega328. If you are working with a different architecture then the book will provide insight into what you are likely to need to port to your microcontroller.

Norman sent me a copy of the second edition which has been updated to reflect the software changes that have happened since 2020 when the first edition came out.

The book starts with a quick look at the software and then dives deep into the processes behind compilation. The various configuration files for customising the compilation and communication with the boards is covered. One thing I felt was missing was the step before this where these configuration files are discovered and downloaded from the internet, a process I’d recently had to troubleshoot when a website holding those files was offline.

The section on Arduino Language looks at some of the functions, macros and classes used by the framework and in my case highlighted some of the less known ones such as pulseIn and shiftIn for handling PWM input and input from ShiftRegisters. The annotated code samples explain the behaviour and limitations.

Description of the function noTone with annotated code example

Following this is a chapter which looks at replacing some of those functions with low level AVR versions. This can be used to improve performance and reduce storage requirements. It also opens up new capabilities such as changing or reading multiple I/O pins simultaneously. There’s not much too this chapter as it covers a lot of basics such as bit shifting and logic which perhaps would be a bit basic to most of the target audience of this book.

The chapter on alternatives to the ide is the opposite and has lots of details on how we can build and deploy code via PlatformIO or the Arduino Command Line interface.

Platform IO with example of how the command appears and advice on what happens when you shut down the tool

This is full of detail although perhaps misses the “why” aspect to using these other tools which has to be inferred by examining the capabilities these provide. There’s a great section on using a MAKE file for compiling and deploying which could be used for automating your development. It would have been nice to see at least a mention of continuous integration tools such as Github actions or Azure Pipelines which is one place where the CLI is used behind the scenes.

The last three chapters dig into the details of the hardware for the ATMega328P or more specifically how these features are accessed via software. They cover advanced features like programming fuses, watch dog function, timers and low power modes. All of these can be gleaned from the chips data sheets but Norman’s descriptions make it a lot easy to understand these topics.

And the book doesn’t finish there as there are 11 additional appendices with tables, diagrams and references.

Example of an appendix, this one refers to Norman's AVR Assist library for helping with timers, Analogue to Digital conversion and Watch Dog function.

One topic which is not covered by the book is how you might go about creating your own Arduino library for others to use and how to make it appear in the IDE via a configuration file.

All in all this is a excellent reference book for those who are experienced with the Arduino platform and want to expand its capabilities or get more from their AVR microcontroller.

A big thank you to Norman for sending this over, it has already given me ideas for how I can save time on some of my projects and I’m sure I will be dipping into it regularly.

One thought on “Arduino Software Internals

  1. Norman Dunbar says:

    Good morning. Thanks for a decent review of my book.

    the reason I didn’t cover CI like GitHub Actions etc is simply that I don’t use them!

    As to why I didn’t mention the “why” in using PlatformIO or the Arduino-cli, perhaps an oversight. I thought the introduction to those chapters offered a “why” in as much as it mentioned them as alternatives to the IDE, should you wish to use one.

    The target audience is really for beginners onwards, who might like to delve into how things work, which is what I always end up doing. But maybe that’s just me?

    Anyway, thanks again.

    Cheers,
    Norm.

Leave a Reply

Your email address will not be published. Required fields are marked *

 characters available