diff --git a/include/README b/include/README new file mode 100644 index 0000000..194dcd4 --- /dev/null +++ b/include/README @@ -0,0 +1,39 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the usual convention is to give header files names that end with `.h'. +It is most portable to use only letters, digits, dashes, and underscores in +header file names, and at most one dot. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/lib/README b/lib/README new file mode 100644 index 0000000..6debab1 --- /dev/null +++ b/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into executable file. + +The source code of each library should be placed in a an own separate directory +("lib/your_library_name/[here are source files]"). + +For example, see a structure of the following two libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +and a contents of `src/main.c`: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +PlatformIO Library Dependency Finder will find automatically dependent +libraries scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..cabf4f6 --- /dev/null +++ b/platformio.ini @@ -0,0 +1,58 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env:ATmega88P] +platform = atmelavr +board = ATmega88P +framework = arduino +board_build.f_cpu = 1000000L +lib_deps = fastled/FastLED@^3.6.0 + +[env:program_via_DiamexISP] +board = ATmega88P +framework = arduino +platform = atmelavr +upload_protocol = avrispv2 +upload_port = COM10 +upload_speed = 19200 +upload_flags = + -c avrispv2 + -p + $BOARD_MCU + -P + $UPLOAD_PORT + -b + $UPLOAD_SPEED + -c avrispv2 +upload_command = avrdude -p atmega88p -P COM10 -b 19200 -c stk500v2 -U flash:w:.pio\build\program_via_DiamexISP\firmware.hex:i +lib_deps = fastled/FastLED@^3.6.0 + +[env:attiny261] +board = ATmega88P +framework = arduino +platform = atmelavr +upload_protocol = arduino +upload_speed = 115200 +board_build.f_cpu = 8000000L +upload_port = COM10 +board_fuses.lfuse = 0xE2 +board_fuses.hfuse = 0xD9 +board_fuses.efuse = 0xFF +upload_flags = + -C + $PROJECT_PACKAGES_DIR/tool-avrdude/avrdude.conf + -p + $BOARD_MCU + -P + $UPLOAD_PORT + -c + stk500v2 +upload_command = avrdude -B 115200 $UPLOAD_FLAGS -U flash:w:$SOURCE:i +lib_deps = fastled/FastLED@^3.6.0 diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..96190cf --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,143 @@ +#include +#include + +#define HEATER PD3 +#define TEMP A0 +#define TARGETTEMP PC1 +#define LED_PIN PD5 +#define LED_TYPE WS2812B +#define BRIGHTNESS 30 +#define COLOR_ORDER RGB +#define NUM_LEDS 1 +#define DUMMYPIN PD2 + + +CRGB leds[NUM_LEDS]; +int curState = 0; +int stepSize = 30; +uint16_t temp = 20; +uint16_t targetTemp; + +uint8_t ctrPeriod = 0; + +// power cycles / 1s +uint8_t ctrStopPower = 0; + +bool wsp80 = false; + +unsigned int getTargetTemp(); +unsigned int getTemp(); + +void setup() { + + // Serial.begin(1200); + + pinMode(HEATER, OUTPUT); + pinMode(PD5, OUTPUT); + pinMode(DUMMYPIN, INPUT); + + delay(1000); + LEDS.addLeds(leds, NUM_LEDS); + FastLED.setBrightness(BRIGHTNESS); + FastLED.clear(); + FastLED.show(); + + if(getTemp() > 500){ + leds[0] = CRGB(0, 255, 0); + FastLED.show(); + } + else{ + wsp80 = true; + } + +} + +unsigned int getTargetTemp(){ + float m = 0.354; + float b = 115.289; + return int(analogRead(TARGETTEMP)*m+b); +} + +unsigned int getTemp(){ + float ua = 5*(float)analogRead(TEMP)/1024; + float t = (1020*ua-1100)*20000 / (77*(1100-20*ua)); + return (unsigned int)t; +} + + + + +void loop() { + + // ################### wsp80 mode ##################### + // logic part repeats with 1 second + if(millis() % 1000 == 0 && wsp80){ + ctrPeriod = 0; + // check temp of heater + temp = getTemp(); + targetTemp = getTargetTemp(); + + Serial.print("Temp: "); + Serial.print(temp); + Serial.print(";Zieltemperatur: "); + Serial.print(targetTemp); + + + if(targetTemp > temp + 50){ + // full power + ctrStopPower = 50; + } + else if (targetTemp > temp + 20){ + // 1 / 3 of power + ctrStopPower = 16; + } + else if (targetTemp > temp + 5){ + // 1 / 10 of power + ctrStopPower = 5; + } + else if (targetTemp < temp){ + // heater off!!! + ctrStopPower = 0; + } + + + + stepSize = int(float(temp) / float(targetTemp) * 255.0); + if (stepSize > 255){ + stepSize = 255; + } + + leds[0] = CRGB(0+stepSize, 0, 255-stepSize); + FastLED.show(); + + curState += stepSize; + } + + if(millis() % 20 == 0 && wsp80){ + if(ctrPeriod < ctrStopPower){ + // turn heater on + digitalWrite(HEATER, true); + } + else{ + // turn heater off + digitalWrite(HEATER, false); + } + } + + // ############### ws80 ################# + if(millis() % 1000 == 0 && !wsp80){ + ctrPeriod = 0; + targetTemp = getTargetTemp(); + float m = 0.833; + float b = 12.5; + ctrStopPower = uint8_t(m * targetTemp + b); + } + if (millis() % 20 == 0 && !wsp80){ + if(ctrPeriod < ctrStopPower){ + digitalWrite(HEATER, true); + } + else{ + digitalWrite(HEATER, false); + } + } +} diff --git a/test/README b/test/README new file mode 100644 index 0000000..9b1e87b --- /dev/null +++ b/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PlatformIO Test Runner and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PlatformIO Unit Testing: +- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html