Ecrire information capteur sur carte micro sd Catalex MicroSD Card Adapter

Bonjour,
J’ai acheté récemment un adaptateur de carte SD afin d’écrire les informations que mon programme arduino me renvoyait. Le test de la lecture de la carte sd marche, le ficher txt se créé bien sur la carte SD et quand je l’ouvre, il me met dans le programme “testing 1,2,3” donc cela marche. Mais aucunes des informations renvoyer par mes capteurs sont écrits… J’ai du me tromper dans mon programme, ou alors il faut peut etre imbriquer le programme des capteurs dans le programme de la sd. Si quelqu’un pourrait m’aider ca serait nickel. Merci d’avance. Je vous mets le programme en question:

#include <SFE_BMP180.h>
#include <Wire.h>
SFE_BMP180 pressure;
#define ALTITUDE 1655.0
// déclaration des variables programme 2
#define DHT11_PIN 0 // ADC0
byte read_dht11_dat()
{
byte i = 0;
byte result=0;
for(i=0; i< 8; i++)
{
while(!(PINC & _BV(DHT11_PIN))); // wait for 50us
delayMicroseconds(30);
if(PINC & _BV(DHT11_PIN))
result |=(1<<(7-i));
while((PINC & _BV(DHT11_PIN))); // wait '1' finish
}
return result;
}
#include <SPI.h>
#include <SD.h>

File myFile; // สร้างออฟเจก File สำหรับจัดการข้อมูล
const int chipSelect = 0;



void setup()
{ 
   setup1();
   setup2();
   setup3();
}

void loop()
{
  loop1();
  loop2();
  loop3();
}

void setup1()
{
  Serial.begin(9600);
  Serial.println(F("REBOOT"));

  // Initialize the sensor (it is important to get calibration values stored on the device).

  if (pressure.begin())
    Serial.println(F("BMP180 init success"));
  else
  {
    // Oops, something went wrong, this is usually a connection problem,
    // see the comments at the top of this sketch for the proper connections.

    Serial.println(F("BMP180 init fail\n\n"));
    while(1); // Pause forever.
  } 
}
void setup2()
{
DDRC |= _BV(DHT11_PIN);
PORTC |= _BV(DHT11_PIN);
Serial.begin(9600);
Serial.println(F("Ready"));
}
void setup3()
{

Serial.begin(9600);
while (!Serial) {
; // รอจนกระทั่งเชื่อมต่อกับ Serial port แล้ว สำหรับ Arduino Leonardo เท่านั้น
}

Serial.print("Initializing SD card...");
pinMode(SS, OUTPUT);

if (!SD.begin(chipSelect)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");

myFile = SD.open("test.txt", FILE_WRITE); // เปิดไฟล์ที่ชื่อ test.txt เพื่อเขียนข้อมูล โหมด FILE_WRITE

// ถ้าเปิดไฟล์สำเร็จ ให้เขียนข้อมูลเพิ่มลงไป
if (myFile) {
Serial.print("Writing to test.txt...");
myFile.println("testing 1, 2, 3."); // สั่งให้เขียนข้อมูล
myFile.close(); // ปิดไฟล์
Serial.println("done.");
} else {
// ถ้าเปิดไฟลืไม่สำเร็จ ให้แสดง error 
Serial.println("error opening test.txt");
}

// เปิดไฟล์เพื่ออ่าน
myFile = SD.open("test.txt"); // สั่งให้เปิดไฟล์ชื่อ test.txt เพื่ออ่านข้อมูล
if (myFile) {
Serial.println("test.txt:");
// อ่านข้อมูลทั้งหมดออกมา
while (myFile.available()) {
Serial.write(myFile.read());
}
myFile.close(); // เมื่ออ่านเสร็จ ปิดไฟล์
} else {
// ถ้าอ่านไม่สำเร็จ ให้แสดง error 
Serial.println("error opening test.txt");
}
}

void loop1()
{
  char status;
  double T,P,p0,a;

  // Loop here getting pressure readings every 10 seconds.

  // If you want sea-level-compensated pressure, as used in weather reports,
  // you will need to know the altitude at which your measurements are taken.
  // We're using a constant called ALTITUDE in this sketch:
  
  Serial.println();
  Serial.print("provided altitude: ");
  Serial.print(ALTITUDE,0);
  Serial.print(" meters, ");
  Serial.print(ALTITUDE*3.28084,0);
  Serial.println(F(" feet"));
  
  // If you want to measure altitude, and not pressure, you will instead need
  // to provide a known baseline pressure. This is shown at the end of the sketch.

  // You must first get a temperature measurement to perform a pressure reading.
  
  // Start a temperature measurement:
  // If request is successful, the number of ms to wait is returned.
  // If request is unsuccessful, 0 is returned.

  status = pressure.startTemperature();
  if (status != 0)
  {
    // Wait for the measurement to complete:
    delay(status);

    // Retrieve the completed temperature measurement:
    // Note that the measurement is stored in the variable T.
    // Function returns 1 if successful, 0 if failure.

    status = pressure.getTemperature(T);
    if (status != 0)
    {
      // Print out the measurement:
      Serial.print("temperature: ");
      Serial.print(T,2);
      Serial.print(" deg C, ");
      Serial.print((9.0/5.0)*T+32.0,2);
      Serial.println(F(" deg F"));
      
      // Start a pressure measurement:
      // The parameter is the oversampling setting, from 0 to 3 (highest res, longest wait).
      // If request is successful, the number of ms to wait is returned.
      // If request is unsuccessful, 0 is returned.

      status = pressure.startPressure(3);
      if (status != 0)
      {
        // Wait for the measurement to complete:
        delay(status);

        // Retrieve the completed pressure measurement:
        // Note that the measurement is stored in the variable P.
        // Note also that the function requires the previous temperature measurement (T).
        // (If temperature is stable, you can do one temperature measurement for a number of pressure measurements.)
        // Function returns 1 if successful, 0 if failure.

        status = pressure.getPressure(P,T);
        if (status != 0)
        {
          // Print out the measurement:
          Serial.print("absolute pressure: ");
          Serial.print(P,2);
          Serial.print(" mb, ");
          Serial.print(P*0.0295333727,2);
          Serial.println(F(" inHg"));

          // The pressure sensor returns abolute pressure, which varies with altitude.
          // To remove the effects of altitude, use the sealevel function and your current altitude.
          // This number is commonly used in weather reports.
          // Parameters: P = absolute pressure in mb, ALTITUDE = current altitude in m.
          // Result: p0 = sea-level compensated pressure in mb

          p0 = pressure.sealevel(P,ALTITUDE); // we're at 1655 meters (Boulder, CO)
          Serial.print("relative (sea-level) pressure: ");
          Serial.print(p0,2);
          Serial.print(" mb, ");
          Serial.print(p0*0.0295333727,2);
          Serial.println(F(" inHg"));

          // On the other hand, if you want to determine your altitude from the pressure reading,
          // use the altitude function along with a baseline pressure (sea-level or other).
          // Parameters: P = absolute pressure in mb, p0 = baseline pressure in mb.
          // Result: a = altitude in m.

          a = pressure.altitude(P,p0);
          Serial.print("computed altitude: ");
          Serial.print(a,0);
          Serial.print(" meters, ");
          Serial.print(a*3.28084,0);
          Serial.println(" feet");
        }
        else Serial.println(F("error retrieving pressure measurement\n"));
      }
      else Serial.println(F("error starting pressure measurement\n"));
    }
    else Serial.println(F("error retrieving temperature measurement\n"));
  }
  else Serial.println(F("error starting temperature measurement\n"));

  delay(2000);  // Pause for 5 seconds.  
}
void loop2()
{
byte dht11_dat[5];
byte dht11_in;
byte i;// start condition
// 1. pull-down i/o pin from 18ms
PORTC &= ~_BV(DHT11_PIN);
delay(18);
PORTC |= _BV(DHT11_PIN);
delayMicroseconds(40);
DDRC &= ~_BV(DHT11_PIN);
delayMicroseconds(40);
dht11_in = PINC & _BV(DHT11_PIN);
if(dht11_in)
{
Serial.println(F("dht11 start condition 1 not met"));
return;
}
delayMicroseconds(80);
dht11_in = PINC & _BV(DHT11_PIN);
if(!dht11_in)
{
Serial.println(F("dht11 start condition 2 not met"));
return;
}
delayMicroseconds(80);// now ready for data reception
for (i=0; i<5; i++)
dht11_dat[i] = read_dht11_dat();
DDRC |= _BV(DHT11_PIN);
PORTC |= _BV(DHT11_PIN);
byte dht11_check_sum = dht11_dat[0]+dht11_dat[1]+dht11_dat[2]+dht11_dat[3];
if(dht11_dat[4]!= dht11_check_sum)
{
Serial.println(F("DHT11 checksum error"));
}
Serial.print("Current humdity = ");
Serial.print(dht11_dat[0], DEC);
Serial.print(".");
Serial.print(dht11_dat[1], DEC);
Serial.print("% ");
Serial.print("temperature = ");
Serial.print(dht11_dat[2], DEC);
Serial.print(".");
Serial.print(dht11_dat[3], DEC);
Serial.println(F("C"));
delay(2000);
}
void loop3()
{

}

J'ai parcouru rapidement ton code et je crois pas avoir vu un bout où tu écris les valeurs reçues de tes capteurs dans la SD donc normal qu'elles n'y soient pas ...

Tu fais du copier/coller sans trop chercher à comprendre , non ? :D

Salut,

Exemple de code pour enregistrer les données de ma station météo sur une SD,

void sdcar()
{
  heures=hour();
  minutes = minute();
  secondes =second();
  Mois=month();
  jour_mois= day();
  annee=year();
  sensors.requestTemperatures();
  temp_Ext=(sensors.getTempCByIndex(0));
  pression_atm = int ((bmp.readPressure()/100)+17);
  sprintf(myData,"%u/%u/%u    %u:%u:%u  %u  %u", annee,Mois,jour_mois,heures,minutes,secondes,temp_Ext,pression_atm); 
  myFile = SD.open("Meteo2.txt", FILE_WRITE);
  myFile.println(myData);
  myFile.close();
  myFile = SD.open("Meteo2.txt");
  // Lecture du contenu du fichier
  if (myFile) {
  Serial.println("Meteo2.txt:");
  while (myFile.available()) {
  Serial.write(myFile.read());
  }
  // Fermeture fichier
  myFile.close();
  } else {
  
  Serial.println("erreur ouverture meteo2.txt");
  }
  comp_sd = comp_sd+1;
  
}