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

@@ -2,7 +2,7 @@
//
/*
Name: Teensy4.1_Datalogger new.ino
Created: 31.08.2022 18:39:32
Created: 31.08.2022 18:39:32
Author: GAMINGMASHEEN\Julian Graf
*/

@@ -55,6 +55,9 @@ const int power_Temp_sensor = 34, power_Windfahne = 36, LED_Fail = 24, R_Temp_fi

int last_second, last_minute, last_hour, seconds_for_blink;

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

struct calculations {
private:
@@ -113,12 +116,12 @@ public:
};


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

anemometer(){
}
void setup_anemometer(int pin) {
this->reed_contact = Bounce(pin, 10);
}
@@ -131,6 +134,7 @@ public:

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

@@ -141,13 +145,13 @@ public:
}

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++) {
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);
@@ -167,11 +171,12 @@ private:

}anemometer_1, anemometer_2, anemometer_3;

struct temp_sensor {
struct temp_sensor{
private:
int U_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,
391, 424, 460, 498, 538, 581, 603, 626, 672, 722};
public:
@@ -183,17 +188,22 @@ public:

for (int t = 0; t < 9; t++) {
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() {
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;

struct wind_vain {
struct wind_vain{
private:
float wind_sec;
float wind_summ = 0;
@@ -216,8 +226,9 @@ public:
saved_seconds = 0;
}
void file_print() {
file.printf("\nWindruchtung in ° Winkel:\n");
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;
}
@@ -240,11 +251,19 @@ void dateTime(uint16_t* date, uint16_t* time, uint8_t* ms10) {
void write_sd() {
digitalWrite(LED_Write, HIGH);
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);
if (file.open(file_name, FILE_WRITE)) {
if (!file.open(file_name, FILE_WRITE)) {
digitalWrite(LED_Fail, HIGH);
}
else{
Serial.println("Start SD schreiben");

file.println("Messdaten von Windmessmasst");
@@ -259,9 +278,7 @@ void write_sd() {
anemometer_2.file_print();
file.println("Anemometer_3 Werte:");
anemometer_3.file_print();
file.println("Temperatursensor_1 Werte:");
temp_sensor_1.file_print();
file.println("Windfahne_1 Werte:");
wind_vain_1.file_print();

file.close();
@@ -296,6 +313,7 @@ void every_minute() {
anemometer_2.calculate();
anemometer_3.calculate();
wind_vain_1.calculate();
temp_sensor_1.measure();

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

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

Loading…
Cancel
Save