stanleyhuangyc / ArduinoOBD

OBD-II library and sketches for Arduino
http://freematics.com
986 stars 518 forks source link

ReadPID is slow :( is there an alternative way to readPIDs that doesn't block code whilst waiting to receive the PID data? #63

Open IAmOrion opened 5 years ago

IAmOrion commented 5 years ago

I'm making a circuit that has an OLED display to display the values I've read, I have 2 buttons to change what is shown on the OLED, and I also have a strip of NeoPixels that are acting as an RPM / Shift light.

The problem I'm having, is that the NeoPixels don't update quick enough and the Display also has a pause between switching between displays. Also worth noting, I had to use interrupts for my buttons since they were unreliable using a "normal" method of checking for button inputs - again due to whatever is blocking code from this library.

If I fake the data, and don't use the library, everything works great - so why is the library code-blocking?

I've actually just edited this post as I thought it was due to using delay in the library, however I spotted the delays are only used in an I2C related function (so not relevant to my use case of UART) and also after setting the baud rate. So WHY is it pausing? Why does it make my sketch/arduino pause? (I'm actually using an Adafruit ItsyBitsy M0)

If I don't call "readPIDS" then everything is perfect, as soon as I need data, it delays everything but I don't get why.

Using millis() in functions to time the delay, it appears to be blocking for 400 - 500ms each loop