Loading...
Searching...
No Matches
AnalogMillivolts.ino

Prints the voltage on every analog pin, in millivolts, once a second, and the full scale of each pin at start-up.

A0-A2 (RP2040 ADC) read 0-3300 mV and A3-A5 (on-board MAX11635) read 0-2048 mV; analogReadMillivolts() and analogFullScaleMillivolts() handle the difference, so the same code works on every pin.

Output
Serial Monitor at 115200 baud, for example:
A0 1650 mV A1 3 mV A2 0 mV A3 1024 mV A4 0 mV A5 0 mV
// Prints the voltage on every analog pin, in millivolts, once a second.
// A0-A2 (RP2040 ADC) read 0-3300 mV and A3-A5 (on-board MAX11635) read
// 0-2048 mV; analogReadMillivolts() handles the difference, so the same code
// works on every pin.
const pin_size_t PINS[] = {A0, A1, A2, A3, A4, A5};
const char* const NAMES[] = {"A0", "A1", "A2", "A3", "A4", "A5"};
void setup() {
Serial.begin(115200);
while (!Serial) {}
Serial.println("Full scale of each pin:");
for (int i = 0; i < 6; i++) {
Serial.print(NAMES[i]);
Serial.print(": ");
Serial.println(" mV");
}
}
void loop() {
for (int i = 0; i < 6; i++) {
Serial.print(NAMES[i]);
Serial.print(" ");
Serial.print(analogReadMillivolts(PINS[i]));
Serial.print(" mV ");
}
Serial.println();
delay(1000);
}
SerialUSBClass Serial
USB serial port, the one the Serial Monitor uses.
uint32_t analogReadMillivolts(pin_size_t pin)
Reads an analog pin as a voltage, whatever its ADC and full scale.
uint32_t analogFullScaleMillivolts(pin_size_t pin)
Voltage that reads as full scale on an analog pin.
void loop(void)
Written by the sketch: runs over and over after setup(), on core 0.
void setup(void)
Written by the sketch: runs once after reset, on core 0.
void delay(unsigned long)
Waits a number of milliseconds.
uint8_t pin_size_t
Type for Arduino pin numbers (uint8_t).
Definition Common.h:112