12
12
#include < SPI.h>
13
13
#include < SPIFlash.h>
14
14
#include < EEPROM.h>
15
+ // #include <sha204_library.h>
16
+
15
17
16
18
// Define a static node address, remove if you want auto address assignment
17
19
// #define NODE_ADDRESS 3
23
25
24
26
// Pin definitions
25
27
#define TEST_PIN A0
26
- #define RESET_CFG_PIN A1
27
28
#define LED_PIN A2
29
+ #define ATSHA204_PIN 17 // A3
28
30
29
31
#define MEASURE_INTERVAL 60000
30
32
@@ -56,13 +58,9 @@ void setup() {
56
58
digitalWrite (LED_PIN, LOW);
57
59
58
60
// First check if we should boot into clear eeprom mode
59
- pinMode (RESET_CFG_PIN, INPUT);
60
61
pinMode (TEST_PIN,INPUT);
61
- digitalWrite (RESET_CFG_PIN, HIGH); // Enable pullup
62
62
digitalWrite (TEST_PIN, HIGH);
63
63
if (!digitalRead (TEST_PIN)) testMode ();
64
- if (!digitalRead (RESET_CFG_PIN)) resetEEP ();
65
- digitalWrite (RESET_CFG_PIN, LOW);
66
64
digitalWrite (TEST_PIN,LOW);
67
65
digitalWrite (LED_PIN, HIGH);
68
66
@@ -82,7 +80,7 @@ void setup() {
82
80
gw.present (CHILD_ID_HUM,S_HUM);
83
81
84
82
gw.present (CHILD_ID_BATT, S_POWER);
85
- switchClock (1 <<CLKPS2);
83
+ switchClock (1 <<CLKPS2); // Switch to 1Mhz for the reminder of the sketch, save power.
86
84
}
87
85
88
86
@@ -180,21 +178,6 @@ long readVcc() {
180
178
return result; // Vcc in millivolts
181
179
}
182
180
183
-
184
- /*
185
- * Resets eeprom to default value (while blinking LED_PIN)
186
- */
187
- void resetEEP ()
188
- {
189
- for (int i=0 ;i<512 ;i++) {
190
- digitalWrite (LED_PIN, HIGH);
191
- delay (100 );
192
- digitalWrite (LED_PIN, LOW);
193
- delay (100 );
194
- EEPROM.write (i, 0xff );
195
- }
196
- }
197
-
198
181
void switchClock (unsigned char clk)
199
182
{
200
183
cli ();
@@ -204,12 +187,40 @@ void switchClock(unsigned char clk)
204
187
sei ();
205
188
}
206
189
190
+
191
+ // Verify all peripherals, and signal via the LED if any problems.
207
192
void testMode ()
208
193
{
209
- if (humiditySensor.begin ())
194
+ byte tests = 0 ;
195
+
196
+ Serial.println (" Testing peripherals!" );
197
+
198
+ if (humiditySensor.begin ())
199
+ {
200
+ Serial.println (" Si7021 ok!" );
201
+ tests ++;
202
+ }
203
+ else
204
+ {
205
+ Serial.println (" ---> Si7021 FAILED!" );
206
+ }
207
+
210
208
if (flash.initialize ())
211
209
{
212
- while (1 )
210
+ Serial.println (" flash OK!" );
211
+ tests ++;
212
+ }
213
+ else
214
+ {
215
+ Serial.println (" ---> flash failed!" );
216
+ }
217
+
218
+ Serial.println (" Test finished" );
219
+
220
+ if (tests == 2 )
221
+ {
222
+ Serial.println (" Selftest ok!" );
223
+ while (1 ) // Blink OK pattern!
213
224
{
214
225
digitalWrite (LED_PIN, HIGH);
215
226
delay (800 );
@@ -219,7 +230,8 @@ void testMode()
219
230
}
220
231
else
221
232
{
222
- while (1 )
233
+ Serial.println (" ----> Selftest failed!" );
234
+ while (1 ) // Blink FAILED pattern! Rappidly blinking..
223
235
{
224
236
digitalWrite (LED_PIN, HIGH);
225
237
delay (200 );
0 commit comments