Skip to content

Commit

Permalink
✨ Working version
Browse files Browse the repository at this point in the history
  • Loading branch information
mawoka-myblock committed Jun 21, 2024
1 parent 98ee6a6 commit 98bebdc
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 113 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.associations": {
"random": "cpp"
}
}
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.



54 changes: 0 additions & 54 deletions lib/Lux/Lux.cpp

This file was deleted.

9 changes: 0 additions & 9 deletions lib/Lux/Lux.h

This file was deleted.

28 changes: 12 additions & 16 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
src/html/index.html
59 changes: 25 additions & 34 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
#include "Adafruit_TCS34725.h"
#include "Adafruit_VEML7700.h"
#include "SPI.h"
#include <Wire.h>
#include <Arduino.h>
#include <WiFi.h>
#include <DNSServer.h>
#include <WebServer.h>
// 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)
{
Expand Down Expand Up @@ -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<const char *>(html));
delete[] html;
Expand All @@ -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
Expand All @@ -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);
Expand Down

0 comments on commit 98bebdc

Please sign in to comment.