diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..1428c38 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "random": "cpp" + } +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..b903004 --- /dev/null +++ b/README.md @@ -0,0 +1,51 @@ +# Td-Free + +A free and open source device to measure the td value of your filaments + + + +## Requirements +- Soldering Iron +- Some thin wire to connect everything +- Probably a 24v power supply +- At least black filament + +## Shopping List + + +### 12v-Version +- [COB LED Strip](https://s.click.aliexpress.com/e/_DDqwOPl) (`4000K Natural White`, `12v 528 leds`, any length) (**Choose the 528 LEDs!**) +- [5,5x2,1mm round barrel jack](https://s.click.aliexpress.com/e/_DmneAx5) +- [This VEML7700 board](https://de.aliexpress.com/item/1005004926993351.html) +- [Supermini ESP32-C3](https://s.click.aliexpress.com/e/_DFmIcbN) (make sure to choose the board, not the expansion board!) +- [Mini360 Buck Step-Down](https://de.aliexpress.com/item/1005004872563696.html) (you can also use the one provided in the 24v-version, +as this one only supports up to 23v.) + +### 24v-Version +- [COB LED Strip](https://s.click.aliexpress.com/e/_DDqwOPl) (`4000K Natural White`, `24v 528 leds`, any length) (**Choose the 528 LEDs!**) +- [5,5x2,1mm round barrel jack](https://s.click.aliexpress.com/e/_DmneAx5) +- [This VEML7700 board](https://de.aliexpress.com/item/1005004926993351.html) +- [Supermini ESP32-C3](https://s.click.aliexpress.com/e/_DFmIcbN) (make sure to choose the board, not the expansion board!) +- [Buck Step-Down converter](https://s.click.aliexpress.com/e/_DEgvDJD) + +~ 6€ in parts cost (when only calculating per needed) + + +## Printing Instructions +- The `Layer` parts and the `sensor holder` should be printed with black filament, the rest doesn't matter. +Select a cool color combination! +- Use the "auto orient" feature of your slicer! + + +## Assembly instructions +At first, I'd recommend soldering all the components together. +- Solder the power connector to the step-down converter board (back one most likely positive) +- Solder the LED strip to the connector or the step-down converter input as well, so both get 24/12v. +- Solder plus and minus output of the step-down converter to the ESP32 and to the VEML 7700 board. +- Solder SDA to pin 8 on the ESP32 and SCL to pin 10 on the ESP. +- **Flash the ESP (instructions below)** +- Stuff everything into the case and press the power socket into the case (make sure not to short anything). +- Put the lid on and make sure that the corner with the extrusions is above the power socket to hold it in place. + + + diff --git a/lib/Lux/Lux.cpp b/lib/Lux/Lux.cpp deleted file mode 100644 index 5f71c53..0000000 --- a/lib/Lux/Lux.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include "Lux.h" - - -// Define the function with appropriate parameters -std::pair temperature_and_lux_dn40(float gain, float glass_attenuation, float color_raw[4], uint8_t atime) { - // Initial input values - uint8_t ATIME = atime; - float ATIME_ms = (256 - ATIME) * 2.4; - float AGAINx = gain; - float R = color_raw[0]; - float G = color_raw[1]; - float B = color_raw[2]; - float C = color_raw[3]; - - // Device specific values - float GA = glass_attenuation; - float DF = 310.0; - float R_Coef = 0.136; - float G_Coef = 1.0; - float B_Coef = -0.444; - float CT_Coef = 3810; - float CT_Offset = 1391; - - // Analog/Digital saturation - float SATURATION = (256 - ATIME > 63) ? 65535 : 1024 * (256 - ATIME); - - // Ripple saturation - if (ATIME_ms < 150) { - SATURATION -= SATURATION / 4; - } - - // Check for saturation and mark the sample as invalid if true - if (C >= SATURATION) { - return std::make_pair(NAN, NAN); // Return a pair of NaN - } - - // IR Rejection - float IR = (R + G + B - C) / 2.0 > 0 ? (R + G + B - C) / 2.0 : 0.0; - float R2 = R - IR; - float G2 = G - IR; - float B2 = B - IR; - - // Lux Calculation - float G1 = R_Coef * R2 + G_Coef * G2 + B_Coef * B2; - float CPL = (ATIME_ms * AGAINx) / (GA * DF); - CPL = (CPL == 0) ? 0.001 : CPL; - float lux = G1 / CPL; - - // CT Calculations - R2 = (R2 == 0) ? 0.001 : R2; - float CT = CT_Coef * B2 / R2 + CT_Offset; - - return std::make_pair(lux, CT); -} diff --git a/lib/Lux/Lux.h b/lib/Lux/Lux.h deleted file mode 100644 index 378ebf0..0000000 --- a/lib/Lux/Lux.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef COLOR_SENSOR_H -#define COLOR_SENSOR_H - -#include -#include - -std::pair temperature_and_lux_dn40(float gain, float glass_attenuation, float color_raw[4], uint8_t atime); - -#endif // COLOR_SENSOR_H diff --git a/platformio.ini b/platformio.ini index 283b8c9..19ad16a 100644 --- a/platformio.ini +++ b/platformio.ini @@ -8,28 +8,24 @@ ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html -[env:d1_mini] -platform = espressif32 -board = wemos_d1_mini32 -framework = arduino -lib_deps = - #adafruit/Adafruit BusIO@^1.14.5 - adafruit/Adafruit TCS34725@^1.4.4 - #olikraus/U8g2@^2.35.9 -upload_speed = 460800 -monitor_filters = esp32_exception_decoder -board_build.embed_txtfiles = - src/html/index.html +; [env:d1_mini] +; platform = espressif32 +; board = wemos_d1_mini32 +; framework = arduino +; lib_deps = +; adafruit/Adafruit VEML7700 Library@^2.1.6 +; upload_speed = 460800 +; monitor_filters = esp32_exception_decoder +; board_build.embed_txtfiles = +; src/html/index.html [env:mini_c3] platform = espressif32 board = lolin_c3_mini framework = arduino lib_deps = - #adafruit/Adafruit BusIO@^1.14.5 - adafruit/Adafruit TCS34725@^1.4.4 - #olikraus/U8g2@^2.35.9 + adafruit/Adafruit VEML7700 Library@^2.1.6 upload_speed = 460800 monitor_filters = esp32_exception_decoder board_build.embed_txtfiles = - src/html/index.html \ No newline at end of file + src/html/index.html diff --git a/src/main.cpp b/src/main.cpp index c38f31e..e535c5e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,4 @@ -#include "Adafruit_TCS34725.h" +#include "Adafruit_VEML7700.h" #include "SPI.h" #include #include @@ -6,18 +6,17 @@ #include #include // put function declarations here: -Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_300MS, TCS34725_GAIN_1X); +Adafruit_VEML7700 veml = Adafruit_VEML7700(); extern const uint8_t index_html_start[] asm("_binary_src_html_index_html_start"); extern const uint8_t index_html_end[] asm("_binary_src_html_index_html_end"); DNSServer dnsServer; WebServer server(80); -float max_value; -float max_clear_value; +float baseline_reading; IPAddress apIP(192, 168, 0, 1); IPAddress netMsk(255, 255, 255, 0); -float final_td_clear; +float final_td; void replaceTemplateWithData(uint8_t *html, size_t htmlSize, const char *templateTag, float replacement) { @@ -68,7 +67,7 @@ void handleRoot() uint8_t *html = new uint8_t[htmlSize + 1]; // +1 for null terminator memcpy(html, index_html_start, htmlSize + 1); const char *templateTag = "{{value}}"; - float data = final_td_clear; + float data = final_td; replaceTemplateWithData(html, htmlSize, templateTag, data); server.send(200, "text/html", reinterpret_cast(html)); delete[] html; @@ -87,7 +86,7 @@ void setup(void) WiFi.mode(WIFI_AP); WiFi.softAPConfig(apIP, apIP, netMsk); - WiFi.softAP("Td-Test"); + WiFi.softAP("Td-Free"); dnsServer.start(53, "*", apIP); // serve a simple root page @@ -98,43 +97,35 @@ void setup(void) server.onNotFound(handleNotFound); server.begin(); - float max_reading[4]; - float max_clear[4]; - size_t size = 16; - for (int i = 0; i < 4; i++) - { - uint16_t high_r, high_g, high_b, high_c; - tcs.getRawData(&high_r, &high_g, &high_b, &high_c); - max_reading[i] = (high_r + high_g + high_b + high_c); - max_clear[i] = high_c; - delay(500); + + if (!veml.begin()) { + Serial.println("Sensor not found"); + while (1); } - float sum = 0; - float sum_c = 0; - for (int i = 0; i < 4; ++i) - { - sum += max_reading[i]; - sum_c += max_clear[i]; + + float max_reading = 0; + int sample_count = 10; + for (int i = 0; i < sample_count; i++) { + max_reading += veml.readLux(); + delay(200); } - max_value = sum / 4; - max_clear_value = sum_c / 4; + baseline_reading = max_reading / sample_count; // Now we're ready to get readings! } void loop(void) { Serial.println("LOOP"); - uint16_t r, g, b, c, colorTemp; - float red, green, blue; - tcs.getRawData(&r, &g, &b, &c); - tcs.getRGB(&red, &green, &blue); - float transmission = (r + g + b + c); // Adjust the combination method as needed - float td_percent = (transmission / max_value) * 100; - float final_td = 0.812 * td_percent - 0.834; - float clear_percent = c / max_clear_value; + float current_lux = veml.readLux(); + + // Calculate the transmission percentage + if (baseline_reading != 0) { + final_td = (current_lux / baseline_reading) * 100.0; + } else { + final_td = 0; // Avoid division by zero + } - final_td_clear = 120.45848313466772 * clear_percent + 1.2720622896060854; dnsServer.processNextRequest(); server.handleClient(); delay(100);