.st0{fill:#FFFFFF;}

Arduino

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.


Tags

analogRead, bug, SAMD21


You may also like

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

Over the last few weeks, I’ve had the opportunity to test and explore the CrowPi 3, the latest iteration of Elecrow’s educational laptop-style workstation built around the Raspberry Pi 5. What I’ve been using is a late-stage

Read More
CrowPi 3: A hands-on review of a versatile STEM learning platform

In my upcoming course, Introduction to Electronics: First-order filters, you’ll explore fundamental electronics concepts through practical applications, simulations, and hands-on experimentation. The course emphasizes learning by doing, supported by clear theoretical explanations, mathematics, and the use

Read More
Exploring RC High-Pass Filters: A Practical Experiment with Analog Discovery 3