Using analogReadResolution()

Hi to all!

I found one interesting feature that allows to use the full ADC resolution in some Arduino boards: analogReadResolution() - Arduino Reference .

The documentation says that this is only available for "Due, Zero and MKR Family boards".

So, I'm developing a library that requires precise ADC, and my question is the following: What #ifdef I need to use to figure out that target board belongs to these boards with higher ADC resolution?

#ifdef SAM


#ifdef SAM

Can you please share link to the official documentation or place in code to confirm your point?

No. I don't feel like searching for that for you. You are just as capable of doing so as am I.

You should also be as capable of writing a test program to verify it but since I already have one written I will give you that:

#ifdef SAM
#error A board with SAM architecture is selected
#error A board with non-SAM architecture is selected

void setup() {}
void loop() {}

SAM is for Due. SAMD is for m0 boards Zero, M0, MKR

So, I did a google search using "arduino architecture defines"

It lead (very quickly) to a couple of interesting posts here, which int turn lead to an interesting github page.

This thread lead me to this thread which in turn lead me to this github page

Google can (sometimes) be your friend :wink:

PS.. Read each thread ALL the way through :wink:

SAM is for Due. SAMD is for m0 boards Zero, M0, MKR

This is incorrect. Did you test it?

In this case there was no need to differentiate between the Arduino SAM Boards and Arduino SAMD boards so the SAM macro seemed like the most correct answer. You could use the Arduino defined macros ARDUINO_ARCH_SAMD and ARDUINO_ARCH_SAM but the ARDUINO_ARCH_xxx macros are determined only by a folder name and so are much more fragile than the SAM macro, which is defined at a lower level (in CMSIS). Arduino also defines board-specific macros but those aren't going to be very useful for this application since new boards will always be coming out and you'd also need to track 3rd party boards. There are also more specific low level macros:

#if SAM3_SERIES == 1
#ifdef __SAM3X8E__
#ifdef __SAMD21G18A__

sorry, I confused SAM define with the ARDUINO_ARCH defines.

but for check of existence of Arduino function analogReadResolution() I would use Arduino defines ARDUINO_ARCH_SAM and ARDUINO_ARCH_SAMD.