Espruino's Real Time Clock

Introduction

Often you might want to keep the current time - either for a clock, or maybe for Data Logging.

All Espruino boards contain their own Real-Time Clock which allows them to keep time even when it is saving power by being in Deep Sleep. However, depending on the board you have, the accuracy of the clock can vary wildly:

Board Oscillator Accuracy
Espruino Original 1v4+ External Crystal Good
Espruino Original 1v3 Internal RC 1%
Espruino Pico Internal RC 10%
Espruino WiFi External Crystal Good
Puck.js Internal RC w. calibration Good
Pixl.js Internal RC w. calibration Good
MDBT42Q Internal RC w. calibration Good
Bangle.js Internal RC w. calibration Good

If you have an Espruino Original or Pico without a crystal it is possible to add one - see below.

Note: You could also use an external module like the DS3231.

Adding Crystals

Espruino Original

Note: Espruino revision 1.4 boards already have a low speed oscillator on board. It's only 1.3 where you might want to add one.

32.768kHz crystal

You can get crystals from pretty much any electronic component supplier, for instance:

You need something that looks like the above - roughly 8mm long and 2mm wide, with 2 very thin wires. They're not very expensive - less than £1 each usually, however you may also be able to scavenge them from old Quartz watches.

32.768kHz crystal position

Finished crystal

The other four empty pads nearby are for two capacitors for the crystal. These crystals require around 12pF for each capacitor - however in reality there is enough capacitance in the PCB, and the crystal will work perfectly well without them.

Espruino Pico

There are 6 empty pads on the end of the board opposite the USB connector. You'll need:

The crystal goes on the 2 big pads, and the two capacitors go on the small ones.

If you have access to a hot air rework station and some tweezers then that's definitely the easiest way to install the crystal. It is possible to use a soldering iron with a thin tip, but it will take a lot of time and care.

Software

Nothing is needed! Just plug your Espruino in, and the Crystal will automatically be detected and used!

It's recommended that you turn on Set Current Time in the Web IDE's communications settings. Then, when you upload code the correct time (and timezone) will be set, and new Date() will return a Date object which can be queried for the current time.

To set the time manually you can just use the setTime(...) function with the number of seconds since 1970.

However you can also use the clock module which will keep track of time independent of the system time.

This page is auto-generated from GitHub. If you see any mistakes or have suggestions, please let us know.