code is now compatible with standard OLED displays and original code base (default pw length = 32)
This commit is contained in:
parent
3cf22bb65a
commit
f7293003fb
122
CG_scale.ino
122
CG_scale.ino
@ -4,17 +4,19 @@
|
|||||||
(c) 2019 by M. Lehmann
|
(c) 2019 by M. Lehmann
|
||||||
------------------------------------------------------------------
|
------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
#define CGSCALE_VERSION "2.1"
|
#define CGSCALE_VERSION "2.2"
|
||||||
/*
|
/*
|
||||||
|
|
||||||
******************************************************************
|
******************************************************************
|
||||||
history:
|
history:
|
||||||
|
V2.2 18.08.20 code is now compatible with standard OLED displays
|
||||||
|
and original code base (default pw length = 32)
|
||||||
V2.1 18.07.20 added support for ESP8266 based Wifi Kit 8
|
V2.1 18.07.20 added support for ESP8266 based Wifi Kit 8
|
||||||
(by Pulsar07/ (https://heltec.org/project/wifi-kit-8/)
|
(by Pulsar07/ (https://heltec.org/project/wifi-kit-8/)
|
||||||
R.Stransky is a ESP8266 with
|
R.Stransky is a ESP8266 with
|
||||||
* a build in OLED 128x32
|
a build in OLED 128x32
|
||||||
* battery connector with charging management
|
battery connector with charging management
|
||||||
* reset and GPIO0 button
|
reset and GPIO0 button
|
||||||
support for a tare button (PIN_TARE_BUTTON)
|
support for a tare button (PIN_TARE_BUTTON)
|
||||||
bug fixed: wifi password now with up to 64 chars
|
bug fixed: wifi password now with up to 64 chars
|
||||||
bug fixed: wifi data (ssid/passwd) with special
|
bug fixed: wifi data (ssid/passwd) with special
|
||||||
@ -153,6 +155,12 @@ bool updateMenu = true;
|
|||||||
int menuPage = 0;
|
int menuPage = 0;
|
||||||
String errMsg[5];
|
String errMsg[5];
|
||||||
int errMsgCnt = 0;
|
int errMsgCnt = 0;
|
||||||
|
int oledDisplayHeight;
|
||||||
|
int oledDisplayWidth;
|
||||||
|
const uint8_t *oledFontLarge;
|
||||||
|
const uint8_t *oledFontNormal;
|
||||||
|
const uint8_t *oledFontSmall;
|
||||||
|
const uint8_t *oledFontTiny;
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
String updateMsg = "";
|
String updateMsg = "";
|
||||||
bool wifiSTAmode = true;
|
bool wifiSTAmode = true;
|
||||||
@ -169,40 +177,50 @@ void resetCPU() {}
|
|||||||
|
|
||||||
void initOLED() {
|
void initOLED() {
|
||||||
oledDisplay.begin();
|
oledDisplay.begin();
|
||||||
|
oledDisplayHeight = oledDisplay.getDisplayHeight();
|
||||||
|
oledDisplayWidth = oledDisplay.getDisplayWidth();
|
||||||
|
printConsole(T_BOOT, "init OLED display: " + String(oledDisplayWidth) + String("x") + String(oledDisplayHeight));
|
||||||
|
|
||||||
const uint8_t *font;
|
|
||||||
font = u8g2_font_6x12_tr;
|
oledFontLarge = u8g2_font_helvR12_tr;
|
||||||
int displayHeight = oledDisplay.getDisplayHeight();
|
oledFontNormal = u8g2_font_helvR10_tr;
|
||||||
int displayWidth = oledDisplay.getDisplayWidth();
|
oledFontSmall = u8g2_font_5x7_tr;
|
||||||
if (displayHeight <= 32) {
|
oledFontTiny = u8g2_font_4x6_tr;
|
||||||
font = u8g2_font_6x12_tr;
|
|
||||||
|
if (oledDisplayHeight <= 32) {
|
||||||
|
oledFontLarge = u8g2_font_helvR10_tr;
|
||||||
|
oledFontNormal = u8g2_font_6x12_tr;
|
||||||
}
|
}
|
||||||
int ylineHeight = displayHeight/3;
|
int ylineHeight = oledDisplayHeight / 3;
|
||||||
|
|
||||||
|
oledDisplay.setFont(oledFontNormal);
|
||||||
|
|
||||||
oledDisplay.firstPage();
|
oledDisplay.firstPage();
|
||||||
do {
|
do {
|
||||||
if (displayHeight <= 32) {
|
oledDisplay.setFont(oledFontLarge);
|
||||||
|
if (oledDisplayHeight <= 32) {
|
||||||
oledDisplay.drawXBMP(5, 0, 18, 18, CGImage);
|
oledDisplay.drawXBMP(5, 0, 18, 18, CGImage);
|
||||||
} else {
|
} else {
|
||||||
oledDisplay.drawXBMP(20, 12, 18, 18, CGImage);
|
oledDisplay.drawXBMP(20, 12, 18, 18, CGImage);
|
||||||
}
|
}
|
||||||
oledDisplay.setFont(u8g2_font_helvR12_tr);
|
oledDisplay.setFont(oledFontLarge);
|
||||||
if (displayHeight <= 32) {
|
|
||||||
|
if (oledDisplayHeight <= 32) {
|
||||||
oledDisplay.setCursor(30, 12);
|
oledDisplay.setCursor(30, 12);
|
||||||
} else {
|
} else {
|
||||||
oledDisplay.setCursor(45, 28);
|
oledDisplay.setCursor(45, 28);
|
||||||
}
|
}
|
||||||
oledDisplay.print(F("CG scale"));
|
oledDisplay.print(F("CG scale"));
|
||||||
|
|
||||||
oledDisplay.setFont(u8g2_font_5x7_tr);
|
oledDisplay.setFont(oledFontSmall);
|
||||||
if (displayHeight <= 32) {
|
if (oledDisplayHeight <= 32) {
|
||||||
oledDisplay.setCursor(30, 22);
|
oledDisplay.setCursor(30, 22);
|
||||||
} else {
|
} else {
|
||||||
oledDisplay.setCursor(35, 55);
|
oledDisplay.setCursor(35, 55);
|
||||||
}
|
}
|
||||||
oledDisplay.print(F("Version: "));
|
oledDisplay.print(F("Version: "));
|
||||||
oledDisplay.print(CGSCALE_VERSION);
|
oledDisplay.print(CGSCALE_VERSION);
|
||||||
if (displayHeight <= 32) {
|
if (oledDisplayHeight <= 32) {
|
||||||
oledDisplay.setCursor(5, 31);
|
oledDisplay.setCursor(5, 31);
|
||||||
} else {
|
} else {
|
||||||
oledDisplay.setCursor(20, 64);
|
oledDisplay.setCursor(20, 64);
|
||||||
@ -215,32 +233,25 @@ void initOLED() {
|
|||||||
void printOLED(String aLine1, String aLine2, String aLine3 = String(""));
|
void printOLED(String aLine1, String aLine2, String aLine3 = String(""));
|
||||||
|
|
||||||
void printOLED(String aLine1, String aLine2, String aLine3) {
|
void printOLED(String aLine1, String aLine2, String aLine3) {
|
||||||
const uint8_t *font;
|
int ylineHeight = oledDisplayHeight / 3;
|
||||||
font = u8g2_font_6x12_tr;
|
|
||||||
int displayHeight = oledDisplay.getDisplayHeight();
|
|
||||||
int displayWidth = oledDisplay.getDisplayWidth();
|
|
||||||
font = u8g2_font_helvR10_tr;
|
|
||||||
if (displayHeight <= 32) {
|
|
||||||
font = u8g2_font_6x12_tr;
|
|
||||||
}
|
|
||||||
int ylineHeight = displayHeight/3;
|
|
||||||
|
|
||||||
oledDisplay.firstPage();
|
oledDisplay.firstPage();
|
||||||
do {
|
do {
|
||||||
oledDisplay.setFont(u8g2_font_6x12_tr);
|
oledDisplay.setFont(oledFontNormal);
|
||||||
oledDisplay.setCursor(0, ylineHeight * 1);
|
oledDisplay.setCursor(0, ylineHeight * 1);
|
||||||
oledDisplay.print(aLine1);
|
oledDisplay.print(aLine1);
|
||||||
oledDisplay.setCursor(0, ylineHeight * 2);
|
oledDisplay.setCursor(0, ylineHeight * 2);
|
||||||
oledDisplay.print(aLine2);
|
oledDisplay.print(aLine2);
|
||||||
if (aLine3 == "") {
|
if (aLine3 == "") {
|
||||||
oledDisplay.drawLine(0, ylineHeight*2 + 2, displayWidth, ylineHeight*2+2);
|
oledDisplay.drawLine(0, ylineHeight * 2 + 2, oledDisplayWidth, ylineHeight * 2 + 2);
|
||||||
oledDisplay.setFont(u8g2_font_4x6_tr);
|
oledDisplay.setFont(oledFontTiny);
|
||||||
oledDisplay.setCursor(0, displayHeight);
|
oledDisplay.setCursor(0, oledDisplayHeight);
|
||||||
|
oledDisplay.print("IP:" + WiFi.localIP().toString());
|
||||||
String signature = "CG scale: V" + String(CGSCALE_VERSION);
|
String signature = "CG scale: V" + String(CGSCALE_VERSION);
|
||||||
oledDisplay.setCursor(displayWidth - oledDisplay.getStrWidth(signature.c_str()), displayHeight);
|
oledDisplay.setCursor(oledDisplayWidth - oledDisplay.getStrWidth(signature.c_str()), oledDisplayHeight);
|
||||||
oledDisplay.print(signature);
|
oledDisplay.print(signature);
|
||||||
} else {
|
} else {
|
||||||
oledDisplay.setCursor(0, displayHeight);
|
oledDisplay.setCursor(0, oledDisplayHeight);
|
||||||
oledDisplay.print(aLine3);
|
oledDisplay.print(aLine3);
|
||||||
}
|
}
|
||||||
} while ( oledDisplay.nextPage() );
|
} while ( oledDisplay.nextPage() );
|
||||||
@ -248,7 +259,9 @@ void printOLED(String aLine1, String aLine2, String aLine3) {
|
|||||||
|
|
||||||
void printScaleOLED() {
|
void printScaleOLED() {
|
||||||
// print to display
|
// print to display
|
||||||
char buff[8];
|
char buff1[8];
|
||||||
|
char buff[12];
|
||||||
|
char buff2[8];
|
||||||
int pos_weightTotal = 7;
|
int pos_weightTotal = 7;
|
||||||
int pos_CG_length = 28;
|
int pos_CG_length = 28;
|
||||||
if (nLoadcells == 2) {
|
if (nLoadcells == 2) {
|
||||||
@ -260,19 +273,6 @@ void printScaleOLED() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint8_t *font;
|
|
||||||
int linestart = 14;
|
|
||||||
int linedist = 25;
|
|
||||||
int col0=0;
|
|
||||||
int col1=28;
|
|
||||||
font = u8g2_font_helvR12_tr;
|
|
||||||
if (oledDisplay.getDisplayHeight() <=32) {
|
|
||||||
font = u8g2_font_6x12_tr;
|
|
||||||
linestart = 8;
|
|
||||||
linedist = 12;
|
|
||||||
col0=0;
|
|
||||||
col1=28;
|
|
||||||
}
|
|
||||||
oledDisplay.firstPage();
|
oledDisplay.firstPage();
|
||||||
do {
|
do {
|
||||||
if (errMsgCnt == 0) {
|
if (errMsgCnt == 0) {
|
||||||
@ -283,7 +283,7 @@ void printScaleOLED() {
|
|||||||
dtostrf(percentVolt, 3, 0, buff);
|
dtostrf(percentVolt, 3, 0, buff);
|
||||||
oledDisplay.drawBox(49, 2, (percentVolt / (100 / 8)), 4);
|
oledDisplay.drawBox(49, 2, (percentVolt / (100 / 8)), 4);
|
||||||
|
|
||||||
oledDisplay.setFont(u8g2_font_5x7_tr);
|
oledDisplay.setFont(oledFontSmall);
|
||||||
oledDisplay.setCursor(78 - oledDisplay.getStrWidth(buff), 7);
|
oledDisplay.setCursor(78 - oledDisplay.getStrWidth(buff), 7);
|
||||||
if (batType > B_VOLT) {
|
if (batType > B_VOLT) {
|
||||||
dtostrf(percentVolt, 3, 0, buff);
|
dtostrf(percentVolt, 3, 0, buff);
|
||||||
@ -296,46 +296,46 @@ void printScaleOLED() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// print total weight
|
// print total weight
|
||||||
oledDisplay.setFont(font);
|
oledDisplay.setFont(oledFontNormal);
|
||||||
if (oledDisplay.getDisplayHeight() <= 32) {
|
dtostrf(weightTotal, 7, 1, buff);
|
||||||
|
if (oledDisplayHeight <= 32) {
|
||||||
oledDisplay.setCursor(1, 18);
|
oledDisplay.setCursor(1, 18);
|
||||||
oledDisplay.print(F("M = "));
|
oledDisplay.print(F("M = "));
|
||||||
} else {
|
} else {
|
||||||
oledDisplay.drawXBMP(2, pos_weightTotal, 18, 18, weightImage);
|
oledDisplay.drawXBMP(2, pos_weightTotal, 18, 18, weightImage);
|
||||||
oledDisplay.setCursor(93 - oledDisplay.getStrWidth(buff), pos_weightTotal + 17);
|
oledDisplay.setCursor(93 - oledDisplay.getStrWidth(buff), pos_weightTotal + 17);
|
||||||
}
|
}
|
||||||
dtostrf(weightTotal, 5, 1, buff);
|
|
||||||
oledDisplay.print(buff);
|
oledDisplay.print(buff);
|
||||||
oledDisplay.print(F(" g"));
|
oledDisplay.print(F(" g"));
|
||||||
|
|
||||||
// print CG longitudinal axis
|
// print CG longitudinal axis
|
||||||
if (oledDisplay.getDisplayHeight() <=32) {
|
dtostrf(CG_length, 7, 1, buff);
|
||||||
|
if (oledDisplayHeight <= 32) {
|
||||||
oledDisplay.setCursor(1, 32);
|
oledDisplay.setCursor(1, 32);
|
||||||
oledDisplay.print(F("CG = "));
|
oledDisplay.print(F("CG = "));
|
||||||
} else {
|
} else {
|
||||||
oledDisplay.drawXBMP(2, pos_CG_length, 18, 18, CGImage);
|
oledDisplay.drawXBMP(2, pos_CG_length, 18, 18, CGImage);
|
||||||
oledDisplay.setCursor(93 - oledDisplay.getStrWidth(buff), pos_CG_length + 16);
|
oledDisplay.setCursor(93 - oledDisplay.getStrWidth(buff), pos_CG_length + 16);
|
||||||
}
|
}
|
||||||
dtostrf(CG_length, 5, 1, buff);
|
|
||||||
oledDisplay.print(buff);
|
oledDisplay.print(buff);
|
||||||
oledDisplay.print(F(" mm"));
|
oledDisplay.print(F(" mm"));
|
||||||
|
|
||||||
// print CG transverse axis
|
// print CG transverse axis
|
||||||
if (nLoadcells == 3) {
|
if (nLoadcells == 3) {
|
||||||
if (oledDisplay.getDisplayHeight() <=32) {
|
if (oledDisplayHeight <= 32) {
|
||||||
oledDisplay.setCursor(78, 32);
|
oledDisplay.setCursor(78, 32);
|
||||||
oledDisplay.print(F("LR="));
|
oledDisplay.print(F("LR="));
|
||||||
dtostrf(CG_trans, 3, 0, buff);
|
dtostrf(CG_trans, 3, 0, buff);
|
||||||
} else {
|
} else {
|
||||||
oledDisplay.drawXBMP(2, 47, 18, 18, CGtransImage);
|
oledDisplay.drawXBMP(2, 47, 18, 18, CGtransImage);
|
||||||
oledDisplay.setCursor(93 - oledDisplay.getStrWidth(buff), 64);
|
oledDisplay.setCursor(93 - oledDisplay.getStrWidth(buff), 64);
|
||||||
dtostrf(CG_trans, 5, 1, buff);
|
dtostrf(CG_trans, 7, 1, buff);
|
||||||
}
|
}
|
||||||
oledDisplay.print(buff);
|
oledDisplay.print(buff);
|
||||||
oledDisplay.print(F(" mm"));
|
oledDisplay.print(F(" mm"));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
oledDisplay.setFont(u8g2_font_5x7_tr);
|
oledDisplay.setFont(oledFontSmall);
|
||||||
for (int i = 1; i <= errMsgCnt; i++) {
|
for (int i = 1; i <= errMsgCnt; i++) {
|
||||||
oledDisplay.setCursor(0, 7 * i);
|
oledDisplay.setCursor(0, 7 * i);
|
||||||
oledDisplay.print(errMsg[i]);
|
oledDisplay.print(errMsg[i]);
|
||||||
@ -345,6 +345,8 @@ void printScaleOLED() {
|
|||||||
} while ( oledDisplay.nextPage() );
|
} while ( oledDisplay.nextPage() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef PIN_TARE_BUTTON
|
#ifdef PIN_TARE_BUTTON
|
||||||
void handleTareBtn() {
|
void handleTareBtn() {
|
||||||
static unsigned long lastTaraBtn = 0;
|
static unsigned long lastTaraBtn = 0;
|
||||||
@ -579,9 +581,6 @@ void setup() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// init OLED display
|
// init OLED display
|
||||||
#if defined(ESP8266)
|
|
||||||
printConsole(T_BOOT, "init OLED display: " + String(oledDisplay.getDisplayWidth())+ String("x") + String(oledDisplay.getDisplayHeight()));
|
|
||||||
#endif
|
|
||||||
initOLED();
|
initOLED();
|
||||||
|
|
||||||
// init & tare Loadcells
|
// init & tare Loadcells
|
||||||
@ -606,12 +605,13 @@ void setup() {
|
|||||||
|
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
|
|
||||||
|
printConsole(T_BOOT, "Wifi: STA mode - connecing with: " + String(ssid_STA));
|
||||||
|
|
||||||
// Start by connecting to a WiFi network
|
// Start by connecting to a WiFi network
|
||||||
WiFi.persistent(false);
|
WiFi.persistent(false);
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
WiFi.begin(ssid_STA, password_STA);
|
WiFi.begin(ssid_STA, password_STA);
|
||||||
|
|
||||||
printConsole(T_BOOT, "Wifi: STA mode - connect with: " + String(ssid_STA));
|
|
||||||
|
|
||||||
long timeoutWiFi = millis();
|
long timeoutWiFi = millis();
|
||||||
|
|
||||||
@ -835,7 +835,6 @@ void loop() {
|
|||||||
|
|
||||||
printScaleOLED();
|
printScaleOLED();
|
||||||
|
|
||||||
|
|
||||||
// serial connection
|
// serial connection
|
||||||
if (Serial) {
|
if (Serial) {
|
||||||
if (Serial.available() > 0) {
|
if (Serial.available() > 0) {
|
||||||
@ -1710,11 +1709,10 @@ void printUpdateProgress(unsigned int progress, unsigned int total) {
|
|||||||
|
|
||||||
oledDisplay.firstPage();
|
oledDisplay.firstPage();
|
||||||
do {
|
do {
|
||||||
oledDisplay.setFont(u8g2_font_helvR08_tr);
|
oledDisplay.setFont(oledFontSmall);
|
||||||
oledDisplay.setCursor(0, 12);
|
oledDisplay.setCursor(0, 12);
|
||||||
oledDisplay.print(updateMsg);
|
oledDisplay.print(updateMsg);
|
||||||
|
|
||||||
oledDisplay.setFont(u8g2_font_5x7_tr);
|
|
||||||
oledDisplay.setCursor(107, 35);
|
oledDisplay.setCursor(107, 35);
|
||||||
oledDisplay.printf("%u%%\r", (progress / (total / 100)));
|
oledDisplay.printf("%u%%\r", (progress / (total / 100)));
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ CG scale with 3 Loadcells:
|
|||||||
|
|
||||||
// Wifi Kit 8 (https://heltec.org/project/wifi-kit-8/)
|
// Wifi Kit 8 (https://heltec.org/project/wifi-kit-8/)
|
||||||
// is a ESP8266 based board, with integrated OLED and battery management
|
// is a ESP8266 based board, with integrated OLED and battery management
|
||||||
// #define WIFI_KIT_8 1
|
#define WIFI_KIT_8 1
|
||||||
#ifdef WIFI_KIT_8
|
#ifdef WIFI_KIT_8
|
||||||
#define PIN_LOADCELL1_DOUT D6
|
#define PIN_LOADCELL1_DOUT D6
|
||||||
#define PIN_LOADCELL1_PD_SCK D7
|
#define PIN_LOADCELL1_PD_SCK D7
|
||||||
@ -62,6 +62,8 @@ CG scale with 3 Loadcells:
|
|||||||
|
|
||||||
// D3 can be used in parallel to the load cell with Wifi Kit 8
|
// D3 can be used in parallel to the load cell with Wifi Kit 8
|
||||||
#define PIN_TARE_BUTTON D3
|
#define PIN_TARE_BUTTON D3
|
||||||
|
|
||||||
|
#define MAX_SSID_PW_LENGHT 64
|
||||||
#else
|
#else
|
||||||
#define PIN_LOADCELL1_DOUT D6
|
#define PIN_LOADCELL1_DOUT D6
|
||||||
#define PIN_LOADCELL1_PD_SCK D5
|
#define PIN_LOADCELL1_PD_SCK D5
|
||||||
@ -151,7 +153,9 @@ CG scale with 3 Loadcells:
|
|||||||
|
|
||||||
// **** Wifi settings ****
|
// **** Wifi settings ****
|
||||||
|
|
||||||
#define MAX_SSID_PW_LENGHT 64
|
#ifndef MAX_SSID_PW_LENGHT
|
||||||
|
#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"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user