Real time clock bit

I have noticed some interesting discussions on this forum about the need for a “real time clock” bit.
Maybe someone on this forum could pick up the challenge to develop this interesting bit…
I would like to share my first thoughts about this subject with you.
Maybe the following design could work:

. Set year, month, day, hours, minutes, seconds, alarm and time zone with the set and up/down buttons.
. A maximum number of 10 alarms can be set (indicated by the alarm display).
. An alarm sets the SIG line on a 5 Volt level to activate the other connected bits.
. The timer can also be set on “chrono” to use a preset time setting. Then the clock counts down from the preset time to zero and initiates an alarm.
. Maybe an additional bitsnap could be connected to send the real time digital signals to an Arduino so with a little sketch this information could be used further in a project.

Note:
I own an alarm clock, automatically adjusted by the time signals from a low frequency radio station.
@Philip_Verbeek:
I saw your nice radio bit in the bitlab, could it be possible to integrate a radio chip, listening to such a LF (Low Freqency) radio station?

“In the United States, the signals received by radio controlled clocks originate from NIST Radio Station WWVB, which is located near Fort Collins, Colorado. WWVB broadcasts on a frequency of 60 kHz. A radio controlled clock actually has a miniature radio receiver inside, which is permanently tuned to receive the 60 kHz signal”.
See this link:

If this would not work, an oscillator controlled timer could be used, but this version would definetly be less accurate…
:alarm_clock: :smile:

2 Likes

I thought about a bit that would send out through the out bitsnap, a signal that would translate to 0 to 240 (using the 0-255 arduino range for 5 volts), and each increment would be equal to 6 minutes. At midnight it would reset.

2 Likes

Hi @alexpikkert!

I’m Diego from Brazil, nice to meet you! I’m new here in forums and with littleBits too, but a little experienced in embedded systems industry. So I’m trying to adapt myself in littleBits world, excuse-me If I misunderstand something!

It seems very useful to have events controlled either by real time or chronometer. Just playing the evil advocate role (sorry I don’t know if there are such expression in English), I mean trying to find the weakness of the idea:

  1. About the adjustment, over radio works fine in USA and Europe ( if you mean RDS or RBDS standards), in South America I know that it’s poor implemented. Just a remark.
  2. The alarm you plan to trigger a pulse when it occurs? Can have some control like at 6am set to 5V, at 7am set to 0V, at 8am set to 2.5V?
  3. The chronometer can be set once or auto-reload, in that case there should be one more switch.

It seems to be a great tool but I believe that opens a lot of use cases that with a simple display/switches interface will be hard to handle.

It should be nice to have it as an accessory of Arduino bit. I don’t know if there is digital interface in bitsnap, but could be something connected on i2c lines? There are tons of RTC i2c ICs, and it could be completely controlled by Arduino, that will give it more control.

Or, maybe some mix of it, as you already suggested, but in that case I suggest to keep it the simplest to use into switches/display (like only chrono) and all other functions when connected to Arduino.

It’s great to have your the contribution to community, I read a lot of your posts. Good job!
Hope I can contribute back somehow.

Regards,
Diego

3 Likes

Hi Diego @drthuler,
Nice to meet you too !
You don’t have to excuse yourself for any misunderstanding, on this forum you can learn a lot and many other forum members are willing to help and explain.
I only heard about LittleBits in december last year and since then I also have learned a lot on this forum!
It is very good to play the role of the evil advocate (I think it is called “the devil’s advocate” in English) when discussing topics. Everybody can learn from it!

  1. About the radio control option, RDS or RDBS is a different technology, used in (commercial) FM radio transmission for sending additional digital data about the sent music and other things.
    The LF radio signals I am referring to are pure time signals, with an extereme wide receiving range. Fore example here in Europe you can tune it to a station in Switserland.
  2. My plan is to have a trigger of 5Volt, because all other input bits could be activated. Do you have a specific purpose or activation in mind for 2.5 Volt for example?
    A trigger of 0 Volt would not be a real alarm I think…
  3. Auto reload or trigger once indeed needs another little switch. Maybe there could be a special Arduino library developed to set all details in an easy way, just dreaming…
    The bitsnaps are pure analog, bits do not understand digital information.
    the LittleBits (Leonardo) Arduino has 12c lines but for standard applications they are not used. I am also not an expert on this…
    Nice meeting you this way again, keep posting your ideas! :smile:
1 Like

Hi Alex @alexpikkert,

Sorry for the delay, see my comments:

  1. I was really confused about the set clock by Radio, as I worked with RDS before I assume that and didn’t read your explanations, sorry :grin: .
  2. Since you have alarms I figure out that it can be used to schedule tasks, for instance: at 5AM set servo at 30º, at 6AM set at 60º and so on (or a motor speed, light intensity, etc).
    That’s why I thought into set values different to 5V.
    Another point is, if it’s just 5V, so when the alarm is activated it will set the output for how long time?
  3. Yes, we always will find a new use of it and a need of some more switch, that’ what @chris101 explained to me about the guideline “it is more important to provide immediate control than absolute control”.
    About using Arduino it seems to be very easy, but I always look for keep into regular bit library then hack the modules. It should be nice to Arduino bit have some “cape” capability to extend functionality. See an example of RTC module into Arduino using i2c lines:

Tiny RTC with Arduino example

3 Likes

I like your clock @drthuler made from off the shelf components. I’ve been working on a clock bit because some projects need time sense, but do not need HMS precision. Time to the nearest quarter hour will work - this means that a whole day will fit into 8 bits, which is also the width of Arduino’s pwm output! :smiley:

Here is a proposal for a slow time (T = 6min.) Time of Day Bit. It’s precision is one tenth of an hour. This time scale should work for the spin of the Earth, ot the movement of the stars and planets. Maybe don’t use it to time a horse race though …

The accuracy should be pretty good if a real crystal is used. Six months or so until it’s off by one or so.

Here’s the schematic:

The sketch for the onboard Tiny85 reads the input, scales it to a tenth of an hour-per-day (0-239), adds 1 for every 0.1 hours, then sends the time to the output.

The time output can be interpreted in different ways, depending on the bits used:

  • A number bit will scale the 0-239 value to 0-99. This loses precision, but is still good to 15 minutes.

  • An Arduino can read to full precision. Programming it is up to the user - the output from the ToD Bit is 0-4.6 volts, which represents numbers from 0-239 (24.0 hours).

Time can be set with a dimmer (for example) on the input side. Hold the set button while setting the clock, release it to run.

Here’s the (untested) sketch:

// Time of Day
// precision = 1/10 hour (6 min)
// timebit01.ino - for ATtiny85
// clh 07272015

// ------- declarations -------------------------

// define some names for the pins:
const int timeOutput = 0;
const int setTime = 1;
const int timeInput = 2;

// variables used for time management:
unsigned long previousMillis = 0;
unsigned long aTenthOfAnHour = 360000;

// this is the value of the time,
// truncated to the last tenth of an hour:
int outputCount = 0; // 0-239 0 == midnight ; 239 == 11:54pm


// ------- setup --------------------------------

void setup() {
  pinMode(timeOutput, OUTPUT);
  pinMode(setTime, INPUT_PULLUP);

  SetClock();
}

// -------- main --------------------------------

void loop() {
  if (millis() - previousMillis >= aTenthOfAnHour) {
    outputCount++;
    if (outputCount > 255) {
      outputCount = 0;
    }
    analogWrite(timeOutput, outputCount);
    previousMillis += aTenthOfAnHour;    // thanks @drthuler 
  }

  if (digitalRead(setTime) == LOW) {
    SetClock();
  }
}

// ------------ subroutines ---------------

void SetClock()
{
  outputCount = (analogRead(timeInput));
  outputCount = outputCount / 4;
  analogWrite(timeOutput, outputCount);
}

I will build this thing, I have most of the parts, and I’ll order a crystal and caps today. Comments, corrections, or critique? Post 'em below!

1 Like

Hi Chris @chris101 ,

I understood the concept, it’s different from the Alex proposal.
That keeps more immediate control, just an analog clock output that can be connected to Arduino or number bit.
To use it directly (without Arduino) it should be nice a Threshould bit (I didn’t found one) like 2 trim pots to adjust the activate and deactivate analog levels, just to turn on/off (5V/0V) the output. That should be useful with other sensors too, like light, pressure, etc…
Getting back to your bit :smile:
Perhaps, to adjust, could be easier to adjust if it has a dimmer inside the module with the 24h clock printed on the board (see photo), like this there is no need to have a multimeter and make calculations to adjust it.

Just a remark, I didn’t reviewed deeply but it seems to be missing to load PreviousMillis.

previousMillis = millis();

Somewere inside:

if (millis() - previousMillis >= aTenthOfAnHour) {
    ...
}

Obviously easily identifiable when you test it, but since I found it… :thumbsup:

Nice job, keep us updated of your progress.
If you need something just ask!

2 Likes

Ha! Thanks for the debug @drthuler!

:confounded: I realized I left this line out while driving to work. I was going to quietly slip it in this morning, but you are fast! I added the following line:

previousMillis += aTenthOfAnHour;

You don’t need a multimeter to set it, just the same output as used to see the time. You DO have to make calculations though.

1 Like

Hi Chris @chris101 and Diego @drthuler,
Great design !
Did you test the threshold bit i23 with the output? Could it work?

What happens if the ATTiny is counting and by accident the VCC line is disconnected and reconnected? Does it start counting all over again? When working on a project it happened to me many times that power was interrupted. Should there be a kind of “time memory” included?
(Just thinking …)
I am not sure I understand the time setting calculation, can you give some details on this for me?
:smile:

PS Chris,
Which drawing program are you using for your schematics?

1 Like

Alright! I built the circuit using my Arduino Micro, and it worked!

The Dawn of Time:

Set the time using a potentiometer (or a slide dimmer bit) and observing the output with a number bit (or a volt meter, or a servo motor clock …)

Here is the sketch, pinned for the Micro, and 33X faster:

// Time of Day
// precision = 1/10 hour (6 min)
// timebit01.ino

// ------- declarations -------------------------

const int timeOutput = 9;  // use 0 for Tiny85
const int setTime = 7;     // use 1 for Tiny85
const int timeInput = A2;  // use 2 for Tiny85

unsigned long previousMillis = 0;
unsigned long aTenthOfAnHour = 1000;  // use 360000 (360 sec.) for Real Time

int outputCount = 0; // 0-239 0 == midnight ; 239 == 11:54pm


// ------- setup --------------------------------

void setup() {
  pinMode(timeOutput, OUTPUT);
  pinMode(setTime, INPUT_PULLUP);

  SetClock();
}

// -------- main --------------------------------

void loop() {
  if (millis() - previousMillis >= aTenthOfAnHour) {
    outputCount++;
    if (outputCount > 239) {
      outputCount = 0;
    }
    analogWrite(timeOutput, outputCount);
    previousMillis += aTenthOfAnHour;
  }

  if (digitalRead(setTime) == LOW) {
    SetClock();
  }
}

// ------------ subroutines ---------------

void SetClock()
{
  outputCount = (analogRead(timeInput));
  outputCount = outputCount / 4;
  analogWrite(timeOutput, outputCount);
}
1 Like

Hey Alex! I think we were posting at the same time (I took a rather long pause to make the video)!

Setting the clock uses a variable voltage input to set the variable that holds the current time. It gets displayed as it is set, then releasing the button commits it. The time is ticking forward the entire time.

Yes, there should be a time memory, but there isn’t. The time will reset to whatever the last time it was set to.

I use Photoshop and cut and paste to make the schematic. I’ve built up a library of components and wire bends.

I haven’t tested it, but the threshold bit should turn it into an alarm clock!

1 Like

Hi, @chris101! My husband has been bugging me to make a clock bit, so I’m really glad you’re working on this. :slight_smile: We’re both following your progress…

It looks like you are making schematics with Eagle CAD, which has a freeware version, BTW. Once you make a schematic, you can jump to another screen and design an etching.

1 Like

Hi Alex,

I really didn’t found the i23 Threshould bit :grin:, It doesn’t appears at littleBits Shop. I didn’t see the schematics but I believe that it should have default hysteresis, I just figured 2 dimmers in order to set hysteresis. But it does the work for alarm (or scheduled tasks).

About the problem of disconnection it can be a problem, since it doesn’t show a immediate feedback (only if you use the number bit). A simple solution I figured out is to use a high capacitor in micro-controller power supply to give some seconds or even a super-cap to give some hours. So it can keep can even if disconnected for a while.
In this case I recommend to keep micro in low power mode in most part of time. I have good experience with micro-controllers but few with Arduino, but it should have some API for that.

Jude, thanks for the tip, I was looking for something free to draw schematics and layout too, since I’m leaving the company I will lose the Altium license :confused:

2 Likes

Hi @drthuler,
Maybe this is something you could use:
http://fritzing.org/home/
This program generates diagrams and layout from a breadboard setup !
And its free…

3 Likes

Oh, yeah! You can do simulations with fritzing.

2 Likes

Hey @alexpikkert, that’s a very nice tool! I’m used to the professional ones, so complex, full of checks, rules. This one is perfect to work with Arduino!
That’ a brand new world for me! :smiley:
Thanks again

2 Likes

[quote=“drthuler, post:13, topic:22465”]
I really didn’t found the i23 Threshould bit :grin:, It doesn’t appears at littleBits Shop. I didn’t see the schematics but I believe that it should have default hysteresis, I just figured 2 dimmers in order to set hysteresis. But it does the work for alarm (or scheduled tasks).
…[/quote]

I believe they have just run out of the threshold bit - it’ll be back when they produce more inventory. Here is the page for it, along with a technical description. It’s essentially a Schmitt trigger with a potentiometer in place of feedback resistor. A pretty simple circuit using an op-amp:

2 Likes

I have been obsessed with this project for the last couple weeks, and just submitted my design for the Time of Day module to the Bit Lab for evaluation. It is similar to the prototype I made and proposed above.

Here are some pictures:

It works!

Here’s what it looks like, close up:


That’s a LOT of soldering. I needed this diagram to keep it all straight:


(I saw a dream bit asking for a fish. Do you suppose the above drawing would work for that? Squint if you don’t see it!)

Used in a circuit, it looks like this:

The time used by this bit comes from the 16.00 MHz ceramic resonator. I had initially thought I would need a quartz crystal, but the resonator’s resolution is fine for this application (and it reduces the number of components on the already crowded board by the two capacitors.)

Here is the updated schematic, with added protection of the time frequency circuitry, AND those opa4342, rail-to-rail op-amps that I got from ebay:

The ATTiny85 sketch is really simple. It looks at time as an 8 bit number, digitized from 0 to 240. This value is fed out through the pwm output, and *hella-*filtered (op-amped RC: 4700 ohms and 10 µF) to a steady analog voltage of 0 to 4.704. This gives a voltage:time conversion of 196mV per hour. Since this value is important for using the bit, I wrote it right on the circuit board. Here’s the sketch:

// Time of Day
// precision = 1/10 hour (6 min)
// 072815 - clh timebit01.ino
// 080415 - clh made into a perf-board bit

// ------- declarations -------------------------

const int timeOutput = 0;  // (pin 5)
const int setSwitch = 1;   // (pin 6)
const int timeInput = A1;  // (pin 7)

unsigned long previousMillis = 0;
unsigned long aTenthOfAnHour = 360000.;

byte outputCount = 0; // 0 is 12am & 239 is 11:54pm

// ------- setup --------------------------------

void setup() { 
  pinMode(timeOutput, OUTPUT);
  pinMode(setSwitch, INPUT); 

  SetClock();
}

// -------- main --------------------------------

void loop() {
  // Do this part every aTenthOfAnHour milliseconds
  if (millis() - previousMillis >= aTenthOfAnHour) {
    outputCount++;
    if (outputCount > 239) {
      outputCount = 0;
    }
    analogWrite(timeOutput, outputCount);
    previousMillis += aTenthOfAnHour;
  }

  // Do this part every time through
  if (digitalRead(setSwitch) == LOW) {
   SetClock();
  }
}

// ------------ subroutines ---------------

void SetClock()
{
  outputCount = analogRead(timeInput) / 4;
  analogWrite(timeOutput, outputCount);
}

If anyone is thinking of making their own real time bit, please discuss it here. I’d love to help, and also learn from your ideas!

ps, there’s a project using this bit, the Functional Analog Clock.

2 Likes

[quote=“alexpikkert, post:9, topic:22465”]
… Did you test the threshold bit i23 with the output? Could it work? …[/quote]

Could and does! I had a 10:00am meeting this morning, so I set a threshold to 40 and stuck it on my ToD bit (which has been running 4 days straight now) and here is the result:

[quote=“alexpikkert, post:9, topic:22465”]
… What happens if the ATTiny is counting and by accident the VCC line is disconnected and reconnected? Does it start counting all over again? When working on a project it happened to me many times that power was interrupted. Should there be a kind of “time memory” included?
(Just thinking …)
…[/quote]

I’ve been thinking on that. The bit normally resets to whatever it was set to previously by virtue of having the same input conditions. However I just tried a 1000µF 6.3v capacitor between the VCC and GND on the Tiny. It seems to hold the data for 2 seconds or so - enough to recover from an oops?

2 Likes

Here’s my take on the real time bit idea. I think it would be handy to have a digital timeout bit that can exactly stay on or off for either 1 second or 1 minute. Then we can rely on it in circuits like this:

Pictured above is a stopwatch without the reset button or pause button. Once I added those features, the pulse started veering way off.

When I change the pulse to a timeout set to around a minute (the closest I can get is 1:02 minutes), then a pesky problem is that the 12 o’clock hour looks like “00”. :frowning:

3 Likes