Good afternoon. I'm using ESP32 and I'm facing a problem. My code works until I include the LiquidCrystal_I2C.h library. After connecting, the ECU does not communicate.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display
#include "OBD9141.h"
OBD9141 obd;
#define RX_PIN 16 // connect to transceiver Rx for ESP32
#define TX_PIN 17 // connect to transceiver Tx
bool init_success;
TaskHandle_t Task1;
TaskHandle_t Task2;
// Определяем пины светодиодов
const int led1 = 2;
const int led2 = 4;
unsigned long timer; // переменная времени
float time_inj = 0;
float rpm = 0;
float q_l_sec = 0;
float l_h = 0;
float l_100 = 0;
float speed_car = 0;
void setup() {
// lcd.init();
// lcd.backlight();
// lcd.setCursor(0, 0);
// lcd.print("Hello, world!");
Serial.begin(115200);
obd.begin(Serial2, RX_PIN, TX_PIN);
delay(2000);
Serial.println("initialization");
timer = millis(); // запускаем отсчет времени
//создаем задачу, которая будет выполняться на ядре 0 с максимальным приоритетом (1)
xTaskCreatePinnedToCore(
Task1code, /* Функция задачи. */
"Task1", /* Ее имя. */
10000, /* Размер стека функции */
NULL, /* Параметры */
1, /* Приоритет */
&Task1, /* Дескриптор задачи для отслеживания */
0); /* Указываем пин для данного ядра */
delay(500);
//Создаем задачу, которая будет выполняться на ядре 1 с наивысшим приоритетом (1)
xTaskCreatePinnedToCore(
Task2code, /* Функция задачи. */
"Task2", /* Имя задачи. */
10000, /* Размер стека */
NULL, /* Параметры задачи */
1, /* Приоритет */
&Task2, /* Дескриптор задачи для отслеживания */
1); /* Указываем пин для этой задачи */
delay(500);
while (!obd.init()) {
return;
}
}
void Task1code(void* pvParameters) {
for (;;) {
Serial.println("Looping");
bool init_success = obd.init();
Serial.print("init_success:");
Serial.println(init_success);
if (init_success) {
bool res;
while (1) {
res = obd.getCurrentPID(0x0C, 2);
if (res) {
Serial.print("Result 0x0C (RPM): ");
Serial.println(obd.readUint16() / 4);
rpm = obd.readUint16() / 4;
}
res = obd.getlongPID(0x60, 0x12, 2);
if (res) {
Serial.print("Result (time inj #1): ");
Serial.println((obd.readUint_long16() * 2));
time_inj = (obd.readUint_long16() * 2);
}
res = obd.getCurrentPID(0x0D, 1);
if (res) {
Serial.print("Result 0x0D (speed): ");
speed_car = (obd.readUint8());
Serial.println(obd.readUint8());
}
if (millis() - timer > 10000) // проверяем сколько прошло миллисекунд
{
res = obd.getCurrentPID(0x05, 1);
if (res) {
Serial.print("Result 0x05 (TEMP): ");
speed_car = (obd.readUint8() - 40);
Serial.println(obd.readUint8() - 40);
}
timer = millis(); // сбрасываем таймер
}
}
}
}
}
void Task2code(void* pvParameters) {
for (;;) {
q_l_sec = (rpm / 60.0) * 2.0 * (time_inj / 1000000.0) * (0.13 / 60.0);
//полная формула
// q_l_sec = (rpm / 60.0) * (кол-во цилиндров / 2.0) * (time_inj / 1000000.0) * ((130.0 / 1000.0) / 60.0)
l_h = q_l_sec * 3600; //литры в час мгновенное
l_100 = (l_h / speed_car) * 100.0; // потуги литры на 100 км тоже потуги
/*Serial.print("L/h ");
Serial.println(l_h);
Serial.print("L/100 ");
Serial.println(l_100);
*/
}
}
void loop() {
}
Good afternoon. I'm using ESP32 and I'm facing a problem. My code works until I include the LiquidCrystal_I2C.h library. After connecting, the ECU does not communicate.