diff --git a/src/receiver.cpp b/src/receiver.cpp index 738c926..262a0bd 100644 --- a/src/receiver.cpp +++ b/src/receiver.cpp @@ -11,13 +11,19 @@ #define esc1pin 15 #define esc2pin 13 -#define fallbackpin 36 +#define voltageEnable 12 +#define voltagePin 36 #define failsafeValue 127 #define ONE_WIRE_BUS 14 #define fanRelais 16 #define DELETEBEFOREPAIR 0 +// Resistors in Ohms +const float deviderR1 = 1275; // needs to be calibrated carefully using a multimeter because of tolerances of the resistors +const float deviderR2 = 22000; +const float refVoltage = 3.3; + Servo esc1; Servo esc2; SSD1306 display(0x3c, 5, 4); @@ -194,7 +200,36 @@ void checkTemperature() { sendTemperatureDecimals = (temperature - sendTemperature) * 100; } +void checkVoltage() { + digitalWrite(voltageEnable, HIGH); + Serial.print("Voltage: "); + int value = analogRead(voltagePin); + Serial.println(value); + + + float batteryVoltage = 0.0; + int total = 0; + + for (int i = 0; i < 10; i++) { + total += analogRead(voltagePin); + } + + batteryVoltage = (refVoltage / 4095.0) * ((float)total / 10.0); + // Now we have the actual Voltage, lets calculate the value befor the devider + batteryVoltage = batteryVoltage / ( deviderR1 / (deviderR1 + deviderR2)); + + sendVoltage = abs(floor(batteryVoltage)); + sendVoltageDecimals = (batteryVoltage - sendVoltage) * 100; + Serial.print("Voltage: "); + Serial.println(batteryVoltage); + digitalWrite(voltageEnable, LOW); // change to low + delay(5); + Serial.print("VoltageOFF: "); + Serial.println(analogRead(voltagePin)); +} + void setup() { + Serial.begin(115200); Serial.println("ESPNowSkate Receiver"); @@ -202,6 +237,8 @@ void setup() { display.flipScreenVertically(); display.setFont(ArialMT_Plain_16); + pinMode(voltageEnable, OUTPUT); + // Init escs, min and max value similar as Traxxas TQI 1100, 1900 // chanel, minAngel, maxAngel, minPulseWidth, maxPulseWidth esc1.attach(esc1pin, 0, 0, 255, 1100, 1900); @@ -260,4 +297,5 @@ void loop() { } checkTemperature(); + checkVoltage(); } diff --git a/src/remote.cpp b/src/remote.cpp index 0d8cebd..36b13ee 100644 --- a/src/remote.cpp +++ b/src/remote.cpp @@ -48,7 +48,7 @@ byte hallCenterMargin = 5; byte currentSetting = 0; const byte numOfSettings = 11; -const float minVoltage = 3.25; +const float minVoltage = 3.4; const float maxVoltage = 4.1; const float refVoltage = 3.3; // Resistors in Ohms @@ -469,8 +469,8 @@ void drawPage() { // TODO : check how that will work once hal is wired first = boardData[B_SPEED]; last = boardData[B_SPEED_D]; - suffix = "KM"; - prefix = "DISTANCE"; + suffix = "KmH"; + prefix = "SPEED"; decimals = 2; break; case 2: @@ -491,14 +491,14 @@ void drawPage() { // Add leading zero if (first <= 9) { if(connected) displayString = "0" + (String)first; - else displayString = "XX"; + else displayString = "--"; } else { if(connected) displayString = (String)first; - else displayString = "XX"; + else displayString = "--"; } // Display numbers - displayString.toCharArray(displayBuffer, 10); + displayString.toCharArray(displayBuffer, 4); u8g2.setFont(u8g2_font_logisoso22_tn ); u8g2.drawStr(x + 55, y + 13, displayBuffer); @@ -506,10 +506,10 @@ void drawPage() { // Add leading zero if (last <= 9) { if(connected) displayString = ".0" + (String)last; - else displayString = ".XX"; + else displayString = ".--"; } else { if(connected) displayString = "." + (String)last; - else displayString = ".XX"; + else displayString = ".--"; } // Display decimals