I have used the Freematics with their library.
https://freematics.com/products/freematics-obd-ii-uart-adapter-mk2/
is what I used.
#include <U8g2lib.h>
#include "freeRTOSSTUFF.h"
#include <OBD2UART.h>
////
//const int SerialDataBits = 115200;
const int DisplayK = 100000;
/////////////////////////////////////////////////////////////////////////////////////////////
void setup()
{
// //// CORE 0
xTaskCreatePinnedToCore ( fUpdateDisplay, "fUpdateDisplay", DisplayK, NULL, Priority4, NULL, TaskCore0 ); // assigned to core
}
////
void loop() {}
////
/////////////////////////////////////////////////////
void fUpdateDisplay( void * parameter )
{
U8G2_SSD1309_128X64_NONAME0_F_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 5, /* dc=*/ 2, /* reset=*/ 4);
COBD obd;
byte version = obd.begin();
log_i("Freematics OBD-II Adapter %d", version);
if ( u8g2.begin() )
{
log_i( "u8gx.begin() all OK" );
}
int xValIncrement = 10;
int Xval = 0;
int Val;
String temp = "";
temp.reserve(200);
u8g2.setFont(u8g2_font_ncenB08_tr); // choose a suitable font
for (;;)
{
u8g2.clearBuffer(); // clear the internal memory
////
temp.concat( "Batt: " );
temp.concat( String(obd.getVoltage()) );
temp.concat( "V " );
// PID_FUEL_LEVEL
temp.concat( " Fuel: ");
obd.readPID( PID_FUEL_LEVEL, Val);
temp.concat( String(Val) );
temp.concat( "%" );
u8g2.setCursor( 0, Xval ); u8g2.print( temp ); // do not 0 Val, used below // send the bat and fuel to the oled
temp = "";
// DISPLAY FUEL LEVEL BAR
u8g2.drawHLine( 0, 15, 100); // top
int Y = 17;
for ( int x = 0; x <= Val; x++)
{
u8g2.drawVLine( x, Y, 3);
log_i( "X %d, Y %d", x, Y );
}
u8g2.drawVLine( 25, 14, 8); // 25%
u8g2.drawVLine( 50, 14, 8); // 50%
u8g2.drawVLine( 75, 14, 8); // 75 percent
u8g2.drawVLine( 100, 14, 8); // 100%
u8g2.drawHLine( 0, 21, 100);
Val = 0;
//PID_RPM
Xval = 43;
obd.readPID( PID_RPM, Val );
/*/ 100 pixels for 5000 rmp = 50 pixel per 1000 rpm
*/
int rpm = Val / 50;
Y = 27;
for ( int x = 0; x <= rpm; x++)
{
u8g2.drawVLine( x, Y, 5);
}
u8g2.drawVLine( 50, Xval + 2, 8); // 25%
temp.concat( String( Val) );
temp.concat( " RPM's " );
u8g2.setCursor( 25, Xval ); u8g2.print( temp ); Val = 0;
temp = "" ;
// PID_COOLANT_TEMP
Xval = Xval + xValIncrement;
temp.concat( "Coolant: " );
obd.readPID( PID_COOLANT_TEMP, Val);
temp.concat( String(Val) );
temp.concat( "C / ");
temp.concat( String( ((float)Val * 1.8f) + 32.0f) );
temp.concat( " F");
u8g2.setCursor( 0, Xval ); u8g2.print( temp ); Val = 0;
temp = "";
// // PID_SPEED
// Xval = Xval + xValIncrement;
// u8g2.drawStr( 0, Xval, "Speed: " );
// Xval = Xval + xValIncrement;
// u8g2.setFont( u8g2_font_osb41_tf ); // choose a suitable font
// obd.readPID( PID_SPEED, Val);
// float mph = (float)Val * .62137119f;
// u8g2.setCursor( 0, 50 ); u8g2.print( int(mph) );
//
u8g2.sendBuffer(); // transfer internal memory to the display
// // Serial.print(uxTaskGetStackHighWaterMark( NULL ));
// // Serial.println();
// // Serial.flush();
// // vTaskDelay(7);
Xval = xValIncrement; // reset Xval for the next loop.
Val = 0; // set value to 0 for next loop
vTaskDelay( 500 );
}
vTaskDelete( NULL );
} // void fUpdateDisplay( void * parameter )
////
//////////////////////////////////////////////////////