0

Conflict between SD reader and I2C OLED display
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Conflict between SD reader and I2C OLED display

by GiacomInox on Fri Dec 04, 2020 2:24 pm

I'm using the SD card reader in conjunction with the SSD1306 128x64 oled display. Both work correctly when used singularly, initializing the SD reader seems to be preventing the arduino from communicating with the screen:

Code: Select all | TOGGLE FULL SIZE
#include <SD.h>

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

File myFile;
void setup() {
  Serial.begin(9600);
  Serial.print("Initializing SD... ");
  if (!SD.begin(10)) {
    Serial.println("initialization failed!");
    while (1);
  }
  Serial.println("initialization done.");

  //File root = SD.open("/");

  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }

  // Show initial display buffer contents on the screen --
  // the library initializes this with an Adafruit splash screen.

  // Clear the buffer
  display.clearDisplay();

  // Draw a single pixel in white
  display.drawPixel(10, 10, WHITE);

  // Show the display buffer on the screen. You MUST call display() after
  // drawing commands to make them visible on screen!
  display.display();
  delay(2000);
  display.setCursor(0,0);
  myFile = SD.open("TARGET.TXT");
  while(myFile.available())
  {
    Serial.print(myFile.read());
  }
  display.display();
}

void loop() {
}


I'm getting this on the serial monitor:
Initializing SD... initialization done.
SSD1306 allocation failed

What could be the problem?

GiacomInox
 
Posts: 3
Joined: Fri Dec 04, 2020 2:20 pm

Re: Conflict between SD reader and I2C OLED display

by adafruit_support_bill on Fri Dec 04, 2020 2:44 pm

Sounds like a memory problem. What processor are you using?

https://learn.adafruit.com/memories-of- ... ot-dot-dot

adafruit_support_bill
 
Posts: 81608
Joined: Sat Feb 07, 2009 10:11 am

Re: Conflict between SD reader and I2C OLED display

by GiacomInox on Fri Dec 04, 2020 3:01 pm

I'm using an Arduino Uno with a 328p. The editor tells me the RAM usage is at about 60% at compiling. Does the SD require additional memory at runtime?

GiacomInox
 
Posts: 3
Joined: Fri Dec 04, 2020 2:20 pm

Re: Conflict between SD reader and I2C OLED display

by adafruit_support_bill on Fri Dec 04, 2020 4:20 pm

Memory is tight on the UNO. It has only 2K of SRAM. The OLED display takes up a big chunk of that for the frame buffer. The SD library will try to allocate a 512 byte block buffer - plus a little extra for the file structure.

adafruit_support_bill
 
Posts: 81608
Joined: Sat Feb 07, 2009 10:11 am

Re: Conflict between SD reader and I2C OLED display

by GiacomInox on Fri Dec 04, 2020 4:59 pm

I'm only interested in displaying text, and I've read that the text-only U8x8 library doesn't require a buffer. Can it work on any SSD1306 models? I don't fully understand the setup instructions

GiacomInox
 
Posts: 3
Joined: Fri Dec 04, 2020 2:20 pm

Re: Conflict between SD reader and I2C OLED display

by adafruit_support_bill on Fri Dec 04, 2020 5:04 pm

I'm not familiar with that library.

adafruit_support_bill
 
Posts: 81608
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.