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

 September 4, 2019

By  Peter

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"}

In this Maker Mind Meld summit presentation, Dal Gemmell talks about a new generation of wireless networks, based on cutting-edge blockchain technology, that delivers a new kind of open, decentralized wireless network built by individuals

Read More
Dal Gemmell – A blockchain-powered decentralized network owned by you

Happy New Year! The turn of a year is an opportunity to reflect (look back) and plan (look forward). 2022 was another challenging year in many respects, and 2023 will be no less challenging. However,

Read More
Start 2023 with Tech Explorations