Thanks for the reply. I changed the program around to write to the LCD then init the SD all in setup()
Then I added some more code to loop() to make it clearer that it was writing to the LCD.
The result was that the initial LCD operation worked, as you would expect, then the SD init waits for a while, several seconds before returning false.
The subsequent LCD operations in loop() fail to do anything, I can see the loop running from the Serial.println() calls, but nothing on the LCD.
Here's the revised code:
Code:
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <SD.h>
#define OLED_DC 3
#define OLED_CS 6
#define OLED_CLK 1
#define OLED_MOSI 2 //Data
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
Sd2Card card;
int count =0;
const int chipSelect = 0;
void setup() {
delay(5000);
pinMode(chipSelect, OUTPUT);
pinMode(OLED_CS, OUTPUT);
Serial.begin(9600);
Serial.println("start");
display.begin(SSD1306_SWITCHCAPVCC);
display.clearDisplay();
// draw mulitple circles
testdrawcircle();
display.display();
delay(2000);
Serial.println("display done");
if (!card.init(chipSelect)) {
Serial.println("Card failed, or not present");
}
else {
Serial.println("card initialised.");
}
}
void loop() {
display.clearDisplay();
// draw mulitple circles
testdrawcircle();
display.display();
delay(2000);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
count++;
display.println("hello world");
Serial.println("hello world");
display.display();
delay(1000);
}
void testdrawcircle(void) {
for (int16_t i=0; i<display.height(); i+=2) {
display.drawCircle(display.width()/2, display.height()/2, i, WHITE);
display.display();
}
}
It isn't much different, but I took out the splash screen display because it was doing something odd that doesn't look important just now and I replaced it with drawing circles and a text message.