[Update 2] Wall Clock

More updates on the project!

The GitHub Repo is as always the place for the latest code.

I still haven’t changed the circuit I am working on. The only change I made on the hardware side is that the arduino now is always connected to a computer. Since I recently setup an old laptop to work as a 24×7 online home server, this is something I can afford to do without losing my power supply.

For now, I have removed the alarm functionality. As I am now considering the Arduino to be an extension of the laptop, I don’t need it to have on board audio. The laptop can blare alarms via the speakers I scavenged last month via a simple Bash script.

Getting raw values for time and weather is actually very easy. I use python for this, but it could probably be done with your programming language of choice. All I do is use the function time.localtime(time.time()) to get localtime as a convenient struct, and use OpenWeathrMap API to receive weather as a JSON object. I send all the information I want to the Arduino via pySerial.

Things were a little less easy to achieve on the Arduino side. The two major issues I faced were the fact that I now needed the board to count time from whenever accurate time was read from the computer. After thinking about it, I define a “local epoch”, zerotime, and update the value of the variable to reflect the last time data was received from the serial port. My new rawtime is the difference between uptime and zerotime.

The second problem was that Serial.read() on the board only returns one byte of serial data at a time. It took me a lot of time to figure out how to work around that constraint. I worked around it by broadcasting an intent byte from the computer telling whether the following data was time or weather. After that, the computer sends the data byte by byte to the board. Back on the Ardunio, there seems to be a requirement of a 60 millisecond delay between receiving the intent byte, and receiving the actual data. I suspect it has something to do with the fact that the intent is read in the main loop, while the data is read in the corresponding functions. If there is no data the board just goes on with life as normal.

I also finally got around to accounting for leap years in day counting. Not that it matters much, because accurate local time is frequently received from a reliable source. But it bugged at me to not have logically reliable internal timekeeping as well.

Here’s an image of the latest display (and the home server in background).

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.


%d bloggers like this: