diff options
Diffstat (limited to 'linz/oekofen_thermo')
| -rw-r--r-- | linz/oekofen_thermo/.gitignore | 5 | ||||
| -rw-r--r-- | linz/oekofen_thermo/platformio.ini | 16 | ||||
| -rw-r--r-- | linz/oekofen_thermo/src/MCP42010.cpp | 21 | ||||
| -rw-r--r-- | linz/oekofen_thermo/src/MCP42010.h | 25 | ||||
| -rw-r--r-- | linz/oekofen_thermo/src/main.cpp | 46 |
5 files changed, 113 insertions, 0 deletions
diff --git a/linz/oekofen_thermo/.gitignore b/linz/oekofen_thermo/.gitignore new file mode 100644 index 0000000..89cc49c --- /dev/null +++ b/linz/oekofen_thermo/.gitignore | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | .pio | ||
| 2 | .vscode/.browse.c_cpp.db* | ||
| 3 | .vscode/c_cpp_properties.json | ||
| 4 | .vscode/launch.json | ||
| 5 | .vscode/ipch | ||
diff --git a/linz/oekofen_thermo/platformio.ini b/linz/oekofen_thermo/platformio.ini new file mode 100644 index 0000000..2c7b00e --- /dev/null +++ b/linz/oekofen_thermo/platformio.ini | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | ; PlatformIO Project Configuration File | ||
| 2 | ; | ||
| 3 | ; Build options: build flags, source filter | ||
| 4 | ; Upload options: custom upload port, speed and extra flags | ||
| 5 | ; Library options: dependencies, extra library storages | ||
| 6 | ; Advanced options: extra scripting | ||
| 7 | ; | ||
| 8 | ; Please visit documentation for the other options and examples | ||
| 9 | ; https://docs.platformio.org/page/projectconf.html | ||
| 10 | |||
| 11 | [env:d1_mini] | ||
| 12 | platform = espressif8266 | ||
| 13 | board = d1_mini | ||
| 14 | framework = arduino | ||
| 15 | monitor_speed = 115200 | ||
| 16 | upload_speed = 115200 | ||
diff --git a/linz/oekofen_thermo/src/MCP42010.cpp b/linz/oekofen_thermo/src/MCP42010.cpp new file mode 100644 index 0000000..aa6de2b --- /dev/null +++ b/linz/oekofen_thermo/src/MCP42010.cpp | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | #include "MCP42010.h" | ||
| 2 | |||
| 3 | MCP42010::MCP42010(uint8_t ss_pin) | ||
| 4 | : _ss_pin(ss_pin), _spiset(10000000, MSBFIRST, SPI_MODE0) | ||
| 5 | {} | ||
| 6 | |||
| 7 | void MCP42010::setup() | ||
| 8 | { | ||
| 9 | pinMode(_ss_pin, OUTPUT); | ||
| 10 | SPI.begin(); | ||
| 11 | } | ||
| 12 | |||
| 13 | void MCP42010::setPot(MCP42010::Poti pot, uint8_t value) | ||
| 14 | { | ||
| 15 | SPI.beginTransaction(_spiset); | ||
| 16 | digitalWrite(_ss_pin, LOW); | ||
| 17 | SPI.transfer(0b00010000 | pot); | ||
| 18 | SPI.transfer(value); | ||
| 19 | digitalWrite(_ss_pin, HIGH); | ||
| 20 | SPI.endTransaction(); | ||
| 21 | } | ||
diff --git a/linz/oekofen_thermo/src/MCP42010.h b/linz/oekofen_thermo/src/MCP42010.h new file mode 100644 index 0000000..9d06e7d --- /dev/null +++ b/linz/oekofen_thermo/src/MCP42010.h | |||
| @@ -0,0 +1,25 @@ | |||
| 1 | #ifndef MCP42010_h | ||
| 2 | #define MCP42010_h | ||
| 3 | |||
| 4 | #include <Arduino.h> | ||
| 5 | #include <SPI.h> | ||
| 6 | |||
| 7 | class MCP42010 | ||
| 8 | { | ||
| 9 | public: | ||
| 10 | enum Poti | ||
| 11 | { | ||
| 12 | P0 = 0b01, | ||
| 13 | P1 = 0b10, | ||
| 14 | }; | ||
| 15 | |||
| 16 | MCP42010(uint8_t ss_pin); | ||
| 17 | void setup(); | ||
| 18 | void setPot(Poti pot, uint8_t value); | ||
| 19 | |||
| 20 | private: | ||
| 21 | uint8_t _ss_pin; | ||
| 22 | SPISettings _spiset; | ||
| 23 | }; | ||
| 24 | |||
| 25 | #endif \ No newline at end of file | ||
diff --git a/linz/oekofen_thermo/src/main.cpp b/linz/oekofen_thermo/src/main.cpp new file mode 100644 index 0000000..5713a0b --- /dev/null +++ b/linz/oekofen_thermo/src/main.cpp | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | #include <Arduino.h> | ||
| 2 | #include <WiFiManager.h> | ||
| 3 | #include <ESP8266WebServer.h> | ||
| 4 | |||
| 5 | #include "MCP42010.h" | ||
| 6 | |||
| 7 | ESP8266WebServer http_service(80); | ||
| 8 | MCP42010 msp42010(D8); | ||
| 9 | |||
| 10 | void setup() { | ||
| 11 | Serial.begin(115200); | ||
| 12 | msp42010.setup(); | ||
| 13 | |||
| 14 | WiFiManager wifiManager; | ||
| 15 | wifiManager.setConfigPortalTimeout(600); | ||
| 16 | Serial.printf_P(PSTR("Setting up WiFi\n")); | ||
| 17 | WiFi.hostname("oekofen"); | ||
| 18 | if (!wifiManager.autoConnect("oekofen-thermo")) | ||
| 19 | { | ||
| 20 | Serial.printf_P(PSTR("Failed to connect and hit timeout\n")); | ||
| 21 | delay(5000); | ||
| 22 | ESP.restart(); | ||
| 23 | } | ||
| 24 | |||
| 25 | http_service.on("/", HTTP_GET, []() { | ||
| 26 | uint8_t val = random(0, 255); | ||
| 27 | //msp42010.setPot(MCP42010::P0, val); | ||
| 28 | msp42010.setPot(MCP42010::P1, val); | ||
| 29 | http_service.send(200, PSTR("text/plain"), String(val)); | ||
| 30 | }); | ||
| 31 | http_service.begin(); | ||
| 32 | |||
| 33 | Serial.println("Setup done"); | ||
| 34 | } | ||
| 35 | |||
| 36 | void loop() { | ||
| 37 | //http_service.handleClient(); | ||
| 38 | if (Serial.available() > 0) | ||
| 39 | { | ||
| 40 | while (Serial.read() >= 0) {} | ||
| 41 | uint8_t val = random(0, 255); | ||
| 42 | //msp42010.setPot(MCP42010::P0, val); | ||
| 43 | msp42010.setPot(MCP42010::P1, val); | ||
| 44 | Serial.println(val, DEC); | ||
| 45 | } | ||
| 46 | } | ||
