-1

After some time off, I decided to get back into my project after some help from this topic I started earlier Difference in pinout (types?) Uno/Mega. Unfortunately, even tho I have read multiple times what has been said about the SPI pins on a mega, the displays simply will not work. Both my LED strips and rotary encoder are working, so my code compiles and uploads as it should. The displays are ssd1307 using SPI.

Pinout from MEGA to displays
49 > RST for display1/display2/display3
50 > DC for display1/display2/display3
51 > SDA for display1/display2/display3
52 > SCK for display1/display2/display3

33 > CS for display1
34 > CS for display2
35 > CS for display3

Here is the code I am trying to use:

#include <Adafruit_NeoPixel.h>
#include "HCuOLED.h"
#include "SPI.h"

Adafruit_NeoPixel REVLEDS = Adafruit_NeoPixel(7, 2, NEO_GRB);
Adafruit_NeoPixel DASHLEDS = Adafruit_NeoPixel(3, 3, NEO_GRB);

#define SCK 52
#define SDA 51
#define DC 50
#define RST 49

HCuOLED HCuOLED_5(SSD1307, 33, DC, RST); // For SSD1307 displays (HCMODU0050 & HCMODU0052)
HCuOLED HCuOLED_4(SSD1307, 34, DC, RST); // For SSD1307 displays (HCMODU0050 & HCMODU0052)
HCuOLED HCuOLED_3(SSD1307, 35, DC, RST); // For SSD1307 displays (HCMODU0050 & HCMODU0052)

#define s1 6
#define s2 5
#define key 4

int newCounter = 0;
int oldCounter = 0;
int oldState;
int newState;
int rotated = 0;
int keyState = 0;
int keyReset = 0;

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

  REVLEDS.begin();
  REVLEDS.setBrightness(25);

  DASHLEDS.begin();
  DASHLEDS.setBrightness(25);

  pinMode(s1, INPUT);
  pinMode(s2, INPUT);

  oldState = 1;
  newState = oldState;

  HCuOLED_5.Reset();
  pinMode(53, OUTPUT);
}

void loop() {

  newState = digitalRead(s1);
  if(newState != oldState){
    if(digitalRead(s2)!= oldState){
      newCounter ++;
    } else {
      newCounter --;
    }
    if(newCounter == (oldCounter+2) ||newCounter == (oldCounter-2)){
      if(newCounter > oldCounter) rotateRight();
      else rotateLeft();
      oldCounter = newCounter;
    }    
  }
  oldState = newState;

  keyState = digitalRead(key);
  //Serial.println(keyState);
  if(keyState == LOW && keyReset == 0){
    onButtonPress();
    keyReset = 1;
  } else if (keyReset == 1 && keyState == HIGH){
    keyReset = 0;
  }  

  for(int i = 0; i < 7; i++){
  REVLEDS.setPixelColor(i, 0,255,0);}
  REVLEDS.show();

  for(int i = 0; i < 3; i++){
  DASHLEDS.setPixelColor(i, 0,0,255);}
  DASHLEDS.show();

  //display 5
  HCuOLED_5.SetFont(Terminal_8pt);
  HCuOLED_5.Cursor(44,0);
  HCuOLED_5.Print("Cpt");
  HCuOLED_5.Cursor(20,10);
  HCuOLED_5.Print("Fastlane");
}

void onButtonPress(){
  Serial.println("Pressed button");
}

void rotateLeft(){
  Serial.println("Rotated left");
}

void rotateRight(){
  Serial.println("Rotated right");
}

Now the question is, what am I missing? TIA!

3
  • the SSD1307 supports SPI and I2C. you should provide a link to the display module. SDA and SCK are used to label I2C pins
    – Juraj
    Sep 23, 2018 at 6:04
  • Sorry forgot to add that this was the SPI version of the ssd1307.
    – sdieters
    Sep 23, 2018 at 9:45
  • Pin 53 is set to OUPUT as you can see in the code. In the link of my original post you can see that I already had these SPI display work on mu UNO, but not on my MEGA. The display in question are these: nl.aliexpress.com/item/… I am also planning on adding 2 bigger ones, which are these: nl.aliexpress.com/item/…
    – sdieters
    Sep 23, 2018 at 10:01

2 Answers 2

0

The displays do not use SPI MISO pin. It is 12 in Uno and 50 on Mega. On Mega you try to use pin 50 for DC pin of the displays and it creates a conflict with SPI. MISO should be an INPUT and DC is OUTPUT.

0

Found the problem... after my break, i forgot that the .refresh() command is actually the command that displays something on the screen, while I kept thinking it was to clear the screen. After adding that to my code together with .clearBuffer(), everything works with the following pinout:

Pinout from MEGA to displays
48 > RST for display1/display2/display3
49 > DC for display1/display2/display3
51 > SDA for display1/display2/display3
52 > SCK for display1/display2/display3

33 > CS for display1
34 > CS for display2
35 > CS for display3

With the following code to show different stuff on screen:

#include "HCuOLED.h"
#include "SPI.h"

#define SCK 52
#define SDA 51
#define DC 49
#define RST 48

HCuOLED HCuOLED_5(SH1106, 33, DC, RST); // For SSD1307 displays (HCMODU0050 & HCMODU0052)
HCuOLED HCuOLED_4(SH1106, 34, DC, RST); // For SSD1307 displays (HCMODU0050 & HCMODU0052)
HCuOLED HCuOLED_3(SH1106, 35, DC, RST); // For SSD1307 displays (HCMODU0050 & HCMODU0052)

int tCounter = 0;

void setup(){  
  HCuOLED_5.Reset();
  //pinMode(53, OUTPUT);
}

void loop() {
  //display 3
  HCuOLED_3.SetFont(Terminal_8pt);
  HCuOLED_3.Cursor(44,0);
  HCuOLED_3.Print("Cpt");
  HCuOLED_3.Cursor(20,10);
  HCuOLED_3.Print("Fastlane");
  HCuOLED_3.SetFont(LCDLarge_24pt);
  HCuOLED_3.Cursor(20,30);
  HCuOLED_3.Print("3 - ");  
  HCuOLED_3.Cursor(65,30);
  HCuOLED_3.Print(tCounter);
  HCuOLED_3.Refresh();
  HCuOLED_3.ClearBuffer();

  //display 4
  HCuOLED_4.SetFont(Terminal_8pt);
  HCuOLED_4.Cursor(44,0);
  HCuOLED_4.Print("Cpt");
  HCuOLED_4.Cursor(20,10);
  HCuOLED_4.Print("Fastlane");
  HCuOLED_4.SetFont(LCDLarge_24pt);
  HCuOLED_4.Cursor(20,30);
  HCuOLED_4.Print("4 - ");
  HCuOLED_4.Cursor(65,30);
  HCuOLED_4.Print(tCounter);
  HCuOLED_4.Refresh();
  HCuOLED_4.ClearBuffer();

  //display 5
  HCuOLED_5.SetFont(Terminal_8pt);
  HCuOLED_5.Cursor(44,0);
  HCuOLED_5.Print("Cpt");
  HCuOLED_5.Cursor(20,10);
  HCuOLED_5.Print("Fastlane");
  HCuOLED_5.SetFont(LCDLarge_24pt);
  HCuOLED_5.Cursor(20,30);
  HCuOLED_5.Print("5 - ");
  HCuOLED_5.Cursor(65,30);
  HCuOLED_5.Print(tCounter);
  HCuOLED_5.Refresh();
  HCuOLED_5.ClearBuffer();

  tCounter++;
}
4
  • and the pin 50?
    – Juraj
    Sep 23, 2018 at 14:42
  • Unused. However It also works if I don't set pin 53 to OUTPUT. Why is this?
    – sdieters
    Sep 23, 2018 at 15:07
  • SPI library does it in begin
    – Juraj
    Sep 23, 2018 at 15:39
  • was use of pin 50 as DC one of the reasons why it didn't work?
    – Juraj
    Sep 23, 2018 at 15:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.