256x64 SH1122 7pin SPI OLED example for MKR boards [code example]

This is an example connection and code for Arduino MKR boards

  • Install U8g2 library
  • If sketch wont compile because of <Wire.h> is missing, add it then remove include later. It is not needed but takes some space.
  • At max brightness it consumes ~60mA
#include <Arduino.h>
#include <SPI.h>
#include <U8g2lib.h>

/* 
SH1122 7pin SPI 256x64 OLED example 
by Killzone_Kid 

Display		|		Arduino MKR Board
	GND		|		GND
	VCC		|		VCC (3.3V)
	SCL		|		SCK (Pin 9)
	SDA		|		MOSI (Pin 8)
	RST		|		Pin 6
	DC		|		Pin 7
	CS		|		Pin 4 (PIN_SPI_SS)
*/

#define PIN_DC 7
#define PIN_RST 6

U8G2_SH1122_256X64_F_4W_HW_SPI u8g2(U8G2_R0, PIN_SPI_SS, PIN_DC, PIN_RST);

void setup()
{
	u8g2.begin();
}

void loop()
{
	u8g2.clearBuffer();
	u8g2.setFont(u8g2_font_helvB08_tr);
	u8g2.drawStr(0, 9, "Hello World");
	u8g2.drawStr(40, 20, "Hello World");
	u8g2.drawStr(80, 31, "Hello World");
	u8g2.drawStr(120, 42, "Hello World");
	u8g2.drawStr(160, 53, "Hello World");
	u8g2.drawStr(200, 64, "Hello World");
	u8g2.sendBuffer();
	delay(1000);

	for (int i = 0; i < 3; ++i)
	{
		for (int j = i; j < 64; j += 3)
		{
			u8g2.drawHLine(0, j, 256);
			u8g2.sendBuffer();
			delay(10);
		};
	}

	delay(1000);
}

NOTABLE PROBLEMS WITH THIS DISPLAY:
It doesnt handle full screen fill well
It makes noise

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