Wednesday, May 27, 2020

Analog Clock using OLED and PIC Microcontroller

Hello Everyone, in this blog post I will show you guys how to make an analog clock on OLED SSD1306, this is a simple and cool project to display some basic animations on the OLED display.


We are going to build this project in the proteus simulation environment and use the PIC18F microcontroller. In terms of the software components, we need I2C Library, OLED Library, and DS1307 RTC Library.
If you are following my blogs you might be aware that these three libraries are already available and tested well, the following are the links to the previous posts, you can refer if you want.
OLED I2C Display Using Microchip PIC Microcontroller
Real Time Clock (DS1307) Interfacing with PIC Microcontroller
(My all new projects will be on GitHub and I am also trying to port all previous projects on GitHub so that these can be maintained well.)

The following are the steps to make an Analog Clock.
  • Make a small circle with a very small radius such as 1
  • Make a big circle with a big radius but make sure to not exceed the screen size.
  • Make Hour Ticks
    • We have 12 Hours and 360 degrees, which means 1 Hour equals 30 degrees.
    • We will use a for loop incremented by 30 degrees, to draw small lines representing ticks for each hour position. This is done by draw_clock_face function.
    • draw_clock_face function uses sine and cosine formulas to draw 12 marks of length 5 at each hour position.
  • Displaying Hour, Minute and Second Hands
    • Displaying timing using clock hands is very similar to displaying marks.
    • Hour Hand should be very small, while minute being medium and second hand should be longest of all.
  • Data from RTC is read and converted to decimal format from BCD format, and this is data is faced to the display_time function.
  • Executing this function per second will have an animation effect of moving the second hand of the clock.
  • In the project, we have called this per 500ms, the reason for this is the digital clock as we wanted to display the colon blinking, which is done half a second.
The following is the code and this can be downloaded or cloned from my GitHub page (click here).

The following is the simulation video link.

In case of any doubt, feel free to contact us.

1 comment: