18
18
- Portenta H7
19
19
- Automation Carrier
20
20
21
- created 18 September 2020
22
- by Silvio Navaretti
23
- modified 30 September 2020
24
- by Riccardo Rizzo
25
21
This example code is in the public domain.
26
22
*/
27
23
#include < AutomationCarrier.h>
28
24
29
25
using namespace automation ;
30
26
31
- float reference = 3.3 ;
27
+ #define REFERENCE_RES 100000
28
+
29
+ float reference = 3 ;
30
+ float lowest_voltage = 2.7 ;
32
31
33
32
void setup () {
34
33
analogReadResolution (16 );
@@ -41,38 +40,42 @@ void loop() {
41
40
float raw_voltage_ch0 = analog_in.read (0 );
42
41
float voltage_ch0 = (raw_voltage_ch0 * reference) / 65535 ;
43
42
float resistance_ch0;
44
- if (voltage_ch0 < 3 ) {
45
- resistance_ch0 = ((-100000 ) * voltage_ch0) / (voltage_ch0 - 3 );
43
+ Serial.print (" Resistance CH0: " );
44
+ if (voltage_ch0 < lowest_voltage) {
45
+ resistance_ch0 = ((-REFERENCE_RES) * voltage_ch0) / (voltage_ch0 - reference);
46
+ Serial.print (resistance_ch0);
47
+ Serial.println (" ohm" );
46
48
} else {
47
49
resistance_ch0 = -1 ;
50
+ Serial.println (" NaN" );
48
51
}
49
- Serial.print (" Resistance ch0: " );
50
- Serial.print (resistance_ch0);
51
- Serial.println (" ohm" );
52
52
53
53
float raw_voltage_ch1 = analog_in.read (1 );
54
54
float voltage_ch1 = (raw_voltage_ch1 * reference) / 65535 ;
55
55
float resistance_ch1;
56
- if (voltage_ch1 < 3 ) {
57
- resistance_ch1 = ((-100000 ) * voltage_ch1) / (voltage_ch1 - 3 );
56
+ Serial.print (" Resistance CH1: " );
57
+ if (voltage_ch1 < lowest_voltage) {
58
+ resistance_ch1 = ((-REFERENCE_RES) * voltage_ch1) / (voltage_ch1 - reference);
59
+ Serial.print (resistance_ch1);
60
+ Serial.println (" ohm" );
58
61
} else {
59
62
resistance_ch1 = -1 ;
63
+ Serial.println (" NaN" );
60
64
}
61
- Serial.print (" Resistance ch1: " );
62
- Serial.print (resistance_ch1);
63
- Serial.println (" ohm" );
64
65
65
66
float raw_voltage_ch2 = analog_in.read (2 );
66
67
float voltage_ch2 = (raw_voltage_ch2 * reference) / 65535 ;
67
68
float resistance_ch2;
68
- if (voltage_ch2 < 3 ) {
69
- resistance_ch2 = ((-100000 ) * voltage_ch2) / (voltage_ch2 - 3 );
69
+ Serial.print (" Resistance CH2: " );
70
+ if (voltage_ch2 < lowest_voltage) {
71
+ resistance_ch2 = ((-REFERENCE_RES) * voltage_ch2) / (voltage_ch2 - reference);
72
+ Serial.print (resistance_ch2);
73
+ Serial.println (" ohm" );
70
74
} else {
71
75
resistance_ch2 = -1 ;
76
+ Serial.println (" NaN" );
72
77
}
73
- Serial.print (" Scaled ch2: " );
74
- Serial.print (resistance_ch2);
75
- Serial.println (" ohm" );
78
+
76
79
Serial.println ();
77
80
delay (250 );
78
81
}
0 commit comments