I'm really getting desperete actually. As I'm pretty bad with Arduino and as I don't know how to program, it took me several hours juste to write a few lines. Moreover, the program i wrote finally didn't work as I expected : the variations of acceleration are always too high. I'm in a cul-de-sac right now. Can't anyone give me a clue ?
Here is what my program looks like, inspired by Leo's program in the post i mentionned before :
#include <SD.h>;
File Fichier;
boolean test;
int increment = 31; //Increment en ms
int raw_xpin = 0.; // Variable numérique de l'accélération
int old_xpin =0.; // Variabe numérique de l'accélération
int n=0.;
float temps = 1.81; //Timer en s
float AcX = 0.; // Variable de l'accélération
float Somme_acc = 0. ; // Somme de Acx
float Ax = 0. ; // Valeur de l'accélération
void setup() {
// Initialisation
Serial.begin(9600);
pinMode(10, OUTPUT); // laisser la broche SS en sortie - obligatoire avec librairie SD
test=SD.begin(4); // initialisation de la carte SD avec broche 4 en tant que CS - renvoie true/false
if (test!=true)
{
while(1);
}
Fichier = SD.open("Valeurs2.txt", FILE_WRITE);
Fichier.println("--------------Nouvelle mesure---------------");
}
void loop() {
//Loop
//Timer
Fichier.print(temps);
Serial.print(temps);
//Accélération
for ( int i=0 ; i<=4 ; i++) {
// read input twice
raw_xpin = analogRead(A3);
raw_xpin = analogRead(A3); // double read
// ignore bad hop-on region of a pot by removing 8 values at both extremes( lot more here, to keep btw -7 and 7 in acceleration )
raw_xpin = constrain(raw_xpin,318,564 ); // contraindre xpin dans bornes
// add some deadband
if (raw_xpin >318 && raw_xpin <564) //vérifier les bornes et comprendre l'accélération numérique entre -7 et 7
{
if (raw_xpin < (old_xpin - 4) || raw_xpin > (old_xpin + 4)) // || = OU //si xpin est assez différent, tolérance
{ old_xpin = raw_xpin;
AcX = -0.0568*old_xpin + 25.05;
Somme_acc = AcX + Somme_acc;
n=n+1; }
}
}
if (n!=0)
{ Ax = Somme_acc/n ; }
Fichier.print(" ");
Fichier.print(Ax);
Fichier.println("");
Serial.print(" ");
Serial.print(Ax);
Serial.println("");
Somme_acc = 0. ;
n=0.;
temps = temps + increment*0.001;
if(temps > 20.)
//Fin des mesures
{
Fichier.println("---------------Fin des mesures---------------");
Fichier.close();
}
}
It just look as bad, here is a screen of acceleration while i vibrate a little my arm (not mooving the sensor) :
So the ADXL, after all I tried, doesn't seem ok... Let's try with the MMA...