Oled screen with arduino nano spi

I have an ERC12864SBSF-2 display and I want to run it with Arduino nano. The screen communicates via SPI. When I write the code below, nothing happens on the screen

#include <SPI.h>

// Pin definitions
#define CS_PIN 10
#define RESET_PIN 8
#define DISP_PIN 9
#define PWM_PIN 6  // PWM signal pin

void setup() {
  pinMode(CS_PIN, OUTPUT);
  pinMode(RESET_PIN, OUTPUT);
  pinMode(DISP_PIN, OUTPUT);
  pinMode(PWM_PIN, OUTPUT);

  // Reset the display
  digitalWrite(RESET_PIN, LOW);
  delay(10);
  digitalWrite(RESET_PIN, HIGH);

  // Initialize the display
  SPI.begin();
  SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE0));
  digitalWrite(CS_PIN, LOW);

  // Turn on the display
  digitalWrite(DISP_PIN, HIGH);

  // Initialize PWM (brightness control)
  analogWrite(PWM_PIN, 128);  // Set brightness to about 50%

  // Send initialization commands to the display (example commands)
  sendCommand(0xAE);  // Display off
  sendCommand(0xA1);  // Segment remap
  sendCommand(0xC8);  // COM scan direction
  sendCommand(0xA6);  // Normal display
  sendCommand(0xA4);  // Display all points normal
  sendCommand(0xAF);  // Display on

  // Clear display (example method)
  clearDisplay();

  // Write "Hello" to the display
  writeText("Merhaba");
}

void loop() {
  // Display update logic or animations can be added here
}

void sendCommand(uint8_t command) {
  // Code to send a command to the display
}

void clearDisplay() {
  // Code to clear the display
}

void writeText(const char* text) {
  // Code to write text to the display
}

// SPI transaction functions to ensure proper communication
void startSPI() {
  digitalWrite(CS_PIN, LOW);
  SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE0));
}

void endSPI() {
  SPI.endTransaction();
  digitalWrite(CS_PIN, HIGH);
}

Look for if there is any Library for it. That will make programming the display unit much easier.

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