Digital Clock

aved
2024-02-26
2025-12-04
  • aved - 2024-02-26

    i need help creating a digital clock in CODESYS that should be displyed on a Raspberry Pi LCD Display trough the Visualization built in CODESYS. I have an idea how to display the time by making a 7 Segment Dysplay in the Visu. But I don't know how to get the actual time into the program. Can anyone help?

     
  • evanclegg - 2024-02-27

    To display the current time, you’ll need to retrieve it from the system clock. In CODESYS, you can use the built-in function SysTime to get the current system time.
    Here’s an example of how you can use it:

    VAR
    dtCurrentTime: DATE_AND_TIME;
    sTime: STRING(8);
    END_VAR

    dtCurrentTime := SysTime();
    sTime := TIME_TO_STRING(dtCurrentTime.t);

    The sTime variable now contains the current time in the format “HH:MM:SSuno online".

     

    Last edit: evanclegg 2024-02-28
  • gatewail0 - 2025-12-04

    You can definitely pull the actual system time into CODESYS without too much trouble. Take a look at the SysTimeRtc or SysTime library—both let you read the current date and time from the Raspberry Pi. You can call SysTimeRtcGet() or SysTimeGetTime() in your PLC code and then format the hours, minutes, and seconds into variables that feed your 7-segment visualization. Once you’ve mapped those values, your Visu display will update automatically each cycle. It’s a pretty common approach for clocks in CODESYS, so you should be able to get it working quickly. golf hit

     

Log in to post a comment.