SSD1331 from UNO to MEGA

Hello, I wrote a program for a lot of SSD1331 display using my UNO. Everything work fine. To increase the number of display I need to transfer my code to a MEGA. Sadly nothing work ! Back to my first test program it don’t work also with the MEGA !

#include <Adafruit_GFX.h>
#include <Adafruit_SSD1331.h>
#include <SPI.h>
#define sclk 13
#define mosi 11
#define cs 10
#define rst 9
#define dc 8
// Color definitions
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
Adafruit_SSD1331 display = Adafruit_SSD1331(cs, dc, rst);
void setup() {
display.begin();
display.fillScreen(RED);
delay(300);
display.fillScreen(GREEN);
delay(300);
display.fillScreen(BLUE);
delay(300);
display.fillScreen(BLACK);
delay(1000);
display.setCursor(20,5);
display.setTextColor(WHITE);
display.setTextSize(2);
display.print(“Hello”);
display.setCursor(8,25);
display.setTextColor(RED);
display.setTextSize(2);
display.print(“YouTUBE”);
display.fillRect(10,40, 75, 20, RED);
display.setCursor(20,47);
display.setTextColor(WHITE);
display.setTextSize(1);
display.print(“Subscribe”);
display.drawRect(0,0,96,64,WHITE);
delay(1000);
}
void loop()
{
display.fillRect(10,40, 75, 20, BLACK);
delay(1000);
display.fillRect(10,40, 75, 20, RED);
display.setCursor(20,47);
display.setTextColor(WHITE);
display.setTextSize(1);
display.print(“Subscribe”);
delay(1000);
}

What is the problem ? my MEGA ? library compatibility ? I’m lost

Thanks for your help

Ok guys don't lose your time ! I saw the SPI bus is on different pins on Mega ! I'm a bullshit. I believed in this nice world Arduino would have build compatible boards ! I forgot some enginers like to trap newbies like me :slight_smile:

On your Uno with hardware SPI:

#define sclk 13
#define mosi 11
#define cs   10
#define rst  9
#define dc   8
Adafruit_SSD1331 display = Adafruit_SSD1331(cs, dc, rst);

On your Mega with hardware SPI:

#define sclk 52
#define mosi 51
#define cs   10
#define rst  9
#define dc   8
Adafruit_SSD1331 display = Adafruit_SSD1331(cs, dc, rst);

If you are determined to use the same pins 8-13 on the Mega, you need to use the software constructor:

Adafruit_SSD1331 display = Adafruit_SSD1331( cs, dc, mosi, sclk, rst);

Thanks a lot David. I did'nt know this difference and the possibility to use the software construction. Really thanks for your help.

As a general rule, start with the software constructor. Especially for a new exotic Arduino.
This means that you can use any pins that are convenient.

When you have verified that your screen is working 100%, you can select the correct hardware pins for SCK and MOSI on your Arduino board. First with the software constructor.
Then you can change to the hardware constructor. (which will be faster)

David.