Browse Source

Update 'Teensy4.1_Datalogger new.ino'

master
Julian Graf 2 years ago
parent
commit
df1a89f509
1 changed files with 44 additions and 27 deletions
  1. 44
    27
      Teensy4.1_Datalogger new.ino

+ 44
- 27
Teensy4.1_Datalogger new.ino View File

// //
/* /*
Name: Teensy4.1_Datalogger new.ino Name: Teensy4.1_Datalogger new.ino
Created: 31.08.2022 18:39:32
Created: 31.08.2022 18:39:32
Author: GAMINGMASHEEN\Julian Graf Author: GAMINGMASHEEN\Julian Graf
*/ */




int last_second, last_minute, last_hour, seconds_for_blink; int last_second, last_minute, last_hour, seconds_for_blink;


time_t getTeensy3Time() {
return Teensy3Clock.get();
}


struct calculations { struct calculations {
private: private:
}; };




struct anemomenter {
struct anemometer{
public: public:
anemometer(){
}


anemometer(){
}
void setup_anemometer(int pin) { void setup_anemometer(int pin) {
this->reed_contact = Bounce(pin, 10); this->reed_contact = Bounce(pin, 10);
} }


void save_wind_speed() { void save_wind_speed() {
wind_speed_per_second[saved_seconds] = 0.4 * count_per_second; wind_speed_per_second[saved_seconds] = 0.4 * count_per_second;
count_per_second = 0;
saved_seconds++; saved_seconds++;
} }


} }


void file_print() { void file_print() {
file.printf("Min:\tMax:\tArith. Mittel:\tStandard Abw.:\tQuadr. Mittel:\tStandard Abw.:\tKub. Mittel:\tStandard Abw.:\tÜbersprungene Sek.:\n");
for (int i = 0; i < saved_minutes; i++) { for (int i = 0; i < saved_minutes; i++) {
file.printf("Min: %f,\tMax: %f,\t", values[i].speed_min, values[i].speed_max);
file.printf("Arith. Mittel: % f,\tStandard Abw.: %f\t", values[i].arithmetic_mean, values[i].arithmetic_deviation);
file.printf("Quadr. Mittel: % f,\tStandard Abw.: %f\t", values[i].square_mean, values[i].square_deviation);
file.printf("Kub. Mittel: %f,\tStandard Abw.: %f\t", values[i].cubic_mean, values[i].cubic_deviation);
file.printf("Übersprungene Sek.: %i\n", values[i].seconds_skipped);
file.printf("%.2f\t%.2f\t", values[i].speed_min, values[i].speed_max);
file.printf("%.2f\t%.2f\t", values[i].arithmetic_mean, values[i].arithmetic_deviation);
file.printf("%.2f\t%.2f\t", values[i].square_mean, values[i].square_deviation);
file.printf("%.2f\t%.2f\t", values[i].cubic_mean, values[i].cubic_deviation);
file.printf("%i\n", values[i].seconds_skipped);
} }


file.printf("Übersprungene Min.: %i\n", 60 - saved_minutes); file.printf("Übersprungene Min.: %i\n", 60 - saved_minutes);


}anemometer_1, anemometer_2, anemometer_3; }anemometer_1, anemometer_2, anemometer_3;


struct temp_sensor {
struct temp_sensor{
private: private:
int U_Temp; int U_Temp;
int R_Temp; int R_Temp;
float Temp = 0;
int saved_minutes = 0;
float Temp[60];
short int array_Temp_datenblatt[20] = { -30, -20, -10, 0, 10, 20, 25, 30, 40, 50, short int array_Temp_datenblatt[20] = { -30, -20, -10, 0, 10, 20, 25, 30, 40, 50,
391, 424, 460, 498, 538, 581, 603, 626, 672, 722}; 391, 424, 460, 498, 538, 581, 603, 626, 672, 722};
public: public:


for (int t = 0; t < 9; t++) { for (int t = 0; t < 9; t++) {
if ((R_Temp >= array_Temp_datenblatt[t + 10]) && (R_Temp <= array_Temp_datenblatt[t + 11])) { if ((R_Temp >= array_Temp_datenblatt[t + 10]) && (R_Temp <= array_Temp_datenblatt[t + 11])) {
Temp = array_Temp_datenblatt[t] + ((R_Temp - array_Temp_datenblatt[t + 10]) * (array_Temp_datenblatt[t + 1] - array_Temp_datenblatt[t]) / (array_Temp_datenblatt[t + 11] - array_Temp_datenblatt[t + 10]));
Temp[saved_minutes] = array_Temp_datenblatt[t] + ((R_Temp - array_Temp_datenblatt[t + 10]) * (array_Temp_datenblatt[t + 1] - array_Temp_datenblatt[t]) / (array_Temp_datenblatt[t + 11] - array_Temp_datenblatt[t + 10]));
} }
} }
saved_minutes++;
} }


void file_print() { void file_print() {
printf("Temperatur: %.2f °C\n", Temp);
file.printf("\nTemperatur:\n");
for (int i = 0; i < saved_minutes; i++) {
file.printf("%.2f °C\n", Temp[i]);
}
saved_minutes = 0;
} }
} temp_sensor_1; } temp_sensor_1;


struct wind_vain {
struct wind_vain{
private: private:
float wind_sec; float wind_sec;
float wind_summ = 0; float wind_summ = 0;
saved_seconds = 0; saved_seconds = 0;
} }
void file_print() { void file_print() {
file.printf("\nWindruchtung in ° Winkel:\n");
for (int i = 0; i < saved_minutes; i++) { for (int i = 0; i < saved_minutes; i++) {
printf("Windrichtung in ° Winkel: %.2f\n", values[i]);
file.printf("%.2f °\n", values[i]);
} }
saved_minutes = 0; saved_minutes = 0;
} }
void write_sd() { void write_sd() {
digitalWrite(LED_Write, HIGH); digitalWrite(LED_Write, HIGH);
char file_name[50]; char file_name[50];
FsDateTime::setCallback(dateTime);


sprintf(file_name, "Windmessmast-%d.%d.%d_%d:%d.txt", year(), month(), day(), hour(), minute());
short int jahr = year();
short int monat = month();
short int tag = day();
short int stunde = hour();
short int minut = minute();
FsDateTime::setCallback(dateTime);
sprintf(file_name, "Windmessmast-%d.%d.%d_%d-%d.txt", jahr, monat, tag, stunde, minut);
sd.begin(SD_CONFIG); sd.begin(SD_CONFIG);
if (file.open(file_name, FILE_WRITE)) {
if (!file.open(file_name, FILE_WRITE)) {
digitalWrite(LED_Fail, HIGH);
}
else{
Serial.println("Start SD schreiben"); Serial.println("Start SD schreiben");


file.println("Messdaten von Windmessmasst"); file.println("Messdaten von Windmessmasst");
anemometer_2.file_print(); anemometer_2.file_print();
file.println("Anemometer_3 Werte:"); file.println("Anemometer_3 Werte:");
anemometer_3.file_print(); anemometer_3.file_print();
file.println("Temperatursensor_1 Werte:");
temp_sensor_1.file_print(); temp_sensor_1.file_print();
file.println("Windfahne_1 Werte:");
wind_vain_1.file_print(); wind_vain_1.file_print();


file.close(); file.close();
anemometer_2.calculate(); anemometer_2.calculate();
anemometer_3.calculate(); anemometer_3.calculate();
wind_vain_1.calculate(); wind_vain_1.calculate();
temp_sensor_1.measure();


if((analogRead(Batterie_input) * 15.3 / float(1023)) < Grenz_U_Batterie) { if((analogRead(Batterie_input) * 15.3 / float(1023)) < Grenz_U_Batterie) {
digitalWrite(LED_Batterie, HIGH); digitalWrite(LED_Batterie, HIGH);
pinMode(LED_Batterie, OUTPUT); pinMode(LED_Batterie, OUTPUT);
pinMode(power_Temp_sensor, OUTPUT); pinMode(power_Temp_sensor, OUTPUT);
pinMode(power_Windfahne, OUTPUT); pinMode(power_Windfahne, OUTPUT);
setSyncProvider((getExternalTime)Teensy3Clock.get());
setSyncProvider(getTeensy3Time);
Serial.begin(9600); Serial.begin(9600);
Serial.println("Teensy 4.1-Datalogger gestartet"); Serial.println("Teensy 4.1-Datalogger gestartet");
if (timeStatus() != timeSet) { if (timeStatus() != timeSet) {
anemometer_2.setup_anemometer(9); anemometer_2.setup_anemometer(9);
anemometer_3.setup_anemometer(22); anemometer_3.setup_anemometer(22);
seconds_for_blink = 0; seconds_for_blink = 0;
Serial.println("Messung startet"); Serial.println("Messung startet");
last_second = second(); last_second = second();
while (last_second == second()) {}; while (last_second == second()) {};
last_second = second(); last_second = second();
last_minute = minute(); last_minute = minute();
last_hour = hour(); last_hour = hour();
} }


// Add the main program code into the continuous loop() function // Add the main program code into the continuous loop() function

Loading…
Cancel
Save