Monitoring Arduino analog inputs

Asked

Viewed 38 times

0

I am monitoring more than one analog input of one Arduous at all times, that is, at all times I am sending data via serial to other software. What would be the best way to send this data so that I can recognize in other software what analog input of the Arduous each data received belongs to?

int CANAL1, CANAL2, CANAL3;

void setup() {
  Serial.begin(115200);
  pinMode(A0, INPUT);  // configura como entrada
  digitalWrite(A0, LOW);
  pinMode(A1, INPUT);  // configura como entrada
  digitalWrite(A1, LOW);
  pinMode(A2, INPUT);  // configura como entrada
  digitalWrite(A2, LOW);
  analogReference(DEFAULT);
}

void loop() {
    CANAL1 = analogRead(A0);
    Serial.print(CANAL1,DEC);
    Serial.print(" ");
    delay(5);
    CANAL2 = analogRead(A1);
    Serial.print(CANAL2,DEC);
    Serial.print(" ");
    delay(5);
    CANAL3 = analogRead(A2);
    Serial.print(CANAL3,DEC);
    Serial.print(" ");
    delay(5);
}

Doing so the data arrives in the serial in sequence. Example:

0 1023 500 1023 400 500 300 200

So if I lose a data, either one, I already totally lose the orientation of which input corresponds to each value.

1 answer

2

Okay, you’re learning how to program. You can create your markup assuming that the software you will receive will be yours as well. Or you will have to read the documentation of the software you receive to format in its style.

In the case of software that will receive be your own, write what you want before each given ADC as for example:

Serial.print("A3:");
Serial.print(CANAL3,DEC);
Serial.print(",");

And the way out will be:

A3:1024,A2:256,A1:87 ...

Obviously in the data client you will need to learn how to tokenize strings.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.