From 0b8366c59fa0b34a70b6b453bfb0f8eaf34a2f16 Mon Sep 17 00:00:00 2001 From: manuel Date: Wed, 21 Oct 2020 15:55:29 +0200 Subject: Add Linz --- linz/oekofen_thermo/.gitignore | 5 ++++ linz/oekofen_thermo/platformio.ini | 16 +++++++++++++ linz/oekofen_thermo/src/MCP42010.cpp | 21 ++++++++++++++++ linz/oekofen_thermo/src/MCP42010.h | 25 ++++++++++++++++++++ linz/oekofen_thermo/src/main.cpp | 46 ++++++++++++++++++++++++++++++++++++ 5 files changed, 113 insertions(+) create mode 100644 linz/oekofen_thermo/.gitignore create mode 100644 linz/oekofen_thermo/platformio.ini create mode 100644 linz/oekofen_thermo/src/MCP42010.cpp create mode 100644 linz/oekofen_thermo/src/MCP42010.h create mode 100644 linz/oekofen_thermo/src/main.cpp (limited to 'linz') 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 @@ +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.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 @@ +; 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:d1_mini] +platform = espressif8266 +board = d1_mini +framework = arduino +monitor_speed = 115200 +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 @@ +#include "MCP42010.h" + +MCP42010::MCP42010(uint8_t ss_pin) + : _ss_pin(ss_pin), _spiset(10000000, MSBFIRST, SPI_MODE0) +{} + +void MCP42010::setup() +{ + pinMode(_ss_pin, OUTPUT); + SPI.begin(); +} + +void MCP42010::setPot(MCP42010::Poti pot, uint8_t value) +{ + SPI.beginTransaction(_spiset); + digitalWrite(_ss_pin, LOW); + SPI.transfer(0b00010000 | pot); + SPI.transfer(value); + digitalWrite(_ss_pin, HIGH); + SPI.endTransaction(); +} 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 @@ +#ifndef MCP42010_h +#define MCP42010_h + +#include +#include + +class MCP42010 +{ + public: + enum Poti + { + P0 = 0b01, + P1 = 0b10, + }; + + MCP42010(uint8_t ss_pin); + void setup(); + void setPot(Poti pot, uint8_t value); + + private: + uint8_t _ss_pin; + SPISettings _spiset; +}; + +#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 @@ +#include +#include +#include + +#include "MCP42010.h" + +ESP8266WebServer http_service(80); +MCP42010 msp42010(D8); + +void setup() { + Serial.begin(115200); + msp42010.setup(); + + WiFiManager wifiManager; + wifiManager.setConfigPortalTimeout(600); + Serial.printf_P(PSTR("Setting up WiFi\n")); + WiFi.hostname("oekofen"); + if (!wifiManager.autoConnect("oekofen-thermo")) + { + Serial.printf_P(PSTR("Failed to connect and hit timeout\n")); + delay(5000); + ESP.restart(); + } + + http_service.on("/", HTTP_GET, []() { + uint8_t val = random(0, 255); + //msp42010.setPot(MCP42010::P0, val); + msp42010.setPot(MCP42010::P1, val); + http_service.send(200, PSTR("text/plain"), String(val)); + }); + http_service.begin(); + + Serial.println("Setup done"); +} + +void loop() { + //http_service.handleClient(); + if (Serial.available() > 0) + { + while (Serial.read() >= 0) {} + uint8_t val = random(0, 255); + //msp42010.setPot(MCP42010::P0, val); + msp42010.setPot(MCP42010::P1, val); + Serial.println(val, DEC); + } +} -- cgit v1.2.3