Loading...
Searching...
No Matches
AnalogReadMultiple.ino

Reads all six analog pins together with analogReadMultiple() and streams them, in millivolts, to the Serial Plotter 20 times a second. A3-A5 are read in one scan of the external ADC, A0-A2 back to back on the RP2040 ADC.

Output
Tools → Serial Plotter at 115200 baud, one line per reading:
A0:1650,A1:3,A2:0,A3:1024,A4:0,A5:0
// Reads all six analog pins together and streams them to the Serial Plotter
// (Tools > Serial Plotter, 115200 baud), 20 times a second.
//
// analogReadMultiple() reads the pins as close together in time as it can:
// A3-A5 in one scan of the external ADC, A0-A2 back to back on the RP2040
// ADC. The values are scaled to millivolts, so the two full scales
// (3.3 V and 2.048 V) plot on the same axis.
const pin_size_t PINS[] = {A0, A1, A2, A3, A4, A5};
const char* const NAMES[] = {"A0", "A1", "A2", "A3", "A4", "A5"};
const uint8_t COUNT = 6;
void setup() {
Serial.begin(115200);
}
void loop() {
uint16_t values[COUNT];
analogReadMultiple(PINS, COUNT, values);
for (uint8_t i = 0; i < COUNT; i++) {
const uint32_t millivolts = values[i] * analogFullScaleMillivolts(PINS[i]) / 4096;
Serial.print(NAMES[i]);
Serial.print(":");
Serial.print(millivolts);
Serial.print(i + 1 < COUNT ? "," : "\n");
}
delay(50);
}
SerialUSBClass Serial
USB serial port, the one the Serial Monitor uses.
void analogReadResolution(int bits)
Sets the number of bits analogRead() returns, for every analog pin.
uint32_t analogFullScaleMillivolts(pin_size_t pin)
Voltage that reads as full scale on an analog pin.
bool analogReadMultiple(const pin_size_t *pins, uint8_t count, uint16_t *results)
Reads several analog pins as close together in time as possible.
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