I'm trying to find the absolute value of the difference between two test results.
We have a tester that outputs results in ASCII and I have been able to display this data in the serial monitor; see image below.
The test sequence goes like this:
(1) Turn the tester on and it sends out a "memory check". This happens only once and we usually turn on the machine on/off once or twice per day.
(2) Device to be tested is hooked up to the tester
(3) "PD" (pressure decay) test is performed
(4) "FLOW" test #1 is performed
(5) Second "FLOW" test #2 is performed
(6) New device is hooked up to the tester
(7) "PD" test is performed
(8) "FLOW" test #1 is performed
(9) Second "FLOW" test #2 is performed
(10) New device is hooked up to the tester
(11) …..
The cycle repeats and each individual device gets one PD test and two FLOW tests. We test approximately 1000 devices per day.
The goal of the program is to find the absolute difference (delta) between the two FLOW tests per device. This difference will eventually be displayed on an LCD.
I envision populating variables called "FLOW 1", "FLOW 2" and "FLOW DELTA".
IF the "FLOW DELTA" is less than 150, the result would be "PASS"
IF the "FLOW DELTA" is greater than 150, the result would be "FAIL".
Per device, the variables would display "WAITING" on the LCD unless they were populated; see image below.
I've been trying to get this to work using sscanf(), but I just can't get anything to compile. I believe that the incoming string is in the following format:
"%d\t%d\t%s\t%f\t%s\t%s\t%s"
So far, here is the code that I'm using to display the string in the serial monitor:
String incomingByte; // for incoming serial data
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}
void loop() {
// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
char incomingByte = Serial.read();
Serial.print(incomingByte);
}
}
I'm not very good at programming, so here what I'm thinking in comments:
// use sscanf() to store the incoming string
// IF the string contains "FLOW", store the value immediately following the word "FLOW" as "FLOW_1". If "FLOW_1" already has a numeric value, then store as "FLOW_2"
// IF the string contains "PD", then set "FLOW_1" and "FLOW_2" to a value of "WAITING" (this resets the values for the next device under test)
// Caculate "RESULT" = abs(FLOW_1 - FLOW_2);
// IF "RESULT" is greater than 150, then "RESULT" is stored as "FAIL"
// IF "RESULT" is less than 150, then "RESULT" is stored as "PASS"
How can I write code to execute my comments? Translating my comments into code is literally like speaking a foreign language where I can't mumble or misspeak, elsewise I get compiling error roadblocks that I don't understand. I'll keep at it, though!