Particle Photon OLED screen and SD card demo

With the help of this great community (especially @peekay123 – thanks!) I was able to build my first Photon demo that I would like to share with you. It is a mashup of some code and libraries I have taken from different posts in this forum and external sources. I tried to document this where possible.

Demo project on Github


Libraries and code


OLED      Photon
SI        A5
CL        A3
DC        D7
R         D5
OC        D6
SC        A2
SO        A4
CD        none
3V        none
+         3.3v
G         GND

Image on SD Card

The image displayed on the screen gets loaded from the SD card. Place it as logo.bmp on the card or change the name in line #102. The file format must be BMP with 24bit.


  • I use the Particle Dev to compile the code in the cloud and push it on the Photon. You can use a local folder structure as long as you don’t refer to it in the #include statements (so only use the .h filenames).
  • In the code I found online I could not use the bmpDraw function as the declarations of read16 and read32 were missing. These are added in the line 69 and 70.
  • Be sure to not mix hardware and software SPI. I had this problem …

Have fun and get in contact if you have questions!


@MikeSeeH, where’s the video! :stuck_out_tongue:

1 Like

Just tried to run this and I keep getting the following error:

Do you have any idea why?


That comes from the fact that Serial now is a macro already, so this code from the library won’t work anymore

#	define SERIAL_DEVICE	0				/* 0:SerialUSB  1=: Serial UART device */
#	if SERIAL_DEVICE == 0  	
#		define Serial Serial				/* Use USB CDC port */
#		define BPS_9600		/* Nothing */ 
#		define BPS_115200 	/* Nothing */ 
#	else

But you’d be better off with the newer/better/faster SDFat library available on Web IDE anyway.
Otherwise you could downgrade to firmware version 0.4.7 and build against that.

Thank’s for the quick reply! I had a feeling something like that was happening. I have programming experience, but new to the embedded world. In fact, I ordered this exact screen just so I could learn off this example!

I just downloaded the SDFat library. Does this replace the SD-card-library-photon-compact library then? After replacing, whats the first thing in the existing code that should be tweaked?

Thanks again!

That's the plan.

I've not tried that combination, but just replace all includes for the old library with the new ones and have a try what errors come.
If they are too obscure, feel free to ask.
Maybe I or someone else finds the time to try it too.

Sounds good. Really appreciate the help, I’ll give myself a good week to try to make things happen and will then report back.

1 Like

One thing I noticed with the new library and that demo .ino is the need to use #pragma SPARK_NO_PREPROCESSOR.

So after I added this to the top of the sketch, the project at least builds


#include "Particle.h"
#include "Adafruit_SSD1351.h"               // additional set of .h/.cpp files in the project 
#include "Adafruit_mfGFX/Adafruit_mfGFX.h"  // import contributed library from the lib drawer
#include "SdFat/SdFat.h"                    // import contributed library from the lib drawer

#define SD_CS  A0    // choose your own chip select pin for SD card
#define cs     D5    // choose your own chip select pin for display
#define rst    D6    // choose your own reset pin for display
#define dc     D4    // choose your own data/command pin for display
#define sclk SCLK    // shared hardware SPI pins
#define mosi MOSI    //

// forward declarations (needed due to SPARK_NO_PREPROCESSOR)
void bmpDraw(char *filename, uint8_t x, uint8_t y);
uint16_t read16(File f);
uint32_t read32(File f);

// instanciate an SD object
SdFat SD;

With your code I did get it to compile, but unfortunately I just have a blue screen. :frowning:

I noticed your pin setup is different form the main code (such as you don’t use cs_oled). You also use “MOSI” and “SCLK” for pins. What pins are those on the Photon?

Thanks again for your help!

These are exactly the same pins but saves me to remember which A??#! was it again :wink:
One pin can have multiple aliases (e.g WKP=A7, DAC=A6, A3=SCLK=DAC2, …)

The other difference in pin mappings comes from the fact that I modified this sketch so that it built

What do your Serial.print() statements tell you?
Add some more if this is still inconclusive?

Oh, that makes sense.

I’m a little confused what Serial.print() does exactly. I’m running the test demo that comes with Adafruit_mfGFX, and everything runs fine except the Serial.Print() statements.

Are these suppose to show up on my board, or on my Particle Dev Serial monitor?

Serial.print() sends these messages down the USB Serial interface to your computer where you can read it out with any serial monitor like Particle Dev, PuTTY or even CLI via particle serial monitor.

Got it! Well then I guess the code is fine. Makes a ton of sense why my screen just stayed blue (I don’t have a picture on my SD yet). I was expecting all those statements to print to my OLED.

So I guess my “real” problem is I don’t know how to see serial.print statements. I have my Serial monitor pulled up in Particle Dev, and it says I’m connected, but nothing shows up. Is there some setup I missed maybe?

In principle this should be correct. The print statements show up on the serial monitor.
If you are on the Mac try the software CoolTerm ( ). I find this easier for debugging.

If you have a working code in the end feel free to send a pull request. I will check my code and try to update it in the next weeks. Currently I am super busy :frowning:

If you are one of those “poor” individuals (or stubborn like me) who stick with Windows, then you’d need to have the USB Serial drivers installed.

I will! Thanks for putting this up to begin with. You have no idea how much time you’ve saved me!

I am, haha. I think I got it working, but it seems a little wonky. The only way it works is disconnecting (from COM3), flashing my code, then while it’s flashing connecting back.

Once connected, if I re-flash new code or restart my Photon nothing happens. I also can’t seem to connect when it’s done flashing and running the code. Is this normal?

That’s also a nice Windows “perk”.
If you keep the connection open from one end if the other end goes offline it won’t be able to reconnect and will demand a new COM port.
So close the connection before reconnect.
PuTTY or CLI do this automatically, but with my current version of Dev it also seems to work well - what version are you on?

Oh yeah? Yup, working perfect following your instructions. Kind of a pain, but doable.
I’m using the latest, 1.5.1. I followed these steps:

Did installing CLI garble things up with Dev?

Finally got a MicroSD to USB so I could put a picture on my card to test the code. Sad to report nothing gets drawn though. :frowning: According to my serial messages everything loads okay, just doesn’t seem to change my screen at all.