Ricbot PTP: Difference between revisions
(Created page with "Back to Ricbot == PTP == Precise Time Protocol (on Raspberry Pi 5) Assuming 2 Raspberry Pis are connected with an Ethernet cable, and both have an IP on eth0. === Install === Install on both master and slave: sudo apt install linuxptp Verify that there is support on 'eth0'. Should have hardware capabilities: $ ethtool -T eth0 Time stamping parameters for eth0: Capabilities: hardware-transmit software-transmit hardware-receive...") |
|||
| (2 intermediate revisions by the same user not shown) | |||
| Line 33: | Line 33: | ||
Start clock master service on eth0 | Start clock master service on eth0 | ||
sudo ptp4l -i eth0 -m -2 | sudo ptp4l -i eth0 -m -2 | ||
It should be activated as a grand master soon. | It should be activated as a grand master soon. | ||
| Line 41: | Line 41: | ||
Run a PTP test slave (-s) with output to console (-m). | Run a PTP test slave (-s) with output to console (-m). | ||
sudo ptp4l -i eth0 -m -2 -s | sudo ptp4l -i eth0 -m -2 -s | ||
After a few minutes, this should yield a time offset on the order of 100 ns. | After a few minutes, this should yield a time offset on the order of 100 ns. | ||
| Line 119: | Line 119: | ||
Also, enable and start this service: | Also, enable and start this service: | ||
sudo systemctl daemon-reload | sudo systemctl daemon-reload | ||
sudo systemctl enable ptp4l-client.service | sudo systemctl enable ptp4l-client.service | ||
sudo systemctl start ptp4l-client.service | sudo systemctl start ptp4l-client.service | ||
Check the status of the client when all is in place | Check the status of the client when all is in place | ||
sudo systemctl status ptp4l-client | sudo systemctl status ptp4l-client | ||
Latest revision as of 14:30, 20 April 2026
Back to Ricbot
PTP
Precise Time Protocol (on Raspberry Pi 5)
Assuming 2 Raspberry Pis are connected with an Ethernet cable, and both have an IP on eth0.
Install
Install on both master and slave:
sudo apt install linuxptp
Verify that there is support on 'eth0'. Should have hardware capabilities:
$ ethtool -T eth0
Time stamping parameters for eth0:
Capabilities:
hardware-transmit
software-transmit
hardware-receive
software-receive
software-system-clock
hardware-raw-clock
Test time master
Start connection to eth0 hardware (as a process in the background)
sudo phc2sys -s CLOCK_REALTIME -c eth0 -w &
Start clock master service on eth0
sudo ptp4l -i eth0 -m -2
It should be activated as a grand master soon.
Test time client
Run a PTP test slave (-s) with output to console (-m).
sudo ptp4l -i eth0 -m -2 -s
After a few minutes, this should yield a time offset on the order of 100 ns.
Kill the phc2sys on the time server after the client test:
sudo pkill phc2sys
Install as a service on Master
Most is copied from https://austinsnerdythings.com/2025/02/18/nanosecond-accurate-ptp-server-grandmaster-and-client-tutorial-for-raspberry-pi/.
Create a service file for the connection to eth0:
sudo nano /etc/systemd/system/phc2sys-grandmaster.service
With:
[Unit] Description=sync PHC with system clock (grandmaster) After=network-online.target Wants=network-online.target [Service] Type=simple ExecStart=/usr/sbin/phc2sys -s CLOCK_REALTIME -c eth0 -w Restart=always RestartSec=3 [Install] WantedBy=multi-user.target
Create a service file for the ptp server:
sudo nano /etc/systemd/system/ptp4l-grandmaster.service
With:
[Unit] Description=Precision Time Protocol (PTP) service (Grandmaster) After=network-online.target Wants=network-online.target [Service] Type=simple ExecStart=/usr/sbin/ptp4l -i eth0 -2 Restart=always RestartSec=3 [Install] WantedBy=multi-user.target
Enable and start these services
sudo systemctl daemon-reload sudo systemctl enable phc2sys-grandmaster.service sudo systemctl enable ptp4l-grandmaster.service sudo systemctl start phc2sys-grandmaster.service sudo systemctl start ptp4l-grandmaster.service
Install as a service on the client
Make a new service file
sudo nano /etc/systemd/system/ptp4l-client.service
With:
[Unit] Description=Precision Time Protocol (PTP) service (Client) After=network-online.target Wants=network-online.target [Service] Type=simple ExecStart=/usr/sbin/ptp4l -i eth0 -2 -m --summary_interval 3 Restart=always RestartSec=3 [Install] WantedBy=multi-user.target
Also, enable and start this service:
sudo systemctl daemon-reload sudo systemctl enable ptp4l-client.service sudo systemctl start ptp4l-client.service
Check the status of the client when all is in place
sudo systemctl status ptp4l-client