SIGN IN
SEARCH PROJECTS
Analog Style Clock on OLED Display
Analog Style Clock on OLED Display © GPL3+
In this project we connect RTC module to arduino. Read time of it and display it on OLED display. The clock has analog look and feel
analogarduinoclockcodediyoledrtctutorial
14,187 VIEWS3 COMMENTS5 RESPECTS
COMPONENTS AND SUPPLIES
Ph a000066 iso (1) ztbmubhmho
Arduino UNO
× 1
62m4126 40
Graphic OLED, 128 x 64
× 1
Maxim ds1307%2b
Real Time Clock (RTC)
× 1
ABOUT THIS PROJECT
This is my attempt to create analog style clock on OLED display
You can find the tutorial on Youtube
CODE
Analog Clock on OLED displayArduino
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
const float pi = 3.14159267 ;
const int clock_center_x=64;
const int clock_center_y=32;
int o=1;
// variables used to calculate coordinates of points on the circle
int x;
int y;
int x1;
int y1;
// variables to store previous values read off RTC module
int seconds=0;
int minutes;
int hours;
void setup() {
Serial.begin(9600);
//put your setup code here, to run once:
//myRTC.setDS1302Time(10, 00,13, 4, 18, 06, 2020);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
// Show initial display buffer contents on the screen --
// the library initializes this with an Adafruit splash screen.
display.display();
delay(2000); // Pause for 2 seconds
// Clear the buffer
display.clearDisplay();
draw_clock_face();
display.display();
}
void draw_second(int second, int mode){
y= (24*cos(pi-(2*pi)/60*second))+clock_center_y;
x =(24*sin(pi-(2*pi)/60*second))+clock_center_x;
if (mode==1) display.drawCircle(x, y, 2, SSD1306_WHITE);
else display.drawCircle(x, y, 2, SSD1306_BLACK);
}
void draw_hour(int hour, int minute, int mode){
y= (18*cos(pi-(2*pi)/12*hour-(2*PI)/720*minute))+clock_center_y;
x =(18*sin(pi-(2*pi)/12*hour-(2*PI)/720*minute))+clock_center_x;
y1=(18*cos(pi-(2*pi)/12*hour-(2*PI)/720*minute))+clock_center_y+1;
x1=(18*sin(pi-(2*pi)/12*hour-(2*PI)/720*minute))+clock_center_x+1;
if (mode==1){
display.drawLine(clock_center_x,clock_center_y,x,y,SSD1306_WHITE);
display.drawLine(clock_center_x+1,clock_center_y+1,x1,y1,SSD1306_WHITE);
}
else{
display.drawLine(clock_center_x,clock_center_y,x,y,SSD1306_BLACK);
display.drawLine(clock_center_x+1,clock_center_y+1,x1,y1,SSD1306_BLACK);
}
}
void draw_minute(int minute, int mode){
y= (24*cos(pi-(2*pi)/60*minute))+clock_center_y;
x =(24*sin(pi-(2*pi)/60*minute))+clock_center_x;
if (mode==1)display.drawLine(clock_center_x,clock_center_y,x,y,SSD1306_WHITE); else display.drawLine(clock_center_x,clock_center_y,x,y,SSD1306_BLACK);
}
void draw_clock_face(void){
// draw the center of the clock
display.drawCircle(clock_center_x, clock_center_y,3, SSD1306_WHITE);
display.fillCircle(clock_center_x, clock_center_y,3, SSD1306_WHITE);
// draw hour pointers around the face of a clock
for (int i=0;i<12;i++){
y= (32*cos(pi-(2*pi)/12*i))+clock_center_y;
x =(32*sin(pi-(2*pi)/12*i))+clock_center_x;
y1= (28*cos(pi-(2*pi)/12*i))+clock_center_y;
x1 =(28*sin(pi-(2*pi)/12*i))+clock_center_x;
display.drawLine(x1,y1,x,y,SSD1306_WHITE);
}
// print string "12" at the top of the face of the clock
display.drawCircle(26*sin(pi)+clock_center_x, (26*cos(pi))+clock_center_y, 6, SSD1306_BLACK);
display.fillCircle(26*sin(pi)+clock_center_x, (26*cos(pi))+clock_center_y, 5, SSD1306_BLACK);
display.setTextSize(1); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(clock_center_x-3,0); // Start at top-left corner
display.println(F("12"));
}
void redraw_clock_face_elements(void){
display.drawCircle(clock_center_x, clock_center_y,3, SSD1306_WHITE);
display.fillCircle(clock_center_x, clock_center_y,3, SSD1306_WHITE);
display.setCursor(clock_center_x-3,0);
display.println(F("12"));
}
void loop() {
myRTC.updateTime();
if (myRTC.seconds!=seconds){
draw_second(seconds,0);
draw_minute(minutes,0);
draw_hour(hours,minutes,0);
draw_second(myRTC.seconds,1);
draw_minute(myRTC.minutes,1);
draw_hour(myRTC.hours,myRTC.minutes,1);
display.display();
seconds=myRTC.seconds;
minutes=myRTC.minutes;
hours=myRTC.hours;
redraw_clock_face_elements();
}
}
SCHEMATICS
Schematics
Schematics nn8vi1eobi
COMMENTS
Please log in or sign up to comment.
luckymary
luckymary
2 years ago
Is it correct the RTC1307 pin VCC and GND connect to A2, A3
battle_challengers
battle_challengers
2 years ago
I think it is wrong
1 thank
EdwinEdgar
EdwinEdgar
a year ago
I am studying this project as I want to create code that will provide on the SS1306 The position of a robot arm. This project will provide useful information. To achieve this.
So far as previously stated by others the trig needs to be checked.
From youtube New Arduino RTC DS1302 Real Time Clock Module For AVR ARM PIC SMD
Note 1 x=Rcosα, and y=Rsinα
Note 2 π-2π=-π
Note 3 i.e. rotates the x-axis by 180 degrees. Hence The x-axis is drawn in the negative
direction. -π.
This is an excellent piece of engineering. You have worked through the project and identified some errors and made corrections to the formulas to give the correct results. OK a minor slip, but very good work.
I can learn from this. Thank you
1 thank
AUTHOR
Dziubym
mdraber
31 PROJECTS30 FOLLOWERS
PUBLISHED ON
June 20, 2020
SEE SIMILAR PROJECTS
YOU MIGHT LIKE
TABLE OF CONTENTS
Analog Style Clock on OLED Display
Components and supplies
About this project
Code
Schematics
Comments(3)
SIMILAR PROJECTS YOU MIGHT LIKE
Analog Style LED POV Clock
A nice looking analog style LED POV clock.
Analog Style LED POV Clock
Project tutorial by Mirko Pavleski
23,813 VIEWS5 COMMENTS41 RESPECTS
How to Use OLED Display with Arduino | Arduino OLED Tutorial
In first part, we will show DHT22 sensor's data on the OLED. In the second part, we will display iPhone, Samsung and LG's logos on OLED.
How to Use OLED Display with Arduino | Arduino OLED Tutorial
by Aqib
27,200 VIEWS7 COMMENTS43 RESPECTS
Arduino OLED Temperature Display with Real Time Clock
In this article, we are going to make an Arduino weather clock which will tell us the time, date and temperature.
Arduino OLED Temperature Display with Real Time Clock
Project tutorial by Keval Doshi
21,958 VIEWS9 COMMENTS39 RESPECTS
Analog Clock using 1Sheeld Graphical LCD
A real-time Analog Clock using 1Sheeld Graphical LCD.
Analog Clock using 1Sheeld Graphical LCD
Project tutorial by Ahmed El-Hinidy
4,671 VIEWS0 COMMENTS9 RESPECTS
Arduino to-the-minute word clock OLED Display
An Arduino based word clock that tells the day of the week, the month, day and year and the time to the minute in words.
Arduino to-the-minute word clock OLED Display
Project showcase by garysat
6,526 VIEWS4 COMMENTS10 RESPECTS
How to Make Analog Clock & Digital clock with Led Strip and MAX7219 Dot module with Arduino
How to Make Analog Clock & Digital clock with Led Strip
Project tutorial by DKARDU
4,970 VIEWS0 COMMENTS9 RESPECTS
Powered by