Slow response with MCP2515/Uno/OLED

Hi all,

I’m very new to this - I come from JavaScript hobby coding into C++. I must admit, JavaScript is much easier :wink:

Anyways, I’ve sourced some parts to build on OBD MFD for my car (2016 Golf GTI).

  • Arduino Uno
  • Elecfreaks CAN Sheild
  • Generic 1.3" OLED (SH1106 I2C)

For the OBD/CAN library, I’m using GitHub - sandeepmistry/arduino-OBD2: An Arduino library for reading OBD-II data from your car over CAN bus
For the OLED library, I’m using u8g2

Its works - but the refresh rate on the display is rather slow (its not smooth). I’ve seen other projects that have instant response to dynamic variables on the display and I’m wondering (and hoping) to get the same result.

Here is my code - am I doing something wrong that is causing the latency on the display?

#include <Wire.h>
#include <CAN.h> // the OBD2 library depends on the CAN library
#include <OBD2.h>
#include <U8g2lib.h>

U8G2_SH1106_128X64_NONAME_2_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);


void showData(float boost, int iat, int rpm){
  
    u8g2.setFont(u8g2_font_ncenB10_tr);
    u8g2.drawStr(5, 17, "BOOST:");
    u8g2.setCursor(75, 15);
    boost = (boost *0.145 - 14.5);
    u8g2.print(boost);
    
    u8g2.setFont(u8g2_font_ncenB10_tr);
    u8g2.drawStr(15, 35, "IAT:");
    u8g2.setCursor(75, 35);
    u8g2.print(iat);

    u8g2.setFont(u8g2_font_ncenB10_tr);
    u8g2.drawStr(9, 52, "RPM:");
    u8g2.setCursor(75, 50);
    u8g2.print(rpm);
}


  
void startUp() {
    u8g2.firstPage();
    do {
      u8g2.drawRFrame(2,2,124,60,7);
      u8g2.setFont(u8g2_font_ncenB14_tr);
      u8g2.drawStr(10,20,"OBD MFD");
     } while ( u8g2.nextPage() );   
}


void setup() {

     CAN.begin(500E3); // set bit rate at 500k
     OBD2.begin();
     u8g2.begin();
     startUp();
     delay(2000);

   while (true) {
    u8g2.firstPage();
       do {
          u8g2.drawRFrame(2,2,124,60,7);
          u8g2.setFont(u8g2_font_ncenB10_tr);
          u8g2.drawStr(15,20,"Connecting.."); 
          } while ( u8g2.nextPage() );
     delay(2000);
     break;

    if (!OBD2.begin()) {
      
      u8g2.firstPage();
       do {
          u8g2.drawRFrame(2,2,124,60,7);
          u8g2.setFont(u8g2_font_ncenB10_tr);
          u8g2.drawStr(15,20,"Failed to connect!");  
          } while ( u8g2.nextPage() );
          break;
      
  }
 }
}


void loop(void) { 
     if(OBD2.begin()){
        float boost = OBD2.pidRead(INTAKE_MANIFOLD_ABSOLUTE_PRESSURE);
        int iat = OBD2.pidRead(AIR_INTAKE_TEMPERATURE);
        int rpm = OBD2.pidRead(ENGINE_RPM);
        u8g2.firstPage();
        do { 
        showData(boost,iat, rpm);
        } while ( u8g2.nextPage() );
  }
}

Thanks,
David

No one?.. :disappointed_relieved:

So I've done some research and testing.

Testing:
When using "Serial.print" I can see that data is polled very fast from the CAN BUS.

Research:
I2C is a lot slower than SPI interface when driving OLED's. I guess the issue I'm experiencing is with the display's HW capabilities. So my lack of research around the OLED interface is what has lead me to such an experience.

But regardless - if anyone can contribute to solving my issue, or if this thread needs to be in another sub-forum - I'd highly appreciate the assistance.