How to display time on my Particle Maker Kit OLED display

Hello all,

I have a photon maker kit. I wired up the OLED and ran the test program. I also did all the beginner tutorials. I included the libraries for the display and sparktime. How can I get the OLED to display real time on the screen. I am a noob as far as programming goes. Can I get some help on how would I go about with this?

1 Like

so post your working demo code and I’m certain folks here can help you get your OLED to display time…

Meanwhile check out the Time Library

I’m obsessed with clocks and time… :neutral_face:

#include "SparkTime/SparkTime.h"
#include "Adafruit_SSD1306/Adafruit_GFX.h"
#include "Adafruit_SSD1306/Adafruit_SSD1306.h"

/* Uncomment this block to use hardware SPI
// If using software SPI (the default case):
#define OLED_MOSI   D0
#define OLED_CLK    D1
#define OLED_DC     D2
#define OLED_CS     D3
#define OLED_RESET  D4
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
*/

// use hardware SPI
#define OLED_DC     D3
#define OLED_CS     D4
#define OLED_RESET  D5
Adafruit_SSD1306 display(OLED_DC, OLED_RESET, OLED_CS);


#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2


#define LOGO16_GLCD_HEIGHT 16 
#define LOGO16_GLCD_WIDTH  16

static const unsigned char logo16_glcd_bmp[] =
{ 0B00000000, 0B11000000,
  0B00000001, 0B11000000,
  0B00000001, 0B11000000,
  0B00000011, 0B11100000,
  0B11110011, 0B11100000,
  0B11111110, 0B11111000,
  0B01111110, 0B11111111,
  0B00110011, 0B10011111,
  0B00011111, 0B11111100,
  0B00001101, 0B01110000,
  0B00011011, 0B10100000,
  0B00111111, 0B11100000,
  0B00111111, 0B11110000,
  0B01111100, 0B11110000,
  0B01110000, 0B01110000,
  0B00000000, 0B00110000 };

#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

UDP UDPClient;
SparkTime rtc;

unsigned long currentTime;
unsigned long lastTime = 0UL;
String timeStr;


void setup()   {                
  rtc.begin(&UDPClient, "north-america.pool.ntp.org");
  rtc.setTimeZone(-5);
  Serial.begin(9600);
  
  // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  display.begin(SSD1306_SWITCHCAPVCC);
  // init done
  
  display.display(); // show splashscreen
  delay(2000);
  display.clearDisplay();   // clears the screen and buffer
// text display tests
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.println("AG");
  display.display();
  delay(2000);
}

//begin time function

how do I get it to display current time on the OLED?

you can edit your post and put your code between three “backtics” (on a mac, it is just left of the “1”)

it will look like this:

void loop()
{
  myFunction();
  int myVariable = 0;
  String myString = "abcdef"
}

btw, it looks like you code doesn’t have a loop() function… does it even compile?

1 Like

it compiles

great, then you can edit your post so folks can read it!

the are called tildes ~~~ you want backtics: `

You need three backtics to make it work:

```cpp
(copy paste your code)
```

1 Like

sorry about that I am new to this

I can print text on the display. I have included the libraries for display and time in the INO file. I do not know how to take it from here. I’m trying to learn, any help you guys can provide will be much appreciated.

something like this (untested)


#include "Adafruit_SSD1306/Adafruit_GFX.h"
#include "Adafruit_SSD1306/Adafruit_SSD1306.h"

/* Uncomment this block to use hardware SPI
// If using software SPI (the default case):
#define OLED_MOSI   D0
#define OLED_CLK    D1
#define OLED_DC     D2
#define OLED_CS     D3
#define OLED_RESET  D4
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
*/

// use hardware SPI
#define OLED_DC     D3
#define OLED_CS     D4
#define OLED_RESET  D5
Adafruit_SSD1306 display(OLED_DC, OLED_RESET, OLED_CS);


#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2


#define LOGO16_GLCD_HEIGHT 16 
#define LOGO16_GLCD_WIDTH  16

static const unsigned char logo16_glcd_bmp[] =
{ 0B00000000, 0B11000000,
  0B00000001, 0B11000000,
  0B00000001, 0B11000000,
  0B00000011, 0B11100000,
  0B11110011, 0B11100000,
  0B11111110, 0B11111000,
  0B01111110, 0B11111111,
  0B00110011, 0B10011111,
  0B00011111, 0B11111100,
  0B00001101, 0B01110000,
  0B00011011, 0B10100000,
  0B00111111, 0B11100000,
  0B00111111, 0B11110000,
  0B01111100, 0B11110000,
  0B01110000, 0B01110000,
  0B00000000, 0B00110000 };

#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

void setup()   
{
  Time.zone(-5);
  Serial.begin(9600);
  display.begin(SSD1306_SWITCHCAPVCC);
  display.display(); // show splashscreen
  delay(2000);
  display.clearDisplay();   // clears the screen and buffer
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.println("AG");
  display.display();
  delay(2000);
}

void loop()
{
  static int lastSecond = 61;
  if (Time.second() != lastSecond)
  {
    char myTimeString[125] = "";
    const int currentTime = Time.now();
    sprintf(myTimeString, "%02d:%02d:%02d", Time.hour(currentTime), Time.minute(currentTime), Time.second(currentTime));
    display.clearDisplay();   // clears the screen and buffer
    display.setTextSize(2);
    display.setTextColor(WHITE);
    display.setCursor(0,0);
    display.println(myTimeString);
    display.display();
    lastSecond = Time.second(currentTime);
  }
}

that worked. I’ve got the clock working but it shows the wrong time. I’m guessing I need to adjust the time zone.

perhaps…

Time.zone(-5);

put your UTC offset there…

I’m happy you have it working!!!

1 Like

you did not use the spark time library for getting that on the display. I have a lot to learn. My objective was to make an alarm clock of the kit. Such that the alarm could trigger of relays. I’m doing this for a school project. I appreciate you helping me out.

This works as well…tested.

display.println(Time.format(Time.now(),"%I:%M.%S%p"));

Reference to what all the %letters mean is here:
newlib C Time stuff

1 Like

yeah, I think you can get it done without the overhead of the library.

look at using Particle.function() to be able to set the alarm time…

and create a time object to use for the alarm:

struct AlarmObject{
  bool isActive;
  int Hour;
  int Minute;
  int Second;
};

AlarmObject wakeTime = {false,6,30,0}; // default wakeup time, unarmed


void setup() 
{

}

void loop()
{

}

oh yeah, Particle has a terrific Time library… that and a little programming and you will have exactly what you need!

Hi,

Could you please share the links to the test program and the beginner tutorial? I just got the Photon Maker Kit and I am really exited about testing out the screen!

Thanks!

Guillaume

Unfortunately I’m unaware of such a tutorial, but there are some threads that deal with this display.
I’ll post a link in a minute, but meanwhile you could locate the Adafruit_SSD1306 library on http://build.particle.io/build which includes a sample sketch

Here’s the mentioned thread

I did locate that piece of code in the mean time and found this very good post: Getting Started with the Maker Kit OLED: How To

I am up and running, thanks.

Guillaume

2 Likes