SD module and Nokia 5110(8544) display

Hi to all! Any help is highly appreciated, therefore thanks in advance for reading and responding.

I am trying to develop a temperature logger (into SD card) that is also displaying the reading on a Nokia 5110 (which uses Philips8544) display in real time.

I am able to make DHT11 temperature/humidity sensor work separately with SD(logging temperature and humidity) and the Display(displayin the temperature and humidity. When it comes into combining SD and the display I am stuck.

Currently I have taken out the DHT11 sensor and added a temporary variable-counter with for().
Connection diagram is at the beginning comments in the code.

Compiler finds no errors. When I upload the code SD logger works but display is stuck with star logo of Adafruit. When I move following part of the code into setup() then display works but logger stops.

display.clearDisplay();
display.setTextSize(2);
display.setTextColor(BLACK);
display.print(i); 
display.display();
#include <SPI.h>
#include <SD.h>
const int chipSelect = 4; //connects to SD reader modules pin 5(from left)
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
Adafruit_PCD8544 display = Adafruit_PCD8544(13, 12, 5, 7, 6);

// Display is connected to :
// pin 13 - Serial clock out (CLK)
// pin 12 - Serial data out (DIN)
// pin 5 - Data/Command select (DC)
// pin 7 - LCD chip select (CE)
// pin 6 - LCD reset (RST)


//SD module is connceted to:
//MISO-12
//CLK-13
//MOSI-11
//SS-4

void setup() {
Serial.begin(9600);
display.begin();
display.setContrast(28);
//if I move display.print(); to here then the functions works
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
//      return;
}
}

void loop() {

int x = 1;
for (int i = 0; i > -1; i = i + x) {
File dataFile = SD.open("datalog.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
  dataFile.println(i);
  dataFile.close();
  
  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(BLACK);
  display.print(i);
  display.display();
  
  // print to the serial port too:
  Serial.println(i);
}
if (i == 255) x = -1;             // switch direction at peak
delay(100);
}
}

At a guess, I think your LCD wiring might be the problem. The matter is clouded by you using the SPI bus. The 5110 can run on SPI but it doesn't care if it is on Arduino's SPI bus or not. Indeed, the Henning Karlsen library specifically calls for wiring off the SPI bus. I understand this is because it has its own software version in the library and, as a result, my 5110 shield runs fine on a Uno using SPI and a Mega without SPI, but I had to edit the library in order to do this. From this though, one would expect that, if 5110 is on Arduino's SPI bus the wiring has to comply to that bus and I don't think yours does. I think my 5110 was

4 DIN D11 MOSI 11
5 CLK D13 CLK 13

If your 5110 is working fine in a simple hello world without any reference to SPI or SD, I think that proves the point, as your SPI pins are only SPI if you are using the SPI library.

Nick_Pyner thanks for the help.
I am a bit more confused, now. You suggest to use SPI without calling SPI.h library? Which library to modify then?
As per connection CLK is already on pin 13. You suggest to switch DIN(MOSI) from 12 to 11? Have tried -no success. I have read tons of datasheets and forums but cannot figure out whether it's allowed to to assign SPI to specific pins or any pin. Some say any pins might be assigned for SPI some say only Chip Enable AKA Chip Select AKA Slave Select should be D4(some say D10) and the rest is flexible......

BTW I am trying it on PRO MINI board.

Interrupt:
You suggest to use SPI without calling SPI.h library? Which library to modify then?

No, I am saying the 5110 does not need the SPI library, indeed I don't think I have ever seen a 5110 demo that uses it. Your SD card run on Arduino's hardware SPI and must have the library. You don't need to modify any library, even though I did.

As per connection CLK is already on pin 13. You suggest to switch DIN(MOSI) from 12 to 11?

OK if you have CLK on 13, but I'm sure I had DIN on pin 11.

Have tried -no success. I have read tons of datasheets and forums but cannot figure out whether it's allowed to to assign SPI to specific pins or any pin. Some say any pins might be assigned for SPI some say only Chip Enable AKA Chip Select AKA Slave Select should be D4(some say D10) and the rest is flexible......

5110 can go anywhere but, if you are using hardware SPI for SD you can only use the hardware SPI pins, and in the prescribed manner. The CS pin is NOT part of the SPI bus and can be anywhere but, for SD, is usually pin 4 by convention, and that is the common pin used by the standard ethernet/SD shield. Pin 10 must be called for output when using SD on a Uno, but need not be actually connected.

I believe all of the above applies to Pro Mini, as it is just a stripped-down Uno and uses the same pins.