Shield Data Logger
Publicado por Jesús Manuel (1 intervención) el 02/10/2018 10:49:50
Buenos días a todos/as
Soy nuevo en esto de Aurdino. Y estoy montan un UNO con un Shield data logger, he conseguido poner el RTC y lo mas complicado , llevo tres días es que me reconozca la SD para guardar datos.
He creado partición y he formateado son SD Asociation. Ahora me reconoce la tarjeta pero no consigo que escriba en la SD:
Este es el código que estoy utilizando:
Un Saludo
Jesús
Soy nuevo en esto de Aurdino. Y estoy montan un UNO con un Shield data logger, he conseguido poner el RTC y lo mas complicado , llevo tres días es que me reconozca la SD para guardar datos.
He creado partición y he formateado son SD Asociation. Ahora me reconoce la tarjeta pero no consigo que escriba en la SD:
Este es el código que estoy utilizando:
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
// include the SD library:
#include <SD.h>
// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;
// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
const int chipSelect = 10;
const int prueba = 8;
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.print("\nInitializing SD card...");
// On the Ethernet Shield, CS is pin 4. It's set as an output by default.
// Note that even if it's not used as the CS pin, the hardware SS pin
// (10 on most Arduino boards, 53 on the Mega) must be left as an output
// or the SD library functions will not work.
pinMode(10, OUTPUT); // change this to 53 on a mega
// we'll use the initialization code from the utility libraries
// since we're just testing if the card is working!
if (!card.init(SPI_HALF_SPEED, chipSelect)) {
Serial.println("initialization failed. Things to check:");
Serial.println("* is a card is inserted?");
Serial.println("* Is your wiring correct?");
Serial.println("* did you change the chipSelect pin to match your shield or module?");
return;
} else {
Serial.println("Wiring is correct and a card is present.");
}
// print the type of card
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");
}
}
void loop()
{
// Abrimos el fichero. Nota: solo se puede abrir un fichero a la vez. Para abrir un segundo fichero hay que cerrar el anterior.
File dataFile = SD.open("datalog.txt", FILE_WRITE);
// si el fichero esta disponible escribir en el:
if (dataFile) {
dataFile.println(prueba);
dataFile.close();
// escribe tambien en el Serial:
//Serial.println(prueba);
}
// // Si el fichero no se ha abierto, lanzar un mensaje de error:
else {
Serial.println("error opening datalog.txt");
delay (500);
return ;
}
}
Un Saludo
Jesús
Valora esta pregunta


0