VFLEX featured by Jeff Geerling on YouTube · 191K views. Mentioned briefly as part of a bigger topic

Watch on YouTube →

View summary / highlights

[0:00] I built this PTP clock and now every time I look at it and my watch at the same time, I'm not quite sure what time it is. I walked right into Seagull's

[1:51] built this clock and why after I built it, I'm going to I to go back to square one because my pi time server is actually drifting by a second or two,

[3:37] clean up the flux around them to make it look really nice? I can usually get most of it off, but there's always a little bit left over that doesn't seem to come

[5:15] need to put some options in the Pi config, reboot, install the RGB matrix library, then compile the PTP clock app. And, actually, I ran into a few issues

[6:54] displays had like 0.1 millimeters of overhang on the LED part and I didn't want to put pressure on that. With that design sorted out the two matrices come

[8:44] see that we are not in sync. In fact, this has drifted another second since I wrote the script for this video. So, we're almost 3 seconds off now. And

[10:36] reason, is taking both of these pulses every time. And so that the the actual time that it thinks it is can be off by 100 milliseconds. Problem that causes is

[12:28] my blog post that shows all the details and all the commands to run if you want to build one of your own. Until next time, I'm Jeff Geerling.

View verbatim transcript

Transcript generated from the video audio for accessibility.

[0:00] I built this PTP clock and now every time I look at it and my watch at the same time,

[0:05] I'm not quite sure what time it is. I walked right into Seagullslaw. That might be Seagullslaw,

[0:10] I'm not sure, but you might notice my voice is a little funny. That's because I've had a

[0:14] sinus thing going on. And now that my sinuses are clearing up, my voice is like, yeah,

[0:18] I'm going to take you back 30 years. Anyway, my watch only gives me the seconds, which are off by a

[0:24] little. This clock has nine more digits, which means I'm getting time down to the nanosecond.

[0:29] The eagle eye among you might notice these last digits are little blotchy, which is very much

[0:33] unlike the precision clock mark for over on my clock shelf. That's okay, though. The main thing here

[0:39] is this is showing me PTP time from a special time server I have in the rack room. What's PTP? Well,

[0:45] for now, just think of it like NTP but for lands. And because of that, it can be way more precise.

[0:52] That's useful for things like at the Blues Game I did and I covered on Girling Engineering,

[0:55] they use it to sync audio and video in an entire stadium. And that same tech is the basis for

[1:01] white rabbit and even more in same timing standard used for like Earth scale neutrino detectors.

[1:06] Anyway, I saw this clock in Oliver at lens 39c3 presentation. Excuse me what precise time is it?

[1:13] And after seeing that, I immediately sent him a message asking if he'd share how he made it.

[1:17] He went above and beyond, open sourcing his code and the list of all the parts I'd need.

[1:22] And I didn't even know at the time, but this thing is running on a Raspberry Pi 4.

[1:26] But that makes me ask why not just use another computer? Well, the Pi is particularly good because

[1:32] it meets two essential requirements for a PTP clock. One, it's easy to interface with LED matrix

[1:38] displays using its GPIO. And two, it has a special network adapter inside that supports PTP hardware

[1:44] time stamping. Now, again, I'm not going to get into the details of why something like PTP hardware

[1:49] time stampings important in this video, but I will tell you how I built this clock. And why,

[1:54] after I built it, I'm going to have to go back to square one because my Pi time server is actually

[1:58] drifting by a second or two, even though I thought I had it dialed in. Anyway, the parts you need will

[2:03] cost around 120 to 150 bucks depending on whether the AI bubble is popped yet. The most important part

[2:09] is the Raspberry Pi. Any Pi 4 will do. Right now the RGB matrix doesn't work on the Pi 5, so just

[2:15] stick with an older Pi 4. Then you need a hat. Specifically, this A to Fruit RGB matrix hat.

[2:21] This will let the Pi talk to the LED matrices. Then, of course, the matrices themselves. These

[2:26] are wave shares daisy chainable 64 by 32 pixel LED matrix panels, and they come with all the cables

[2:32] that you need to plug them into the hat. To power it all, you need to supply at least four amps through

[2:37] this parallel jack, so throwing a 5 volt foreign power adapter. And finally, to boot up the Pi, you need a

[2:42] micro SD card. Luckily, I already had a bunch of those. Now, you could technically build a clock that

[2:47] gets time from an NTP server on the internet and displays that on here. But I wanted PTP time,

[2:53] and I wanted it so that the time only shows up if you have a PTP server running on your network.

[2:58] So I guess if you don't have a PTP server, you'll need to have one of those, too. I actually have

[3:02] a little time Pi project on GitHub that shows you how to build one of your own, but I'm warning you,

[3:07] this is a very deep rabbit hole, and you can easily sink a few thousand hours, not to mention

[3:13] thousands of dollars into time. The hardware is pretty straightforward, but you do need to do a

[3:18] little soldering. And yes, my friends are more over the ocean. That's how we sit. So don't tell me

[3:22] about how you solder. Anyway, that's pretty straightforward. There are just three headers to put on,

[3:27] and make sure you put them on the right way when you stick them in there. And one question I have,

[3:31] though, something I've never quite gotten the hang of. After you finish soldering something like a GPIO

[3:36] header with all those pins, how do you clean up the flux around them to make it look really nice?

[3:40] I can usually get most of it off, but there's always a little bit left over that doesn't seem to come

[3:44] up with IPA. Is that just a matter of what type of rosin or flux I'm using? Let me know if you know

[3:50] in the comments. Once the hats put together, you just plug everything together. I'm not going to

[3:54] bore you with the details, but the best part of soldering something is seeing it not burn up and

[3:59] make sparks the first time you turn it on. Now, I'm powering this particular setup off a Raspberry

[4:03] Pi Power adapter that can supply 5 amps, but only if you use the right USB-C PD circuit. This little

[4:10] V-Flex adapter is probably only getting 3 amps, which is going to make the display flicker a little.

[4:14] You really need a 5 volt 4 amp power adapter. Also, in some of my testing, I had the power leads

[4:19] plugged into the screw terminal with the crimp on connectors they came with, but that's a little

[4:23] janky. I actually snip those off and stripped back the wire and then put that in the screw terminal.

[4:28] I think for a permanent install, I might put in my own soldered connector straight through the

[4:32] board though. But I got sidetracked again. You're probably wondering how I'm getting all these fancy

[4:36] spinning cubes and conways game of life running on here. Well, these are demo scripts you can run as

[4:41] part of the R-Pie RGB LED Matrix library maintained by Henners-Eller. If you put everything together

[4:47] correctly, you can run a command like this and get the LED matrices to show some pretty cool things.

[4:52] But I'm not interested in that, but I don't even need color. I want to take these amazing RGB

[4:57] LED displays and have them just display one color and do one thing, show a PTP clock.

[5:02] Now, I have all the exact commands to run on my blog and I'm actually leaving out a few steps

[5:07] in this video like you have to disable audio on the pie to make the matrix work correctly.

[5:11] But I'll put a link to that blog post with all the details in the description.

[5:14] The main things are you need to put some options in the Pieconfig reboot, install the RGB

[5:19] Matrix library, then compile the PTP clock app. And actually, I ran into a few issues with that,

[5:24] so I pushed up some code changes for OliverTreeView. But once I got past all that, it worked.

[5:30] I was getting PTP time through my network and this display showed it. And since I was using that

[5:34] pie-powered app, probably getting just three amps, the display was kind of dimming in and out a little

[5:38] bit. But hey, it worked. So the next step was to wrap up the software in a system-by-service

[5:43] and then see if I could get it to launch automatically while it booted up. I rebooted the pie

[5:48] and waited a bit and eventually it did it it worked. Looking more closely at the two sides separately,

[5:52] it looks like the part with the nanoseconds maybe doesn't dim as much as the other side, at least with

[5:57] this three-amp setup. But I decided to buy a 4M DC adapter to fix that entirely and I'll link you

[6:02] to it in the description if you want one of your own. Now just laying out on the desk, it's a little

[6:06] bit of a mess. And I noticed Oliver had some kind of J-reg metal bracket on stage during his

[6:11] presentation to hold it together. But I wanted something to make it easier to put the displays

[6:15] together and let you either stand it up like I have here or stick it on a magnetic surface using

[6:19] the magnet screws' wave share included. So I got out my calipers and my ruler, took a few

[6:24] measurements and got to designing. I'm still like a newborn baby in the world of CAD software,

[6:29] but at least I can draw a circle infusion now without wondering if I just broke the universe.

[6:33] My idea was just to have a brace between the two sides and use four of the screws that came with

[6:37] the displays to screw them together through the brace. And my confidence was high on print number one.

[6:42] But I should know by now it's gonna take a few more revisions. My final design was this with some

[6:48] little standoff so I could get my fingers around the round magnet screws. It also has a little bit

[6:52] of extra wiggle room since I noticed the two wave share displays had like 0.1 millimeters of

[6:57] overhang on the LED part and I didn't want to put pressure on that. With that design sorted out,

[7:01] the two matrices come together and look like one long screen, which looks really cool actually.

[7:06] Add a little cable management on the back and this thing is starting to look like something

[7:10] professional, which is kind of weird for me. I think I might spend a little time designing an

[7:14] angled stand that holds the pie in place too, but that's a future Jeff thing. I got this clock

[7:18] working and the first thing of course was that I checked whether it was in sync with my watch

[7:22] and it wasn't. And here's the part of the video where I show you what happened.

[7:26] Okay, bear with me while I get this camera out of here. I'm gonna show you what I think is going on.

[7:36] So here's two clocks. This is my clock rack. I have many projects up here that I have not shown

[7:42] off yet and I'm working on videos for them, but I have this GPS distribution and this clock is

[7:48] timed directly off GPS. So this is right now pretty much the most accurate clock I have in the

[7:53] studio and it's pretty close to the time that I have on my watch. So you can see 13, 14, 15, 16,

[8:00] 17, but you might notice the clock behind it is off a little bit. This is a master clocks. This

[8:06] is like a broadcast clock and it runs off NTP time. It's not the clock's fault. My NTP time server

[8:11] is getting its time through the same system that my PTP is getting. I am sorry about my voice here,

[8:17] but it is going all over the place. Anyway, this one's getting its time from the time pi that's

[8:23] in the back and that pi is getting its time from GPS. Now its time is distributed from GPS to the

[8:29] network interface card on that pi because it has a special timing chip in it. And then that is

[8:35] distributing the time to the pi's internal clock which distributes it to this clock. So this clock is

[8:40] within like a millisecond of the PTP time on my network. And you can see that we are not in sync.

[8:46] In fact, this has drifted another second since I wrote the script for this video. So we're almost

[8:51] three seconds off now. And here's the problem. My time server back in the back is using an Intel i226

[8:58] network interface card and the driver for that in Linux, it has a bug in it. And I'll tell you how

[9:04] that bug looks. So over here I have my oscilloscope set up with this. This is my GPS mini-many rack

[9:10] clock that I built with the Raspberry Pi Pico. This clock is taking a GPS input just like the precision

[9:17] clock over there. And this GPS input is going into the pi and the pi is putting the time out here.

[9:25] So the time here, I don't have seconds on it. Somebody I'll get that. But the time here should line up

[9:30] with the time over there. And I can see on here more easily the pulse per second. The pulse that

[9:36] is getting sent out to the network interface card on my time pi and what I think is the problem.

[9:42] So with the Intel 226 driver, what it does is it says every time that there's a pulse, every time

[9:48] that there's one of these little things, trigger a new second. And when it triggers a new second,

[9:52] it says, okay, hey GPS, what time is it? And then it puts that time into its memory and says,

[9:57] this is the start of the second of, you know, what is it right now? Of 229 and 50, 229 and 51, etc.

[10:05] And most network cards, the drivers will take the rising edge. So see how this,

[10:12] this is a voltage, there's zero volts, then there's a rising edge and then a falling edge,

[10:16] rising edge falling edge. And you can see that this is happening once every second.

[10:20] So if I look on here, we can see these pulses. They are, I have this measurement, the frequency

[10:26] and the pulse width. The frequency is one hertz, that's one pulse per second. And the pulse width

[10:32] is 100 milliseconds. The Intel I226 driver for whatever reason is taking both of these pulses

[10:39] every time. And so the actual time that it thinks it is can be off by 100 milliseconds. The problem

[10:45] that causes is sometimes it might be taking like the previous second of GPS data. Other times it

[10:50] might take the next second of GPS data and it confuses the clock. So there's actually a patch for that

[10:55] that I might try applying. The other alternative is I'm thinking about setting up this is my

[11:01] time pi. So this would be my main clock and I have two of these. So I could have two clocks going

[11:05] and choose the best one and I would give any given moment. This has a different network interface

[11:10] that uses the Raspberry Pi's built-in Broadcom chip, which doesn't have that silly rising and

[11:15] falling edge bug. I don't know. Let me know in the comments what you think I should do.

[11:19] For now, I might just apply the patch and see if I can get the other time server running back there.

[11:25] But I've spent probably, I told you, it's a time-sake. I probably spent 10 hours or 20 hours

[11:31] trying to get that time server to run perfectly where this one might just run perfectly out of the

[11:35] box. So I might just go this route. Anyway, let's come back over here and get to the conclusion of

[11:41] this video. You don't have to listen me blabbing on and having my voice go up and down all the time

[11:45] forever. Yes, so anyway, I'd really like to thank Oliver Edlin for sharing his work on this.

[12:07] When I saw this, I was like, I got to have this thing and I was so happy that he shared his code

[12:12] because even if it's not perfect, it's something and it helps me with this visual aid, which

[12:17] also helped me immediately see that my network time is off and I need to fix that. So

[12:22] I'm already a useful tool for me and it's a very cool visual aid for PTP. But anyway, I have all

[12:27] the links to everything in the description including my blog post that shows all the details and

[12:31] all the commands to run if you want to build one of your own. And until next time, I'm Jeff Kearling.