j'ai fais mon montage, ça fonctionne bien sauf....
j'ai une initialisation au démarrage, il est sur une pile 9volt, et j'aimerais justement qu'il ne s'initialise pas au démarrage sinon ça a aucun intérêt, j'aimerais l'initialisé une fois à plat et ensuite qu'il garde ces valeur de calibration en mémoire.
es ce que c'est possible?
ci-dessous le code.
#include <MPU6050_tockn.h>
#include <Wire.h>
MPU6050 mpu6050(Wire);
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 20 chars and 4 line display
LiquidCrystal_I2C lcd(0x27, 20, 4);
void setup() {
Serial.begin(115200);
Wire.begin();
mpu6050.begin();
mpu6050.calcGyroOffsets(false);
// initialize the LCD,
lcd.init();
// Turn on the blacklight and print a message.
lcd.backlight();
lcd.clear();
lcd.setCursor (0,0); //
lcd.print("Bus T6");
lcd.setCursor (0,1); //
lcd.print("Calibration - 3");
lcd.setCursor (0,1); //
delay(1000);
lcd.print("Calibration - 2");
delay(1000);
lcd.setCursor (0,1); //
lcd.print("Calibration - 1");
delay(1000);
}
void loop() {
mpu6050.update();
Serial.print("angleX : ");
Serial.print(mpu6050.getAngleX());
Serial.print(" angleY : ");
Serial.print(mpu6050.getAngleY());
Serial.print(" angleZ : ");
Serial.println(mpu6050.getAngleZ());
lcd.clear();// clearn previous values from screen
lcdDisplay(
mpu6050.getAngleX(),// send Av - Ar
mpu6050.getAngleY(),// send G - D
mpu6050.getAngleZ() // send angle Z
);
delay(100);
}// loop end
lcd.setCursor (0,0); //character zero, line 1
lcd.print("Av - Ar :");
lcd.setCursor (9,0); //
lcd.print(x);
lcd.setCursor (0,1); //character zero, line 2
lcd.print("G - D :");
lcd.setCursor (9,1); //
lcd.print(y);
lcd.setCursor (0,3); //character zero, line 3
lcd.print("Angle Z:");
lcd.setCursor (9,3); //
lcd.print(z);
}
Lorsque tu appuies sur le bouton, tu lances une calibration. Tu peux choisir de ne tester le bouton que dans setup() ou dans loop(), c'est toi qui voit.
Tu sauves le résultat de la calibration en EEPROM pour pouvoir le réutiliser plus tard.
Dans setup() tu testes s'il y a des données de calibration dans l'EEPROM:
Lecture / écrituree des données de calibration en mémoire EEPROM
#include <EEPROM.h>
struct caldata{
char magicword[10];
float calx,caly,calz;
};
uint16_t eepromAdrs=0;
caldata mydata;
// Read a data struct at address adrs
// return true if success
boolean readConfig(uint16_t adrs, caldata *data){
EEPROM.get(adrs, *data);
return strcmp(data->magicword, "DEADBEEF")==0;
}
// Write a data struct at address adrs
void writeConfig(uint16_t adrs, caldata data){
EEPROM.put(adrs, data);
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
// try to read the data in EEPROM
if (readConfig(eepromAdrs, &mydata)){
// if sucess print them
Serial.println("Data found");
Serial.print("Magic word: "); Serial.println(mydata.magicword);
Serial.print("calx: "); Serial.println(mydata.calx);
Serial.print("caly: "); Serial.println(mydata.caly);
Serial.print("calz: "); Serial.println(mydata.calz);
} else {
// if data are missing initialize them
Serial.println("No data found, creating them");
strcpy(mydata.magicword, "DEADBEEF");
mydata.calx = 987.654;
mydata.caly = 876.543;
mydata.calz = 654.321;
writeConfig(eepromAdrs, mydata);
}
Serial.println("Type c to change calibration data.");
Serial.println("Type r to read calibration data.");
Serial.println("Type d to delete calibration data");
}
void loop() {
// wait for a keyboard input
if (Serial.available()){
char c=Serial.read();
if (c=='c'){
// change data
if (strcmp(mydata.magicword,"DEADBEEF")==0){
// if data already exist change them
mydata.calx += 1000.0;
mydata.caly += 1000.0;
mydata.calz += 1000.0;
} else {
// if data are missing create new one
strcpy(mydata.magicword, "DEADBEEF");
mydata.calx = 987.654;
mydata.caly = 876.543;
mydata.calz = 654.321;
}
writeConfig(eepromAdrs, mydata);
}
if (c=='r'){
// read data in memory
if (readConfig(eepromAdrs, &mydata)){
// if success print them
Serial.print("Magic word: "); Serial.println(mydata.magicword);
Serial.print("calx: "); Serial.println(mydata.calx);
Serial.print("caly: "); Serial.println(mydata.caly);
Serial.print("calz: "); Serial.println(mydata.calz);
} else {
// if data are missing print a warning
Serial.println("No data");
}
}
if(c=='d'){
// delete data in memory by deleting magicword (not very secure)
strcpy(mydata.magicword, "");
writeConfig(eepromAdrs, mydata);
}
}
}
EDIT: programme changé pour quelque chose de plus facile à réutiliser.
Une fonction pour lire les données et une pour les écrire.
Dans loop(), un exemple de leur utilisation.
Alors j'avais tout tester sur une breadboard, j'avais fais un boitier et tout fonctionnait mais j'avais des fils partout, et du coup pour améliorer je voulais ajouter le bouton initialisation et surtout je voulais un PCB pour plus avoir ces fils, mais dans la création de mon pcb, j'ai une piste qui passait trop près d'un pad et ça fais contact, mais j'avais d'abord fait le tout sur une breadboard