Bonjour à tous,
Alors voilà, je suis actuellement en classe préparatoire scientifique et dans le cadre de mon TIPE je souhaite créer et programmer une balise permettant de capter l'effort d'une vague sur une surface et d'enregistrer les valeurs sur une carte SD connectée à un shield ethernet. Pour s'effectuer, j'ai conçue une simple balance avec une cellule de charge et un module HX711 pour l'amplification. Le tout est relié à une carte Arduino Mega 2560. D'autres parts, j'ai branché un écran LCD 16x2 pour afficher la progression et d'éventuelles erreurs.

Côté branchement le tout est bon, j'ai déjà fait des tests avec des programmes pour calibrer ma balance et tout fonctionne.
Seulement dans mon programme, le programme bloque au niveau de la ligne scale.tare(); (ligne 39) dans la fonction setup, et lorsque j'enlève la ligne scale.tare(); le programme bloque à la ligne masse = scale.get_units(),10; dans la fonction loop.

Donc voilà j'aimerai savoir si quelqu'un a une idée de ce qui pourrait empêcher mon programme de bien fonctionner, merci

Je mets mes programmes en PJ.

Mon programme:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
 
#include <LiquidCrystal.h>
const int E = 11;
const int RS = 12;
const int D4 = 3;
const int D5 = 5;
const int D6 = 6;
const int D7 = 7;
const int COLS = 16;
const int ROWS = 2;
LiquidCrystal LCD(RS,E,D4,D5,D6,D7);
 
#include <SdFat.h>
SdFat SDcard;
SdFile file;
const int SD_PIN = 4;
 
#include "HX711.h"
float calibration_factor = -880;
HX711 scale(53, 23);
 
unsigned long t0;
float masse;
 
void setup() {
  // Initialization of modules : scale, LCD, Serial monitor, SD card || Initialisation des modules : balance, LCD, moniteur série, carte SD 
    // Serial monitor || Moniteur série
  Serial.begin(9600);
  Serial.println("Initialisation des modules");
    // SD card || Carte SD
  SDcard.begin(SD_PIN);
  Serial.println("SD ok");
    // LCD
  LCD.begin(COLS,ROWS);
  Serial.println("LCD ok");
    // Scale || Balance
  scale.set_scale(calibration_factor);
  Serial.println("Balance calibration ok");
  scale.tare(); // <-- Where it blocks || Où ça bloque
  Serial.println("Balance tare ok");
  // Start countdown || Lancement du compte à rebours
  LCD.clear();
  LCD.setCursor(0,0);
  LCD.print("New entry in 3");
  Serial.println("New entry in 3");
  delay(1000);
  LCD.print("New entry in 2");
  Serial.println("New entry in 2");
  delay(1000);
  LCD.print("New entry in 2");
  Serial.println("New entry in 2");
  delay(1000);
  LCD.clear();
  // Opening file and writing new entry || Ouverture du fichier et écriture d'une nouvelle entrée
  if (file.open("données.txt", FILE_WRITE)) 
  {
    file.println("");
    file.println("Nouvelle entrée:");
    file.println("");
    file.close();
    LCD.print("Writing data...");
    Serial.print("Writing data...");
    LCD.setCursor(0,1);
    LCD.print("Time : "); 
    LCD.setCursor(11,1);
    LCD.print("s");
  }
  t0 = millis();
  Serial.print("t0 = ");
  Serial.println(t0);
}
 
void loop() {
 // Acquiring data || Acquisistion des données
 unsigned long t = millis();
 masse = scale.get_units(),10;
 // Displaying clock || Affichage de la montre
 LCD.setCursor(7,1);
 LCD.print(t/1000);
 // Writing data || Ecriture des données
 if (file.open("données.txt", FILE_WRITE))
 {
    file.print(t-t0);
    file.print(" ; ");
    file.println("masse");
    file.close();
 }
 else // If SD out || si SD retirée
 {
  LCD.clear();
  LCD.print("SD out or ERROR");
  LCD.setCursor(0,1);
  LCD.print("Please reset");
  for(;;);
 }
}
Programme de calibration

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
 
/*
 Setup your scale and start the sketch WITHOUT a weight on the scale
 Once readings are displayed place the weight on the scale
 Press +/- or a/z to adjust the calibration_factor until the output readings match the known weight
 Arduino pin 5 -> HX711 CLK
 Arduino pin 6 -> HX711 DOUT
 Arduino pin 5V -> HX711 VCC
 Arduino pin GND -> HX711 GND 
*/
 
#include "HX711.h"
 
HX711 scale(53, 23);
 
float calibration_factor = -300; // this calibration factor is adjusted according to my load cell
float units;
float ounces;
 
void setup() {
  Serial.begin(9600);
  Serial.println("HX711 calibration sketch");
  Serial.println("Remove all weight from scale");
  Serial.println("After readings begin, place known weight on scale");
  Serial.println("Press + or a to increase calibration factor");
  Serial.println("Press - or z to decrease calibration factor");
 
  scale.set_scale();
  scale.tare();  //Reset the scale to 0
 
  long zero_factor = scale.read_average(); //Get a baseline reading
  Serial.print("Zero factor: "); //This can be used to remove the need to tare the scale. Useful in permanent scale projects.
  Serial.println(zero_factor);
}
 
void loop() {
 
  scale.set_scale(calibration_factor); //Adjust to this calibration factor
 
  Serial.print("Reading: ");
  units = scale.get_units(), 10;
  if (units < 0)
  {
    units = 0.00;
  }
  ounces = units * 0.035274;
  Serial.print(units);
  Serial.print(" grams"); 
  Serial.print(" calibration_factor: ");
  Serial.print(calibration_factor);
  Serial.println();
 
  if(Serial.available())
  {
    char temp = Serial.read();
    if(temp == '+' || temp == 'a')
      calibration_factor += 5;
    else if(temp == '-' || temp == 'z')
      calibration_factor -= 5;
  }
}