Hello friends!
I was coming back to ask for help with this project,
I have an MMA7361 WITH SD SHIELD
I'm using the accelerometer library and everything is fine, but I need
implement the saving of the data of the three axes of the accelerometer
in the sd,
I recently asked for help from a member who has helped me a lot,
but no matter how hard you look, some other error always comes out of nowhere
and I HAVE this error, as if I did not read the sd (it is as if the SD was not connected)
So if anyone could help me, I would appreciate very much since it is a very important project where I study.
Error: "There was a failure to start communication"
CODE:
#include <SD.h>
#include <AcceleroMMA7361.h>
AcceleroMMA7361 accelero;
File Archivo; // Variable para luego manejar el fichero txt
int x;
int y;
int z;
void setup()
{
Serial.begin(9600);
accelero.begin(13, 12, 11, 10, A0, A1, A2);
accelero.setARefVoltage(3.3); //sets the AREF voltage to 3.3V
accelero.setSensitivity(LOW); //sets the sensitivity to +/-6G
accelero.calibrate();
}
void loop()
{
x = accelero.getXAccel();
y = accelero.getYAccel();
z = accelero.getZAccel();
Serial.print("\nx: ");
Serial.print(x);
Serial.print(" \ty: ");
Serial.print(y);
Serial.print(" \tz: ");
Serial.print(z);
Serial.print("\tG*10^-2");
delay(333); //make it readable
Escribir_SD();
}
void Escribir_SD() {
File Archivo;
//Se muestra por el monitor si la comunicación se ha establecido correctamente
//o ha habido algún tipo de error.
if (!SD.begin(10)) {
Serial.println("Se ha producido un fallo al iniciar la comunicación");
return;
}
Serial.println("Se ha iniciado la comunicación correctamente");
/* ESCRIBIENDO DATOS EN LA MEMORIA SD DE ARDUINO */
//Se abre el documento sobre el que se va a leer y escribir.
Archivo = SD.open("datalog.txt", FILE_WRITE);
//Se comprueba que el archivo se ha abierto correctamente y se procede a
//escribir en él.
if (Archivo) {
//Se escribe información en el documento de texto datos.txt angulo x.
Archivo.print(x );// Escribe linea con salto de fila
//Se escribe información en el documento de texto datos.txt angulo y.
Archivo.print(y );
Archivo.println(z );
// Si necesito escribir mas cosas añado filas con Archivo.println("Lo que quiera poner")
//Se cierra el archivo para almacenar los datos.
Archivo.close();
//Se muestra por el monitor que los datos se han almacenado correctamente.
Serial.println("Todos los datos fueron almacenados");
}}
Connection
Connection