-
Notifications
You must be signed in to change notification settings - Fork 0
/
friedrichshafen.ino
144 lines (124 loc) · 3.15 KB
/
friedrichshafen.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
Test microSD
Test progam for microSD card (mSD-Bee), connected to XBEE2 (SPI).
*/
#include <SPI.h>
#include <SD.h>
#include <senseBoxIO.h>
#include <RV8523.h>
#include <Wire.h>
#include <Adafruit_HDC1000.h> // http://librarymanager/All#Adafruit_HDC1000_Library
#define BUFF_MAX 32
// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;
File Data;
Adafruit_HDC1000 hdc = Adafruit_HDC1000();
RV8523 rtc;
unsigned int recv_size = 0;
char recv[BUFF_MAX];
void setup()
{
// init serial library
Serial.begin(9600);
//while (!Serial); // wait for serial monitor
Serial.println("Test microSD");
// microSD in XBEE2 Socket
senseBoxIO.powerXB2(false); // power off to reset microSD
delay(250);
senseBoxIO.powerXB2(true); // power on
senseBoxIO.SPIselectXB1();
// init card
const int chipSelect = PIN_XB1_CS;
if (!card.init(SPI_HALF_SPEED, chipSelect))
{
Serial.println("Error - Not Found");
senseBoxIO.statusRed();
return; // don't continue
}
// print card type
Serial.print("\nCard Type: ");
switch (card.type())
{
case SD_CARD_TYPE_SD1: Serial.println("SD1"); break;
case SD_CARD_TYPE_SD2: Serial.println("SD2"); break;
case SD_CARD_TYPE_SDHC: Serial.println("SDHC"); break;
default: Serial.println("Unknown"); break;
}
// init volume/partition
if (!volume.init(card))
{
Serial.println("Error - Not Found FAT16/FAT32 Partition");
senseBoxIO.statusRed(); // status red
senseBoxIO.powerXB2(false); // shutdown microSD
return; // don't continue
}
// open/list volume/partition
Serial.println("\nFiles:");
root.openRoot(volume);
root.ls(LS_R | LS_DATE | LS_SIZE);
senseBoxIO.powerI2C(true);
SD.begin(PIN_XB1_CS);
Serial.println("Init RTC...");
delay(200);
rtc.begin();
rtc.start();
rtc.batterySwitchOver(1);
Serial.println("Init HDC...");
hdc.begin();
// status green
senseBoxIO.statusGreen();
}
void loop()
{
uint8_t sec, min, hour, day, month;
uint16_t year;
// Uhrzeit befindet sich in den einzelnen Variablen !
rtc.get(&sec, &min, &hour, &day, &month, &year);
Data = SD.open("Data.txt", FILE_WRITE);
Data.print(String(year) + String("-"));
if (month < 10)
{
Data.print("0");
}
Data.print(String(month) + String("-"));
if (day < 10)
{
Data.print("0");
}
Data.print(String(day) + String("T"));
if (hour < 10)
{
Data.print("0");
}
Data.print(String(hour) + String(":"));
if (min < 10)
{
Data.print("0");
}
Data.println(String(min) + String("+01:00,") + String(hdc.readTemperature()) + String(",") + String(hdc.readHumidity()));
Data.close();
Serial.print(String(year) + String("-"));
if (month < 10)
{
Serial.print("0");
}
Serial.print(String(month) + String("-"));
if (day < 10)
{
Serial.print("0");
}
Serial.print(String(day) + String("T"));
if (hour < 10)
{
Serial.print("0");
}
Serial.print(String(hour) + String(":"));
if (min < 10)
{
Serial.print("0");
}
Serial.println(String(min) + String("+01:00,") + String(hdc.readTemperature()) + String(",") + String(hdc.readHumidity()));
delay(60000);
}