Using the Particle OLED Library
Great, now that we understand the hardware setup, let’s put some code on
this thing and see what it can do. Using the Particle library we’ve written,
you’ll be able to write text, draw lines and shapes, and generally display
anything that’ll fit on the screen.
Getting the Particle OLED Library
For this page we’ll be using the online Particle environment. If you’re using
the Particle Dev environment instead, you can get the library and code
examples from the GitHub repository.
DOWNLOAD THE PARTICLE OLED LIBRARY
Load the Demo Example
If you haven’t created a Particle user account and claimed your board,
you’ll need to do that now. Starting here is a great idea if you’re having
trouble.
Once you’re logged into build.particle.io and have a device selected (all this
is covered at the link above), you’ll want to click on the
create new app
button in the sidebar – it’s big and blue, you can’t miss it. Call your app
something like ‘OLED_test’.
Next – this is the important part – we include the
SparkFunMicroOLED
library. To do this:
Click on the icon that looks like a bookmark (it’s all the way to the left
on the black skinny sidebar, 4th up from the bottom)
In the text box under ‘community libraries’, search for ‘OLED’ and
you’ll see ‘SparkFunMicroOLED’ come up (though it might be cut off
a little bit, don’t worry).
It should look something like this:
Page 4 of 1
2
Click on the library name, and a bunch of stuff will pop up, including
all the library files as well as a few options of what to do with the
library.
In this case, we just want to use the library in our app, so click on the
‘include in app’ button.
This will lead you to list of all your apps - click on the name of the app
you just created, and you should see a statement like
#include "SparkFunMicroOLED/SparkFunMicroOLED.h" at the top of
your app.
Last thing is to add the math library to our sketch - on the line below
the first
#include statement, type in: #include "math.h"
Now that we’ve included the library in our app, let’s give it some code - just
copy the demo code below and paste it into your app, below the include
statements.
Page 5 of 1
2
/*
MicroOLEDShieldExample.ino
SparkFunMicroOLEDLibraryHelloWorldExample
JimLindblom@SparkFunElectronics
OriginalCreationDate:June22,2015
Thissketchprintsafriendly,recognizablelogoontheOLEDS
hield,then
goesontodemotheMicroOLEDlibrary'sfunctionalitydrawi
ngpixels,
lines,shapes,andtext.
Har
dwareConnections:
ThissketchwaswrittenspecificallyforthePhotonMicroOL
EDShield,whichdoesallthewiringforyou.IfyouhaveaMi
croOLEDbreakout,usethefollowinghardwaresetup:
MicroOLEDPhoton
GNDGND
VDD3.3V(VCC)
D1/MOSIA5(don'tchange)
D0/SCKA3(don'tchange)

D2
D/CD6(canbeanydigitalpin)
RSTD7(canbeanydigitalpin)
CSA2(canbeanydigitalpin)
Developmentenvironmentspecifics:
IDE:ParticleBuild
HardwarePlatform:ParticlePhoton
SparkFunPhotonMicroOLEDShield
Thiscodeisbeerware;ifyouseeme(oranyotherSpar
kFun
employee)atthelocal,andyou'vefoundourcodehelpful,
pleasebuyusaround!
Distributedasis;nowarrantyisgiven.
*/
//////////////////////////////////
//MicroOLEDObjectDeclaration//
//////////////////////////////////
//DeclareaMicroOLEDobject.Ifnoparametersaresupplied,
defaultpinsare
//used,whichwillworkforth
ePhotonMicroOLEDShield(RST
=D7,DC=D6,CS=A2)
MicroOLEDoled;
void setup()
{
oled.begin();//InitializetheOLED
oled.clear(ALL);//Clearthedisplay'sinternalmemory
oled.display();//Displaywhat'sinthebuffer(splashscre
en)
delay(1000);//Delay1000ms
oled.clear(PAGE);//Clearthebuffer.
randomSeed(analogRead(A0)+ analogRead(A1));
}
void loop()
{
pixelExample();//Runthep
ixelexamplefunction
Page 6 of 1
2

DEV-13628

Mfr. #:
Manufacturer:
SparkFun
Description:
Display Development Tools PhotonMicro OLED Shield
Lifecycle:
New from this manufacturer.
Delivery:
DHL FedEx Ups TNT EMS
Payment:
T/T Paypal Visa MoneyGram Western Union

Products related to this Datasheet