Hello everyone,
I bought the Freematics OBD2 UART V2.1 Adapter, got me a pair of DOIT ESP32 DEV KIT boards, 3 ESP32 S2-mini and some TFT 1.28' GC9A01 displays.
I know that this is an Arduino Forum but really cant figure it out and I mean I'm using Arduino IDE.
Uploaded my sketch, connected both the display and the OBD2 adapter to one of my ESP32 S2-mini and tried plugging it in to my Mini One R50 2005.
Long story short, no output on my display and yes I connected everything the right way.
Now I ask myself what Problem It could be. (I will attach my sketch at the end)
-
It could be the Baud rate. I can't find out which Baud rate the Freematics V2.1 is using.
-
It could be the serial.begin, so that the ESP32 S2-mini isn't even getting the data right.
-
My Mini One R50 isn't even able to communicate with the adapter. I don't know where to look up these details and I am not even sure if they are able to be found anywhere.
My sketch for the S2-mini (I already changed the Serial.begin(Don't know if it did something)):
#include <SPI.h>
#include <Adafruit_GC9A01A.h>
#include <Adafruit_GFX.h>
#include <OBD2UART.h>
// ---------- HSPI Pins ----------
#define HSPI_MOSI 13
#define HSPI_SCK 14
// ---------- Display Pins ----------
#define CS_PIN 5
#define DC_PIN 21
#define RST_PIN 18
// ---------- Display Setup ----------
Adafruit_GC9A01A tft(CS_PIN, DC_PIN, HSPI_MOSI, HSPI_SCK, RST_PIN);
COBD obd;
// ---------- Variablen ----------
String lastText = "";
// ---------- Position ----------
int centerX = 120;
int centerY = 120;
// ---------- Fester Bereich für Zahlen ----------
int16_t valWidth = 70;
int16_t valHeight = 50;
void setup() {
Serial1.begin(115200);
Serial.begin(115200, SERIAL_8N1, 16, 17);
if (obd.begin()) {
if (obd.begin()) {
Serial.println("OBD2 verbunden!");
}
} else {
Serial.println("OBD2 Adapter nicht gefunden.");
}
tft.begin();
tft.setRotation(0);
tft.fillScreen(GC9A01A_BLACK);
// ---------- Feste Texte EINMAL zeichnen ----------
tft.setTextSize(2);
tft.setTextColor(GC9A01A_WHITE);
int16_t x1, y1; uint16_t w, h;
String header = "Geschw.";
tft.getTextBounds(header, 0, 0, &x1, &y1, &w, &h);
tft.setCursor(centerX - w/2, 20);
tft.print(header);
String unit = "km/h";
tft.getTextBounds(unit, 0, 0, &x1, &y1, &w, &h);
tft.setCursor(centerX - w/2, 220);
tft.print(unit);
// Anfangsanzeige
drawValue("---");
}
void loop() {
int speed = 0;
String newText;
if (obd.readPID(PID_SPEED, speed)) {
newText = String(speed); // keine führenden Nullen
} else {
newText = "---"; // kein Signal
}
if (newText != lastText) {
drawValue(newText);
lastText = newText;
}
delay(100);
}
// ---------- Zahl zeichnen (größer, mittig) ----------
void drawValue(String val) {
tft.setTextSize(6); // größere Zahl
tft.setTextColor(GC9A01A_WHITE, GC9A01A_BLACK); // Text + Hintergrund
// Alte Zahl löschen
int16_t x1, y1; uint16_t w, h;
if (lastText != "") {
tft.getTextBounds(lastText, 0, 0, &x1, &y1, &w, &h);
tft.fillRect(centerX - w/2 - 5, centerY - h/2 - 5, w + 10, h + 10, GC9A01A_BLACK);
}
// Neue Zahl mittig berechnen
tft.getTextBounds(val, 0, 0, &x1, &y1, &w, &h);
tft.setCursor(centerX - w/2, centerY - h/2);
tft.print(val);
}