I made a post a while ago about a project I have been working on using a Freematics OBD-II UART Adapter V2.1, an Arduino UNO and a Adafruit 1.14 TFT display. the code I was assisted with works quite well, I'm trying to add some more commands/ different commands specifically voltage and VIN retrieval. I used the library properties to try and assist me in getting the code working (library properties linked here) ArduinoOBD/libraries/OBD2UART/OBD2UART.h at master · stanleyhuangyc/ArduinoOBD · GitHub . both commands will display only zeros, there is a chance with the voltage, that the reason I'm getting a zero value is because I had to modify the OBD connector in a way where it dose not get power from itself so it is not always powered on in the vehicle, but the VIN should work if I knew what I was doing incorrectly. I'm also not sure if I can display a decimal with the "char buffer" command. any assistance would be much appreciated.
// HMD G1 BLOCK 2 code
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library for ST7735
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
#include <SPI.h>
#include <OBD2UART.h>
COBD obd;
#define TFT_CS 10
#define TFT_RST 9 // Or set to -1 and connect to Arduino RESET pin
#define TFT_DC 8
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
int MODE1 = 2;
int KPH = 12;
int LEDBACK1 = 9;
int potPin = A1;
char buffer[21];
void setup() {
delay(2000);
pinMode(MODE1, INPUT);
pinMode(KPH, INPUT);
pinMode(LEDBACK1,OUTPUT);
Serial.begin(115200);
tft.setTextColor(ST77XX_GREEN,ST77XX_BLACK);
//void setup Master color
tft.init(135, 240);
tft.fillScreen(ST77XX_BLACK);
tft.setRotation(3);
tft.setTextSize(2);
tft.setCursor(30, 50);
tft.print("MPH ");
tft.print("---");
tft.setRotation(3);
tft.setTextSize(2);
tft.setCursor(30,30 );
tft.print("RPM ");
tft.print("--00");
tft.setRotation(3);
tft.setTextSize(2);
tft.setCursor(130,30 );
tft.print("|");
tft.print("--- ");
tft.print("%");
// Demo display
delay(1000);
obd.begin();
while (!obd.init());
tft.fillScreen(ST77XX_BLACK);
tft.setRotation(3);
tft.setTextSize(2);
tft.setCursor(50, 40);
tft.println("OBD CONNECTED");
tft.setRotation(3);
tft.setTextSize(2);
tft.setCursor(10, 60);
int valueVIN;
bool getVIN(valueVIN);
tft.print(valueVIN);
delay(4000);
// Connection to display
tft.fillScreen(ST77XX_BLACK);
// Clear display
}
void loop() {
tft.setTextColor(ST77XX_WHITE,ST77XX_BLACK); //void loop master color
int potentiometerValue =
analogRead (potPin);
int brightness = potentiometerValue / 4;
analogWrite(LEDBACK1,brightness);
// dimming control
if (digitalRead(KPH) ==LOW){
int value;
tft.setRotation(3);
tft.setTextSize(2);
tft.setCursor(30, 50);
tft.print("MPH ");
if (obd.readPID(PID_SPEED, value)){
float a = value;
float b = 1.609344;
int c = 0;
c = a / b;
sprintf(buffer, "%3i", c);
tft.print(buffer);
}
}
// MPH
else{
int valueKPH;
tft.setRotation(3);
tft.setTextSize(2);
tft.setCursor(30, 50);
tft.print("KPH ");
if (obd.readPID(PID_SPEED, valueKPH)){
sprintf(buffer, "%3i", valueKPH );
tft.print(buffer);
}
}
// KPH
// speed control
int value2;
tft.setRotation(3);
tft.setTextSize(2);
tft.setCursor(30,30 );
tft.print("RPM ");
if (obd.readPID(PID_RPM, value2)) {
value2-=value2 % 100;
sprintf(buffer, "%4i", value2);
tft.print(buffer);
}
// RPM control
int value3;
tft.setRotation(3);
tft.setTextSize(2);
tft.setCursor(130,30 );
tft.print("|");
if (obd.readPID(PID_RELATIVE_THROTTLE_POS, value3)) {
sprintf(buffer, "%3i", value3);
tft.print(buffer);
}
tft.print("%");
if (digitalRead(MODE1) ==HIGH){
// Throttle pos control
int valueFUEL;
tft.setRotation(3);
tft.setTextSize(2);
tft.setCursor(130,50 );
tft.print("|");
if (obd.readPID(PID_FUEL_LEVEL, valueFUEL)) {
sprintf(buffer, "%3i", valueFUEL);
tft.print(buffer);
}
tft.print("%");
int valueTEMP;
tft.setRotation(3);
tft.setTextSize(2);
tft.setCursor(130,70 );
if (obd.readPID(PID_COOLANT_TEMP, valueTEMP)) {
sprintf(buffer, "%3i", valueTEMP);
tft.print(buffer);
}
tft.print("C");
int valueVOLT;
tft.setRotation(3);
tft.setTextSize(2);
tft.setCursor(30,70 );
float getVoltage(valueVOLT);
sprintf(buffer, "%2i", valueVOLT);
tft.print(buffer);
tft.print("V");
}
// Info mode set
else{
tft.setRotation(3);
tft.setTextSize(2);
tft.setCursor(130,50 );
tft.print(" ");
tft.setCursor(130,70 );
tft.print(" ");
tft.setCursor(30,70 );
tft.print(" ");
}
}
// Normal mode set