File tree Expand file tree Collapse file tree 5 files changed +74
-11
lines changed Expand file tree Collapse file tree 5 files changed +74
-11
lines changed Original file line number Diff line number Diff line change 4
4
This example reads the temperatures measured by the thermocouple
5
5
connected to the MKR THERM shield and prints them to the Serial Monitor
6
6
once a second.
7
-
7
+
8
8
The circuit:
9
9
- Arduino MKR board
10
10
- Arduino MKR THERM Shield attached
11
11
- A K Type thermocouple temperature sensor connected to the shield
12
-
12
+
13
13
This example code is in the public domain.
14
14
*/
15
15
@@ -34,7 +34,7 @@ void loop() {
34
34
Serial.println (" °C" );
35
35
36
36
Serial.print (" Temperature " );
37
- Serial.print (THERM.readTemperature ());
37
+ Serial.print (THERM.readTemperature (CELSIUS ));
38
38
Serial.println (" °C" );
39
39
40
40
Serial.println ();
Original file line number Diff line number Diff line change
1
+ /*
2
+ MKR THERM Shield - Read Sensors
3
+
4
+ This example reads the temperatures (in Fahrenheit and kelvins) measured by the thermocouple
5
+ connected to the MKR THERM shield and prints them to the Serial Monitor
6
+ once a second.
7
+
8
+ The circuit:
9
+ - Arduino MKR board
10
+ - Arduino MKR THERM Shield attached
11
+ - A K Type thermocouple temperature sensor connected to the shield
12
+
13
+ This example code is in the public domain.
14
+ */
15
+
16
+ #include < Arduino_MKRTHERM.h>
17
+
18
+ void setup () {
19
+
20
+ Serial.begin (9600 );
21
+
22
+ while (!Serial);
23
+
24
+ if (!THERM.begin ()) {
25
+ Serial.println (" Failed to initialize MKR THERM shield!" );
26
+ while (1 );
27
+ }
28
+ }
29
+
30
+ void loop () {
31
+
32
+ Serial.print (" Reference temperature " );
33
+ Serial.print (THERM.readReferenceTemperature ());
34
+ Serial.println (" °C" );
35
+
36
+ Serial.print (" Temperature in Fahrenheit " );
37
+ Serial.print (THERM.readTemperature (FAHRENHEIT));
38
+ Serial.println (" °F" );
39
+
40
+ Serial.print (" Temperature in Kelvin " );
41
+ Serial.print (THERM.readTemperature (KELVIN));
42
+ Serial.println (" K" );
43
+
44
+ Serial.println ();
45
+
46
+ delay (1000 );
47
+ }
Original file line number Diff line number Diff line change 1
1
#######################################
2
2
# Syntax Coloring Map For Arduino_MKRTHERM
3
- #######################################
3
+ #######################################
4
4
# Class
5
5
#######################################
6
6
@@ -9,8 +9,8 @@ MKRTHERM KEYWORD1
9
9
THERM KEYWORD1
10
10
11
11
#######################################
12
- # Methods and Functions
13
- #######################################
12
+ # Methods and Functions
13
+ #######################################
14
14
15
15
begin KEYWORD2
16
16
end KEYWORD2
@@ -21,3 +21,7 @@ readReferenceTemperature KEYWORD2
21
21
#######################################
22
22
# Constants
23
23
#######################################
24
+
25
+ FAHRENHEIT LITERAL1
26
+ CELSIUS LITERAL1
27
+ KELVIN LITERAL1
Original file line number Diff line number Diff line change @@ -73,7 +73,7 @@ uint32_t THERMClass::readSensor()
73
73
return read;
74
74
}
75
75
76
- float THERMClass::readTemperature ()
76
+ float THERMClass::readTemperature (int units )
77
77
{
78
78
uint32_t rawword;
79
79
float celsius;
@@ -82,9 +82,9 @@ float THERMClass::readTemperature()
82
82
83
83
// Check for reading error
84
84
if (rawword & 0x7 ) {
85
- return NAN;
85
+ return NAN;
86
86
}
87
- // The temperature is stored in the last 14 word's bits
87
+ // The temperature is stored in the last 14 word's bits
88
88
// sendend by the Thermocouple-to-Digital Converter
89
89
if (rawword & 0x80000000 ) {
90
90
// Negative value, drop the lower 18 bits and explicitly extend sign bits.
@@ -96,7 +96,13 @@ float THERMClass::readTemperature()
96
96
// multiply for the LSB value
97
97
celsius = (int32_t )rawword * 0 .25f ;
98
98
99
- return celsius;
99
+ if (units == FAHRENHEIT) {
100
+ return (celsius * 9.0 / 5.0 ) + 32.0 ;
101
+ } else if (units == KELVIN) {
102
+ return (celsius + 273.15 );
103
+ } else {
104
+ return celsius;
105
+ }
100
106
}
101
107
102
108
float THERMClass::readReferenceTemperature ()
Original file line number Diff line number Diff line change 23
23
#include < Arduino.h>
24
24
#include < SPI.h>
25
25
26
+ enum {
27
+ FAHRENHEIT,
28
+ CELSIUS,
29
+ KELVIN
30
+ };
31
+
26
32
class THERMClass {
27
33
public:
28
34
THERMClass (int cs = A4, SPIClass& spi = SPI);
29
35
30
36
int begin ();
31
37
void end ();
32
38
33
- float readTemperature ();
39
+ float readTemperature (int units = CELSIUS );
34
40
float readReferenceTemperature ();
35
41
36
42
private:
You can’t perform that action at this time.
0 commit comments