# Particle Photon OLED screen and SD card demo

**URL:** <https://community.particle.io/t/particle-photon-oled-screen-and-sd-card-demo/18145>\
**Category:** Tutorials\
**Created:** [December 9, 2015, 8:58pm UTC](https://community.particle.io/t/particle-photon-oled-screen-and-sd-card-demo/18145 "2015-12-09T20:58:21Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![MikeSeeH](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/mikeseeh/32/7974_2.png) [@MikeSeeH](https://community.particle.io/u/MikeSeeH)\
**Post date:** [December 9, 2015, 8:58pm UTC](https://community.particle.io/t/particle-photon-oled-screen-and-sd-card-demo/18145/1 "2015-12-09T20:58:21Z")

</div>

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

> **[mikeseeh/photon-demo-oled-sdcard](https://github.com/mikeseeh/photon-demo-oled-sdcard)**
>
> photon-demo-oled-sdcard - Particle Photon OLED screen and SD card demo

## Hardware

- Photon – SparkFun Photon RedBoard  
[https://www.sparkfun.com/products/13321](https://www.sparkfun.com/products/13321)
- Adafruit OLED Breakout Board - 16-bit Color 1.5" w/microSD holder  
[http://www.adafruit.com/products/1431](http://www.adafruit.com/products/1431)

## Libraries and code

- Adafruit mfGFX and SSD1351 Library  
[https://github.com/pkourany/Adafruit\_SSD1351\_Library/](https://github.com/pkourany/Adafruit_SSD1351_Library/)  
with rotation support from [https://github.com/mikeseeh/Adafruit\_SSD1351\_Library](https://github.com/mikeseeh/Adafruit_SSD1351_Library)
- bmpDraw Code  
[https://github.com/adafruit/Adafruit-SSD1351-library/blob/master/examples/bmp/bmp.ino](https://github.com/adafruit/Adafruit-SSD1351-library/blob/master/examples/bmp/bmp.ino)

## Wiring

```
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.

## Remarks

- 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!

---

<div class="post-metadata">

**Author:** ![peekay123](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peekay123/32/810_2.png) [@peekay123](https://community.particle.io/u/peekay123)\
**Post date:** [December 9, 2015, 9:04pm UTC](https://community.particle.io/t/particle-photon-oled-screen-and-sd-card-demo/18145/2 "2015-12-09T21:04:44Z")

</div>

@MikeSeeH, where’s the video! 😛

---

<div class="post-metadata">

**Author:** ![jahydin](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@jahydin](https://community.particle.io/u/jahydin)\
**Post date:** [March 20, 2016, 10:30am UTC](https://community.particle.io/t/particle-photon-oled-screen-and-sd-card-demo/18145/3 "2016-03-20T10:30:24Z")

</div>

Hello!  
Just tried to run this and I keep getting the following error: ![](https://us1.discourse-cdn.com/flex026/uploads/particle/original/2X/f/f5fcd3c790f215b69df45aa5674ba594b6e0b1a3.JPG)

Do you have any idea why?

Thanks!

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [March 20, 2016, 5:25pm UTC](https://community.particle.io/t/particle-photon-oled-screen-and-sd-card-demo/18145/4 "2016-03-20T17:25:04Z")

</div>

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

```cpp
#	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.

---

<div class="post-metadata">

**Author:** ![jahydin](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@jahydin](https://community.particle.io/u/jahydin)\
**Post date:** [March 20, 2016, 7:06pm UTC](https://community.particle.io/t/particle-photon-oled-screen-and-sd-card-demo/18145/5 "2016-03-20T19:06:35Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [March 20, 2016, 7:21pm UTC](https://community.particle.io/t/particle-photon-oled-screen-and-sd-card-demo/18145/6 "2016-03-20T19:21:07Z")

</div>

> [@jahydin](#):
>
> Does this replace the SD-card-library-photon-compact library then?

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.

---

<div class="post-metadata">

**Author:** ![jahydin](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@jahydin](https://community.particle.io/u/jahydin)\
**Post date:** [March 21, 2016, 12:46pm UTC](https://community.particle.io/t/particle-photon-oled-screen-and-sd-card-demo/18145/7 "2016-03-21T12:46:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [March 21, 2016, 4:19pm UTC](https://community.particle.io/t/particle-photon-oled-screen-and-sd-card-demo/18145/8 "2016-03-21T16:19:42Z")

</div>

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

```cpp

#pragma SPARK_NO_PREPROCESSOR

#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;

```

---

<div class="post-metadata">

**Author:** ![jahydin](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@jahydin](https://community.particle.io/u/jahydin)\
**Post date:** [March 22, 2016, 12:15am UTC](https://community.particle.io/t/particle-photon-oled-screen-and-sd-card-demo/18145/9 "2016-03-22T00:15:57Z")

</div>

![](https://us1.discourse-cdn.com/flex026/uploads/particle/original/2X/b/b26228a84e91517f1c9e145b2381e63f64428948.JPG)

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

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!

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [March 22, 2016, 7:12am UTC](https://community.particle.io/t/particle-photon-oled-screen-and-sd-card-demo/18145/10 "2016-03-22T07:12:08Z")

</div>

These are exactly the same pins but saves me to remember which A??#! was it again 😉  
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  
[https://github.com/adafruit/Adafruit-SSD1351-library/blob/master/examples/bmp/bmp.ino](https://github.com/adafruit/Adafruit-SSD1351-library/blob/master/examples/bmp/bmp.ino)

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

---

<div class="post-metadata">

**Author:** ![jahydin](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@jahydin](https://community.particle.io/u/jahydin)\
**Post date:** [March 22, 2016, 2:40pm UTC](https://community.particle.io/t/particle-photon-oled-screen-and-sd-card-demo/18145/11 "2016-03-22T14:40:14Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [March 22, 2016, 2:55pm UTC](https://community.particle.io/t/particle-photon-oled-screen-and-sd-card-demo/18145/12 "2016-03-22T14:55:15Z")

</div>

`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`.

---

<div class="post-metadata">

**Author:** ![jahydin](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@jahydin](https://community.particle.io/u/jahydin)\
**Post date:** [March 22, 2016, 3:06pm UTC](https://community.particle.io/t/particle-photon-oled-screen-and-sd-card-demo/18145/13 "2016-03-22T15:06:53Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![MikeSeeH](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/mikeseeh/32/7974_2.png) [@MikeSeeH](https://community.particle.io/u/MikeSeeH)\
**Post date:** [March 22, 2016, 3:33pm UTC](https://community.particle.io/t/particle-photon-oled-screen-and-sd-card-demo/18145/14 "2016-03-22T15:33:47Z")

</div>

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 ( [http://freeware.the-meiers.org](http://freeware.the-meiers.org) ). 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 ☹

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [March 22, 2016, 3:36pm UTC](https://community.particle.io/t/particle-photon-oled-screen-and-sd-card-demo/18145/15 "2016-03-22T15:36:14Z")

</div>

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.

[https://s3.amazonaws.com/spark-website/Particle.zip](https://s3.amazonaws.com/spark-website/Particle.zip)

---

<div class="post-metadata">

**Author:** ![jahydin](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@jahydin](https://community.particle.io/u/jahydin)\
**Post date:** [March 22, 2016, 4:45pm UTC](https://community.particle.io/t/particle-photon-oled-screen-and-sd-card-demo/18145/16 "2016-03-22T16:45:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jahydin](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@jahydin](https://community.particle.io/u/jahydin)\
**Post date:** [March 22, 2016, 4:53pm UTC](https://community.particle.io/t/particle-photon-oled-screen-and-sd-card-demo/18145/17 "2016-03-22T16:53:41Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [March 22, 2016, 6:26pm UTC](https://community.particle.io/t/particle-photon-oled-screen-and-sd-card-demo/18145/18 "2016-03-22T18:26:33Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jahydin](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@jahydin](https://community.particle.io/u/jahydin)\
**Post date:** [March 22, 2016, 8:51pm UTC](https://community.particle.io/t/particle-photon-oled-screen-and-sd-card-demo/18145/19 "2016-03-22T20:51:24Z")

</div>

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: [https://docs.particle.io/guide/getting-started/connect/photon/](https://docs.particle.io/guide/getting-started/connect/photon/)

Did installing CLI garble things up with Dev?

---

<div class="post-metadata">

**Author:** ![jahydin](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@jahydin](https://community.particle.io/u/jahydin)\
**Post date:** [March 25, 2016, 3:24pm UTC](https://community.particle.io/t/particle-photon-oled-screen-and-sd-card-demo/18145/20 "2016-03-25T15:24:35Z")

</div>

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. ☹ According to my serial messages everything loads okay, just doesn’t seem to change my screen at all.

[Next page](https://community.particle.io/t/particle-photon-oled-screen-and-sd-card-demo/18145.md?page=2)
