Pages: [1]   Go Down
Author Topic: PCD8544 LCD (Nokia 5110) + SD card SPI issues  (Read 2183 times)
0 Members and 1 Guest are viewing this topic.
California
Offline Offline
Jr. Member
**
Karma: 0
Posts: 51
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I have my LCD working just fine with my Arduino Uno, but when I initialize the SD library via SD.begin() or even just hook up my SD card reader (Seeedstudio SD card shield v2.1) wired via a breadboard rather then plugging in directly so I can use the SPI pins for both then the LCD stops working.   It does not matter if the LCD is initialized before or after the SD card.

Trying to initialize the SD library with the SD card connected and with or without the LCD connected also fails.  I'm using the hardware SPI pins (11-13) and a level shifter for those signals.  Note, that I've modified the PCD8544 library to use 13 = SCLK, 12 = MISO, 11 = MOSI and 9 = SPI select (10 is SD select).

Basically my problems boil down to:
1. I can't initialize the SD card library
2. I can't use the LCD with the SD card

Anyways, I've double & triple checked my wiring and everything seems ok.  Just lost as how to debug this further. 

Also, if anyone can suggest a good app for creating wiring diagrams for a Mac that would be great.  I realize it's hard to debug this without seeing how things are wired up. smiley-sad

Thanks!

Code:
#include <VirtualWire.h>
#include <PCD8544.h>
#include <Wire.h>
#include <RTClib.h>
#include <SD.h>


uint8_t debug = 0;

#undef int
#undef abs
#undef double
#undef float
#undef round

/* Define Digital PINS */
#define SPI_CLK         13 /* SPI CLK */
#define SPI_MISO        12 /* SPI MISO */
#define SPI_MOSI        11 /* SPI MOSI */
#define SD_SELECT       10 /* SD Card SPI Select */
#define LCD_SELECT      9  /* LCD SPI Select */
#define LCD_DC          8  /* LCD data/command */
#define LCD_RESET       7  /* LCD Reset */
#define LED_PIN         6  /* LED Status */
#define RX_PIN          5  /* RF315Mhz RX */

/*
 * DS1307 pins:
 * RTC_SCL = Analog 5 I2C
 * RTC_SDA = Analog 4 I2C
 */

#define GMTOFFSET    -8 * 60 * 60 /* PST is GMT-8 */

#define RF_BAUD 600
#define DELAY 2750

PCD8544 LCD;
RTC_DS1307 RTC;

unsigned long missed = 0;
unsigned long received = 0;
uint8_t temp_mask = 0;
unsigned long mstimer;
int t1 = 0;
int t2 = 0;
int t3 = 0;
int t4 = 0;

void setup() {
    pinMode(LED_PIN, OUTPUT);

    /* USB Serial */
    Serial.begin(9600);

    /* I2C & RTC Setup */
    Wire.begin();
    RTC.begin();

    if (! RTC.isrunning()) {
        Serial.println("RTC is NOT running!");
    }
    // following line sets the RTC to the date & time this sketch was compiled
//    RTC.adjust(DateTime(__DATE__, __TIME__));

   
    /* Wireless receiver */
    Serial.println("Starting receiver!");
    vw_set_ptt_inverted(true);
    vw_set_rx_pin(RX_PIN);
    vw_setup(RF_BAUD);
    vw_rx_start();

    pinMode(LCD_SELECT, OUTPUT);
    pinMode(SD_SELECT, OUTPUT);

    /* initialize LCD */
    LCD.begin_custpins(84, 48, SPI_CLK, SPI_MOSI, LCD_DC,
            LCD_RESET, LCD_SELECT);

    /* initialize SD Card on SPI Bus */
    if (!SD.begin(SD_SELECT)) {
        Serial.println("SD card initialize failed, or not present");
    } else {
        Serial.println("SD card initialize success!");
    }
    delay(3000);
}
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49040
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Trying to initialize the SD library with the SD card connected and with or without the LCD connected also fails.
This would imply that there is not a conflict with the LCD. The problem is simply that you are unable to make the SD card reader/writer work. Is this the case?

Have you tried making the SD read/writer work without the LCD and RTC libraries in the sketch, and without the LCD and RTC connected?
Logged

California
Offline Offline
Jr. Member
**
Karma: 0
Posts: 51
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

No I haven't yet.  I suppose the next step is probably to plug the shield directly to the Uno and see what happens...

Actually, maybe that's my problem: I'm using a level shifter for the data pins and resistor divider for the SPI select from the Uno to the shield... but obviously when the shield is plugged directly into the board those won't be there.  That would infer that the shield already has the circuitry to drop the voltage from 5V to 3.3V and in effect that's happening twice.

Still doesn't explain why adding SD.begin() without the SD shield breaks the LCD... maybe I'm initializing the SPI bus twice and that's "bad"?
Logged

Pages: [1]   Go Up
Jump to: