Bonjour, j'ai un problème avec mon code de capteur de pression. En gros, lors d'un code tout simple avec juste un analogRead j'obtiens ce que je veux, c'est a dire des valeurs au alentour de 850 et qui augmente ou baisse suivant ce que je veux. là où ca ne va pas, c'est lorsque que je veux intégrer ce code dans un plus gros, bien plus gros et j'obtien la valeur 1023 qui ne change pas. Je ne trouve où ça pêche, si vous pouviez m'aider.
Bonne journée
/*
*
*/
#include <SPI.h>
#include <SD.h>
/* accelerometerADXL
* X to A0
* Y to A1
* Z to A2
* AREF to 3.3
*/
/*
* MPX4115AP
* Analaog to A3
* MPX4115A
* to A4
*
* SD
* MOSI 11
* MISO 12
* SCK 13
* CS 4
*/
int actu = 0;
int precedent;
boolean bouton = LOW;
const int xInput = A0;
const int yInput = A1;
const int zInput = A2;
float pression = A5;
const int chipSelect = 4;
// Raw Ranges:
// initialize to mid-range and allow calibration to
// find the minimum and maximum for each axis X: 491-528, Y: 489-529, Z: 493-532
int xRawMin = 491;
int xRawMax = 528;
int yRawMin = 489;
int yRawMax = 529;
int zRawMin = 493;
int zRawMax = 532;
// Take multiple samples to reduce noise
const int sampleSize = 10;
int pinBouton;
int measurePre = A3;
const int relais = 3;
const int ledR = 1;
const int ledV = 2;
unsigned long tempsPrecedentPa = 0, tempsActuelPa = 0;
unsigned long currentMillisParra = millis();
File fusee;
void setup()
{
pinBouton=6;
pinMode(pinBouton,INPUT);
pinMode(relais, OUTPUT);
pinMode(ledR, OUTPUT);
pinMode(ledV, OUTPUT);
Serial.begin(9600);
digitalWrite(relais, HIGH);
analogReference(EXTERNAL);
Serial.begin(9600);
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("Initializing SD card...");
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("card initialized.");
fusee = SD.open("donnees.txt", FILE_WRITE); //on peut en ouvrir qu'un à la fois //
if (fusee) { //si le fichier a bien été ouvert :
fusee.print("X, Y, Z, ");
fusee.println("PressionStat ,PressionTot");
fusee.close();
Serial.println("Fait");
} else { // sinon :
Serial.println("Erreur lors de l'ouverture de test.txt");
}
}
void donne()
{
int xRaw = ReadAxis(xInput); //lecture donnée accéléromètre
int yRaw = ReadAxis(yInput);
int zRaw = ReadAxis(zInput);
{
Serial.print("Raw Ranges: X: ");
Serial.print(xRawMin);
Serial.print("-");
Serial.print(xRawMax);
Serial.print(", Y: ");
Serial.print(yRawMin);
Serial.print("-");
Serial.print(yRawMax);
Serial.print(", Z: ");
Serial.print(zRawMin);
Serial.print("-");
Serial.print(zRawMax);
Serial.println();
Serial.print(xRaw);
Serial.print(", ");
Serial.print(yRaw);
Serial.print(", ");
Serial.print(zRaw);
// Convert raw values to 'milli-Gs"
long xScaled = map(xRaw, xRawMin, xRawMax, -1000, 1000);
long yScaled = map(yRaw, yRawMin, yRawMax, -1000, 1000);
long zScaled = map(zRaw, zRawMin, zRawMax, -1000, 1000);
// re-scale to fractional Gs
float xAccel = xScaled / 1000.0;
float yAccel = yScaled / 1000.0;
float zAccel = zScaled / 1000.0;
Serial.print(" :: "); // affichage donnée accéléromètre
Serial.print(xAccel);
Serial.print("G, ");
Serial.print(yAccel);
Serial.print("G, ");
Serial.print(zAccel);
Serial.println("G");
fusee = SD.open("donnees.txt", FILE_WRITE);
fusee.print(xAccel);
fusee.print(" ,");
fusee.print(yAccel);
fusee.print(" ,");
fusee.println(zAccel);
fusee.close();
delay(500);
}
}
int ReadAxis(int axisPin)
{
long reading = 0;
analogRead(axisPin);
delay(1);
for (int i = 0; i < sampleSize; i++)
{
reading += analogRead(axisPin);
}
return reading/sampleSize;
}
void parachuteSecours() // timer de déploiment en cas de non fonctionnement du déclenchement auto
{
if (bouton == LOW)
{
bouton = HIGH;
precedent = millis();
}
if (bouton ==HIGH)
{
actu = millis();
if(actu - precedent > 10000)
{
digitalWrite(relais , LOW);
}
}
//EN COURS
}
void pressiond()
{ //lecture pression
Serial.println(analogRead(pression));
}
void loop()
{
donne();
Serial.println(analogRead(pression));
boolean etatBouton=digitalRead(pinBouton); //debut timer parachute
Serial.println(etatBouton);
if (etatBouton == 0)
{
parachuteSecours();
}
}