diff --git a/Teensy4.1_Datalogger new.ino b/Teensy4.1_Datalogger new.ino new file mode 100644 index 0000000..e7da967 --- /dev/null +++ b/Teensy4.1_Datalogger new.ino @@ -0,0 +1,235 @@ +// Visual Micro is in vMicro>General>Tutorial Mode +// +/* + Name: Teensy4.1_Datalogger new.ino + Created: 03.05.2022 12:04:32 + Author: GAMINGMASHEEN\Julian Graf +*/ + +#include +#include +#include + +#define SD_FAT_TYPE 3 + +#ifndef SDCARD_SS_PIN +const uint8_t SD_CS_PIN = SS; +#else // SDCARD_SS_PIN +// Assume built-in SD is used. +const uint8_t SD_CS_PIN = SDCARD_SS_PIN; +#endif // SDCARD_SS_PIN + +#if HAS_SDIO_CLASS +#define SD_CONFIG SdioConfig(FIFO_SDIO) +#elif ENABLE_DEDICATED_SPI +#define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI) +#else // HAS_SDIO_CLASS +#define SD_CONFIG SdSpiConfig(SD_CS_PIN, SHARED_SPI) +#endif // HAS_SDIO_CLASS + +#if SD_FAT_TYPE == 0 +SdFat sd; +File file; +#elif SD_FAT_TYPE == 1 +SdFat32 sd; +File32 file; +#elif SD_FAT_TYPE == 2 +SdExFat sd; +ExFile file; +#elif SD_FAT_TYPE == 3 +SdFs sd; +FsFile file; +#else // SD_FAT_TYPE +#error Invalid SD_FAT_TYPE +#endif // SD_FAT_TYPE + +// Define User Types below here or use a .h file +// +const char software_name[] = "Software: Teensy_datalog V.2"; +const int min_voltage_batterie = 13; +const int fixed_resistor_temperatur = 500; + +const int power_Temp_sensor = 34, power_Windfahne = 36, LED_Fail = 24, + LED_Write = 5, LED_Normal = 6, LED_Batterie = 7, + taster_manuell_speichern = 28, Windfahne = 20, T_sensor_input = 17, Batterie_input = 38; + +int last_second, last_minute, last_hour; + + +struct calculations { +private: + + float summ; + float square_summ; + float cubic_summ; + +public: + + void calculate(float speed_per_second[60], int amount_saved) { + summ = 0; + square_summ = 0; + cubic_summ = 0; + + for (int i = 0; i < amount_saved; i++) { + summ = summ + speed_per_second[i]; + square_summ = square_summ + pow(speed_per_second[i], 2); + cubic_summ = cubic_summ + pow(speed_per_second[i], 3); + } + arithmetic_mean = summ / float(amount_saved); + square_mean = pow((square_summ / float(amount_saved)), (1 / 2.0)); + cubic_mean = pow((cubic_mean / float(amount_saved)), (1 / 3.0)); + + summ = 0; + square_summ = 0; + cubic_summ = 0; + + for (int i = 0; i < amount_saved; i++) { + summ = summ + pow((speed_per_second[i] - arithmetic_mean), 2); + square_summ = square_summ + pow((speed_per_second[i] - square_mean), 2); + cubic_summ = cubic_summ + pow((speed_per_second[i] - cubic_mean), 2); + } + arithmetic_deviation = pow((summ / float(amount_saved - 1)), (1 / 2.0)); + square_deviation = pow((square_summ / float(amount_saved - 1)), (1 / 2.0)); + cubic_deviation = pow((cubic_summ / float(amount_saved - 1)), (1 / 2.0)); + } + + float arithmetic_mean; + float arithmetic_deviation; + + float square_mean; + float square_deviation; + + float cubic_mean; + float cubic_deviation; +}; + + +struct anemomenter_maessurement { +public: + int pin = 0; + int seconds_saved = 0; + int minutes_saved = 0; + + void meassure() { + if (reed_contact.update() && reed_contact.fallingEdge()) { + count_per_second++; + } + } + + void save_wind_speed() { + wind_speed_per_second[seconds_saved] = 0.4 * count_per_second; + seconds_saved++; + } + + void calculate() { + values[minutes_saved].calculate(wind_speed_per_second, seconds_saved); + seconds_saved = 0; + minutes_saved++; + } + + +private: + int count_per_second = 0; + int saved_seconds = 0; + int saved_minutes = 0; + float wind_speed_per_second[60]; + + calculations values[60]; + + + Bounce reed_contact = Bounce(pin, 10); + +}anemometer_1, anemometer_2, anemometer_3; + + + +// Define Function Prototypes that use User Types below here or use a .h file +// + + +// Define Functions below here or use other .ino or cpp files +// +void every_second() { + + anemometer_1.save_wind_speed(); + anemometer_2.save_wind_speed(); + anemometer_3.save_wind_speed(); + + last_second = second(); +} + +void every_minute() { + anemometer_1.calculate(); + anemometer_2.calculate(); + anemometer_3.calculate(); + + last_minute = minute(); +} + +void every_hour() { + + last_hour = hour(); +} + +// The setup() function runs once each time the micro-controller starts +void setup() +{ + //set input and output + pinMode(Windfahne, INPUT); + pinMode(Batterie_input, INPUT); + pinMode(T_sensor_input, INPUT); + pinMode(taster_manuell_speichern, INPUT); + pinMode(LED_Write, OUTPUT); + pinMode(LED_Fail, OUTPUT); + pinMode(LED_Normal, OUTPUT); + pinMode(LED_Batterie, OUTPUT); + pinMode(power_Temp_sensor, OUTPUT); + pinMode(power_Windfahne, OUTPUT); + + setSyncProvider((getExternalTime)Teensy3Clock.get()); + + Serial.begin(9600); + Serial.println("Teensy 4.1-Datalogger gestartet"); + if (timeStatus() != timeSet) { + Serial.println("Fehler bei Synchronisieren der Uhrzeit mit der RTC"); + digitalWrite(LED_Fail, HIGH); + return; + } + Serial.println("Uhrzeit erfolgreich mit der RTC synchronisiert"); + if (!sd.begin(SD_CONFIG)) { + digitalWrite(LED_Fail, HIGH); + sd.initErrorHalt(&Serial); + } + + anemometer_1.pin = 2; + anemometer_2.pin = 9; + anemometer_3.pin = 22; + + + 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 +void loop() +{ + anemometer_1.meassure(); + anemometer_2.meassure(); + anemometer_3.meassure(); + + if (second() != last_second) { + if (minute() != last_minute) { + if (hour() != last_hour) { + every_hour(); + } + every_minute(); + } + every_second(); + } + +} diff --git a/Teensy4.1_Datalogger new.sln b/Teensy4.1_Datalogger new.sln new file mode 100644 index 0000000..5db885b --- /dev/null +++ b/Teensy4.1_Datalogger new.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.1.32421.90 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Teensy4.1_Datalogger new", "Teensy4.1_Datalogger new.vcxproj", "{2E6F448E-0966-4C65-8DA5-8AFD46F294D2}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Teensy4.1-Datenlogger-Software", "..\Projekt\Teensy4.1-Datenlogger-Software\Teensy4.1-Datenlogger-Software.vcxproj", "{C5F80730-F44F-4478-BDAE-6634EFC2CA88}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2E6F448E-0966-4C65-8DA5-8AFD46F294D2}.Debug|x86.ActiveCfg = Debug|Win32 + {2E6F448E-0966-4C65-8DA5-8AFD46F294D2}.Debug|x86.Build.0 = Debug|Win32 + {2E6F448E-0966-4C65-8DA5-8AFD46F294D2}.Release|x86.ActiveCfg = Release|Win32 + {2E6F448E-0966-4C65-8DA5-8AFD46F294D2}.Release|x86.Build.0 = Release|Win32 + {C5F80730-F44F-4478-BDAE-6634EFC2CA88}.Debug|x86.ActiveCfg = Debug|Win32 + {C5F80730-F44F-4478-BDAE-6634EFC2CA88}.Debug|x86.Build.0 = Debug|Win32 + {C5F80730-F44F-4478-BDAE-6634EFC2CA88}.Release|x86.ActiveCfg = Release|Win32 + {C5F80730-F44F-4478-BDAE-6634EFC2CA88}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {349760AA-D265-433D-A4B4-7278AE8A0FCC} + EndGlobalSection +EndGlobal diff --git a/Teensy4.1_Datalogger new.vcxproj b/Teensy4.1_Datalogger new.vcxproj new file mode 100644 index 0000000..8535b21 --- /dev/null +++ b/Teensy4.1_Datalogger new.vcxproj @@ -0,0 +1,119 @@ + + + + + Release + Win32 + + + Debug + Win32 + + + + {2E6F448E-0966-4C65-8DA5-8AFD46F294D2} + + + Teensy4.1_Datalogger new + + + + Application + true + MultiByte + v143 + + + Application + false + true + MultiByte + v143 + + + Application + true + MultiByte + + + + + Application + false + true + MultiByte + + + + + + + + + + + + + + + + + + + + + + + + + Level3 + MaxSpeed + true + true + true + $(ProjectDir)__vm\.Teensy4.1_Datalogger new.vsarduino.h;%(ForcedIncludeFiles) + __AVR_atmega32u4__;__AVR_ATmega32U4__;__AVR_ATmega32u4__;F_CPU=16000000L;ARDUINO=108019;ARDUINO_AVR_YUN;ARDUINO_ARCH_AVR;USB_VID=0x2341;USB_PID=0x8041;__cplusplus=201103L;_VMICRO_INTELLISENSE;%(PreprocessorDefinitions) + + + true + true + true + + + + + Level3 + Disabled + true + $(ProjectDir)..\Teensy4.1_Datalogger new;$(ProjectDir)..\libraries\SdFat\src;$(ProjectDir)..\..\arduino-1.8.10\hardware\teensy\avr\libraries\SPI;$(ProjectDir)..\..\arduino-1.8.10\hardware\teensy\avr\libraries\Time;$(ProjectDir)..\..\arduino-1.8.10\hardware\teensy\avr\libraries\Bounce;$(ProjectDir)..\..\arduino-1.8.10\hardware\teensy\avr\cores\teensy4;$(ProjectDir)..\..\arduino-1.8.10\hardware\teensy\avr\cores\teensy4\avr;$(ProjectDir)..\..\arduino-1.8.10\hardware\teensy\avr\cores\teensy4\debug;$(ProjectDir)..\..\arduino-1.8.10\hardware\teensy\avr\cores\teensy4\util;$(ProjectDir)..\..\arduino-1.8.10\hardware\tools\arm\arm-none-eabi\include;$(ProjectDir)..\..\arduino-1.8.10\hardware\tools\arm\lib\gcc\arm-none-eabi\5.4.1\include;$(ProjectDir)..\..\arduino-1.8.10\hardware\tools\arm\arm-none-eabi\include\c++\5.4.1;$(ProjectDir)..\..\arduino-1.8.10\hardware\tools\arm\arm-none-eabi\include\c++\5.4.1\tr1;$(ProjectDir)..\..\arduino-1.8.10\hardware\tools\arm\arm-none-eabi\include\c++\5.4.1\bits;$(ProjectDir)..\..\arduino-1.8.10\hardware\tools\arm\arm-none-eabi\include\c++\5.4.1\arm-none-eabi;$(ProjectDir)..\..\arduino-1.8.10\hardware\teensy;%(AdditionalIncludeDirectories) + $(ProjectDir)__vm\.Teensy4.1_Datalogger new.vsarduino.h;%(ForcedIncludeFiles) + true + __HARDWARE_imxrt1062__;__HARDWARE_IMXRT1062__;_VMDEBUG=1;__IMXRT1062__;TEENSYDUINO=148;ARDUINO=108010;F_CPU=600000000;USB_SERIAL;LAYOUT_US_ENGLISH;__cplusplus=201103L;_VMICRO_INTELLISENSE;%(PreprocessorDefinitions) + + + true + + + + + + + + CppCode + + + + + + + VisualMicroDebugger + + + + + + + + + + \ No newline at end of file diff --git a/Teensy4.1_Datalogger new.vcxproj.filters b/Teensy4.1_Datalogger new.vcxproj.filters new file mode 100644 index 0000000..070d938 --- /dev/null +++ b/Teensy4.1_Datalogger new.vcxproj.filters @@ -0,0 +1,25 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + + + + Header Files + + + \ No newline at end of file diff --git a/__vm/.Teensy4.1_Datalogger new.vsarduino.h b/__vm/.Teensy4.1_Datalogger new.vsarduino.h new file mode 100644 index 0000000..14c3e8b --- /dev/null +++ b/__vm/.Teensy4.1_Datalogger new.vsarduino.h @@ -0,0 +1,99 @@ +/* + Editor: https://www.visualmicro.com/ + This file is for intellisense purpose only. + Visual micro (and the arduino ide) ignore this code during compilation. This code is automatically maintained by visualmicro, manual changes to this file will be overwritten + The contents of the _vm sub folder can be deleted prior to publishing a project + All non-arduino files created by visual micro and all visual studio project or solution files can be freely deleted and are not required to compile a sketch (do not delete your own code!). + Note: debugger breakpoints are stored in '.sln' or '.asln' files, knowledge of last uploaded breakpoints is stored in the upload.vmps.xml file. Both files are required to continue a previous debug session without needing to compile and upload again + + Hardware: Teensy 4.0 (teensy40), Platform=teensy4, Package=teensy +*/ + +#if defined(_VMICRO_INTELLISENSE) + +#ifndef _VSARDUINO_H_ +#define _VSARDUINO_H_ +#define __HARDWARE_imxrt1062__ +#define __HARDWARE_IMXRT1062__ +#define _VMDEBUG 1 +#define __IMXRT1062__ +#define TEENSYDUINO 148 +#define ARDUINO 108010 +#define F_CPU 600000000 +#define USB_SERIAL +#define LAYOUT_US_ENGLISH +#define __cplusplus 201103L +#undef __cplusplus +#define __cplusplus 201103L + + +#define __arm__ +#define __ARM__ +#define __attribute__(x) +typedef void *__builtin_va_list; +#define __extension__ +#define __ATTR_PURE__ +#define __ATTR_CONST__ +#define __inline__ +#define __asm__(x) +#define __volatile__ +#define NEW_H +#undef _WIN32 +#define __STDC__ +//#define __GNUC__ 2 +//#define __GNUC_MINOR__ 5 +#define __ARM_ARCH_7EM__ + +extern int at_quick_exit(void (*f)(void)); +int at_quick_exit(void (*f)(void)) { +} +extern int quick_exit(void (*f)(void)); +int quick_exit(void (*f)(void)) { +} + + + +#define __INT64_TYPE__ 8 +#define __INTPTR_TYPE__ 4 +#define __INT32_TYPE__ 4 + +typedef long intptr_t; +typedef long __intptr_t; +typedef unsigned long __uintptr_t; +typedef long __int32_t; +typedef unsigned long __uint32_t; +typedef unsigned short __uint16_t; +typedef short __int16_t; +typedef unsigned short __uint8_t; +typedef short __int8_t; +typedef unsigned long __uint64_t; +typedef double __int64_t; +typedef unsigned long uint64_t; +typedef double int64_t; +typedef unsigned short uint8_t; +typedef short int8_t; + +typedef unsigned int uint16_t; +typedef short int16_t; +typedef long __int32_t; +typedef unsigned long __uint32_t; + +#define at_quick_exit(x) + +#include "arduino.h" +#define abs(x) ((x)>0?(x):-(x)) +#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) +#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) +#define radians(deg) ((deg)*DEG_TO_RAD) +#define degrees(rad) ((rad)*RAD_TO_DEG) +#define sq(x) ((x)*(x)) + +#define __asm__ + +#define __disable_irq() __asm__ volatile(""); +#define __enable_irq() __asm__ volatile(""); + + +#include "Teensy4.1_Datalogger new.ino" +#endif +#endif diff --git a/__vm/Compile.vmps.xml b/__vm/Compile.vmps.xml new file mode 100644 index 0000000..580cb9b --- /dev/null +++ b/__vm/Compile.vmps.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + 128 last_second = second(); +129 last_minute = minute(); +130 last_hour = hour(); +131 +132 } +133 +134 // Add the main program code into the continuous loop() function +-->135 void loop() +136 { +137 anemometer_1:meassure(); +138 anemometer_2:meassure(); +139 anemometer_3:meassure(); +140 +141 if (second() != last_second) { +142 +143 every_second(); +144 + + + + + + + + \ No newline at end of file diff --git a/__vm/Configuration.Debug.vmps.xml b/__vm/Configuration.Debug.vmps.xml new file mode 100644 index 0000000..197deab --- /dev/null +++ b/__vm/Configuration.Debug.vmps.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file