Hallo ich habe einen code erstellt um die prozent meines e-golf abzurufen leider funktioniert der nicht. Hat jemand so was ähnliches gemacht?
C
<#include "BluetoothSerial.h"
#include "ELMduino.h"
#include
#include
#include
#include "golf.h"
BluetoothSerial SerialBT;
#define ELM_PORT SerialBT
#define DEBUG_PORT Serial
// Use hardware SPI
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
//String MACadd = "8C:DE:52:DB:34:0C"; //enter the ELM327 MAC address
//uint8_t address[6] = {0x8C, 0xDE, 0x52, 0xDB, 0x34, 0x0C}; //enter the ELM327 MAC address after the 0x
ELM327 myELM327;
uint32_t rpm = 0;
void setup()
{
// Initialize the hardware, the BMA423 sensor has been initialized internally
tft.init();
// Drehen 1
tft.setRotation(1);
//Hintergrund
tft.fillScreen(TFT_BLACK);
tft.setSwapBytes(true);
//BILD
tft.pushImage(0,0,275,183,golf);
//Text Größe
tft.setTextSize(1);
// Set "cursor" at top left corner of display (0,0) and select font 4
tft.setCursor(0, 0, 4);
// Set the font colour to be white with a black background
tft.setTextColor(TFT_BLUE);
// We can now plot text on screen using the "print" class
tft.drawString("Verbinde mit OBD-II", 10, 10, 4);
//tft.drawString("Made by", 35, 60, 4);
tft.drawString("", 35, 90, 4);
#if LED_BUILTIN
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
#endif
DEBUG_PORT.begin(19200);
SerialBT.setPin("1234");
ELM_PORT.begin("Golf", true);
if (!ELM_PORT.connect("OBDII"))
// MAC adress: 8c:de:52:db:34:0c
// address
{
DEBUG_PORT.println("Couldn't connect to OBD scanner - Phase 1");
tft.pushImage(0,0,275,183,golf);
tft.setTextColor(TFT_RED);
tft.drawString("Error Phase1", 10, 10, 4);
while(1);
}
if (!myELM327.begin(ELM_PORT, true, 2000))
{
Serial.println("Couldn't connect to OBD scanner - Phase 2");
tft.pushImage(0,0,275,183,golf);
tft.setTextColor(TFT_RED);
tft.drawString("Error Phase2", 10, 10, 4);
while (1);
}
Serial.println("Connected to ELM327");
tft.pushImage(0,0,275,183,golf);
tft.setTextSize(1);
tft.setTextColor(TFT_GREEN);
tft.drawString("OBD 2 verbunden", 10, 30, 4);
delay(2500);
tft.fillScreen(TFT_BLACK);
}
void loop()
{
// Show the data
//tft->fillRect(98, 100, 70, 85, TFT_BLACK);
tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.fillRect(240, 240, 0, 0, TFT_BLACK);
tft.drawString("<< e-GOLF >>", 35, 10, 4);
tft.setTextSize(1);
tft.setCursor(40, 70);
float soc = getBatterySOC();
float hvVoltage = getHVBatteryVoltage();
tft.fillScreen(TFT_BLACK);
if (soc >= 0) {
tft.drawString("SoC: " + String(soc) + "%", 0, 20, 2);
} else {
tft.drawString("Fehler bei SoC Abfrage", 0, 20, 2);
}
if (hvVoltage >= 0) {
tft.drawString("HV Spannung: " + String(hvVoltage) + "V", 0, 60, 2);
} else {
tft.drawString("Fehler bei HV Spannung Abfrage", 0, 60, 2);
}
delay(1000); // Verzögerung für zyklische Abfrage
}
float getBatterySOC() {
char command[] = "221DD0";
myELM327.sendCommand(command);
delay(100); // Kurze Verzögerung
if (myELM327.findResponse()) {
char* response = myELM327.payload;
return parseBatterySOC(response);
}
return -1; // Fehlerfall
}
float parseBatterySOC(char* response) {
int responseValue = strtol(response, NULL, 16); // Konvertiert Hexadezimalstring in Integer
return (float)responseValue / 2.0; // Halbieren des Werts und Konvertieren in Prozent
}
float getHVBatteryVoltage() {
char command[] = "221606";
myELM327.sendCommand(command);
delay(100); // Kurze Verzögerung
if (myELM327.findResponse()) {
char* response = myELM327.payload;
return parseHVBatteryVoltage(response);
}
return -1; // Fehlerfall
}
float parseHVBatteryVoltage(char* response) {
int responseValue = strtol(response, NULL, 16); // Konvertiert Hexadezimalstring in Integer
// Die Umrechnung hängt von der spezifischen Antwortstruktur ab
return (float)responseValue; // Beispielinterpretation, anpassen nach Bedarf
}>
Alles anzeigen