ELMDuino problem with interval readings

Hi,
I am trying to get some information from my Mazda 6 2016 via VLink BT adapter using ESP32 with ELMDuino library. Now the readings are done continuously, but I don`t need to get values so oft. First value give information about distance from latest DPF regeneration, second if DPF regeneration is active or not. Is sufficient to get those values every 3-5 second. How to implement it? I tried to do it with timer and interruption but it looks that is not good solution for BT communication. I want to have LED on when regeneration is active. DPF regeneration distance is for futhure development of project. Could You help me do it in right way?

#include "BluetoothSerial.h"
#include "ELMduino.h"

BluetoothSerial SerialBT;
#define ELM_PORT   SerialBT
#define DEBUG_PORT Serial
#define LED 2 // wbudowana dioda LED
ELM327 vlink; //przypisanie nazwy vlink
byte count1 = 0; //zmienna pomocnicza iteracji
byte count2 = 0; //zmienna pomocnicza iteracji
byte count3 = 0; //zmienna pomocnicza iteracji

void setup()
{
  pinMode(LED, OUTPUT); //ustawienie pinu 2 jako wyjscie

  DEBUG_PORT.begin(115200); //ustawienie do komunikacji po usb
  SerialBT.setPin("1234"); //kod pin do parowania z vlinkiem
  ELM_PORT.begin("M6",true); //aktywacja BT, true=debug on
  
  if (!ELM_PORT.connect("V-LINK"))
  {
	while (count1 < 8) //dioda led miga 4 razy co 1 sekunde gdy nie uda sie polaczyc z interfejsem
	{
  		digitalWrite(LED, !digitalRead(LED));
  		delay(1000);
  		count1++;
	}
	while(1);
  }

  if (!vlink.begin(ELM_PORT))
  {
	while (count2 < 10) //dioda led miga 5 razy co 1 sekunde gdy nie uda sie polaczyc z interfejsem
	{
  		digitalWrite(LED, !digitalRead(LED));
  		delay(1000);
  		count2++;
	}
	while(1);
  }


  Serial.println("Connected to V-LINK");
  while (count3 < 4) //dioda led miga szybko 2 razy uda sie polaczyc z interfejsem
	{
  		digitalWrite(LED, !digitalRead(LED));
  		delay(250);
  		count3++;
	}

  }

void loop()
{
  uint32_t dpfDist = vlink.processPID(34, 1076, 4, 4, 1, 0); //PID odleglosci od ostatniego wypalania
  byte D = vlink.responseByte_0;
  byte C = vlink.responseByte_1;
  byte B = vlink.responseByte_2;

  if (vlink.nb_rx_state == ELM_SUCCESS)
  	{	
		Serial.print("B: "); Serial.println(B);
    		Serial.print("C: "); Serial.println(C);
    		Serial.print("D: "); Serial.println(D);
  	}

  uint32_t dpfRegen = vlink.processPID(34, 896, 1, 1, 1, 0); //PID aktywnej regeneracji filtra
  byte DR = vlink.responseByte_0;

  if (vlink.nb_rx_state == ELM_SUCCESS)
  	{
    		if (DR==1)
		{
	 		digitalWrite(LED, HIGH);
		}
    		else if (DR==0)
		{
			digitalWrite(LED, LOW);
		}
  	}

}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.