Found: a bug in analogRead() returns false readings in SAMD21 Arduinos 

 September 4, 2019

By  Peter

Join Our Mailing List

We publish fresh content each week. Read how-to's on Arduino, ESP32, KiCad, Node-RED, drones and more. Listen to interviews. Learn about new tech with our comprehensive reviews. Get discount offers for our courses and books. Interact with our community.

One email per week, no spam, unsubscribe at any time.

Alain Pannetrat recently wrote a blog article in which he shows how he found a bug in the implementation of the Arduino analogRead() function for the SAMD21.

The SAMD21 is used in the Arduino Zero, and in Alain’s Omzlo CANZERO node.

The bug in analogRead() causes the readings on the SAMD21 analog pins to be offset by around 35mV. This is hardly the end of the world, but still a very interesting finding that has real-world implications.

This error will produce incorrect results in any calculations that involve analog readings. Temperature, light, voltage from a battery to calculate available energy, etc.

Alain’s process of finding the source of the error is very interesting. Originally, he theorised that the error can be either in the hardware of the microcontroller, or the implementation of the SAMD21 analogRead() function.

Hardware or software?

More testing was needed, and Alain went on to write his own bare-minimal analogRead function to see exactly what comes out of the microcontorller.

This test showed an accurate voltage measurement from the microcontroller, which meant that the bug seems to be in the software implementation of analogRead.

Nice find Alain!

Read all the details in the Omzlo blog.


analogRead, bug, SAMD21

You may also like

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Capacitors are fundamental components in electronic circuits, and understanding how they work is crucial for anyone looking to build and design their own circuits. In this segment, we’ll explore the various kinds of capacitors you

Read More
Introduction to Capacitors and RC Circuits

The Khadas VIM1S is a high-quality yet affordable single-board computer well suited to hobbyists’ needs. While it doesn’t have the power of its siblings, such as the Edge2, it strikes a fine balance between performance

Read More
Khadas VIM1S: Unbox, Set Up, and Review