Skip to content

Commit 9f23cd5

Browse files
committed
Modified begin function on MKRTherm.cpp
Modified Begin function, on MKRTherm.cpp, in order to return error if shield not present.
1 parent 3ab4efd commit 9f23cd5

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

examples/ReadSensor/ReadSensor.ino

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ void setup() {
2020

2121
while (!Serial);
2222

23-
THERM.begin();
23+
if (!THERM.begin()) {
24+
Serial.println("Failed to initialize MKR Therm shield!");
25+
while (1);
26+
}
2427
}
2528

2629
void loop() {

src/MKRTherm.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,19 @@ THERMClass::THERMClass(int cs, SPIClass& spi) :
2828

2929
int THERMClass::begin()
3030
{
31+
uint32_t rawword;
32+
3133
pinMode(_cs, OUTPUT);
3234
digitalWrite(_cs, HIGH);
3335
_spi->begin();
3436

37+
rawword = readSensor();
38+
if (rawword == 0xFFFFFF) {
39+
end();
40+
41+
return 0;
42+
}
43+
3544
return 1;
3645
}
3746

@@ -64,7 +73,6 @@ uint32_t THERMClass::readSensor()
6473
return read;
6574
}
6675

67-
6876
float THERMClass::readTemperature()
6977
{
7078
uint32_t rawword;
@@ -91,8 +99,6 @@ float THERMClass::readTemperature()
9199
return celsius;
92100
}
93101

94-
95-
96102
float THERMClass::readInternalTemperature()
97103
{
98104
uint32_t rawword;

0 commit comments

Comments
 (0)