CAN Bus and OLED - display not updating

Hi,

I’m using several modules to create a CAN bus network. At the moment I have 2 nodes, one creating an input and the other with the OLED attached displaying the output.

/*

   OLED
   ===
   1....GND: (arduino pin GND)
   2....VCC: (arduino pin 5V)
   3....D0: CLK Clock (arduino pin 13)
   4....D1: MOSI data (arduino pin 11)
   5....RST: Reset (arduino pin 5)
   6....DC: data / command (arduino pin 6)
   7....CS: Chip select signal (arduino pin 7)

   CAN controller
   ===
   1....Int NC
   2....SCK (arduino pin 13)
   3....MOSI (arduino pin 11)
   4....MISO (arduino pin 12)
   5....CS (arduino pin 7)
   6....GND (arduino pin GND)
   7....Vcc (arduino pin 5V)

*/

#include "U8glib.h"            // U8glib library for the OLED
#include <SPI.h>
#include "mcp_can.h"

const int SPI_CAN_CS_PIN = 10;
MCP_CAN CAN(SPI_CAN_CS_PIN);                                    // Set CS pin

unsigned int messageData[2];
unsigned int displayData[2];

//THIS ONE DID WORK - U8GLIB_SH1106_128X64 u8g(13, 11, 10, 9, 8);  // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
U8GLIB_SH1106_128X64 u8g(7, 6, 3, 4, 5);  // SW SPI Com: SCK = 7, MOSI = 6, CS = 3, A0 = 4, RST = 5


void draw(void) {
  u8g.setFont(u8g_font_unifont);                   // select font
  /*u8g.setFont(u8g_font_profont17r);
    u8g.setPrintPos(0,24);
    u8g.print(messageData[0]);
    Serial.println(messageData[0]);
    u8g.setPrintPos(0,48);
    u8g.print(messageData[1]);
    Serial.println(messageData[1]);*/
  u8g.drawStr(20, 20, "Testy!");
}

void displayVariables(void) {
  displayData[0] = messageData[0];
  displayData[1] = messageData[1];
}

void readCAN(void) {
  
  unsigned char messageLength = 0;
  unsigned char messageBuffer[2];
  
  CAN.readMsgBuf(&messageLength, messageBuffer);
  messageData[0] = CAN.getCanId();
  messageData[1] = messageBuffer[1];
}

void drawOLED(void) {
  displayVariables();
  u8g.firstPage();  
  do {
    draw();
  } while( u8g.nextPage() );
}

void setup() {
  
  Serial.begin(9600);
  CAN.begin(CAN_500KBPS);          // init can bus : baudrate = 500k

}


void loop() {

  readCAN();
  drawOLED();
  delay(2000);
}

If I change the test text to display it will not update the display until I comment-out this line CAN.readMsgBuf(&messageLength, messageBuffer);.

I know the data to display should not change before being rendered, and hence the displayVariables() function.

Any ideas would be appreciated.

Something odd is happening. The display text will print when I disconnect the node from the CAN bus. Further more, uncommenting the parts in the draw() function I can see from the Serial console, that the correct data is being received right up to the drawing part ... but then does not update.

I placed some Serial.print statements around the place to get a grip of control:

loop called
readCAN called
drawOLED called
displayVariables called
displayVariables displayData[0]: 112
displayVariables displayData[1]: 0
draw called
draw displayData[0]: 112
draw displayData[1]: 0

But the OLED is not outputting displayData values.