Projet

How to Set up a Real-Time Clock in Embedded Systems With the ROCK 4SE

Accurate Real Time Monitoring with the ROCK 4SE

Scroll down

This guide shows how to set up a real-time clock (RTC) in embedded systems with the ROCK 4SE to allow real-time monitoring with no main power or connection to the internet.

Learn how to set up the real-time clock (RTC) on the ROCK 4SE in just 10 steps and learn how to use a Serial-to-USB cable to access the console for both boards. The officially supported operating systems, Debian Bullseye (Desktop) and Ubuntu Server (Headless), both support these features.

The ROCK 4SE and ROCK 4C+ single board computers come with a built-in Real Time Clock (RTC) function as standard, which, when set up, can keep accurate time even when not connected to a network time service. They also have a Serial UART attached to the GPIO header for Serial Console access to the operating system for monitoring and debugging.

Note: The ROCK 4C+ does not have the RTC battery connector fitted, but it does have the Serial UART connected to the GPIO header.

What is a real-time clock (RTC) in embedded systems?

A real-time clock (RTC) is used in embedded systems to keep track of the precise time and date even when the device is not connected to the network or the main power is off. The RTC is powered by its own internal lithium battery, and even if the power of the system is turned off, the RTC clock keeps running.

Applications of the real-time clock on the ROCK 4 SE

What are the applications of RTC?

The RTC is widely used in various applications, including industrial manufacturing, commercial machines maintenance, healthcare machines management, agriculture installations, and many more. The ROCK board, with its RTC capability, can be integrated into any electronic device where real-time monitoring is required.

Some applications of the RTC include:

  • Scheduled maintenance of industrial and commercial machines
  • Manufacturing robots
  • Street light management
  • Traffic lights signals
  • Speed cameras
  • Remote agricultural installations
  • Laptops, PCs and tablets
  • Digital cameras
  • Healthcare devices
  • Etc.

So, let’s discover how to set up the RTC on the ROCK 4SE and start tracking time!

Step 1: Real-Time Clock

Most desktop and laptop PCs have a battery-backed RTC built into the motherboard, but many SBCs do not. The ROCK 4SE & ROCK 4C+ both have RTC functions supported by the PMIC, but only the ROCK 4SE has an RTC battery connector located on the underside of the board. It requires a battery (not supplied) of the type as shown below:

Type: CR2032

Voltage: 3.0V

Connector: XH1.25mm

Tip: RTC batteries are widely available – make sure yours has a connector with the correct polarity.

Step 2: Battery Installation

Ensure the ROCK 4SE is powered off before connecting the battery to the battery connector terminal.

Ground (Black lead) is nearest to the USB-C socket (Top Left), and Positive (Red lead) is nearest to the HDMI connector (Top Right), as viewed from the underside of the board below:

Step 3: Operating System Setup

Set up your operating system for the ROCK 4SE with either Debian Bullseye or Ubuntu Server. There are separate Getting Started instructions on how to do this here:

To obtain an accurate time setting, the ROCK 4SE needs to be connected to the internet using either Ethernet or WiFi. Once the RTC has been set up, networking can be disconnected, and the time will be kept from the RTC.

Step 4: Set the timezone

Set up the time zone. A list of available timezones can be displayed by running the following command in the Terminal:

timedatectl list-timezones

This example shows setting the timezone to London, UK time zone. The system automatically knows that it is currently in British Summer Time (BST).

Tip: Use TAB completion by typing the first few letters of the timezone, then press the TAB key.

sudo timedatectl set-timezone Europe/London

View the clock settings with the timedatectl command:

timedatectl

When the system starts up, the system clock may not have synchronised – System clock synchronised: no.

Step 5: Sync clocks

Wait until the System clock has synchronised. This can take five minutes or more. Keep refreshing timedatectl until System clock synchronised is marked yes.

After the system clock has synchronised, run the following command to write the system clock time to the hardware clock:

hwclock -r

Now, if you run timedatectl again, you should find that the Universal time (UTC) and RTC time are synchronised. It is recommended to run the RTC in UTC time, i.e. with RTC in Local TZ: no.

If you power off and disconnect networking, you can now run the system without being connected to a network, and the system will keep accurate time from the hardware clock.

Step 6: Serial Console

Both the ROCK 4SE and ROCK 4C+ have a Serial UART connected to the GPIO header, so you can attach the board to a host PC using a USB-to-Serial cable and Serial Console application. This allows access to the boot sequence and kernel ring buffer output as the board boots up for monitoring and debugging, and once the system has booted, you can log in to the shell from the console.

If you are running Ubuntu Server as a headless device, this is especially useful for accessing the system before SSH access is established. More advanced use enables the whole boot sequence to be monitored and interrupted for debugging purposes, even before the OS initialises.

Step 7: USB-to-Serial Cable

There are many USB-to-Serial cables available on the market. The ROCK board’s UART operates at a data rate of 1.5Mbps, so the cable must be able to support this. 3.3V cables based on the FTDI FT232R USB to Serial UART are suitable, for example, this one.

Warning: Some USB-to-Serial cables operate at 5.0V – DO NOT USE these as they will damage your board.

Step 8: GPIO Connections

The ROCK’s serial console is exported on UART2 by default, which is connected to the following pins on the GPIO header. With the board powered off, connect the cable as shown below:

ROCK GPIO Pin GPIO Function Cable Connector Cable Function
Pin 6 GND Black GND
Pin 8 UART2_TX White RXD
Pin 10 UART2_RX Green TXD
Not Connected Red 5V Power

 

Tip: Tape the Red power terminal (5.0V) on the cable safely away so that it cannot accidentally touch any of the GPIO pins, as this will damage your board.

Step 9: Serial Terminal

Several Serial Terminal applications are available that run on the host PC. We used Minicom on a Debian Linux host.

Install Minicom with:

sudo apt install minicom

To run Minicom without root privileges, make sure that your user is in the dialout group:

groups

If not, run the following command to add your user to the dialout group, then log out and back in again:

sudo usermod -aG dialout $USER

With the USB-to-serial cable plugged into your host, check which serial device it is attached to:

sudo dmesg

In our case, the device is on ttyUSB0.

Create a minicom configuration file in your home directory named .minirc.rock (note the preceding dot) with the following contents:

pu port	/dev/ttyUSB0
pu baudrate	1500000
pu bits	8
pu parity	N
pu stopbits	1
pu rtscts	No

Now start minicom in a Terminal on the host with:

minicom rock

You should see output similar to the below:

Tip: Hardware flow control “rtscts” must be set to “no” to allow keyboard input.

Now, power on the ROCK. The U-boot messages will stream through the console, then Linux will initialise, and the kernel boot messages will appear, ending with a login prompt.

Step 10: Log in

When the OS has finished booting, you may have to press “enter” to make the login prompt appear.

At the prompt, log in with username rock, and then you can run bash commands in the shell. There may be times when keyboard input is interrupted by kernel messages, so just press “enter” to return to the prompt and repeat the command.

Tip: Debian and Ubuntu’s default username is rock with password rock – we advise changing this to a more secure password.

Summary

This guide showed how to set up and configure the RTC so that your ROCK 4SE board can keep accurate time even when it is not connected to the internet or a network with time services.

This is necessary for stand-alone projects that use time and date information. It is also important for some cloud services that use access tokens which contain time stamps which must be set correctly.

For users who want to get under the bonnet of Linux on the ROCK 4SE or ROCK 4C+, we also showed how to use a USB-to-Serial cable to access the ROCK’s serial console. This gives access to the boot sequence and kernel messages. It also provides a way to log into the OS from a host PC without having a monitor attached to the ROCK or when SSH access is not possible.

Reference: timedatectl

 

Ready to ROCK your next project? Browse our ROCK Shop to find out the range of incredible ROCK single-board computers – the perfect Raspberry Pi alternative, compute modules and accessories. Be one of the first to know:

Do you want to know more about ROCK and how we, here at OKdo, can help solve your problem? Talk to us, get in touch with our Sales team to find the perfect solution. 

Looking for something else? Discover our BlogsGetting Started Guides and Projects for more inspiration!

 

 

Vous aimez ce que vous lisez ? Pourquoi ne pas montrer votre appréciation en donnant un peu d'amour.

D'un simple tapotement à l'écrasement de ce bouton d'amour et montrez à quel point vous avez aimé ce projet.

Intimité

Notre site Web utilise des cookies et des technologies similaires pour vous fournir un meilleur service lorsque vous effectuez une recherche et passez une commande, à des fins d'analyse ou pour personnaliser nos publicités. Vous pouvez modifier vos paramètres de cookies en lisant notre politique en matière de cookie. Faute de quoi, nous considérerons que vous acceptez notre utilisation des cookies.

Location

Please select an option to see content specific to your location and shop online.

Browse the US site