Jul 022016
 
LED Clock + Arduino

4 years ago (time flies by!) I built a 6 digit 16 segment LED display. It’s using SPI and thus can be extended to many digits. It does not refresh all signals, so it’s limited in length, but it’s working for 6 digits. Which is enough for a clock.

Using Arduino as a quick check works well. Synchronizing the clock from a PC works too. There’s a problem though I did not expect: sending data to the Arduino via output redirection to /dev/ttyUSB0 fails to work. Reason is that the interface gets closes when done which breaks communication.

2 choices for the fix:

tail -f /dev/ttyUSB0 &

or

stty -F /dev/ttyUSB0 cs8 38400 ignbrk -brkint -icrnl -imaxbel \
-opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke \
noflsh -ixon -ixoff -crtscts -hupcl

The latter sets baurate too, but the important part is the -hupcl which does not close the interface when the shell is done.

So now I can synchronize the time from the PC to the Arduino via:

TZ_adjust=9;d=$(date +%s);t=$(echo "60*60*$TZ_adjust/1" | bc);echo T$(echo $d+$t | bc) >
/dev/ttyUSB0

Adjust TZ_adjust for your time zone. Also the Arduino clock is very inaccurate, so for a real clock, get a proper RTC with a good and more accurate crystal. The one I have is off by 900ppm (about 3s too fast per hour).