restructured
This commit is contained in:
		
							
								
								
									
										13
									
								
								CG_scale.ino
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								CG_scale.ino
									
									
									
									
									
								
							@@ -71,6 +71,12 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
*/
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// **** Please UNCOMMENT to choose special hardware *****************
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//#define WIFI_KIT_8    //is a ESP8266 based board, with integrated OLED and battery management
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// ******************************************************************
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Required libraries, can be installed from the library manager
 | 
					// Required libraries, can be installed from the library manager
 | 
				
			||||||
#include <HX711_ADC.h>      // library for the HX711 24-bit ADC for weight scales (https://github.com/olkal/HX711_ADC)
 | 
					#include <HX711_ADC.h>      // library for the HX711 24-bit ADC for weight scales (https://github.com/olkal/HX711_ADC)
 | 
				
			||||||
#include <U8g2lib.h>        // Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
 | 
					#include <U8g2lib.h>        // Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
 | 
				
			||||||
@@ -97,7 +103,11 @@
 | 
				
			|||||||
#if defined(__AVR__)
 | 
					#if defined(__AVR__)
 | 
				
			||||||
#include "settings_AVR.h"
 | 
					#include "settings_AVR.h"
 | 
				
			||||||
#elif defined(ESP8266)
 | 
					#elif defined(ESP8266)
 | 
				
			||||||
#include "settings_ESP8266.h"
 | 
					  #ifdef WIFI_KIT_8
 | 
				
			||||||
 | 
					    #include "settings_WIFI_KIT_8.h"
 | 
				
			||||||
 | 
					  #else
 | 
				
			||||||
 | 
					    #include "settings_ESP8266.h"
 | 
				
			||||||
 | 
					  #endif
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// HX711 constructor array (dout pin, sck pint):
 | 
					// HX711 constructor array (dout pin, sck pint):
 | 
				
			||||||
@@ -359,7 +369,6 @@ void handleTareBtn() {
 | 
				
			|||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
      tareBtnCnt++;
 | 
					      tareBtnCnt++;
 | 
				
			||||||
      if (tareBtnCnt > 10) {
 | 
					      if (tareBtnCnt > 10) {
 | 
				
			||||||
        Serial.println("tare button pressed");
 | 
					 | 
				
			||||||
        printOLED("TARE ==>", "  tare load cells ...");
 | 
					        printOLED("TARE ==>", "  tare load cells ...");
 | 
				
			||||||
        // avoid keybounce
 | 
					        // avoid keybounce
 | 
				
			||||||
        tareBtnCnt = -1000;
 | 
					        tareBtnCnt = -1000;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -124,3 +124,8 @@ U8G2_SH1106_128X64_NONAME_1_HW_I2C oledDisplay(U8G2_R0, /* reset=*/ U8X8_PIN_NON
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// Battery cells
 | 
					// Battery cells
 | 
				
			||||||
#define BAT_CELLS                     2
 | 
					#define BAT_CELLS                     2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// **** end of settings ****
 | 
				
			||||||
 | 
					#warning AVR settings have been loaded
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -45,35 +45,15 @@ CG scale with 3 Loadcells:
 | 
				
			|||||||
*/
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define PIN_LOADCELL1_DOUT            D6
 | 
				
			||||||
 | 
					#define PIN_LOADCELL1_PD_SCK          D5
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Wifi Kit 8 (https://heltec.org/project/wifi-kit-8/) 
 | 
					#define PIN_LOADCELL2_DOUT            D2
 | 
				
			||||||
// is a ESP8266 based board, with integrated OLED and battery management
 | 
					#define PIN_LOADCELL2_PD_SCK          D1
 | 
				
			||||||
#define WIFI_KIT_8 1
 | 
					 | 
				
			||||||
#ifdef WIFI_KIT_8
 | 
					 | 
				
			||||||
  #define PIN_LOADCELL1_DOUT            D6
 | 
					 | 
				
			||||||
  #define PIN_LOADCELL1_PD_SCK          D7
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  #define PIN_LOADCELL2_DOUT            D3
 | 
					#define PIN_LOADCELL3_DOUT            D7
 | 
				
			||||||
 | 
					#define PIN_LOADCELL3_PD_SCK          D0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  #define PIN_LOADCELL2_PD_SCK          D8
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
  #define PIN_LOADCELL3_DOUT            D0
 | 
					 | 
				
			||||||
  #define PIN_LOADCELL3_PD_SCK          D0
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // D3 can be used in parallel to the load cell with Wifi Kit 8
 | 
					 | 
				
			||||||
  #define PIN_TARE_BUTTON               D3
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  #define MAX_SSID_PW_LENGHT            64
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
  #define PIN_LOADCELL1_DOUT            D6
 | 
					 | 
				
			||||||
  #define PIN_LOADCELL1_PD_SCK          D5
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  #define PIN_LOADCELL2_DOUT            D2
 | 
					 | 
				
			||||||
  #define PIN_LOADCELL2_PD_SCK          D1
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  #define PIN_LOADCELL3_DOUT            D7
 | 
					 | 
				
			||||||
  #define PIN_LOADCELL3_PD_SCK          D0
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// **** Measurement settings ****
 | 
					// **** Measurement settings ****
 | 
				
			||||||
@@ -101,13 +81,8 @@ CG scale with 3 Loadcells:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// Please UNCOMMENT the display used
 | 
					// Please UNCOMMENT the display used
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef WIFI_KIT_8
 | 
					U8G2_SH1106_128X64_NONAME_1_HW_I2C oledDisplay(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ D3, /* data=*/ D4);
 | 
				
			||||||
  // Wifi Kit 8 has a fixed wired 128x32 display
 | 
					//U8G2_SSD1306_128X64_NONAME_1_HW_I2C oledDisplay(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ D3, /* data=*/ D4);
 | 
				
			||||||
  U8G2_SSD1306_128X32_UNIVISION_1_HW_I2C oledDisplay(U8G2_R0, /* reset=*/ 16, /* clock=*/ 5, /* data=*/ 4);
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
  U8G2_SH1106_128X64_NONAME_1_HW_I2C oledDisplay(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ D3, /* data=*/ D4);
 | 
					 | 
				
			||||||
  //U8G2_SSD1306_128X64_NONAME_1_HW_I2C oledDisplay(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ D3, /* data=*/ D4);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// **** Voltage measurement settings ****
 | 
					// **** Voltage measurement settings ****
 | 
				
			||||||
@@ -153,9 +128,7 @@ CG scale with 3 Loadcells:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// **** Wifi settings ****
 | 
					// **** Wifi settings ****
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifndef MAX_SSID_PW_LENGHT
 | 
					 | 
				
			||||||
#define MAX_SSID_PW_LENGHT          32
 | 
					#define MAX_SSID_PW_LENGHT          32
 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Station mode: connect to available network
 | 
					// Station mode: connect to available network
 | 
				
			||||||
#define SSID_STA                    "myWiFi"
 | 
					#define SSID_STA                    "myWiFi"
 | 
				
			||||||
@@ -187,3 +160,8 @@ const char ip[4] =                  {1,2,3,4};    // default IP address
 | 
				
			|||||||
#define DEFAULT_NAME                "Model"          // default model name
 | 
					#define DEFAULT_NAME                "Model"          // default model name
 | 
				
			||||||
#define MODEL_FILE                  "/models.json"   // file to store models
 | 
					#define MODEL_FILE                  "/models.json"   // file to store models
 | 
				
			||||||
#define JSONDOC_SIZE                20000            // max file size in bytes
 | 
					#define JSONDOC_SIZE                20000            // max file size in bytes
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// **** end of settings ****
 | 
				
			||||||
 | 
					#warning ESP8266 settings have been loaded
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										173
									
								
								settings_WIFI_KIT_8.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										173
									
								
								settings_WIFI_KIT_8.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,173 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					  -----------------------------------------------------------
 | 
				
			||||||
 | 
					            Settings for WIFI KIT 8 (ESP8266) board
 | 
				
			||||||
 | 
					  -----------------------------------------------------------
 | 
				
			||||||
 | 
					  General settings for the CG scale.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Wifi Kit 8 (https://heltec.org/project/wifi-kit-8/) 
 | 
				
			||||||
 | 
					  is a ESP8266 based board, with integrated OLED and battery management
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// **** Loadcell hardware settings ****
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define NUMBER_LOADCELLS                3       // if set to 2, the parameters of loadcell 3 are ignored
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define DISTANCE_X1                     30      // mm
 | 
				
			||||||
 | 
					#define DISTANCE_X2                     350     // mm
 | 
				
			||||||
 | 
					#define DISTANCE_X3                     220     // mm
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define LOADCELL1_CALIBRATION_FACTOR    900     // user set calibration factor
 | 
				
			||||||
 | 
					#define LOADCELL2_CALIBRATION_FACTOR    900     // user set calibration factor
 | 
				
			||||||
 | 
					#define LOADCELL3_CALIBRATION_FACTOR    900     // user set calibration factor
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					CG scale with 2 Loadcells:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<-         ||=== Loadcell 1 ========== Loadcell 2
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					            |        |                     |
 | 
				
			||||||
 | 
					            |---X1---|---------X2----------|
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CG scale with 3 Loadcells:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					       --   ||   Loadcell 1
 | 
				
			||||||
 | 
					       |    ||      ||
 | 
				
			||||||
 | 
					       |    ||      ||
 | 
				
			||||||
 | 
					       |    ||      ||
 | 
				
			||||||
 | 
					<-    X3    ||      ||================ Loadcell 2
 | 
				
			||||||
 | 
					       |    ||      ||
 | 
				
			||||||
 | 
					       |    ||      ||
 | 
				
			||||||
 | 
					       |    ||      ||
 | 
				
			||||||
 | 
					       --   ||   Loadcell 3 
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					            |        |                     |
 | 
				
			||||||
 | 
					            |---X1---|---------X2----------|
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define PIN_LOADCELL1_DOUT            D6
 | 
				
			||||||
 | 
					#define PIN_LOADCELL1_PD_SCK          D7
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define PIN_LOADCELL2_DOUT            D3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define PIN_LOADCELL2_PD_SCK          D8
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					#define PIN_LOADCELL3_DOUT            D0
 | 
				
			||||||
 | 
					#define PIN_LOADCELL3_PD_SCK          D0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// D3 can be used in parallel to the load cell with Wifi Kit 8
 | 
				
			||||||
 | 
					#define PIN_TARE_BUTTON               D3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// **** Measurement settings ****
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define STABILISINGTIME               3000     // ms
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define UPDATE_INTERVAL_OLED_MENU     500      // ms
 | 
				
			||||||
 | 
					#define UPDATE_INTERVAL_LOADCELL      100      // ms
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define SMOOTHING_LOADCELL            0.4     // IIR filter: smoothing value from 0.00-1.00
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define MINIMAL_CG_WEIGHT             10      // g     if lower, no CG is displayed (0mm)
 | 
				
			||||||
 | 
					#define MINIMAL_TOTAL_WEIGHT          1       // g     if lower, weight = 0 is displayed
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// **** Calibration settings ****
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define REF_WEIGHT                    1500     // g
 | 
				
			||||||
 | 
					#define REF_CG                        100      // mm
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// **** Display settings ****
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Wifi Kit 8 has a fixed wired 128x32 display
 | 
				
			||||||
 | 
					U8G2_SSD1306_128X32_UNIVISION_1_HW_I2C oledDisplay(U8G2_R0, /* reset=*/ 16, /* clock=*/ 5, /* data=*/ 4);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// **** Voltage measurement settings ****
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// analog input pin
 | 
				
			||||||
 | 
					#define VOLTAGE_PIN                   A0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// supply voltage
 | 
				
			||||||
 | 
					#define V_REF                         3300     // set supply voltage from 1800 to 5500mV
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// voltage divider
 | 
				
			||||||
 | 
					#define RESISTOR_R1                   20000    // ohm
 | 
				
			||||||
 | 
					#define RESISTOR_R2                   10000    // ohm
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					                  voltage input
 | 
				
			||||||
 | 
					                     |
 | 
				
			||||||
 | 
					                     |
 | 
				
			||||||
 | 
					                    | |
 | 
				
			||||||
 | 
					                    | |  R1
 | 
				
			||||||
 | 
					                    | |
 | 
				
			||||||
 | 
					                     |
 | 
				
			||||||
 | 
					  analog Pin  <------+
 | 
				
			||||||
 | 
					                     |
 | 
				
			||||||
 | 
					                    | |
 | 
				
			||||||
 | 
					                    | |  R2
 | 
				
			||||||
 | 
					                    | |
 | 
				
			||||||
 | 
					                     |
 | 
				
			||||||
 | 
					                     |
 | 
				
			||||||
 | 
					                    GND
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// calculate voltage to percent
 | 
				
			||||||
 | 
					#define ENABLE_PERCENTLIST            true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Battery type
 | 
				
			||||||
 | 
					#define BAT_TYPE                      B_VOLT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Battery cells
 | 
				
			||||||
 | 
					#define BAT_CELLS                     2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// **** Wifi settings ****
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define MAX_SSID_PW_LENGHT          64
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Station mode: connect to available network
 | 
				
			||||||
 | 
					#define SSID_STA                    "myWiFi"
 | 
				
			||||||
 | 
					#define PASSWORD_STA                ""
 | 
				
			||||||
 | 
					#define TIMEOUT_CONNECT             25000   //ms
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Access point mode: create own network
 | 
				
			||||||
 | 
					#define SSID_AP                     "CG scale"
 | 
				
			||||||
 | 
					#define PASSWORD_AP                 ""
 | 
				
			||||||
 | 
					const char ip[4] =                  {1,2,3,4};    // default IP address
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define ENABLE_MDNS                 true          // enable mDNS to reach the webpage with hostname.local
 | 
				
			||||||
 | 
					#define ENABLE_OTA                  true          // enable over the air update
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// **** https update settings ****
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define ENABLE_UPDATE               true
 | 
				
			||||||
 | 
					#define HTTPS_PORT                  443
 | 
				
			||||||
 | 
					#define HOST                        "github.com"
 | 
				
			||||||
 | 
					#define URL                         "/nightflyer88/CG_scale/releases/latest"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// **** Model memory settings ****
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define MAX_MODELNAME_LENGHT        32               // max chars 
 | 
				
			||||||
 | 
					#define DEFAULT_NAME                "Model"          // default model name
 | 
				
			||||||
 | 
					#define MODEL_FILE                  "/models.json"   // file to store models
 | 
				
			||||||
 | 
					#define JSONDOC_SIZE                20000            // max file size in bytes
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// **** end of settings ****
 | 
				
			||||||
 | 
					#warning WIFI KIT 8 settings have been loaded
 | 
				
			||||||
		Reference in New Issue
	
	Block a user