Heltec Wifi Kit V3 with code from V2 Problems

Hi,
I’m a newbe, i’m sorry for my stupid questions…
I’m building a center of gravity scale for my model aircrafts.
I have 2 HX711 wight cells ans a Heltec Wifi Kit V3.
The Code is for a V2 and i have mdified the code so it compiles and i can upload it to the board but the screen is staying dark and i have no idea what i did wrong.
Any help is gratly apriciated.

// Visual Micro is in vMicro>General>Tutorial Mode

//

/*

Name:       CGScale.ino

Created:  20.10.2019 13:22:22

Author:     WS-WSHOP\elsen

Updated: 01.12.2019

    - Added autoamtic zeroing after switching on ofer 50 measurement cycles

*/

/// Used for deep sleep

#include “soc/rtc.h”;

/// Wifi setup

#include <WiFi.h>

#include <WiFiUdp.h>

const char * networkName = “Drcopter”; // WiFi network name and password:

const char * networkPass = “1234546789”;

const char * udpAddress = “255.255.255.255”;

const char * networkIP = “10.10.1.1”;

const int udpPort = 3333;

int RSSI = 0;

int RSSI_OLD;

byte packetBuffer[128]; //buffer to hold incoming and outgoing packets

String UDP_PACKET;

WiFiUDP udp;

boolean B_RECONNECT = false; // Is set to true when the connection gets lost because of RSSI Signal lost

boolean connected = false; // Are we currently connected?

boolean connected_old = true; // Previous state of the connected bool

/// OLED setup

#include <U8g2lib.h>

U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=/ 21, / clock=/ 18, / data=*/ 17); // Full buffer rendering

/// Variables for the Display

unsigned long prevMillis = 0; // will store last time the display was updated

long DISPLAY_interval = 250; // transmit interval (milliseconds)

int inByte = 0; // incoming serial byte

char ver[] = “01.12.2019”; // Software version

boolean B_TX_INFO = true; // When the flag is set we send an info string to then PC

boolean B_TX_LOG = false; // When the flag is set we send a log message via udp

int UDP_TX_COUNT = 0; // Counts up every time a UDP-packet is send

int TX_INFO_INTERVALL = 20; // Every time UDP_TX_COUNT is greater than this the INFO packet will be sent

int N_PAGE = 2; // Display page (0=Setup, 1=Std Page, 2=Weight)

int N_PAGE_OLD = 4; // Display page (0=Setup, 1=Std Page, 2=Weight)

int N_PAGE_MAX = 3; // Max display page

int t_DISP_SLEEP = 600; // Time in Seconds after the display is set to power save mode in case no button is pressed

unsigned long T_DISPLAY_WAKEUP = 0; // Value set whenever a button is pressed

/// Setup the scale amps

#include “HX711.h”

HX711 scale_F;

HX711 scale_R;

/// Variables for the Scale filter intervall

unsigned long prMillis = 0; // will store last time the scale value was filtered

long T_SCALE_INT = 100; // Read and filter interval (milliseconds)

bool B_CALOFF_INPROGRESS = false; // Bool get’s set when offset measurement or calibration is ongoing

/// Setup EEPROM

#include “EEPROM.h”

#define EEPROM_SIZE 64

const int AD_OFFS_F = 1; // EEPROM address of front scale offset

const int AD_GAIN_F = 5; // EEPROM address of front scale gain

const int AD_OFFS_R = 13; // EEPROM address of rear scale offset

const int AD_GAIN_R = 17; // EEPROM address of rear scale gain

const int AD_L1 = 21; // EEPROM address of L1 (distance between the scales [mm])

const int AD_L2 = 25; // EEPROM address of L2 (distance between the front scale and the leading edge [mm])

/// Variables for the UDP transmit intervall

unsigned long previousMillis = 0; // will store last time the data was transmitted over serial

long UDP_Interval = 100; // transmit interval [ms]

/// Variables for Deep sleep button

int B_SLEEP_STATE; // the current reading from the input pin

int B_SLEEP_STATE_LAST = LOW; // the previous reading from the input pin

unsigned long lastDebounceTime = 0; // the last time the output pin was toggled

unsigned long debounceDelay = 2000; // the debounce time; increase if the output flickers

/// Variables for multi button

int B_MULTI_STATE; // the current reading from the input pin

int B_MULTI_STATE_LAST = LOW; // the previous reading from the input pin

unsigned long LDebTime = 0; // the last time the output pin was toggled

unsigned long DebDelay = 1; // the debounce time; increase if the output flickers

/// Misc Variables

float F_SCALE_F = 0; // Holds the filtered and calibrated value of the scale

int offset_F = 0; // Holds the scale offset

float gain_F = -0.00011; // Holds the scale gain

float F_SCALE_R = 0; // Holds the filtered and calibrated value of the scale

int offset_R = 0; // Holds the scale offset

float gain_R = -0.00011; // Holds the scale gain

float F_TOT = 0; // Holds the total aircraft weight

float CG = 0; // Holds the CG value

float L2 = 30; // Holds the length between the front measurement point and the leading edge stop

float L1 = 118; // Holds the length between the front and the rear scale

float U_BAT; // Holds the filtered supply battery voltage

int BAT_CHG_ST; // Battery charge state in percent

float BAT_CHG_ST_OLD = 101; // Holds the previous measured battery charge state in percent

float U_BAT_GAIN = 0.002635; // Gain [V/bit] to convert ADC input to V

char dispStr[6]; // null terminated char array used to pass to renderer

static const unsigned char CG_BASIS[] U8X8_PROGMEM = {

0x80, 0x1f, 0x00, 0xe0, 0x7f, 0x00, 0xf0, 0xf3, 0x00, 0xf8, 0xc3, 0x01,

0xfc, 0x03, 0x03, 0xfe, 0x03, 0x07, 0xfe, 0x03, 0x06, 0xff, 0x03, 0x06,

0xff, 0x03, 0x0c, 0xff, 0x03, 0x0c, 0x03, 0xfc, 0x0f, 0x03, 0xfc, 0x0f,

0x03, 0xfc, 0x07, 0x06, 0xfc, 0x07, 0x06, 0xfc, 0x07, 0x0c, 0xfc, 0x03,

0x18, 0xfc, 0x01, 0x70, 0xfc, 0x00, 0xe0, 0x7f, 0x00, 0x80, 0x1f, 0x00 };

static const unsigned char WEIGHT[] U8X8_PROGMEM = {

0x00, 0x02, 0x00, 0x80, 0x1f, 0x00, 0x80, 0x10, 0x00, 0xc0, 0x30, 0x00,

0xc0, 0x30, 0x00, 0xc0, 0x30, 0x00, 0xf0, 0xff, 0x00, 0xf0, 0xff, 0x00,

0xf8, 0xff, 0x01, 0xf8, 0xff, 0x01, 0xf8, 0xff, 0x01, 0xf8, 0xff, 0x03,

0xfc, 0xff, 0x03, 0xfc, 0xff, 0x03, 0xfc, 0xff, 0x03, 0xfe, 0xff, 0x07,

0xfe, 0xff, 0x07, 0xfe, 0xff, 0x07, 0xfe, 0xff, 0x07, 0xff, 0xff, 0x0f };

//** Setup *****************************************************************************************************************

void setup()

{

/// Serial port setup

Serial.begin(115200);

Serial.println(“Booting…”);

/// The end of deep sleep

esp_sleep_enable_ext0_wakeup(GPIO_NUM_13, 1); //1 = High, 0 = Low

delay(100);

/// Slow down cpu to prevent glitches on HX711

setCpuFrequencyMhz(80);

/// Setup pins

pinMode(LED_BUILTIN, OUTPUT); // Active if UDP packet is transmitted

pinMode(3, OUTPUT); // HX711 supply

pinMode(32, INPUT); // Multi button

pinMode(13, INPUT); // Butto for deep sleep

/// Get EEPROM values

if (!EEPROM.begin(EEPROM_SIZE))

{

Serial.println("Failed to initialise EEPROM");

Serial.println("Restarting...");

delay(3000);

ESP.restart();

}

offset_F = EEPROM.readInt(AD_OFFS_F);

offset_R = EEPROM.readInt(AD_OFFS_R);

gain_F = EEPROM.readFloat(AD_GAIN_F) / 100000;

gain_R = EEPROM.readFloat(AD_GAIN_R) / 100000;

L1 = EEPROM.readFloat(AD_L1);

L2 = EEPROM.readFloat(AD_L2);

if (gain_F == NAN) gain_F = 1;

if (gain_R == NAN) gain_R = 1;

if (offset_F == NAN) offset_F = 0;

if (offset_R == NAN) offset_R = 0;

Serial.println("Scale front offset read from EEPROM is " + String(offset_F));

Serial.println("Scale rear offset read from EEPROM is " + String(offset_R));

Serial.println("Scale front gain read from EEPROM is " + String(gain_F * 100000));

Serial.println("Scale rear gain read from EEPROM is " + String(gain_R * 100000));

Serial.println("Scale L1 read from EEPROM is " + String(L1));

Serial.println("Scale L2 read from EEPROM is " + String(L2));

/// Start Display

u8g2.begin();

u8g2.enableUTF8Print();

u8g2.setFlipMode(1);

delay(10);

U_BAT = analogRead(1) * U_BAT_GAIN + 0.4; /// Calculate initial battery voltage

REFRESH_DISPLAY();

/// Start Wifi as AccessPoint

connectToWiFi_AP(networkName, networkPass);

udp.begin(WiFi.localIP(), udpPort); ///initializes UDP, this initializes the transfer buffer

/// Start Scale

digitalWrite(3, HIGH); /// Enable supply to HX711

scale_F.begin(4, 5); /// Start the front scale. Pinorder is SDA, SCK

scale_R.begin(6, 7); /// Start the rear scale. Pinorder is SDA, SCK

/// Zero the scales on startup

ZERO_SCALES(50);

}

//** Main void *************************************************************************************************************

void loop()

{

/// UDP Packet receive

int packetSize = udp.parsePacket();

String UDP_RX_COMMAND = “”;

if (packetSize)

{

udp.read(packetBuffer, packetSize); /// read the packet into the buffer

for (int i = 1; i <= packetSize; i++)

{

  UDP_RX_COMMAND = UDP_RX_COMMAND + char(packetBuffer[i - 1]);

}

String POS = getValue(UDP_RX_COMMAND, ';', 0);

String CMD = getValue(UDP_RX_COMMAND, ';', 1);

String VALUE = getValue(UDP_RX_COMMAND, ';', 2);

   if ((POS == "0") && (CMD == "REB")) esp_restart();

else if ((POS == "0") && (CMD == "TAR")) ZERO_SCALES(VALUE.toInt());

else if ((POS == "0") && (CMD == "TARF")) ZERO_SCALEF(VALUE.toInt());

else if ((POS == "0") && (CMD == "TARR")) ZERO_SCALER(VALUE.toInt());

else if ((POS == "0") && (CMD == "CALF")) CALIBRATE_SCALE_F(VALUE.toFloat());

else if ((POS == "0") && (CMD == "CALR")) CALIBRATE_SCALE_R(VALUE.toFloat());

else if ((POS == "0") && (CMD == "INIT")) INIT_UNIT();

else if ((POS == "0") && (CMD == "INFO")) B_TX_INFO = true;

else if ((POS == "0") && (CMD == "SL1")) SETL1(VALUE.toFloat());

else if ((POS == "0") && (CMD == "SL2")) SETL2(VALUE.toFloat());

}

/// Debounce the ON/OFF Button and then send the unit to sleep

int reading = digitalRead(13);

if (reading != B_SLEEP_STATE_LAST)

{

lastDebounceTime = millis();

}

if ((millis() - lastDebounceTime) > debounceDelay) {

if (reading != B_SLEEP_STATE) {

  B_SLEEP_STATE = reading;

  if (B_SLEEP_STATE == HIGH)

  {

    //GoToSleep();

  }

}

}

B_SLEEP_STATE_LAST = reading;

if ((digitalRead(32) == HIGH) || (digitalRead(33) == HIGH))

{

  T_DISPLAY_WAKEUP = millis(); // Reset display wakeup time

  u8g2.setPowerSave(0);

}

// Timer

unsigned long currentMillis = millis();

/// Timer for Scale reading and filter

if (currentMillis - prMillis >= T_SCALE_INT)

{

  prMillis = currentMillis;

  if (B_CALOFF_INPROGRESS == false) CALC_SCALE_VALUE();

}

/// Timer for display refresh

if (currentMillis - prevMillis >= DISPLAY_interval)

{

  prevMillis = currentMillis;

  if (millis() > T_DISPLAY_WAKEUP + (t_DISP_SLEEP * 1000))

  {

    u8g2.setPowerSave(1);

  }

  else

  {

    u8g2.setPowerSave(0);

    REFRESH_DISPLAY();

  }

}

/// Timer for UDP transmit

if (currentMillis - previousMillis >= UDP_Interval)

{

  UDP_TX_COUNT++;

  if (UDP_TX_COUNT > TX_INFO_INTERVALL)

  {

    UDP_TX_COUNT = 0;

    B_TX_INFO = true;

  }

  RSSI = 100 - WiFi.RSSI() * -1;

  previousMillis = currentMillis;

  if ((connected) && (B_CALOFF_INPROGRESS == false))

  {

    UDP_TX();

  }

}

}

//** Subroutines *************************************************************************************************************

/// - CAL_SCALE_VALUE()

void CALC_SCALE_VALUE()

{

double ffactor = 1;

float F_SCALE_SAMPLE_F = (scale_F.read() - offset_F) * gain_F; //calculate weigth with gain and offset

int error = abs(F_SCALE_F - F_SCALE_SAMPLE_F);

if (error > 20)

{

ffactor = 0.8;

}

else if (error > 10 && error <= 20)

{

ffactor = 0.7;

}

else if (error > 1 && error < 10)

{

ffactor = 0.4;

}

else if (error < 1)

{

ffactor = 0.05;

}

F_SCALE_F = (1 - ffactor) * F_SCALE_F + ffactor * F_SCALE_SAMPLE_F;

if (F_SCALE_F == NAN) F_SCALE_F = 0;

if ((F_SCALE_F < 0) && (F_SCALE_F > -0.05)) F_SCALE_F = 0;

float F_SCALE_SAMPLE_R = (scale_R.read() - offset_R) * gain_R; //calculate weigth with gain and offset

error = abs(F_SCALE_R - F_SCALE_SAMPLE_R);

if (error > 20)

{

ffactor = 0.8;

}

else if (error > 10 && error <= 20)

{

ffactor = 0.7;

}

else if (error > 1 && error < 10)

{

ffactor = 0.4;

}

else if (error < 1)

{

ffactor = 0.05;

}

F_SCALE_R = (1 - ffactor) * F_SCALE_R + ffactor * F_SCALE_SAMPLE_R;

if (F_SCALE_R == NAN) F_SCALE_R = 0;

if ((F_SCALE_R < 0) && (F_SCALE_R > -0.05)) F_SCALE_R = 0;

F_TOT = F_SCALE_F + F_SCALE_R;

if (F_TOT > 5)

{

CG = (F_SCALE_F * L2 + F_SCALE_R * L2 + F_SCALE_R * L1) / F_TOT;

}

else

{

CG = 0;

}

}

/// Display refresh u8g2-----------------------------------------------

void REFRESH_DISPLAY()

{

int x_start = 0;

u8g2.clearBuffer();

u8g2.setFont(u8g2_font_artossans8_8r); // 8X8 Font

u8g2.drawLine(0, 10, 128, 10);

int n_stations = WiFi.softAPgetStationNum();

char c_stations[2];

String(n_stations).toCharArray(c_stations, 8);

u8g2.drawStr(120, 8, c_stations);

u8g2.drawStr(0, 8, “WLAN CLIENTS:”);

// All 16x16 Font things happen from here onwards

u8g2.setFont(u8g2_font_helvB24_tr); // 18X18 Font

String(CG,1).toCharArray(dispStr, 8);

x_start = 137 - strlen(dispStr) * 18;

u8g2.drawStr(x_start, 38, dispStr);

u8g2.drawXBM(0, 17, 20, 20, CG_BASIS);

u8g2.drawXBM(0, 44, 20, 20, WEIGHT);

String((int)F_TOT).toCharArray(dispStr, 8);

x_start = 128 - strlen(dispStr) * 18;

u8g2.drawStr(x_start, 64, dispStr);

u8g2.sendBuffer();

}

///- UDP Data transmission ----------------------------------------

void UDP_TX()

{

String datastring;

if (B_TX_INFO)

{

datastring = "A;INFO;" + String(ver) + ";" + String(gain_F * 100000) + ";" + String(offset_F) + ";" + String(gain_R * 100000) + ";" + String(offset_R) + ";" + String(L1) + ";" + String(L2);

B_TX_INFO = false;

udp.beginPacket(udpAddress, udpPort);

udp.print(datastring);

udp.endPacket();

}

else if (B_TX_LOG){}

else

{

datastring = "A;VAL;" + String(F_SCALE_F) + ";" + String(F_SCALE_R) + ";" + String(CG) + ";" + String(F_TOT) + ";NULL;NULL;NULL";

udp.beginPacket(udpAddress, udpPort);

udp.print(datastring);

udp.endPacket();

}

}

void UDP_TX_LOG(String txt)

{

B_TX_LOG = true;

delay(110);

String datastring = "A;LOG; " + txt + “;NULL;NULL;NULL;NULL;NULL;NULL”;

udp.beginPacket(udpAddress, udpPort);

udp.print(datastring);

udp.endPacket();

B_TX_LOG = false;

}

// - Wifi connection routine -------------------------------------

/// If used as access point

void connectToWiFi_AP(const char * ssid, const char * pass)

{

Serial.println("Creating WiFi network: " + String(ssid));

// delete old config

WiFi.disconnect(true);

delay(50);

//register event handler

WiFi.onEvent(WiFiEvent_AP);

delay(50);

//Initiate connection

WiFi.softAPsetHostname(“OnTargetGW”);

IPAddress ip(10, 10, 1, 1);

IPAddress gateway(10, 10, 1, 1);

IPAddress subnet(255, 255, 255, 0);

WiFi.softAPConfig(ip, gateway, subnet);

WiFi.softAP(ssid, pass, 10, 0, 8);

delay(50);

Serial.println(“Waiting for WIFI client…”);

}

void WiFiEvent_AP(WiFiEvent_t event) {

T_DISPLAY_WAKEUP = millis(); // Reset display wakeup time

switch (event)

{

case WIFI_EVENT_AP_STACONNECTED:

Serial.printf("Client connected to soft-AP = %d\n", WiFi.softAPgetStationNum());

delay(10);

connected = true;

break;

case WIFI_EVENT_AP_STADISCONNECTED:

Serial.print("SYSTEM_EVENT_AP_STADISCONNECTED");

if (WiFi.softAPgetStationNum() == 0)

{

  connected = false;

  Serial.println("No station connected anymore");

}

else

{

  connected = true;

}

break;

}

}

/// If used as client

void connectToWiFi_STA(const char * ssid, const char * pwd)

{

Serial.println(“Starting WiFi setup”);

delay(50);

// delete old config

WiFi.disconnect(true);

delay(33);

//register event handler

WiFi.onEvent(WiFiEvent_STA);

delay(33);

//Initiate connection

WiFi.begin(ssid, pwd);

Serial.println(“Waiting for WIFI connection…”);

}

void WiFiEvent_STA(WiFiEvent_t event)

{

if ((N_PAGE > 0) && (N_PAGE < 3)) T_DISPLAY_WAKEUP = millis(); // Reset display wakeup time

switch (event)

{

case IP_EVENT_STA_GOT_IP: //When connected set

Serial.print("SYSTEM_EVENT_STA_GOT_IP: ");

Serial.println(WiFi.localIP());

connected = true;

delay(100);

B_RECONNECT = true;

break;

case WIFI_EVENT_STA_DISCONNECTED:

Serial.println("SYSTEM_EVENT_STA_DISCONNECTED");

connected = false;

B_RECONNECT = false;

connectToWiFi_STA(networkName, networkPass);

break;

case IP_EVENT_STA_LOST_IP:

T_DISPLAY_WAKEUP = millis(); // Reset display wakeup time

Serial.println("SYSTEM_EVENT_STA_LOST_IP");

connected = false;

B_RECONNECT = false;

connectToWiFi_STA(networkName, networkPass);

break;

}

}

///- Go to sleep --------------------------------------------------

void GoToSleep()

{

u8g2.clearBuffer();

u8g2.setFont(u8g2_font_artossans8_8r); // 8X8 Font

Serial.println(“Sleep Button detected, waiting for 2 seconds now…”);

UDP_TX_LOG(“Sleep Button detected, waiting for 2 seconds now…”);

u8g2.clear();

u8g2.drawStr(0, 16, “Switching”);

u8g2.setFont(u8g2_font_px437wyse700b_mr); // 16X16 Font

u8g2.drawStr(0, 32, "OFF ");

u8g2.sendBuffer();

delay(40);

u8g2.drawStr(0, 32, "OFF. ");

u8g2.sendBuffer();

delay(40);

u8g2.drawStr(0, 32, "OFF… ");

u8g2.sendBuffer();

delay(40);

u8g2.drawStr(0, 32, "OFF… ");

u8g2.sendBuffer();

delay(40);

u8g2.drawStr(0, 32, "OFF… ");

u8g2.sendBuffer();

delay(40);

u8g2.drawStr(0, 32, “OFF…”);

u8g2.sendBuffer();

Serial.println(“Going to sleep now”);

UDP_TX_LOG(“Going to sleep now”);

delay(100);

esp_deep_sleep_start();

}

//- Converters

String getValue(String data, char separator, int index)

{

int found = 0;

int strIndex[] = { 0, -1 };

int maxIndex = data.length() - 1;

for (int i = 0; i <= maxIndex && found <= index; i++)

{

if (data.charAt(i) == separator || i == maxIndex)

{

  found++;

  strIndex[0] = strIndex[1] + 1;

  strIndex[1] = (i == maxIndex) ? i + 1 : i;

}

}

return found > index ? data.substring(strIndex[0], strIndex[1]) : “”;

}

//- Calibration and zeroing ---------------------------------------

/// Zeroing

void ZERO_SCALES(int cycles)

{

B_CALOFF_INPROGRESS = true;

Serial.println(“Zero request received.”);

UDP_TX_LOG(“Zero request received”);

u8g2.clearBuffer();

u8g2.setFont(u8g2_font_px437wyse700b_mr); // 16X16 Font

u8g2.drawStr(8, 40, “ZEROING”);

u8g2.sendBuffer();

offset_F = scale_F.read_average(cycles);

F_SCALE_F = (scale_F.read() - offset_F) * gain_F; //calculate weigth with gain and offset

Serial.println("New offset calculated front: " + String(offset_F));

UDP_TX_LOG("New offset calculated front: " + String(offset_F));

EEPROM.writeInt(AD_OFFS_F, offset_F);

offset_R = scale_R.read_average(cycles);

F_SCALE_R = (scale_R.read() - offset_R) * gain_R; //calculate weigth with gain and offset

Serial.println("New offset calculated rear: " + String(offset_R));

UDP_TX_LOG("New offset calculated rear: " + String(offset_R));

EEPROM.writeInt(AD_OFFS_R, offset_R);

EEPROM.commit();

B_CALOFF_INPROGRESS = false;

B_TX_INFO = true;

}

void ZERO_SCALEF(int cycles)

{

B_CALOFF_INPROGRESS = true;

Serial.println(“Zero front request received.”);

UDP_TX_LOG(“Zero front request received.”);

u8g2.clearBuffer();

u8g2.setFont(u8g2_font_px437wyse700b_mr); // 16X16 Font

u8g2.drawStr(8, 40, “ZERO FT”);

u8g2.sendBuffer();

offset_F = scale_F.read_average(cycles);

F_SCALE_F = (scale_F.read() - offset_F) * gain_F; //calculate weigth with gain and offset

Serial.println("New offset calculated front: " + String(offset_F));

UDP_TX_LOG("New offset calculated front: " + String(offset_F));

EEPROM.writeInt(AD_OFFS_F, offset_F);

EEPROM.commit();

B_CALOFF_INPROGRESS = false;

B_TX_INFO = true;

}

void ZERO_SCALER(int cycles)

{

B_CALOFF_INPROGRESS = true;

Serial.println(“Zero rear request received.”);

UDP_TX_LOG(“Zero rear request received.”);

u8g2.clearBuffer();

u8g2.setFont(u8g2_font_px437wyse700b_mr); // 16X16 Font

u8g2.drawStr(8, 40, “ZERO RE”);

u8g2.sendBuffer();

offset_R = scale_R.read_average(cycles);

F_SCALE_R = (scale_R.read() - offset_R) * gain_R; //calculate weigth with gain and offset

Serial.println("New offset calculated rear: " + String(offset_R));

UDP_TX_LOG("New offset calculated rear: " + String(offset_R));

EEPROM.writeInt(AD_OFFS_R, offset_R);

EEPROM.commit();

B_CALOFF_INPROGRESS = false;

B_TX_INFO = true;

}

/// Calibration

void CALIBRATE_SCALE_F(float calweight)

{

B_CALOFF_INPROGRESS = true;

Serial.println(“Gain calibration request received.”);

UDP_TX_LOG(“Gain calibration request received.”);

delay(50);

u8g2.clearBuffer();

u8g2.setFont(u8g2_font_px437wyse700b_mr); // 16X16 Font

u8g2.drawStr(0, 40, “CAL FRT”);

u8g2.sendBuffer();

gain_F = calweight / (offset_F - scale_F.read_average(15)) * -1;

F_SCALE_F = (scale_F.read() - offset_F) * gain_F; //calculate weigth with gain and offset

EEPROM.writeFloat(AD_GAIN_F, gain_F * 100000);

EEPROM.commit();

Serial.println("New front gain calculated: " + String(gain_F * 100000));

UDP_TX_LOG("New front gain calculated: " + String(gain_F * 100000));

B_TX_INFO = true;

B_CALOFF_INPROGRESS = false;

}

void CALIBRATE_SCALE_R(float calweight)

{

B_CALOFF_INPROGRESS = true;

Serial.println(“Gain calibration request received.”);

UDP_TX_LOG(“Gain calibration request received.”);

delay(50);

u8g2.clearBuffer();

u8g2.setFont(u8g2_font_px437wyse700b_mr); // 16X16 Font

u8g2.drawStr(0, 40, “CAL REAR”);

u8g2.sendBuffer();

gain_R = calweight / (offset_R - scale_R.read_average(15)) * -1;

F_SCALE_R = (scale_R.read() - offset_R) * gain_R; //calculate weigth with gain and offset

EEPROM.writeFloat(AD_GAIN_R, gain_R * 100000);

EEPROM.commit();

Serial.println("New rear gain calculated: " + String(gain_F * 100000));

UDP_TX_LOG("New rear gain calculated: " + String(gain_F * 100000));

B_TX_INFO = true;

B_CALOFF_INPROGRESS = false;

}

void SETL1(float distance)

{

L1 = distance;

EEPROM.writeFloat(AD_L1, distance);

EEPROM.commit();

Serial.println("New L1 written to EEPROM: " + String(distance));

UDP_TX_LOG("New L1 written to EEPROM: " + String(distance));

B_TX_INFO = true;

}

void SETL2(float distance)

{

L2 = distance;

EEPROM.writeFloat(AD_L2, distance);

EEPROM.commit();

Serial.println("New L2 written to EEPROM: " + String(distance));

UDP_TX_LOG("New L2 written to EEPROM: " + String(distance));

B_TX_INFO = true;

}

// Init new unit to gain 1 and offset 0. Reboot after.

void INIT_UNIT()

{

Serial.println(“Unit initialisation command received.”);

UDP_TX_LOG(“Unit initialisation command received.”);

delay(50);

u8g2.clearBuffer();

u8g2.setFont(u8g2_font_px437wyse700b_mr); // 16X16 Font

u8g2.drawStr(22, 32, “INIT”);

u8g2.sendBuffer();

EEPROM.writeInt(1, 0);

EEPROM.writeInt(13, 0);

EEPROM.writeFloat(5, 1);

EEPROM.writeFloat(17, 1);

EEPROM.commit();

Serial.println(“Done, restarting now…”);

UDP_TX_LOG(“Done, restarting now…”);

delay(1000);

esp_restart();