Nokia 5110 LCD + SD card module

Hi, im a newbie in arduino and im doing a datalogger project which is to store adc data values into the sd card. im using arduino uno, keypad and also nokia 5110 lcd to display some strings. However, im facing problems logging data into the sd card as i interface with nokia 5110 lcd..

When i pressed '1' on the keypad, on the serial monitor it shows :

FreeRam:
277

Press '1' to start recording ADC data
Press '2' to stop recording
Press '3' to convert and store in SD card
Sample pins: 2
ADC bits: 10
ADC clock kHz: 125
Sample Rate: 4032.26
Sample interval usec: 248.0000
error: open csvFile failed

I wonder what is the problem as it does not continue to log data into the SD card..
Attached is my code!
Thanks!!

Adafruit_Analog_keypad.ino (24.8 KB)

Use the hash icon to post your code in the proper manner. It is probably just a pin conflict, most likely where the 5110 is on pin 4, or perhaps pin 10. If you are short of pins, note that 5110 can go on the SPI bus.

Thanks for replying!!
My pins for 5110 are as follows:

SCLK - Arduino UNO pin 8
DIN - Arduino UNO pin 9
DC - Arduino UNO pin 4
CE - Arduino UNO pin A0
RST - Arduino UNO pin A1

For the SD card,

SD UNO
GND GND
+5V +5V
CS Pin 10
MOSI Pin 11
SCK Pin 13
MISO Pin 12

Is any of my pins wrong?

Quite possibly. Now is the time to take a deep breath, throw caution to the winds, bite the bullet, and post the code - as advised previously.

Also, does the 5110 work OK without the SD?

The code is abit too long to be posted here..so i attached it on my first post!
Sorry if i caused any inconvenience but are you able to view my code?

The 5110 can work with and without the SD card. It is able to print strings!
But the problem is it does not log data..

Sorry about the post earlier.. i think i made a mistake saying that the 5110 work well with and without SD card..
I tested with the CardInfo code to check if the sd card is present without putting in the Nokia LCD code yet, and the SD card does not have a problem.
However, after adding in the Nokia 5110 LCD code, i could not even write a "Hello" on the LCD screen.
The screen only shows an Adafruit logo and the serial monitor shows weird characters..

/*
  SD card test

 This example shows how use the utility libraries on which the'
 SD library is based in order to get info about your SD card.
 Very useful for testing a card when you're not sure whether its working or not.

 The circuit:
  * SD card attached to SPI bus as follows:
 ** MOSI - pin 11 on Arduino Uno/Duemilanove/Diecimila
 ** MISO - pin 12 on Arduino Uno/Duemilanove/Diecimila
 ** CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila
 ** CS - depends on your SD card shield or module.
 		Pin 4 used here for consistency with other Arduino examples


 created  28 Mar 2011
 by Limor Fried
 modified 9 Apr 2012
 by Tom Igoe
 */
// include the SD library:
#include <SPI.h>
#include <SD.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>

// Software SPI (slower updates, more flexible pin options):
// pin 7 - Serial clock out (SCLK)
// pin 6 - Serial data out (DIN)
// pin 5 - Data/Command select (D/C)
// pin 4 - LCD chip select (CS)
// pin 3 - LCD reset (RST)
Adafruit_PCD8544 display = Adafruit_PCD8544(8, 9, 4, A0, A1);

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;

// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
const int chipSelect = 10;

void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  display.begin();
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  Serial.print("\nInitializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output
  // or the SD library functions will not work.
  pinMode(10, OUTPUT);     // change this to 53 on a mega


  // we'll use the initialization code from the utility libraries
  // since we're just testing if the card is working!
  if (!card.init(SPI_HALF_SPEED, chipSelect)) {
    Serial.println("initialization failed. Things to check:");
    Serial.println("* is a card is inserted?");
    Serial.println("* Is your wiring correct?");
    Serial.println("* did you change the chipSelect pin to match your shield or module?");
    return;
  } else {
    Serial.println("Wiring is correct and a card is present.");
  }

  // print the type of card
  Serial.print("\nCard type: ");
  switch (card.type()) {
    case SD_CARD_TYPE_SD1:
      Serial.println("SD1");
      break;
    case SD_CARD_TYPE_SD2:
      Serial.println("SD2");
      break;
    case SD_CARD_TYPE_SDHC:
      Serial.println("SDHC");
      break;
    default:
      Serial.println("Unknown");
  }

  // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
  if (!volume.init(card)) {
    Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
    return;
  }


  // print the type and size of the first FAT-type volume
  uint32_t volumesize;
  Serial.print("\nVolume type is FAT");
  Serial.println(volume.fatType(), DEC);
  Serial.println();

  volumesize = volume.blocksPerCluster();    // clusters are collections of blocks
  volumesize *= volume.clusterCount();       // we'll have a lot of clusters
  volumesize *= 512;                            // SD card blocks are always 512 bytes
  Serial.print("Volume size (bytes): ");
  Serial.println(volumesize);
  Serial.print("Volume size (Kbytes): ");
  volumesize /= 1024;
  Serial.println(volumesize);
  Serial.print("Volume size (Mbytes): ");
  volumesize /= 1024;
  Serial.println(volumesize);


  Serial.println("\nFiles found on the card (name, date and size in bytes): ");
  root.openRoot(volume);

  // list all files in the card with date and size
  root.ls(LS_R | LS_DATE | LS_SIZE); 

}

void loop(void) {
  display.println("Hello");
  display.display();
}

Matoo:
The code is abit too long to be posted here..so i attached it on my first post!
Sorry if i caused any inconvenience but are you able to view my code?

Not really, there are too many irrelevant comments and I'm struggling to find the setup section. I'm afraid this is getting all too scientific for me, not helped by the fact that I have the luxury of no choice about where the SD card goes, and the use of standard code.
As a consequence I have

const int chipSelect = 4;

void setup() [
pinMode(10, OUTPUT);// Uno

just like everybody else does, whereas you have the 5110 on 4. I use D6,7,5,11,13 for 5110, CE is pin 7.

I guess your problem lies around there somewhere.

Is your Pin 11 and 13 of the 5110 connected together with the SCK and MOSI of the SD card?

Pin 13 - SCLK
Pin 11 - DIN
Pin 7 - CE
Pin 6 - DC
Pin 5 - RST

My chipSelect for SD card is 10..

Yes. This is the SPI bus.

My note:

c5110 pin assignments

1 RST D6
2 CE D7
3 DC D5
4 DIN D11 MOSI 11
5 CLK D13 CLK 13
6 VCC 3v3
7 LED to GND GND
8 GND GND

The library may need to be edited to accommodate this.

Ok! Thanks! Im trying now.
What do you mean by the library need to be edited?

Matoo:
What do you mean by the library need to be edited?

I said MAY need to be edited. I am using the standard Philips library PCD8544. The pin call is included therein, which is a really bad idea but, once done, should not need to be touched again. The Henning Karlsen library does not do this, but I'm happy to stick with the original.