-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatalogger.ino
66 lines (48 loc) · 1.24 KB
/
Datalogger.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
#include <Arduino.h>
/*
SD card datalogger
The circuit:
* SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 10
original, created by Tom Igoe
28.10.12 Yves Masur
*/
#include <SD.h> //Pilote pour carte SD
const char * FNAME = "ENERGY.TXT" // Nom du fichier
void init_file()
{
Serial.print("Initializing SD card...");
// make sure that the default chip select pin is set to
// output, even if you don't use it:
pinMode(SS_PIN, OUTPUT);
// see if the card is present and can be initialized:
if (!SD.begin(SS_PIN))
{
Serial.println("SD card failed, or not present");
// don't do anything more:
return;
}
Serial.println("SD card initialized.");
}
void log2File(String dataString)
{
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open(FNAME, FILE_WRITE);
// if the file is available, write to it:
if (dataFile)
{
dataFile.println(dataString);
dataFile.close();
// print to the serial port too:
Serial.println(dataString);
}
// if the file isn't open, pop up an error:
else
{
Serial.println("error opening " FNAME);
}
}