Hi, I'm making a small datalogging device using an Arduino Pro Mini that reads from a selection of analog pins and send the readings over serial. Then I have a python script to read the values into a CSV file on my PC.
In the setup function I want to send a list of the pins being read as a 'header' to the CSV file, so the data can be saved like this:
A0,A1,A2,
2.80,2.77,2.51,
2.45,2.43,2.39,
2.34,2.29,2.28,
2.27,2.21,2.20,
2.18,2.13,2.10,
etc
However instead of getting A0 I get 14 out of the serial monitor (likewise for the other pin names) - here is a dump of the data that comes through the serial monitor currently:
14,15,16,
2.80,2.77,2.51,
2.45,2.43,2.39,
2.34,2.29,2.28,
2.27,2.21,2.20,
2.18,2.13,2.10,
I am aware that as int types A0 == 14 for the purposes of using analogRead(), but I don't know how to send out the list in the 'A0' form.
const int inputpins[3] = {A0,A1,A2}; // define the pins being measured
int pin_count = sizeof(inputpins)/sizeof(inputpins[0]); // Count the number of pins
float Vcc = 5.01; // For scaling ADC measurements to voltage
void setup() {
Serial.begin(9600);
for (int pin = 0; pin < pin_count;pin++){ // set up serial
Serial.print(inputpins[pin]); // send list of pins being measured!!
Serial.print(",");
}
Serial.println();
}
void loop() {
String values;
for (int pin = 0; pin < pin_count;pin++){
float V = analogRead(inputpins[pin])*Vcc/1024.0; // read voltage from pin (have to convert the string entry into 'int' first by removing the 0)
values += V;
values += ","; // append the readings to the string of values followed by a ","
}
Serial.println(values); // send values to serial
delay(500);
}
I've tinkered a fair amount with Arduino over the years, but have never had to deal with anything other than int and float types for most of my projects, and only ever using Serial.print to print basic messages so have never had this kind of issue arise previously.