[solved] SD card and OLED troubles (Adafruit OLED 1.5” 1431)


I am trying to use the Adafruit OLED 1.5” 1431 with the Photon.

Development is local with the CLI and the following libraries:

The graphics demo works perfect.
When I try to use the SD card I get the following errors …

bmp.cpp:30:17: error: ‘File’ was not declared in this scope
uint16_t read16(File f);

bmp.cpp:31:17: error: ‘File’ was not declared in this scope
uint32_t read32(File f);

Also …

bmp.cpp:133:20: error: ‘read16’ cannot be used as a function
bmp.cpp:134:63: error: ‘read32’ cannot be used as a function
bmp.cpp:220:23: error: ‘uint16_t read16(File)’ redeclared as different kind of symbol
bmp.cpp:30:10: error: previous declaration of 'uint16_t read16’
bmp.cpp: In function ‘uint32_t read32(File)’:

Currently I am stuck …

Any tips for me?


What code are you using for your project?
Have you tried to build one of the SD-Card samples?

@MikeSeeH, the errors suggest you are missing an #include file. Can you post your app so we can take a look and better help you.

Thanks for your responses so far…
I manage to get the SD card communication working with putting …

uint16_t read16(File &f);
uint32_t read32(File &f);

… at the top of the file just before setup.

Currently I am able to set the color of the screen (fillScreen) and then load the image from the SD card. Unfortunately drawPixel does not work anymore. The screen does not change.

I assume that the CS is still on the SD card … will try to solve this now.

Any tips on that?

I will post the full code on Github and link it here once its working …

@MikeSeeH, the CS for the SD has to be different from the one on the display.

I have …

#define sclk      A3
#define mosi      A5
#define dc        D7
#define cs_oled   D6
#define cs_sd     A2
#define rst       D5
Adafruit_SSD1351 tft = Adafruit_SSD1351(cs_oled, dc, mosi, sclk, rst);

@MikeSeeH, here is the issue - the display runs in SPI mode 3 while the SD requires SPI mode 0. These are opposing modes. The solution is to use one device with software SPI (slower) and the other with hardware SPI which I see you have done for the OLED. You may need to assign different MOSI and SCLK pins than the hardware SPI though that will need to be tested.

I am not sure what you mean. Can you explain the sequence of what works and what doesn’t better?

@peekay123 here is what works …

  1. Initialize the OLED and fillScreen(MAGENTA)
  2. Initializing SD card
  3. Load the BMP file from the SD and iterate through it (debugged via serial)

What is not working:
During step 3 the code calls drawPixel but the image on the OLED does not change.
(Just to be on the safe side I always try to draw in green.)

Here is my code:

As the OLED and SD card share the MOSI and SCLK pins I am not sure I understood you correctly.


… and thanks for your work on the mfGFX and SSD1351 libraries!

@MikeSeeH, you may want to try drawing a few graphic primitives before doing the SD load to see if the display is responding. I have to do a bit of research in the meantime.

Yes this works.

As step 1 I do fillScreen(MAGENTA) and this works perfectly.
A fillScreen after accessing the SD card does not work anymore.

Thanks for your help!

@MikeSeeH, what I proposed is you do some lines and circles prior to the SD stuff.

@peekay123 I included the mfGFX graphic tests before the SD card access and this works.

@MikeSeeH, try putting the tft.begin() code AFTER the SD.begin() code and run again.

I have now …

  Serial.print("Initializing SD card...");
  if (!SD.begin(cs_sd)) { Serial.println("failed!"); return;  }
  Serial.println("SD OK!");
  bmpDraw("lily128.bmp", 0, 0);

Screen stays black …

1 Like

Found the solution … I have to initialize the SD card differently to use software SPI:

SD.begin(mosi, miso, sclk, cs_sd)

Now I can draw on the screen but the image is corrupt … :smile:

Switched now to hardware SPI and the image gets displayed correctly.

Thanks for your help!

@MikeSeeH, not sure what you had first, then switched to, then switched again but glad it’s working :stuck_out_tongue_winking_eye:

1 Like

TFT was software SPI and SD was hardware SPI … although the same pins were used.

a) both software SPI: corrupt image
b) both hardware SPI: correct image

I will cleanup the code and post it as tutorial.

1 Like

Hello Mike
I have the same problem with i2c128x64 oled and sd card like you. I have understand from your post that I have to use software spi for oled but my oled work with i2c protocol. So in your point of view what can I do to solve my problem? And my second question is that in this code :slight_smile:
What I replace with its argument parameters?

I2C is not only a different protocol but an entirely different HW interface.
In order to instruct the library to use that instead of SPI you’ll probably need to call a different constructor or begin() overload - providing the library does support I2C, but Adafruit_SSD1351_Photon does not.