Determine Device Type from code?

Is there a way to query the hardware device type from code? I’d like to run the same code on Argon and Boron, but the process to read battery level is different between them, Argon has it on an ADC, Boron has a function getVCell().


The general way to test for features is in the docs however that specific example is not.

To determine if the device has the FuelGauge class put in a test for:

// FuelGauge code
// Get battery voltage code

Or maybe instead:

float voltage = analogRead(BATT) * 0.0011224;
// FuelGauge code

Neither is perfect but both will work right now.

Great. That points me in the right direction. Can the #if test be used in the normal c code file, or only in the header file? (I was thinking it only worked in the header). I would test but I only have an Argon with me right now so can’t try it on both right now.

Thank you!

Works in any .ino, .cpp, .c, or .h file.

1 Like

Thanks! You’ve been extremely helpful on a few issues I’ve had over time. Can’t thank you enough.