Bonsoir à toutes et tous,
Je bricole l'Arduino depuis quelques temps mais sans vraiment avoir un bon niveau en programmation. Généralement, en cherchant j'arrive toujours à résoudre mes problèmes. Cependant, même si j'ai trouvé une configuration qui fonctionne, je suis obligé de passer par un stratagème que je ne comprends pas du tout et je souhaiterais avoir vos lumières sur le pourquoi du comment.
Mon but est d'enregistrer sur une carte SD les informations suivantes :
- Différentiel de pression utilisant un capteur approprié
- Date, heure
- Vitesse GPS
Le schéma est attaché en PJ de ce message.
Le code suivant fonctionnement parfaitement :
#include <SoftwareSerial.h>
#include <TinyGPS.h>
#include <SD.h>
#include <SPI.h>
#include <Wire.h>
#include "SDP6x.h"
File sdcard_file;
int CS_pin = 4;
TinyGPS gps;
SoftwareSerial ss(0, 1);
//Variables pour le GPS
static void print_date(TinyGPS &gps);
unsigned long date;
unsigned long heure;
unsigned long fix_age;
unsigned long speed;
//Variables pour la carte SD
String data;
String virgule = ";";
void setup() {
Serial.begin(9600); //Setting baudrate at 9600
ss.begin(4800);
initialisation_sd_card();
// On écrit les en-têtes
data = "millis()" + virgule + "date"+ virgule + "heure" + virgule + "fkmph" + virgule + "difPressure";
Serial.println (data);
sdcard_file = SD.open("pitot6.txt", FILE_WRITE); //Looking for the data.txt in SD card
if (sdcard_file) { //If the file is found
sdcard_file.println(data); //Writing to file
sdcard_file.close(); //Closing the file
}
else {
Serial.println("Failed to open the file");
}
}
void loop() {
initialisation_sd_card();//Lorsque je retire cette ligne, j'ai un problème
//**********************************************************************GPS**********************************************************************
bool newData = false;
unsigned long chars;
unsigned short sentences, failed;
// For one second we parse GPS data and report some key values
for (unsigned long start = millis(); millis() - start < 1000;)
{
while (ss.available())
{
char c = ss.read();
if (gps.encode(c)) // Did a new valid sentence come in?
newData = true;
}
}
float fkmph = gps.f_speed_kmph();
gps.get_datetime(&date, &heure, &fix_age);
//**********************************************************************SD CARD**********************************************************************
data = millis() + virgule + date + virgule + heure + virgule + fkmph + virgule + SDP6x.GetPressureDiff();
Serial.println (data);
sdcard_file = SD.open("pitot6.txt", FILE_WRITE); //Looking for the data.txt in SD card
if (sdcard_file) { //If the file is found
sdcard_file.println(data); //Writing to file
sdcard_file.close(); //Closing the file
}
else {
Serial.println("Failed to open the file");
}
}
void initialisation_sd_card()
{
pinMode(CS_pin, OUTPUT);//declaring CS pin as output pin
if (SD.begin())
{
Serial.println("SD card is initialized and it is ready to use");
} else
{
Serial.println("SD card is not initialized");
return;
}
}
J'ai le retour "data" suivant :
476017;41119;20444200;1.54;8.54
Cependant, lorsque je retire initialisation_sd_card(); à l'entrée du loop {}, j'ai le retour "data" suivant :
476017;41119;20444200;1.54;-10000000.00
Dans le premier cas, la valeur de 8,54 est la valeur de pression différentielle que je recherche, tout va bien. Dans le second cas, j'ai une valeur fixe de -10000000.00 qui ne veut rien dire du tout.
Je ne comprends absolument pas en quoi il est nécessaire de réutiliser ma fonction initialisation_sd_card(); pour faire fonctionner mon capteur monté en I2C. Certainement un lien avec la ligne pinMode(CS_pin, OUTPUT);, mais je ne comprends pas du tout pourquoi.
Pour info, voici la datasheet du capteur : http://kr.mouser.com/datasheet/2/682/Sensirion_Differential_Pressure_Sensors_SDP600Seri-1511233.pdf
Pour info, voici le code qui ne marche pas :
#include <SoftwareSerial.h>
#include <TinyGPS.h>
#include <SD.h>
#include <SPI.h>
#include <Wire.h>
#include "SDP6x.h"
File sdcard_file;
int CS_pin = 4;
TinyGPS gps;
SoftwareSerial ss(0, 1);
//Variables pour le GPS
static void print_date(TinyGPS &gps);
unsigned long date;
unsigned long heure;
unsigned long fix_age;
unsigned long speed;
//Variables pour la carte SD
String data;
String virgule = ";";
void setup() {
Serial.begin(9600); //Setting baudrate at 9600
ss.begin(4800);
initialisation_sd_card();
// On écrit les en-têtes
data = "millis()" + virgule + "date"+ virgule + "heure" + virgule + "fkmph" + virgule + "difPressure";
Serial.println (data);
sdcard_file = SD.open("pitot6.txt", FILE_WRITE); //Looking for the data.txt in SD card
if (sdcard_file) { //If the file is found
sdcard_file.println(data); //Writing to file
sdcard_file.close(); //Closing the file
}
else {
Serial.println("Failed to open the file");
}
}
void loop() {
//**********************************************************************GPS**********************************************************************
bool newData = false;
unsigned long chars;
unsigned short sentences, failed;
// For one second we parse GPS data and report some key values
for (unsigned long start = millis(); millis() - start < 1000;)
{
while (ss.available())
{
char c = ss.read();
if (gps.encode(c)) // Did a new valid sentence come in?
newData = true;
}
}
float fkmph = gps.f_speed_kmph();
gps.get_datetime(&date, &heure, &fix_age);
//**********************************************************************SD CARD**********************************************************************
data = millis() + virgule + date + virgule + heure + virgule + fkmph + virgule + SDP6x.GetPressureDiff();
Serial.println (data);
sdcard_file = SD.open("pitot6.txt", FILE_WRITE); //Looking for the data.txt in SD card
if (sdcard_file) { //If the file is found
sdcard_file.println(data); //Writing to file
sdcard_file.close(); //Closing the file
}
else {
Serial.println("Failed to open the file");
}
}
void initialisation_sd_card()
{
pinMode(CS_pin, OUTPUT);//declaring CS pin as output pin
if (SD.begin())
{
Serial.println("SD card is initialized and it is ready to use");
} else
{
Serial.println("SD card is not initialized");
return;
}
}
Si quelqu'un a une explication pour que je comprenne, je suis preneur!
D'avance merci à vous!
