I'm trying to get an accurate time on an Arduino. I have an Ethernet Shield 2 attached to an Arduino Mega. There's also a couple current sensors and a barcode scanner. The main reason for this post is for those people that happen to have the Ethernet Shield 2 on any Arduino, and want to get the time. Every single example on the internet or in the Arduino IDE examples doesn't work, except for this one:
https://www.arduino.cc/en/Tutorial/UdpNtpClient
So as of the time of reading this, that tutorial will most likely be out of data, but let's say for the next 6 months it'll be the place to go.
So, here's a little insight into what I'm doing and my decisions along with some code at the end:
1. I have an Arduino. That means no clock.
2. I have an Ethernet Shield 2. That means there are an abundance of clocks on the internet.
3. I am not hooking up a clock to the Arduino. That means I need to use the Arduino to keep time.
4. So I'm going to do this by polling a clock on the internet, keeping that time around and adding the time since boot to that time. It isn't a clock you'd want to use as your morning alarm clock, but it'll be accurate enough for what I need.
So I hacked together two functions from that tutorial:
unsigned long getCurrentTime() {
unsigned long result = 0;
sendNTPpacket(timeServer); // send an NTP packet to a time server
// wait to see if a reply is available
delay(1000);
if (Udp.parsePacket()) {
// We've received a packet, read the data from it
Udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer
// the timestamp starts at byte 40 of the received packet and is four bytes,
// or two words, long. First, extract the two words:
unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
// combine the four bytes (two words) into a long integer
// this is NTP time (seconds since Jan 1 1900):
unsigned long secsSince1900 = highWord << 16 | lowWord;
Serial.print("Seconds since Jan 1 1900 = ");
Serial.println(secsSince1900);
// now convert NTP time into everyday time:
Serial.print("Unix time = ");
// Unix time starts on Jan 1 1970. In seconds, that's 2208988800:
const unsigned long seventyYears = 2208988800UL;
// subtract seventy years:
unsigned long epoch = secsSince1900 - seventyYears;
// print Unix time:
Serial.println(epoch);
result = epoch;
}
else {
result = 2099414000; // Picked a date so we can test when not connected to the internet.
}
return result;
}
String timeToString(unsigned long value) {
String result = "";
unsigned long epoch = value;
// print the hour, minute and second:
result += String((epoch % 86400L) / 3600); // print the hour (86400 equals secs per day)
result += String('-');
if (((epoch % 3600) / 60) < 10) {
// In the first 10 minutes of each hour, we'll want a leading '0'
result += String('0');
}
result += String((epoch % 3600) / 60); // print the minute (3600 equals secs per minute)
result += String('-');
if ((epoch % 60) < 10) {
// In the first 10 seconds of each minute, we'll want a leading '0'
result += String('0');
}
result += String(epoch % 60); // print the second
return result;
}
unsigned long startTime;
void setup() {
// ...
startTime = getCurrentTime();
}
And anytime you want the current time viola!
timeToString(startTime + millis() / 1000)
Tuesday, August 20, 2019
Arduino Eithernet Shield 2 NTP Time
Posted by
Chris Bensen
at
7:00 AM
2
comments
Wednesday, July 24, 2019
Fusion 360 - Threads Not Exported to STL
There is one thing that I always have problems with, so hopefully by writing this short blog post I'll remember more often. That problem is creating threads properly. Usually I noticed after I have already printed the part. Always remember to choose the "Modeled" check box. I wish I could make this the default.
Also, if you need to remove part of the hole after the threads in the timeline, you'll have thread remnants, so move the threads to be later in the timeline, then "Cut" the hole.

Posted by
Chris Bensen
at
7:00 AM
0
comments
Thursday, July 18, 2019
Very Large Raspberry Pi Cluster - Part VI
At this point I've shown how the all the Pi will be held in place to make a 2U rack, and next is the overall structure but that will have to wait until next week. So for this post I wanted to talk a little about the software and what we're going to run on all these Pi. A lot of data will be processed and sent to the cluster. So here's the high level of the software stack:
- Each Pi will network boot from a central server running Oracle Linux
- The boot image will be running Oracle Linux
- It will be running Kubernetes and Docker
- There will be a very large video wall run by a Windows server
- Everything will be written in Java
- Gluon is helping
Posted by
Chris Bensen
at
7:00 AM
0
comments
Labels: Raspberry Pi
Thursday, July 11, 2019
Very Large Raspberry Pi Cluster - Part V
Posted by
Chris Bensen
at
4:00 PM
1 comments
Labels: Raspberry Pi
Wednesday, July 3, 2019
Very Large Raspberry Pi Cluster - Part IV
So I've had a couple weeks here without much of a progress update. A lot of work has gone on. So here's a quick update before the holiday. First some photos. The first one is of the original prototype 3D printed out with some Pi in it.

Posted by
Chris Bensen
at
7:00 AM
0
comments
Labels: Raspberry Pi
Thursday, June 20, 2019
Very Large Raspberry Pi Cluster - Part III
I spent most of today fighting with Fusion 360 so I don't have much progress to report besides a serious complaint about Fusion 360. A new updated was released. If I didn't upgrade I couldn't save. If I upgraded I lost my changes. I had no choice but to upgrade, loose my changes and redo them. Then when I loaded up my models there were errors with unresolved imported components. The error states that if I save my model in this state I will loose my model. Personally I find this unacceptable and while I like Fusion 360, I like the disruption to the CAD world, many of the features, the price is reasonable and the fact that it runs on Mac and Windows, I also find it extremely buggy and a toy. I may be switching back to SolidWorks. Hopefully I get all of this resolved in the next few days and can report on the progress.
Update: After restarting Fusion 360 five times, and reloading the model after closing it with the error saying it will be destroyed, I finally got all the linked models and everything to load. So it was just a lot of ignoring errors and closing and reopening things and much ado about nothing, but extremely worrisome that just an update being pushed could cause such concern.
Posted by
Chris Bensen
at
7:00 AM
0
comments
Labels: Raspberry Pi
Wednesday, June 12, 2019
Very Large Raspberry Pi Cluster - Part II
Last week I posted about the very very large Raspberry Pi cluster that I'm building for Code One. Read that post here.
I realized after that post went live that I didn't give any backstory as to what we are actually building. When building something like this it's easy to document the entire process, it just takes 2-3 times as long to build. I figured I'd document the process in a fast and loose to blogs, YouTube and Twitter. So, before we go any further with the status of current progress let's backup.
Last year Stephen Chin and Gerald Venzl came to me with an idea. The conversation went something like this:
Stephen: "Gerald has an idea"
Gerald: "Let's build a HUGE biggest Raspberry Pi cluster for 2019 CodeOne. Like 1000 Raspberry Pis. The developers will love it. We will call it OSCAR!"
Me: "1000 is a lot, but 1024 is a better number"
Gerald, Stephen: "😃"
Back in the lab a few months later Jasper Potts and I did some math about how to pull off a cluster like this and we produced this rendering.
There will be 49 2U racks containing 21 Raspberry Pis (last weeks post was about this).
There will be 22 network switches.
There will be 18 USB power supplies.
There will be one server.
There will be 8 fans. This thing is going to get hot.
There will be 5 six foot server racks.
It will consume 120 amps of power.
It will require a fork lift to move.
It will network boot because can you imagine flashing 1024 SD cards?
In actuality, the server running the entire thing may be more powerful than all those Pis.
All of this barely fits in 5 racks.
This will travel to other Oracle events around the world next year.
WARNING: Actual numbers may vary, but the 1024 is the goal.
Posted by
Chris Bensen
at
7:00 AM
0
comments
Labels: Raspberry Pi
Wednesday, June 5, 2019
Very Large Raspberry Pi Cluster - Part I
I am building a very large Raspberry Pi Cluster and I'm going to document the process here. My goal is to post once a week until it's complete and shows up at Oracle Code One in San Francisco September 2019. Thus far an unimaginable amount of work has been put into this project to determine if it's even viable. We think it's viable so I'm going to start talking about it. There may be some mistakes. No, there will be some mistakes. Hopefully I won't make too many of them.
For the first taste, here is a rendering of a 2U rack that will hold 20 Raspberry Pi Model 3B+. I've printed out about 50 versions of this and this packs the most in while still allowing heat dissipation and still being serviceable in a standard server rack.
Posted by
Chris Bensen
at
7:00 AM
0
comments
Labels: Raspberry Pi
Tuesday, May 14, 2019
Fusion 360 Autosave
Why this isn't the default I have absolutely no idea, but the first thing you should do when learning Fusion 360 is to turn on this option:
How to Turn on Automatic Save in Fusion 360
Posted by
Chris Bensen
at
7:00 AM
0
comments
Saturday, May 4, 2019
Tuesday, April 30, 2019
New Chapter
It has been nearly a year since I last posted to this blog. It isn't that I haven't wanted to or that I've been sitting around watching TV. I've been busy. Real busy. I now work for the Oracle Developer Marketing team as a Groundbreaker building experiences for developers. It's an amazing opportunity that I had to jump into 1000%. Here's one experience that I built last year and blogged about but not on this blog. Go check it out https://blogs.oracle.com/developers/building-the-oracle-code-one-2018-escape-rooms. Not only do I get to draw on my 20+ years of Software Engineering/Architecture experience, I get to use everything I've ever learned about being an inventor, tinkerer professional photographer, maker, prop builder, and videographer. I use 3D printers, CNC, camera's, Arduino, Raspberry Pis and a whole lot more on a daily basis. So follow me on Twitter https://twitter.com/chrisbensen and YouTube https://www.youtube.com/channel/UCLf9yhC2uo7TxNIwiJqIDcw as a lot more content should be coming! Like the world's largest Raspberry Pi cluster.
Posted by
Chris Bensen
at
7:00 AM
1 comments
Thursday, July 5, 2018
Buying Stuff on Amazon
Posted by
Chris Bensen
at
7:00 AM
1 comments






