1

Im currently working on a datalogger that uses oled i2c displays and current sensors. Both of them uses adafruit libraries. To write the data, im using arduino's sd library, but somehow, the sd library interferes with my i2c components that they won't work while sd card functions work. adding any sort of code from the sd library would completely make the i2c components malfunction. To test this, i tried to view 2 different text in 2 different i2c displays.

Here's the current code where the i2c components work :

#include <Adafruit_SSD1306.h>
#include "SdFat.h"

#define OLED_RESET 4
Adafruit_SSD1306 Display1(OLED_RESET);
Adafruit_SSD1306 Display2(OLED_RESET);



int i, j;

void setup()   {

  //Serial.begin(9600);

  Display1.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  Display1.clearDisplay();
  Display1.display();

  Display2.begin(SSD1306_SWITCHCAPVCC, 0x3D);
  Display2.clearDisplay();
  Display2.display();

}


void loop() {

  Display1.setTextSize(1);
  Display1.setTextColor(WHITE, BLACK);
  Display1.setCursor(0, 0 );
  Display1.println("Hello");
  Display1.display();
  Display1.clearDisplay();

  Display2.setTextSize(1);
  Display2.setTextColor(WHITE, BLACK);
  Display2.setCursor(0, 0);
  Display2.println("There");
  Display2.display();
  Display2.clearDisplay();

}

And here is the code where the components doesn't work

#include <Adafruit_SSD1306.h>
#include "SdFat.h"

#define OLED_RESET 4
Adafruit_SSD1306 Display1(OLED_RESET);
Adafruit_SSD1306 Display2(OLED_RESET);
SdFat SD;

int i, j;

void setup()   {

  //Serial.begin(9600);

  Display1.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  Display1.clearDisplay();
  Display1.display();

  Display2.begin(SSD1306_SWITCHCAPVCC, 0x3D);
  Display2.clearDisplay();
  Display2.display();

}


void loop() {

  Display1.setTextSize(1);
  Display1.setTextColor(WHITE, BLACK);
  Display1.setCursor(0, 0 );
  Display1.println("Hello");
  Display1.display();
  Display1.clearDisplay();

  Display2.setTextSize(1);
  Display2.setTextColor(WHITE, BLACK);
  Display2.setCursor(0, 0);
  Display2.println("There");
  Display2.display();
  Display2.clearDisplay();

}

Adding any sort of code that involves the sd card library like adding files or declaring the SD command itself would make the i2c components unusable, does anyone know how to fix this?

8
  • I don't see SD library in your sketch. You use SdFat – Juraj May 29 at 5:17
  • 3
    you run out of memory with the display buffers and the SD buffer – Juraj May 29 at 7:13
  • 1
    the memory is allocated at runtime so the build process can't evaluate it. the display library has buffer = (uint8_t *)malloc(WIDTH * ((HEIGHT + 7) / 8))) – Juraj May 29 at 9:16
  • 1
    There are no compilation errors for the memory issue, because the compiler can only calculate the global/static memory usage. The local variables are not counted there. Thags the reason why the Arduino IDE warns you at (I think) 75% memory usage. That it works with just one display supports the hypopyhsis of running out of memory – chrisl May 29 at 9:20
  • 1
    A practical solution is probably to get an Arduino with more RAM. There are a lot of those, but the Nano Every (6KB rather than 2KB) seems to make sense. Some of the things I mentioned in answer to a similar question might be worth reading. Even with them you might be at or over the limit though. – timemage May 29 at 12:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.