Nano+MCP23017+KS0108 LCD 128x64 problem

Hi, I have a problem with starting a 128x64 LCD display with a KS0108 controller and an MCP23017 I2C expander, with an Arduino nano module, Arduino and LCD via direct connection work correctly, via the expander I have no results. here is the code:

#include <Wire.h>
#include <Adafruit_MCP23X17.h>  // Biblioteka do obsługi MCP23017
#include <KS0108_GLCD.h>  // Biblioteka do obsługi KS0108

Adafruit_MCP23X17 mcp;  // Tworzymy obiekt dla MCP23017

// Definicje pinów MCP23017 dla wyświetlacza KS0108
#define GLCD_CS1          4   // Pin 4 - CS1
#define GLCD_CS2          3   // Pin 3 - CS2
#define GLCD_RESET        2   // Pin 2 - RESET
#define GLCD_RS           7   // Pin 7 - DI (Data Input, odpowiednik RS w Twojej konfiguracji)
#define GLCD_RW           6   // Pin 6 - RW (Read/Write)
#define GLCD_E            5   // Pin 5 - E (Enable)
#define GLCD_DB0          8   // Pin 8 - DB0
#define GLCD_DB1          9   // Pin 9 - DB1
#define GLCD_DB2          10  // Pin 10 - DB2
#define GLCD_DB3          11  // Pin 11 - DB3
#define GLCD_DB4          12  // Pin 12 - DB4
#define GLCD_DB5          13  // Pin 13 - DB5
#define GLCD_DB6          14  // Pin 14 - DB6
#define GLCD_DB7          15  // Pin 15 - DB7

// Konstruktor z 15 argumentami, gdzie RS = DI (Data In)
KS0108_GLCD display(GLCD_RS, GLCD_RW, GLCD_E, GLCD_DB0, GLCD_DB1, GLCD_DB2, GLCD_DB3, GLCD_DB4, GLCD_DB5, GLCD_DB6, GLCD_DB7, GLCD_CS1, GLCD_CS2, GLCD_RESET);

void setup() {
  Serial.begin(9600);

  // Inicjalizacja MCP23017 z adresem I2C
  if (!mcp.begin_I2C(0x20)) {  // Używamy domyślnego adresu I2C 0x20
    Serial.println("MCP23017 initialization failed!");
    while (1);  // Zatrzymuje program, jeśli MCP23017 nie jest poprawnie zainicjowany
  }

  // Skonfiguruj piny MCP23017 jako wyjścia
  mcp.pinMode(GLCD_RS, OUTPUT);     // RS (Data/Command)
  mcp.pinMode(GLCD_RW, OUTPUT);     // RW (Read/Write)
  mcp.pinMode(GLCD_E, OUTPUT);      // E (Enable)
  mcp.pinMode(GLCD_CS1, OUTPUT);    // CS1 (Chip Select 1)
  mcp.pinMode(GLCD_CS2, OUTPUT);    // CS2 (Chip Select 2)
  mcp.pinMode(GLCD_RESET, OUTPUT);  // RESET (Reset)
  mcp.pinMode(GLCD_DB0, OUTPUT);    // DB0 - DB7 (Data bits)
  mcp.pinMode(GLCD_DB1, OUTPUT);    
  mcp.pinMode(GLCD_DB2, OUTPUT);    
  mcp.pinMode(GLCD_DB3, OUTPUT);    
  mcp.pinMode(GLCD_DB4, OUTPUT);    
  mcp.pinMode(GLCD_DB5, OUTPUT);    
  mcp.pinMode(GLCD_DB6, OUTPUT);    
  mcp.pinMode(GLCD_DB7, OUTPUT);    

  // Inicjalizacja wyświetlacza
  if (!display.begin(true)) {  // True dla CS aktywowanego na wysokim poziomie
    Serial.println("Display initialization failed!");
    while (1);  // Zatrzymuje program, jeśli wyświetlacz nie jest poprawnie zainicjowany
  }

  // Zerowanie pamięci wyświetlacza
  clearScreen();  // Funkcja czyszcząca ekran

  // Rysowanie piksela w lewym górnym rogu
  display.drawPixel(0, 0, KS0108_ON);
  display.display();  // Wyświetl piksela
}

void loop() {
  // Brak kodu w pętli głównej, ponieważ testujemy tylko wyświetlacz
}

void clearScreen() {
  // Zerowanie pamięci wyświetlacza
  display.clearDisplay();  // Zerowanie bufora wyświetlacza
  delay(10);  // Czekaj chwilę, aż czyszczenie zostanie zakończone
}

SDA-A4, SCL-A5 pinout
Can someone help or point me in the right direction?

A3?

van_der_decken yes,its A5-SCL :+1:

I did wonder. :slight_smile:

It is not at all clear to me how this constructor

KS0108_GLCD display(GLCD_RS, GLCD_RW, GLCD_E, GLCD_DB0, GLCD_DB1, GLCD_DB2, GLCD_DB3, GLCD_DB4, GLCD_DB5, GLCD_DB6, GLCD_DB7, GLCD_CS1, GLCD_CS2, GLCD_RESET);

which sets up the associated output pins on the Nano is expected to somehow connect to the I2C expander. The KS0108_GLCD library seems to have no provisions for I2C operation. Perhaps you could explain how this works behind the scenes. Because on the face of it, you appear to have an I2C expander that you configure various pins as outputs, and a display library that knows nothing about that. I'm just not seeing how that works.

Wrong library. As pointed out, that library is only for use with KS0108 directly connected to Arduino pins.

I have used this one successfully:

That is because you can't do that.
Why do you want to use an expander anyway?

Thanks for the tip, I changed the pin configuration in this library for my expander and it worked. :+1: