Bonjour, je réalise un projet qui utilise arduino uno & shield et beaucoup de capteurs (la plupart d'entre eux connectés en i2c)
Et je tente de créer un programme qui regroupe dans une carte sd toutes les données recueillies par les capteurs.
Mais le vérificateur arduino me dit qu'il y a quelques erreurs, mais quand je les corrige, d'autres "étranges" erreurs apparaîssent!
Voici mon programme, pouvez-vous me dire ce qu'il ne va pas, s'il vous plaît?
#include<SD.h>
#include<SPI.h>
#include<Wire.h>
int address_sensor1= 72; //binary equivalent is 1001000
int address_sensor2= 73; //binary equivalent is 1001001
int address_sensor3= 74; //binary equivalent is 1001100
int address_sensor4= 75; //binary equivalent is 1001101
File Data;
void setup() {
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Wire.begin();
Serial.begin(9600);
if (!SD.begin(4)) {
Serial.println("Initialisation impossible !");
return;
}
Serial.println("Initialisation OK.");
// Check to see if the file exists:
if (!SD.exists("Data.txt")) {
Serial.println("Data.txt existe.");
}
else {
Serial.println("Data.txt n'existe pas.");
Serial.println("Création de Data.txt...");
Data = SD.open("Data.txt", FILE_WRITE);
Data.close();
}
Data = SD.open("Data.txt", FILE_WRITE);
if (Data) {
Serial.print("Ecriture sur Data.txt...");
Data.println("Test 1, 2, 3.");
// close the file:
Data.close();
Serial.println("OK.");
}
else {
// if the file didn't open, print an error:
Serial.println("Erreur d'ouverture du Data.txt");
}
{
void loop()
{ Wire.requestFrom(4, 6); // request 6 bytes from slave device #4
while (Wire.available()) { // slave may send less than requested
char c = Wire.read(); // receive a byte as character
Serial.print(c); // print the character
Wire.beginTransmission(address_sensor1); //Send a request to begin communication with the device at the specified address
Wire.write(0); //Sends a bit asking for register 0, the data register of the TC74 sensor
Wire.endTransmission(); //this ends transmission of data from the arduino to the temperature sensor
//this now reads the temperature from the TC74 sensor
Wire.requestFrom(address_sensor1, 1);//this requests 1 byte from the specified address
while(Wire.available() == 0);
int celsius1= Wire.read();
Serial.print(celsius1)}
}
// make a string for assembling the data to log:
String dataString = "";
// read three sensors and append to the string:
dataString += String(celsius1)
delay(2000);
}
delay(500);
}
}
Merci !²