I am trying to use an SSD1306 128x64 OLED display with an SD card breakout board; both are setup to use the SPI interface. The display works fine until I include the SD.h file in the code; nothing else is done with the SD card module, just including the SD.h file is all it takes to disable the OLED display (see code below). If I don't include the SD.h file, the display clears and shows the "Initializing SD card..." message.
Any suggestions why this is happening?
BTW: I'm using an UNO.
/*
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 10 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 <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <splash.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define CHAR_WIDTH 6
#define CHAR_HEIGHT 8
#define OLED_DC 6
#define OLED_CS 7
#define OLED_RESET 8
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT,
&SPI, OLED_DC, OLED_RESET, OLED_CS);
// set up variables using the SD utility library functions:
//Sd2Card card;
//SdVolume volume;
//SdFile root;
const int chipSelect = 10;
void setup()
{
display.begin(SSD1306_SWITCHCAPVCC);
display.cp437(true); // Use full 256 char 'Code Page 437' font
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.display();
delay(2000);
display.println("Initializing SD card...");
display.display();
// REAMINING CODE IS COMMENTED OUT
/* if (!card.init(SPI_HALF_SPEED, chipSelect))
{
display.println("initialization failed. Things to check:");
display.println("* is a card inserted?");
display.println("* is your wiring correct?");
display.println("* did you change the chipSelect pin to match your shield or module?");
while (1);
}
else
{
display.println("Wiring is correct and a card is present.");
}
display.display();
// print the type of card
/* display.println();
display.print("Card type: ");
switch (card.type())
{
case SD_CARD_TYPE_SD1:
display.println("SD1");
break;
case SD_CARD_TYPE_SD2:
display.println("SD2");
break;
case SD_CARD_TYPE_SDHC:
display.println("SDHC");
break;
default:
display.println("Unknown");
}
// Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
if (!volume.init(card))
{
display.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
while (1);
}
display.print("Clusters: ");
display.println(volume.clusterCount());
display.print("Blocks x Cluster: ");
display.println(volume.blocksPerCluster());
display.print("Total Blocks: ");
display.println(volume.blocksPerCluster() * volume.clusterCount());
display.println();
// print the type and size of the first FAT-type volume
uint32_t volumesize;
display.print("Volume type is: FAT");
display.println(volume.fatType(), DEC);
volumesize = volume.blocksPerCluster(); // clusters are collections of blocks
volumesize *= volume.clusterCount(); // we'll have a lot of clusters
volumesize /= 2; // SD card blocks are always 512 bytes (2 blocks are 1KB)
display.print("Volume size (Kb): ");
display.println(volumesize);
display.print("Volume size (Mb): ");
volumesize /= 1024;
display.println(volumesize);
display.print("Volume size (Gb): ");
Serial.println((float)volumesize / 1024.0);
display.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) {
}