Commit 83d11c99 authored by Jochen Rößner's avatar Jochen Rößner
Browse files

Initial commit

parents
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
]
}
echo -n "-D BUILDTIME='\"$(date +%F-%H:%M:%S)\"'"
\ No newline at end of file
; 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:esp12e]
platform = espressif8266
board = d1_mini
framework = arduino
; build_flags = -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG
build_flags =
-DCORE_DEBUG_LEVEL=4
!sh build_timestamp.sh
; build_flags = -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG
; Custom Serial Monitor port
monitor_port = /dev/ttyUSB0
; Custom Serial Monitor speed (baud rate)
monitor_speed = 74880
upload_port = /dev/ttyUSB0
src_filter = +<*> -<*.ino*>
lib_deps =
# Main
winlinvip/SimpleDHT
olkal/HX711_ADC
AsyncMqttClient
ArduinoJson
ESPAsyncTCP
ESP Async WebServer
ESPAsync_WifiManager
# App
#include <Arduino.h>
#include <EEPROM.h>
#include "Updater.h"
#include <ArduinoJson.h>
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <string>
#include <SimpleDHT.h>
#include <HX711_ADC.h>
// for DHT11,
// VCC: 5V or 3V
// GND: GND
// DATA: 2
int pinDHT11 = D4;
SimpleDHT11 dht11(pinDHT11);
const int HX711_dout = D7; //mcu > HX711 dout pin
const int HX711_sck = D8; //mcu > HX711 sck pin
//HX711 constructor:
HX711_ADC LoadCell(HX711_dout, HX711_sck);
const int calVal_calVal_eepromAdress = 0;
unsigned long t = 0;
void setup() {
Serial.begin(74880);
Serial.setDebugOutput(true);
float calibrationValue; // calibration value
calibrationValue = 696.0; // uncomment this if you want to set this value in the sketch
#if defined(ESP8266) || defined(ESP32)
//EEPROM.begin(512); // uncomment this if you use ESP8266 and want to fetch this value from eeprom
#endif
//EEPROM.get(calVal_eepromAdress, calibrationValue); // uncomment this if you want to fetch this value from eeprom
LoadCell.begin();
unsigned long stabilizingtime = 2000; // tare preciscion can be improved by adding a few seconds of stabilizing time
boolean _tare = true; //set this to false if you don't want tare to be performed in the next step
LoadCell.start(stabilizingtime, _tare);
if (LoadCell.getTareTimeoutFlag()) {
Serial.println("Timeout, check MCU>HX711 wiring and pin designations");
}
else {
LoadCell.setCalFactor(calibrationValue); // set calibration factor (float)
Serial.println("Startup is complete");
}
while (!LoadCell.update());
Serial.print("Calibration value: ");
Serial.println(LoadCell.getCalFactor());
Serial.print("HX711 measured conversion time ms: ");
Serial.println(LoadCell.getConversionTime());
Serial.print("HX711 measured sampling rate HZ: ");
Serial.println(LoadCell.getSPS());
Serial.print("HX711 measured settlingtime ms: ");
Serial.println(LoadCell.getSettlingTime());
Serial.println("Note that the settling time may increase significantly if you use delay() in your sketch!");
if (LoadCell.getSPS() < 7) {
Serial.println("!!Sampling rate is lower than specification, check MCU>HX711 wiring and pin designations");
}
else if (LoadCell.getSPS() > 100) {
Serial.println("!!Sampling rate is higher than specification, check MCU>HX711 wiring and pin designations");
}
}
void loop() {
// start working...
Serial.println("=================================");
Serial.println("Sample DHT11...");
// read without samples.
byte temperature = 0;
byte humidity = 0;
int err = SimpleDHTErrSuccess;
if ((err = dht11.read(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
Serial.print("Read DHT11 failed, err="); Serial.print(SimpleDHTErrCode(err));
Serial.print(","); Serial.println(SimpleDHTErrDuration(err)); delay(1000);
return;
}
Serial.print("Sample OK: ");
Serial.print((int)temperature); Serial.print(" *C, ");
Serial.print((int)humidity); Serial.println(" H");
// DHT11 sampling rate is 1HZ.
delay(1500);
static boolean newDataReady = 0;
const int serialPrintInterval = 500; //increase value to slow down serial print activity
// check for new data/start next conversion:
if (LoadCell.update()) newDataReady = true;
// get smoothed value from the dataset:
if (newDataReady) {
if (millis() > t + serialPrintInterval) {
float i = LoadCell.getData();
Serial.print("Load_cell output val: ");
Serial.println(i);
newDataReady = 0;
t = millis();
}
}
// receive command from serial terminal, send 't' to initiate tare operation:
if (Serial.available() > 0) {
char inByte = Serial.read();
if (inByte == 't') LoadCell.tareNoDelay();
}
// check if last tare operation is complete:
if (LoadCell.getTareStatus() == true) {
Serial.println("Tare complete");
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment