Hi
Thanks for the replies here is my code:
int buttom = 2;//asignamos al boton guardar el pin digital 2
int volatile interrup = 0;// para la interrupcion con un boton debemos definir una variable que esta cambiara para que active el guardado de datos en la SD
int volatile accAvailable=0;
int volatile gyrAvailable=0;
//----------------------------------------------------
//BIBLIOTECAS Y VARIABLES TARJETA SD
//----------------------------------------------------
#include <SPI.h>
#include <SD.h>
File file;
#define SSpin 10
//----------------------------------------------------
//BIBLIOTECAS Y VARIABLES SENSOR IMU
//----------------------------------------------------
#include "SparkFunLSM6DS3_Personal.h"
#include "Wire.h"
//Create a instance of class LSM6DS3
LSM6DS3 myIMU( I2C_MODE, 0x6A ); //I2C device address 0x6A
//----------------------------------------------------
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
attachInterrupt( digitalPinToInterrupt(buttom), save, CHANGE);//desiganos la interrupción que activara la funcion guardar al boton_guardar
//----------------------------------------------------
//setup SD
//----------------------------------------------------
// Open serial communications and wait for port to open:
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("Initializing SD card...");
if (!SD.begin(SSpin)) {
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");
file = SD.open("IMU.txt", FILE_WRITE);
//----------------------------------------------------
//setup IMU
//----------------------------------------------------
/* Initialise the sensor */
//Call .begin() to configure the IMUs
if( myIMU.begin() != 0 )
{
Serial.println("Device error");
}
else
{
Serial.println("Device OK!");
}
myIMU.settings.gyroEnabled = 1; //Can be 0 or 1
myIMU.settings.gyroRange = 2000; //Max deg/s. Can be: 125, 245, 500, 1000, 2000
myIMU.settings.gyroSampleRate = 104; //Hz. Can be: 13, 26, 52, 104, 208, 416, 833, 1666
myIMU.settings.accelEnabled = 1;
myIMU.settings.accelRange = 16; //Max G force readable. Can be: 2, 4, 8, 16
myIMU.settings.accelSampleRate = 104; //Hz. Can be: 13, 26, 52, 104, 208, 416, 833, 1666, 3332, 6664, 13330
}
void save(){
interrup=1;//asignamos a la variable interrup el valor de uno, de manera que active el código para guardar los datos de la SD
}
void loop() {
//------------------------------------------------------------------------------
//Escribimos los valores del IMU en la SD
//------------------------------------------------------------------------------
float ax, ay, az, gx, gy, gz;
if (file) {
if (interrup==0) {
if (myIMU.accelerationAvailable()==true
&& myIMU.gyroscopeAvailable()==true
&& myIMU.readFloatAccelX()
&& myIMU.readFloatAccelY()
&& myIMU.readFloatAccelZ()
&& myIMU.readFloatGyroX()
&& myIMU.readFloatGyroY()
&& myIMU.readFloatGyroZ()){
//El orden de las componentes depende de la orientación en la que dispondremos el IMU
//Accelerometer (g)
archivo.print(myIMU.readFloatAccelX(), 4);archivo.print(",");
archivo.print(myIMU.readFloatAccelY(), 4);archivo.print(",");
archivo.print(myIMU.readFloatAccelZ(), 4);archivo.print(",");
//Gyroscope (º/s)
archivo.print(myIMU.readFloatGyroX(), 4);archivo.print(",");
archivo.print(myIMU.readFloatGyroY(), 4);archivo.print(",");
archivo.print(myIMU.readFloatGyroZ(), 4);archivo.print(",");
//Tiempo (ms)
archivo.println(millis());
}
} else {
archivo.close();
}
} else {
Serial.println("Error en la apertura de IMU.txt");
}
}
I have already tested the IMU frequency with the SD and its about 103.5-104Hz, which is okey. However I get the error I told you before in millis().