Arduino Nano R4 with u8g2 and LED-Display 128x64 on macos

Hi @ruediheimlicher

I was not able to reproduce this. When I run your sketch on my board, it blinks after uploading, even when the board is only powered by the USB cable.

My suggestion for troubleshooting the problem you encountered would be to add some Serial.println calls to determine whether the u8g2.begin call is hanging. Something like this:

  Serial.begin(9600);
  while (!Serial) {}  // Wait for serial port to be opened in Serial Monitor.
  pinMode(led, OUTPUT);

  Serial.println("Initializing display...");
  if (u8g2.begin()) {
    Serial.println("Display initialization successful!");
  } else {
    Serial.println("Display initialization failed :(");
  }

I was able to reproduce this. I was able to fix it by adding a u8g2.setFont call to the setup function and a u8g2.sendBuffer call after the u8g2.print call:

#include <U8g2lib.h>

// give it a name:
int led = LED_BUILTIN;
uint8_t loopcounter = 13; // dummy

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

void setup() 
{
  Serial.begin(9600);
  pinMode(led, OUTPUT);
  u8g2.begin();
  u8g2.setFont(u8g2_font_ncenB08_tr);

  u8g2.drawFrame(4,4,40,10);

  u8g2.sendBuffer();
}

void loop() 
{
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  u8g2.setCursor(4,32);
  u8g2.print(loopcounter++);
  u8g2.sendBuffer();
  delay(1000);               // wait for a second
}

Give that sketch a try.

It seems to be a quirk of Arduino IDE 1.x. I am able to reproduce it by uploading while the port of the board is open in Serial Monitor. I don't think it causes any problems, so you can ignore it if you like. If it bothers you, just update to the modern Arduino IDE 2.x and the problem will no longer occur.