Voltage in box measuring fully working
This commit is contained in:
parent
41cc32d73b
commit
5645bb8846
@ -11,13 +11,19 @@
|
|||||||
|
|
||||||
#define esc1pin 15
|
#define esc1pin 15
|
||||||
#define esc2pin 13
|
#define esc2pin 13
|
||||||
#define fallbackpin 36
|
#define voltageEnable 12
|
||||||
|
#define voltagePin 36
|
||||||
#define failsafeValue 127
|
#define failsafeValue 127
|
||||||
#define ONE_WIRE_BUS 14
|
#define ONE_WIRE_BUS 14
|
||||||
#define fanRelais 16
|
#define fanRelais 16
|
||||||
|
|
||||||
#define DELETEBEFOREPAIR 0
|
#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 esc1;
|
||||||
Servo esc2;
|
Servo esc2;
|
||||||
SSD1306 display(0x3c, 5, 4);
|
SSD1306 display(0x3c, 5, 4);
|
||||||
@ -194,7 +200,36 @@ void checkTemperature() {
|
|||||||
sendTemperatureDecimals = (temperature - sendTemperature) * 100;
|
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() {
|
void setup() {
|
||||||
|
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial.println("ESPNowSkate Receiver");
|
Serial.println("ESPNowSkate Receiver");
|
||||||
|
|
||||||
@ -202,6 +237,8 @@ void setup() {
|
|||||||
display.flipScreenVertically();
|
display.flipScreenVertically();
|
||||||
display.setFont(ArialMT_Plain_16);
|
display.setFont(ArialMT_Plain_16);
|
||||||
|
|
||||||
|
pinMode(voltageEnable, OUTPUT);
|
||||||
|
|
||||||
// Init escs, min and max value similar as Traxxas TQI 1100, 1900
|
// Init escs, min and max value similar as Traxxas TQI 1100, 1900
|
||||||
// chanel, minAngel, maxAngel, minPulseWidth, maxPulseWidth
|
// chanel, minAngel, maxAngel, minPulseWidth, maxPulseWidth
|
||||||
esc1.attach(esc1pin, 0, 0, 255, 1100, 1900);
|
esc1.attach(esc1pin, 0, 0, 255, 1100, 1900);
|
||||||
@ -260,4 +297,5 @@ void loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
checkTemperature();
|
checkTemperature();
|
||||||
|
checkVoltage();
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ byte hallCenterMargin = 5;
|
|||||||
byte currentSetting = 0;
|
byte currentSetting = 0;
|
||||||
const byte numOfSettings = 11;
|
const byte numOfSettings = 11;
|
||||||
|
|
||||||
const float minVoltage = 3.25;
|
const float minVoltage = 3.4;
|
||||||
const float maxVoltage = 4.1;
|
const float maxVoltage = 4.1;
|
||||||
const float refVoltage = 3.3;
|
const float refVoltage = 3.3;
|
||||||
// Resistors in Ohms
|
// Resistors in Ohms
|
||||||
@ -469,8 +469,8 @@ void drawPage() {
|
|||||||
// TODO : check how that will work once hal is wired
|
// TODO : check how that will work once hal is wired
|
||||||
first = boardData[B_SPEED];
|
first = boardData[B_SPEED];
|
||||||
last = boardData[B_SPEED_D];
|
last = boardData[B_SPEED_D];
|
||||||
suffix = "KM";
|
suffix = "KmH";
|
||||||
prefix = "DISTANCE";
|
prefix = "SPEED";
|
||||||
decimals = 2;
|
decimals = 2;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
@ -491,14 +491,14 @@ void drawPage() {
|
|||||||
// Add leading zero
|
// Add leading zero
|
||||||
if (first <= 9) {
|
if (first <= 9) {
|
||||||
if(connected) displayString = "0" + (String)first;
|
if(connected) displayString = "0" + (String)first;
|
||||||
else displayString = "XX";
|
else displayString = "--";
|
||||||
} else {
|
} else {
|
||||||
if(connected) displayString = (String)first;
|
if(connected) displayString = (String)first;
|
||||||
else displayString = "XX";
|
else displayString = "--";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display numbers
|
// Display numbers
|
||||||
displayString.toCharArray(displayBuffer, 10);
|
displayString.toCharArray(displayBuffer, 4);
|
||||||
u8g2.setFont(u8g2_font_logisoso22_tn );
|
u8g2.setFont(u8g2_font_logisoso22_tn );
|
||||||
u8g2.drawStr(x + 55, y + 13, displayBuffer);
|
u8g2.drawStr(x + 55, y + 13, displayBuffer);
|
||||||
|
|
||||||
@ -506,10 +506,10 @@ void drawPage() {
|
|||||||
// Add leading zero
|
// Add leading zero
|
||||||
if (last <= 9) {
|
if (last <= 9) {
|
||||||
if(connected) displayString = ".0" + (String)last;
|
if(connected) displayString = ".0" + (String)last;
|
||||||
else displayString = ".XX";
|
else displayString = ".--";
|
||||||
} else {
|
} else {
|
||||||
if(connected) displayString = "." + (String)last;
|
if(connected) displayString = "." + (String)last;
|
||||||
else displayString = ".XX";
|
else displayString = ".--";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display decimals
|
// Display decimals
|
||||||
|
Loading…
Reference in New Issue
Block a user