Hi I'm currently working on project using an uno, serial lcd and a freematics obd2 v2.1
I want to be able to read and display things like engine and coolant temp ect but I'm having issues getting info from my ute (2017 79 series landcruiser). From what I can understand the 79s obd2 protocol is not fully supported by the freematics obd2 which means I can only read rpm. I've read that it's a timing issue with the protocol, is there something I can do to fix this. My other option is starting from scratch using something like the sparkfun obd2 uart.
I am still very new to coding so if I was to go with the second option I wouldn't know how to do it. Any info or guidance on what to do would be greatly appreciated.
For reference this is the basic code for the freematics obd2
#include <OBD2UART.h>
#include <SoftwareSerial.h>
COBD obd;
SoftwareSerial lcd(10, 11);
void setup()
{
lcd.begin(9600);
obd.begin();
while (!obd.init());
}
void loop()
{
int value;
obd.readPID(PID_RPM, value);
lcd.print(value);
lcd.print ("RPM");
delay(100);
}
and this is the code for displaying multiple values
#include <SoftwareSerial.h>
#include <OBD2UART.h>
COBD obd;
SoftwareSerial lcd(10, 11);
const int buttonPin = 13;
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
void setup()
{
pinMode(buttonPin, INPUT);
lcd.begin(9600);
// start communication with OBD-II UART adapter
obd.begin();
// initiate OBD-II connection until success
while (!obd.init());
bool hasMEMS = obd.memsInit(true);
}
void screen1() // display coolant and oil temp
{ int value;
int value2;
if
((obd.readPID(PID_RPM, value))&& obd.readPID(PID_COOLANT_TEMP, value2))
{ lcd.write(0xFE);
lcd.write(0x01);
lcd.write(254);
lcd.write(128);
lcd.print("OIL TEMP "); // write oil temp and value on lcd
lcd.print(value);
lcd.print("C");
lcd.write(254);
lcd.write(192);
lcd.print("COOLANT TEMP ");//write coolant temp and value on lcd
lcd.print(value2);
lcd.print("C");
}
}
void screen2()
{ int value;
int value2;
if
((obd.readPID(PID_ENGINE_REF_TORQUE, value))&& obd.readPID(PID_ENGINE_LOAD, value2))
{ lcd.write(0xFE);
lcd.write(0x01);
lcd.write(254);
lcd.write(128);
lcd.print(value); // write torque on lcd
lcd.print("Nm");
lcd.write(254);
lcd.write(192);
lcd.print("ENGINE LOAD "); //write engine load on lcd
lcd.print(value2);
lcd.print("%");
}
}
void screen3()
void screen4()
{
unsigned int numberofcodes;
uint16_t code[8];
obd.readDTC(code, numberofcodes);
if (numberofcodes == 0)
{ lcd.write(0xFE);
lcd.write(0x01);
lcd.write(254);
lcd.write(128);
lcd.print("NO CODES");
}
if (numberofcodes >= 1)
{
for (byte i = 0; i < numberofcodes; i++)
{ lcd.write(0x01);
lcd.write(254);
lcd.write(128);
lcd.print(code[i], HEX);
}
}
}
void loop()
{
buttonState = digitalRead(buttonPin);
// compare the buttonState to its previous state
if (buttonState != lastButtonState) {
// if the state has changed, increment the counter
if (buttonState == HIGH) {
// if the current state is HIGH then the button
// wend from off to on:
buttonPushCounter++;
}
if (buttonPushCounter >= 5) {
buttonPushCounter = 1;
}
if (buttonPushCounter == 1)
{ screen1();
}
if (buttonPushCounter == 2)
{ screen2();
}
if (buttonPushCounter == 3)
{ screen3();
}
if (buttonPushCounter == 4)
{ screen4();
}
delay(50);
lastButtonState = buttonState;
}
if (buttonPushCounter == 1)
{ screen1();
}
if (buttonPushCounter == 2)
{ screen2();
}
if (buttonPushCounter == 3)
{ screen3();
}
if (buttonPushCounter == 4)
{ screen4();
}
delay(250);
}