Tag Archive | "time"

Kit Review – Maniacal Labs Epoch Clock

Introduction

The subject of our latest kit review is the “Epoch Clock” from Maniacal Labs, a new organisation started by three young lads with some interesting ideas. Regular readers will know we love a clock – so when the opportunity came to review this one, we couldn’t say no.

At this point you may be thinking “what is Epoch time anyway?”. Good question! It is the number of seconds elapsed since the first of January, 1970 (UTC) – and used by Unix-based computers as the start of their time universe. (For more on the theory of Epoch time, check out Wikipedia). For example - 1379226077 Epoch time is Sun, 15 Sep 2013 06:21:17 GMT. That’s a lot of seconds. If you’re curious, you can do more calculations with the EpochTime website.

Moving forward, this clock kit will show Epoch time in full 32-bit binary glory, using a DS1307 real-time clock IC (with backup battery) and is controlled with an ATmega328P-PU – so you can modify the code easily with the Arduino IDE or WinAVR (etc).

Assembly

The creators have spent a lot of time on not only the packaging and out-of-box-experience, but also the documentation and setup guide – so as long as you’re fine with simple through-hole soldering the kit will not present any challenges. The kit arrives in a sturdy box:

binary epoch clock kit box

… with well packaged components. Everything is included for the finished product, as well as IC sockets, the RTC backup battery and a USB cable so you can power the clock from a USB hub:

binary epoch clock kit box contents

binary epoch clock kit parts contents

The PCB is a good thickness, and has a clear silk-screen and solder mask:

binary epoch clock kit PCB

binary epoch clock kit PCB bottom

Construction is simple, just follow the step-by-step instructions. Starting with the USB socket for power:

binary epoch clock kit USB socket

binary epoch clock kit USB socket bottom

… then the resistors:

binary epoch clock kit resistors

… the LEDs:

binary epoch clock kit first LEDs

… all 32 of them. Note that the LEDs don’t sit flush with the PCB, so a little effort is required to keep them aligned:

binary epoch clock kit all LEDs

 Then the rest of the components just fit as expected. I’ve also added the included header pins for an FTDI programming cable and ICSP to keep my options open:

binary epoch clock kit almost finished

Then simply fit the battery, insert the ICs and you’re done:

binary epoch clock kit finished

Using the clock

The microcontroller is pre-programmed, so you can use the clock straight away. You will however need to set the time first. To make this incredibly easy, there is a special web page that displays the current time and Epoch time, which steps you through the process of setting the time using the buttons.

Or with some code available on the kit github page and a programming cable, you can automatically sync it to the clock. Once setup, the battery will keep the current time in the RTC nicely. The clock is powered by 5V, which is easily supplied with the included USB cable, or you can always hack in your own feed.

So what does Epoch time in 32-bit binary look like? Here’s a short video of the clock in action:

Reading the time requires converting the binary number displayed with the LEDs back to a decimal number – which is of course the Epoch count of seconds since 1/1/1970. Math teachers will love this thing.

But wait, there’s more!

If you get tired of the blinking, there’s a test function which is enabled by holding down both buttons for a second, which turns the Epoch Clock into a nifty Larson Scanner:

To create your own sketches or examine the design files in more detail, it’s all on the clock github page. From a hardware perspective you have an ATmega328P-PU development board with a DS1307 battery-backed real-time clock – with 32 LEDs. So you could also create your own kind of clock or other multi-LED blinking project without too much effort. Review the EpochClockSchematic (.pdf) to examine this in more detail.

Conclusion

I really enjoyed this kit – it was easy to assemble, I learned something new and frankly the blinking LEDs can be quite soothing. The clock would make a great for a conversation-starter in the office, or would make an ideal gift for any Sheldon Cooper-types you might be associated with. Or have competitions to see who can convert the display to normal time. After shots.

Nevertheless it’s a fun and imaginative piece of kit, fully Open Hardware-compliant – and if you’ve made it this far – get some and have fun. Full-sized images are on flickr. Interested in Arduino? Check out my new book “Arduino Workshop” from No Starch Press.

In the meanwhile have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, subscribe  for email updates or RSS using the links on the right-hand column? And join our friendly Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other –  and we can all learn something.

[Note - The kit reviewed was a promotional consideration from Maniacal Labs]

Posted in arduino, ds1307, epoch time, kit review, linux, real time clock, tronixstuffComments (1)

Tutorial – Arduino and PCF8563 real time clock IC

Use the NXP PCF8563 real-time clock IC with Arduino in chapter fifty-four of our Arduino Tutorials. The first chapter is here, the complete series is detailed here.

Updated 20/08/2013

Introduction

Recently a few people have been asking about the PCF8563 real-time clock IC from NXP – so this is a tutorial on how to use it for time, date, alarm clock and square-wave generation purposes.

The PCF8563 is another inexpensive RTC that can be used with an Arduino or other platforms due to the wide operating voltage (1 to 5.5V DC), I2C interface, and very low power consumption (when powered by a backup battery it only draws 0.25 μA). If you aren’t up to speed on the I2C interface, please review the I2C tutorials before moving forward. And please download the data sheet (.pdf).

The PCF8563 is available in various chip packages, for the curious we’re using the TSSOP8 version mounted on a breakout board:

PCF8563_SMD

Don’t panic – you can also get it in a breadboard-friendly DIP (through-hole) package as well, and also on a pre-built module from the usual suspects.

Demonstration Circuit

If you have a pre-made module, you can skip to the next section. However if you’re making up the circuit yourself, you will need:

  • One 32.768 kHz crystal
  • Two 1N4148 diodes*
  • One 3V coin cell (with holder)*
  • Two 10kΩ resistors
  • One 0.1 uF capacitor

And here’s the schematic:

PCF8563

* You can skip the diodes and battery if you don’t want a backup power supply when the main power is turned off or removed. Pin 3 is for the interrupt output (we’ll consider that later) and pin 7 is for the square-wave oscillator output.

Communicating with the PCF8563

Now to get down into the land of I2C once more. When looking through the data sheet NXP mentions two bus addresses, which have the same 7-bits finished with either a 1 for read or 0 for write. However you can just bitshift it over one bit as we don’t need the R/W bit – which gives you a bus address of 0×51.

Next you need to know which registers store the time and date – check the register map (table 4) on page 7 of the data sheet:

PCF8563 time date registers

 There will be a few other registers of interest, but we’ll return to those later. For now, note that the time and date start from 0×02. And one more thing – data is stored in the BCD (binary-coded- decimal) format. But don’t panic, we have a couple of functions to convert numbers between BCD and decimal.

Writing the time and date is a simple matter of collating the seconds, minutes, hours, day of week, day of month, month and year into bytes, converting to BCD then sending them to the PCF8563 with seven Wire.write() functions. Reading the data is also easy, just set the pointer to 0×02 and request seven bytes of data – then run them through a BCD to decimal conversion. With a catch.

And that catch is the need to sort out unwanted bits. Revisit table 4 in the data sheet – if you see an x that’s an unused bit. If any of them are a 1 they will mess up the BCD-decimal conversion when reading the register, so they need to be eliminated just like a whack-a-mole. To do this, we perform an & (bitwise AND) operation on the returned byte and mask out the unwanted bits with a zero. How does that work?

Example – the byte for dayOfMonth is returned – we only need bits 5 to 0. So 6 and 7 are superfluous. If you use (dayOfMonth & B00111111) the & function will set bits 6 and 7 to zero, and leave the other bits as they were.

Now to put all that together in a demonstration sketch. It puts everything mentioned to work and simply sets the time to the PCF8563, and then returns it to the serial monitor. The data is kept in global variables declared at the start of the sketch, and the conversions between BCD and decimal are done “on the fly” in the functions used to send or retrieve data from the PCF8563. Read through the following sketch and see how it works for yourself:

And a quick video of this in operation:

If all you need to do is write and read the time with the PCF8563, you’re ready to go. However there’s a few more features of this unassuming little part which you might find useful, so at least keep reading…

Square-wave output

As with any clock or RTC IC, an oscillator is involved, and as mentioned earlier you can take this from pin 7 of the PCF8563. However – it’s an open-drain output – which means current flows from the supply voltage into pin 7. For example if you want to blink an LED, connect a 560Ω resistor between 5V and the anode of the LED, then connect the cathode to pin 7 of the PCF8563.

The frequency is controlled from the register at 0x0D. Simply write one of the following values for the respective frequencies:

  • 10000000 for 32.768 kHz;
  • 10000001 for 1.024 kHz;
  • 10000010 for 32 kHz;
  • 10000011 for 1 Hz;
  • 0 turns the output off and sets it to high impedance.

The following is a quick demonstration sketch which runs through the options:

And the resulting waveforms from slowest to highest frequency. Note the sample was measured from a point between the LED and resistor, so the oscillations don’t vary between the supply voltage and zero:

PCF8563_1Hz

PCF8563_32Hz

PCF8563_1024Hz

PCF8563_32768Hz

Self-awareness of clock accuracy

The PCF8563 monitors the oscillator and supply voltage, and if the oscillator stops or the voltage drops below a certain point – the first bit of the seconds register (called the VL bit) is set to 1. Thus your sketch can tell you if there’s a chance of the time not being accurate by reading this bit. The default value is 1 on power-up, so you need to set it back to zero after setting the time in your sketch – which is done when you write seconds using the code in our example sketches. Then from that point it can be monitored by reading the seconds register, isolating the bit and returning the value.

Examine the function checkVLerror() in the following example sketch. It reads the seconds byte, isolates the VL bit, then turns on D13 (the onboard LED) if there’s a problem. The only way to restore the error bit to “OK” is to re-set the time:

And now for a demonstration of the error-checking at work. We have the PCF8563 happily returning the data to the serial monitor. Then the power is removed and restored. You see D13 on the Arduino-compatible board turn on and then the error is displayed in the serial monitor:

This function may sound frivolous, however if you’re building a real product or serious project using the PCF8563, you can use this feature to add a level of professionalism and instil confidence in the end user.

Alarm Clock

You can use the PCF8563 as an alarm clock, that is be notified of a certain time, day and/or day of the week – at which point an action can take place. For example, trigger an interrupt or turn on a digital output pin for an external siren. Etcetera. Using the alarm in the sketch is quite similar to reading and writing the time, the data is stored in certain registers – as shown in the following table from page seven of the data sheet:

PCF8563 alarm registers

However there is a catch – the MSB (most significant bit, 7) in the registers above is used to determine whether that particular register plays a part in the alarm. For example, if you want your alarm to include hours and minutes, bit 7 needs to be set to 1 for the hour and minute alarm register. Don’t panic – you can easily set that bit by using a bitwise OR (“|”) and B10000000 to set the bit on with the matching data before writing it to the register.

Checking if the alarm has occurred can be done with two methods – software and hardware. Using software you check bit 3 of the register at 0×01 (the “AF” alarm flag bit). If it’s 1 – it’s alarm time! Then you can turn the alarm off by setting that bit to zero. Using hardware, first set bit 1 of register 0×01 to 1 – then whenever an alarm occurs, current can flow into pin 3 of the PCF8563. Yes - it’s an open-drain output – which means current flows from the supply voltage into pin 3. For example if you want to turn on an LED, connect a 560Ω resistor between 5V and the anode of the LED, then connect the cathode to pin 3 of the PCF8563. To turn off this current, you need to turn off the alarm flag bit as mentioned earlier.

Now let’s put all that into a demonstration sketch. It’s documented and if you’ve been following along it shouldn’t be difficult at all:

This is the same as the example 54.1, however we’ve added the required functions to use the alarm. The required alarm data is stored in the global bytes:

and is written to the PCF8563 using the function:

Note the use of bitwise OR (“|”) to add the enable bit 7 to the data before writing to the register. The interrupt pin is also set to activate at the end of this function, however you can remove that part of the code if unnecessary. We also demonstrate checking the alarm status via software using the function:

which simply reads the AF bit in the register at 0×01 and let’s us know if the alarm has occurred via the Serial Monitor. In this function you can add code to take action for your required needs. It also calls the function:

which retrieves the contents of the register at 0×01, sets the AF bit to zero and writes it back. We do this to preserve the status of the other bits in that register. For the curious and non-believers you can see this sketch in action through the following video, first the software and then the hardware interrupt pin method (an LED comes on at the alarm time and is then turned off:

 Conclusion

Hopefully you found this tutorial useful and now have the confidence to use the PCF8563 in your own projects. Furthermore I hope you learned something about the I2C bus and can have satisfaction in that you didn’t take the lazy option of using the library. People often say to me “Oh, there’s a library for that”, however if you used every library – you’d never learn how to interface things for yourself. One day there might not be a library! And then where would you be? So learning the hard way is better for you in the long run. If you have any questions leave a comment below, or ask privately via the contact page.

And if you enjoy my tutorials, or want to introduce someone else to the interesting world of Arduino – check out my book (now in a second printing) “Arduino Workshop” from No Starch Press.

In the meanwhile have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, subscribe  for email updates or RSS using the links on the right-hand column? And join our friendly Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other –  and we can all learn something.

Posted in arduino, I2C, PCF8563, real time clock, tronixstuff, tutorialComments (5)

Project: Clock Four – Scrolling text clock

Introduction

Time for another instalment in my highly-irregular series of irregular clock projects.  In this we have “Clock Four” – a scrolling text clock. After examining some Freetronics Dot Matrix Displays in the stock, it occurred to me that it would be neat to display the time as it was spoken (or close to it) – and thus this the clock was born. It is a quick project – we give you enough to get going with the hardware and sketch, and then you can take it further to suit your needs.

Hardware

You’ll need three major items – An Arduino Uno-compatible board, a real-time clock circuit or module using either a DS1307 or DS3232 IC, and a Freetronics DMD. You might want an external power supply, but we’ll get to that later on.

The first stage is to fit your real-time clock. If you are unfamiliar with the operation of real-time clock circuits, check out the last section of this tutorial. You can build a RTC circuit onto a protoshield or if you have a Freetronics Eleven, it can all fit in the prototyping space as such:

If you have an RTC module, it will also fit in the same space, then you simply run some wires to the 5V, GND, A4 (for SDA) and A5 (for SCL):

By now I hope you’re thinking “how do you set the time?”. There’s two answers to that question. If you’re using the DS3232 just set it in the sketch (see below) as the accuracy is very good, you only need to upload the sketch with the new time twice a year to cover daylight savings (unless you live in Queensland). Otherwise add a simple user-interface – a couple of buttons could do it, just as we did with Clock Two. Finally you just need to put the hardware on the back of the DMD. There’s plenty of scope to meet your own needs, a simple solution might be to align the control board so you can access the USB socket with ease – and then stick it down with some Sugru:

With regards to powering the clock – you can run ONE DMD from the Arduino, and it runs at a good brightness for indoor use. If you want the DMD to run at full, retina-burning brightness you need to use a separate 5 V 4 A power supply. If you’re using two DMDs – that goes to 8 A, and so on. Simply connect the external power to one DMD’s terminals (connect the second or more DMDs to these terminals):

The Arduino Sketch

You can download the sketch from here. Please use IDE v1.0.1 . The sketch has the usual functions to set and retrieve the time from DS1307/3232 real-time clock ICs, and as usual with all our clocks you can enter the time information into the variables in void setup(), then uncomment setDateDs1307(), upload the sketch, re-comment setDateDs1307, then upload the sketch once more. Repeat that process to re-set the time if you didn’t add any hardware-based user interface.

Once the time is retrieved in void loop(), it is passed to the function createTextTime(). This function creates the text string to display by starting with “It’s “, and then determines which words to follow depending on the current time. Finally the function drawText() converts the string holding the text to display into a character variable which can be passed to the DMD.

And here it is in action:

Conclusion

This was a quick project, however I hope you found it either entertaining or useful – and another random type of clock that’s easy to reproduce or modify yourself. We’re already working on another one which is completely different, so stay tuned.

In the meanwhile have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, subscribe  for email updates or RSS using the links on the right-hand column? And join our friendly Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other –  and we can all learn something.

Posted in arduino, clocks, dmd, ds1307, DS3232, freetronics, learning electronics, LED matrix, microcontrollers, projects, scrolling, time clock, timing, tutorialComments (10)

Project: Clock One

Let‘s make a huge analogue and digital clock using a dot-matrix display. 

Updated 18/03/2013

For some strange reason I have a fascination with various types of electronic clocks (which explains this article). Therefore this project will be the start of an irregular series of clock projects whose goal will be easy to follow and produce interesting results. Our “Clock One” will use a Freetronics Dot Matrix Display board as reviewed previously. Here is an example of an operating Clock One:

As you can see, on the left half of the board we have a representation of an analogue clock. Considering we only have sixteen rows of sixteen LEDs, it isn’t too bad at all. The seconds are illuminated by sixty pixels that circumnavigate the square clock throughout the minute. On the right we display the first two letters of the day of the week, and below this the date. In the example image above, the time is 6:08. We omitted the month – if you don’t know what month it is you have larger problems.

Hardware

To make this happen you will need:

  • Freetronics Dot Matrix Display board;
  • If you want the run the display at full brightness (ouch!) you will need a 5V 2.8A power supply – however our example is running without the external supply and is pretty strong
  • An Arduino board of some sort, an Uno or Eleven is a good start
  • A Maxim DS1307 real-time clock IC circuit. How to build this is explained here. If you have a Freetronics board, you can add this circuit directly onto the board!

Software

Planning the clock was quite simple. As we can only draw lines, individual pixels, and strings of text or individual characters, some planning was required in order to control the display board. A simple method is to use some graph paper and note down where you want things and the coordinates for each pixel of interest, for example:

Using the plan you can determine where you want things to go, and then the coordinates for pixels, positions of lines and so on. The operation for this clock is as follows:

  • display the day of week
  • display the date
  • draw the hour hand
  • draw the minute hand
  • then turn on each pixel representing the seconds
  • after the 59th second, turn off the pixels on the left-hand side of the display (to wipe the clock face)

There isn’t a need to wipe the right hand side of the display, as the characters have a ‘clear’ background which takes care of this when updated. At this point you can download the Arduino sketch from here. Note that the sketch was written to get the job done and ease of reading and therefore not what some people would call efficient. Some assumed knowledge is required – to catch up on the use of the display, see here; and for DS1307 real-time clock ICs, see here.

The sketch uses the popular method of reading and writing time data to the DS1307 using functions setDateDs1307 and getDateDs1307. You can initally set the time within void setup() – after uploading the sketch, comment out the setDateDs1307 line and upload the sketch again, otherwise every time the board resets or has a power outage the time will revert to the originally-set point.

Each display function is individual and uses many switch…case statements to determine which line or pixel to draw. This was done again to draw the characters on the right due to function limitations with the display library. But again it works, so I’m satisfied with it. You are always free to download and modify the code yourself.  Moving forward, here is a short video clip of the Clock One in action:

For more information about the display used, please visit the Freetronics product pageDisclaimer – The display module used in this article is a promotional consideration made available by Freetronics.

In the meanwhile have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, subscribe  for email updates or RSS using the links on the right-hand column? And join our friendly Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other –  and we can all learn something.

Posted in arduino, clocks, dmd, ds1307, DS3232, freetronics, LED matrix, timing, tutorialComments (18)

Clock Kit Round-up – December 2011

Hello Readers

If there’s one thing that I really like it’s a good clock kit. Once constructed, they can be many things, including:

  • a point of differentiation from other items in the room;
  • a reminder of the past (nixie tubes!) or possible visions of the future;
  • the base of something to really annoy other people;
  • a constant reminder to get back to work;
  • a source of satisfaction from having made something yourself!

So just for fun I have attempted to find and list as many interesting and ‘out of the ordinary’ kits as possible, and ignored the simple or relatively mundane kits out there. If you are in the clock kit business and want a mention, let me know. So in no particular order, we have:

adafruit industries “ice tube” clock

Based around a vintage Soviet-era vacuum IV-18 type fluorescent display, the ice tube clock is a rare kit that includes a nice enclosure which keeps you safe from the high voltages as well as allowing the curious to observe your soldering skills. I reviewed this kit almost a year ago and the clock is still working perfectly. Here is a video of the ice tube clock in action:

After some travelling meeting various people it seems that quite a few of us have an ice tube clock. There is something quite mesmerising about the display, perhaps helping to recall memories of our youth in the 1970s and 80s.

nootropic design Defusable Clock Kit

As recently reviewed, this kit allows you to build a simulated ‘countdown’ timer for a hypothetical explosive device that also doubles as a clock with an alarm. For example:

Whatever you do, don’t make a ‘fake bomb’ and leave it out in public! Only bad things could happen :)

ogilumen nixie tube kits

Not a clock kit as such, however they have made doing it yourself very easy with their power supply and IN-12A nixie board kits. We made one ourselves in a previous review, as shown below:

Alan Parekh’s Multimeter Clock Kit

This is certainly one from left field – using the analogue multimeters to display hours, minutes and seconds. See Alan describe his kit in this video:

Certainly something different and would look great on the wall of any electronics-themed area or would easily annoy those who dislike the status-quo of clock design.

akafugu VFD Modular Clock

The team at akafugu have created a modular baseboard/shield kit which holds a shield containing four IV-17 alphanumeric nixie tubes to create your own clock or display system:

vfd-7

Unlike some of the other nixie tube kits the firmware has been made public and can be modified at will. In the future different display shields will be available to extend the use of the kit.

tubeclock.com kits

This site has two kits available, one using either four or six Soviet-era IN-12 type nixie tubes:

large_red

… and another kit using the Soviet-era IN-14 nixie tubes:

You have to hand it to the former Soviet Union – they knew how to over-produce nixie tubes. One rare example where we can benefit from a command economy!

evil mad science clocks

The certainly not evil people have two clock kits, the first being the Bulbdial Clock Kit:

This uses a unique ring of LEDs around the circumference of the clock face to create shadows to mark the time. It is also available in a range of housing and face styles. Their other kit of interest is the Alpha Clock Five:

The photo of this clock doesn’t do it justice – the alphanumeric displays are 2.3″ tall, making this one huge clock. It also makes use of a Chronodot real-time clock board, which contains a temperature-controlled oscillator  which helps give it an accuracy of +-/ 2 minutes per year. Furthermore you can modify this easily using an FTDI cable and the Arduino IDE with some extra software. Would be great for model railways (or even a real railway station) or those insanely conscious about the time.

Kabtronics Clock Kits

This organisation has several clock kits which span a range of technology from the later part of the twentieth century. These guys can only be true clock enthusiasts! Starting with the 1950s, they have their Nixie-Transistor Clock:

neononwall

Look – no integrated circuits, leaving the kit true to the era. If you need to hide from someone for a weekend, building this would be a good start. Next we move onto the 1960s and the Transistor Clock:

onwall_l

The 1960s brought with it LEDs so they are now used in this kit, however the logic is still all analogue electronics. However next we can move to the 1970s, and finally save some board space with the TTL Clock:

ttlclock_1721

This would still be fun to assemble but somewhat less punishing for those who don’t enjoy solder fumes that much. However you still have a nice kit and something to be proud of. Finally, the last in the line is the 1980s-themed Surface-Mount Technology Clock:

smtclock_l

So here we have a microcontroller, SMT components, and a typical reduction in board size. Their range is an excellent way of demonstrating the advances in technology over the years.

The GPS FLW Display Clock

Wow – this clock makes use of huge Burroughs B7971 15-segment nixie tube displays and a GPS receiver to make a huge, old-style/new-tech clock. Check out the demonstration video:

This thing is amazing. And it is actually cheaper to buy a fully-assembled version (huh). The same organisation also offers another GPS-controlled clock using IN-18 nixie tubes:

nixichron10

Again, it isn’t inexpensive – however the true nixie tube enthusiasts will love it. This clock would look great next to a post-modern vintage hifi tube amplifier. Moving forward to something completely different now, we have the:

adafruit industries monochron®

Almost the polar opposite of the nixie-tube clocks, the monochron uses an ATmega328 microcontroller and a 128 x 64 LCD module to create some interesting clock effects. For example:

Many people have created a variety of displays, including space invaders and the pong game simulation. The clock also includes the laser-cut acrylic housing which provides a useful and solid base for the clock.

Spikenzie Labs Solder : Time™ watch kit

Technically this is a watch kit, however I don’t think that many people would want to walk around wearing one – but it could be used in more permanent or fixed locations. Correct me if I’m wrong people. However in its defence it is a very well designed kit that is easy to solder and produces a nice clock:

It uses a separate real-time controller IC to stay accurate, and the design However this would be a great suggestion as a gift for a younger person to help them become interesting in electronics and other related topics. The asm firmware is also available for you to modify using Microchip MPLAB software if that takes your fancy.

Velleman Kits

The Velleman company has a range of somewhat uninspiring clock kits, starting with the Scrolling/Rolling LED Clock:

… the 2¼” 7-Segment Digital Clock:

This clock includes the housing and also accepts an optional temperature sensor, and therefore can display this as well. There is also the aptly-named – Digital LED Clock:

mk151

It tells the time and would be useful in a 1980s-era idea of the future movie set. The final velleman clock kit is the Jumbo Single-Digit Clock:

In all fairness this one looks quite interesting – the LED display is 57mm tall and the time is display one digit at a time. It is powered by a PIC16F630 however the firmware is proprietary to velleman.

Nocrotec Nixie Clocks

This company has a range of kits using nixie tubes and numitrons (low voltage incadescent displays in tubes). One particularly lovely kit is their IN-8 Blue Dream kit:

in-8-bd-h-side-blue

The blue glow at the base of the nixie tubes is due to an LED mounted at the bottom of the tube. Another aesthetically-pleasing kit is their Little Blue Something nixie clock. Check out their demonstration video:

nixiekits.eu

More IN-12 nixie clocks from Germany, the first being the Manuela_HR. You can buy the kit without an enclosure, or choose from the ‘office’ style:

… or this funky number:

You can specify it with RGB LEDs which colour-cycle to provide the effect shown above. For those not too keen you can also buy the kits pre-assembled. Their other kit is the Sven:

Sven_IN-8-2_720

It is available with IN-8 or IN-14 nixie tubes. The design quality of the enclosure is outstanding, a lot of effort has been made to produce a complete kit that “won’t look like a kit” when completed.

Minty Time

This is a small binary clock kit that fits in an Altoids tin:

This is a nice little kit as it is inexpensive, easy to make and very well documented. You could also mount this in a variety of flat surfaces, limited only by your imagination.

The Chronulator

Here we find a unique design that uses analogue panel meters in a similar method to the multimeter clock detailed previously. Here is an example of the completed kit:

IMG_1113

The kit contains the electronics and meters (or you can delete the meters for a discount if you already have some) however the housing is up to you. Furthermore, this kit has some of the best instructions (.pdf) I have ever seen. They are a credit to the organisation. Our final clock kit is the …

Denkimono

This is another clock kit in the style of ‘suspicious bomb timer’-looking – and it pulls this off quite well. Consider the following video demonstration:

As well as a normal clock it can function as an alarm, stopwatch, countdown timer and lap counter. The instructions (.pdf) are well written and easy to follow. Furthermore the Denkimono is also well priced for the kit and delivery.

Hopefully this catalogue of clock kits was of interest to you. If you have found some other kits to add to the list, or wish to disagree or generally comment about this article please do so via the comment section below. This article was not sponsored in any way.

Have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, subscribe  for email updates or RSS using the links on the right-hand column, or join our Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other –  and we can all learn something.

Posted in clocks, kit review, nixie, review, TTL, VFDComments (8)

Tutorial: Arduino timing methods with millis()

This is chapter thirty-seven of a series originally titled “Getting Started/Moving Forward with Arduino!” by John Boxall – in what feels like an endless series of articles on the Arduino universe. The first chapter is here, the complete series is detailed here. Any files from tutorials will be found here.

[Updated 20/01/2013]

In this article we introduce the millis(); function and put it to use to create various timing examples.

Millis? Nothing to do with lip-syncers… hopefully you recognised milli as being the numerical prefix for one-thousandths; that is multiplying a unit of measure by 0.001 (or ten to the power of negative 3). Interestingly our Arduino systems will count the number of milliseconds (thousands of a second) from the start of a sketch running until the count reaches the maximum number capable of being stored in the variable type unsigned long (a 32-bit [four byte] integer – that ranges from zero to (2^32)-1.

(2^32)-1, or 4294967295 milliseconds converts to 49.71027-odd days. The counter resets when the Arduino is reset, it reaches the maximum value or a new sketch is uploaded. To get the value of the counter at a particular juncture, just call the function – for example:

Where start is an unsigned long variable. Here is a very simple example to show you millis() in action:

The sketch stores the current millis count in start, then waits one second, then stores the value of millis again in finished. Finally it calculates the elapsed time of the delay.  In the following screen dump of the serial monitor, you can see that the duration was not always exactly 1000 milliseconds:

To put it simply, the millis function makes use of an internal counter within the ATmega microcontroller at the heart of your Arduino. This counter increments every clock cycle – which happens (in standard Arduino and compatibles) at a clock speed of 16 Mhz. This speed is controlled by the crystal on the Arduino board (the silver thing with T16.000 stamped on it):

Crystal accuracy can vary depending on external temperature, and the tolerance of the crystal itself. This in turn will affect the accuracy of your millis result. Anecdotal experience has reported the drift in timing accuracy can be around three or four seconds per twenty-four hour period. If you are using a board or your own version that is using a ceramic resonator instead of a crystal, note that they are not as accurate and will introduce the possibility of higher drift levels. If you need a much higher level of timing accuracy, consider specific timer ICs such as the Maxim DS3232.

Now we can make use of the millis  for various timing functions. As demonstrated in the previous example sketch, we can calculate elapsed time. To take this idea forward, let’s make a simple stopwatch. Doing so can be as simple or as complex as necessary, but for this case we will veer towards simple. On the hardware perspective, we will have two buttons – Start and Stop - with the 10k ohm pull-down resistors connected to digital pins 2 and 3 respectively.

When the user presses start the sketch will note the value for millis – then after stop is pressed, the sketch will again note the value for millis, calculate and display the elapsed time. The user can then press start to repeat the process, or stop for updated data. Here is the sketch:

The calls to delay() are used to debounce the switches – these are optional and their use will depend on your hardware. Below is an example of the sketch’s serial monitor output – the stopwatch has started, and then button two pressed six times across periods of time:

If you had a sensor at the start and end of a fixed distance, speed could be calculated: speed = distance ÷ time.

You can also make a speedometer for a wheeled form of motion, for example a bicycle. At the present time I do not have a bicycle to mess about with, however we can describe the process to do so – it is quite simple. (Disclaimer – do so at your own risk etc.)  First of all, let’s review the necessary maths. You will need to know the circumference of the wheel. Hardware – you will need a sensor. For example – a reed switch and magnet. Consider the reed switch to be a normally-open button, and connect as usual with a 10k ohm pull-down resistor. Others may use a hall-effect sensor – each to their own). Remember from maths class:

(image licence)

To calculate the circumference – use the formula:

circumference = 2πr 

where r is the radius of the circle. Now that you have the wheel circumference, this value can be considered as our ‘fixed distance’, and therefore the speed can be calculated by measuring the elapsed time between of a full rotation.

Your sensor – once fitted – should act in the same method as a normally-open button that is pushed every rotation. Our sketch will measure the time elapsed between every pulse from the sensor. To do this, our example will have the sensor output connected to digital pin 2 – as it will trigger an interrupt to calculate the speed. (Interrupts? See chapter three). The sketch will otherwise be displaying the speed on a normal I2C-interface LCD module. The I2C interface is suggested as this requires only 4 wires from the Arduino board to the LCD – the less wires the better.

Here is the sketch for your perusal:

There isn’t that much going on – every time the wheel completes one revolution the signal from the sensor will go from low to high – triggering an interrupt which calls the function speedCalc(). This takes a reading of millis() and then calculates the difference between the current reading and the previous reading – this value becomes the time to cover the distance (which is the circumference of the wheel relative to the sensor – stored in

and is measured in metres). It finally calculates the speed in km/h and MPH. Between interrupts the sketch displays the updated speed data on the LCD as well as the raw time value for each revolution for curiosity’s sake. In real life I don’t think anyone would mount an LCD on a bicycle, perhaps an LED display would be more relevant.

In the meanwhile, you can see how this example works in the following short video clip. Instead of a bike wheel and reed switch/magnet combination, I have connected the square-wave output from a function generator to the interrupt pin to simulate the pulses from the sensor, so you can get an idea of how it works:

That just about sums up the use of millis() for the time being. There is also the micros(); function which counts microseconds. So there you have it – another practical function that can allow more problems to be solved via the world of Arduino. As always, now it is up to you and your imagination to find something to control or get up to other shenanigans.

LEDborder

Have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, subscribe  for email updates or RSS using the links on the right-hand column, or join our Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other –  and we can all learn something.

Posted in arduino, education, learning electronics, lesson, microcontrollers, millis, speedometer, stopwatch, timing, tutorialComments (18)

Tutorial: Arduino and the SPI bus part II

This is chapter thirty-six of a series originally titled “Getting Started/Moving Forward with Arduino!” by John Boxall – A seemingly endless series of articles on the Arduino universe. The first chapter is here, the complete series is detailed here

[Updated 10/01/2013]

This is the second of several chapters in which we are investigating the SPI data bus, and how we can control devices using it with our Arduino systems. If you have not done so already, please read part one of the SPI articles. Again we will learn the necessary theory, and then apply it by controlling a variety of devices. As always things will be kept as simple as possible.

First on our list today is the use of multiple SPI devices on the single bus. We briefly touched on this in part one, by showing how multiple devices are wired, for example:

Notice how the slave devices share the clock, MOSI and MISO lines – however they both have their own chip select line back to the master device. At this point a limitation of the SPI bus becomes prevalent – for each slave device we need another digital pin to control chip select for that device. If you were looking to control many devices, it would be better to consider finding I2C solutions to the problem. To implement multiple devices is very easy. Consider the example 34.1 from part one – we controlled a digital rheostat. Now we will repeat the example, but instead control four instead of one. For reference, here is the pinout diagram:

Doing so may sound complex, but it is not. We connect the SCK, MOSI and  MISO pins together, then to Arduino pins D13, D11, D12 respectively. Each CS pin is wired to a separate Arduino digital pin. In our example rheostats 1 to 4 connect to D10 through to D7 respectively. To show the resistance is changing on each rheostat, there is an LED between pin 5 and GND and a 470 ohm resistor between 5V and pin 6. Next, here is the sketch:

Although the example sketch may be longer than necessary, it is quite simple. We have four SPI devices each controlling one LED, so to keep things easy to track we have defined led1~led4 to match the chip select digital out pins used for each SPI device. Then see the first four lines in void setup(); these pins are set to output in order to function as required. Next – this is very important – we set the pins’ state to HIGH. You must do this to every chip select line! Otherwise more than one CS pins may be initially low in some instances and cause the first data sent from MOSI to travel along to two or more SPI devices. With LEDs this may not be an issue, but for motor controllers … well it could be.

The other point of interest is the function

We pass the value for the SPI device we want to control, and the value to send to the device. The value for l is the chip select value for the SPI device to control, and ranges from 10~7 – or as defined earlier, led1~4. The rest of the sketch is involved in controlling the LED’s brightness by varying the resistance of the rheostats. Now to see example 36.1 in action via the following video clip:


(If you are wondering what I have done to the Freetronics board in that video, it was to add a DS1307 real-time clock IC in the prototyping section).

Next on the agenda is a digital-to-analogue converter, to be referred to using the acronym DAC. What is a DAC? In simple terms, it accepts a numerical value between zero and a maximum value (digital) and outputs a voltage between the range of zero and a maximum relative to the input value (analogue). One could consider this to be the opposite of the what we use the function analogRead(); for. For our example we will use a Microchip MCP4921 (data sheet.pdf):

(Please note that this is a beginners’ tutorial and is somewhat simplified). This DAC has a 12-bit resolution. This means that it can accept a decimal number between 0 and 4095 – in binary this is 0 to 1111 1111 1111 (see why it is called 12-bit) – and the outpout voltage is divided into 4096 steps. The output voltage for this particular DAC can fall between 0 and just under the supply voltage (5V). So for each increase of 1 in the decimal input value, the DAC will output around 1.221 millivolts.

It is also possible to reduce the size of the voltage output steps by using a lower reference voltage. Then the DAC will consider the reference voltage to be the maximum output with a value of 4095. So (for example) if the reference voltage was 2.5V, each increase of 1 in the decimal input value, the DAC will output around 0.6105 millivolts. The minimum reference voltage possible is 0.8V, which offers a step of 200 microvolts (uV).

The output of a DAC can be used for many things, such as a function generator or the playback of audio recorded in a digital form. For now we will examine how to use the hardware, and monitoring output on an oscilloscope. First we need the pinouts:

By now these sorts of diagrams shouldn’t present any problems. In this example, we keep pin 5 permanently set to GND; pin 6 is where you feed in the reference voltage – we will set this to +5V; AVss is GND; and Vouta is the output signal pin – where the magic comes from :) The next thing to investigate is the MCP4921′s write command register:

Bits 0 to 11 are the 12 bits of the output value; bit 15 is an output selector (unused on the MPC4921); bit 14 controls the input buffer; bit 13 controls an inbuilt output amplifier; and bit 12 can shutdown the DAC. Unlike previous devices, the input data is spread across two bytes (or a word of data). Therefore a small amount of work needs to be done to format the data ready for the DAC. Let’s explain this through looking at the sketch for example 36.2 that follows. The purpose of the sketch is to go through all possible DAC values, from 0 to 4095, then back to 0 and so on.

First. note the variable outputvalue - it is a word, a 16-bit unsigned variable. This is perfect as we will be sending a word of data to the DAC. We put the increasing/decreasing value for a into outputValue. However as we can only send bytes of data at a time down the SPI bus, we will use the function highbyte() to separate the high side of the word (bits 15~8) into a byte variable called data.

We then use the bitwise AND and OR operators to set the parameter bits 15~12. Then this byte is sent to the SPI bus. Finally, the function lowbyte() is used to send the low side of the word (bits 7~0) into data and thence down the SPI bus as well.

Now for our demonstration sketch:

And a quick look at the DAC in action via an oscilloscope:

By now we have covered in detail how to send data to a device on the SPI bus. But how do we receive data from a device?

Doing so is quite simple, but some information is required about the particular device. For the rest of this chapter, we will use the Maxim DS3234 “extremely accurate” real-time clock. Please download the data sheet (.pdf) now, as it will be referred to many times.

The DS3234 is not available in through-hole packaging, so we will be using one that comes pre-soldered onto a very convenient breakout board:

It only takes a few moments to solder in some header pins for breadboard use. The battery type is CR1220 (12 x 2.0mm, 3V); if you don’t have a battery you will need to short out the battery holder with some wire otherwise the IC will not work. Readers have reported that the IC doesn’t keep time if the USB and external power are both applied to the Arduino at the same time.

A device will have one or more registers where information is read from and written to. Look at page twelve of the DS3234 data sheet, there are twenty-three registers, each containing eight bits (one byte) of data. Please take note that each register has a read and write address. An example – to retrieve the contents of the register at location 08h (alarm minutes) and place it into the byte data we need to do the following:

Don’t forget to take note of  the function SPI.setBitOrder(MSBFIRST); in your sketch, as this also determines the bit order of the data coming from the device. To write data to a specific address is also quite simple, for example:

Up to this point, we have not concerned ourselves with what is called the SPI data mode. The mode determines how the SPI device interprets the ‘pulses’ of data going in and out of the device. For a well-defined explanation, please read this article. With some devices (and in our forthcoming example) the data mode needs to be defined. So we use:

to set the data mode, within void(setup);. To determine a device’s data mode, as always – consult the data sheet. With our DS3234 example, the mode is mentioned on page 1 under Features List.

Finally, let’s delve a little deeper into SPI via the DS3234. The interesting people at Sparkfun have already written a good demonstration sketch for the DS3234, so let’s have a look at that and deconstruct it a little to see what is going on. You can download the sketch below from here, then change the file extension from .c to .pde.

Don’t let the use of custom functions and loops put you off, they are there to save time. Looking in the function SetTimeDate();, you can see that the data is written to the registers 80h through to 86h (skipping 83h – day of week) in the way as described earlier (set CS low, send out address to write to, send out data, set CS high). You will also notice some bitwise arithmetic going on as well. This is done to convert data between binary-coded decimal and decimal numbers.

Why? Go back to page twelve of the DS3234 data sheet and look at (e.g.) register 00h/80h – seconds. The bits 7~4 are used to represent the ‘tens’ column of the value, and bits 3~0 represent the ‘ones’ column of the value. So some bit shifting is necessary to isolate the digit for each column in order to convert the data to decimal. For other ways to convert between BCD and decimal, see the examples using the Maxim DS1307 in chapter seven.

Finally here is another example of reading the time data from the DS3234:

So there you have it – more about the world of the SPI bus and how to control the devices within.

LEDborder

In the meanwhile have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, subscribe  for email updates or RSS using the links on the right-hand column? And join our friendly Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other –  and we can all learn something.

Posted in arduino, BOB-10160, dac, DS3234, education, learning electronics, lesson, MCP4162, MCP4921, microcontrollers, SPI, tutorial, UncategorizedComments (13)

Project – The “Kid-e-log”

With this project you can build an RFID time-clock system to keep track of employees, children and more.

Updated 18/03/2013

Recently I was listening to a friend who has three teenage children, of whom needed to arrive home before their parent. Unfortunately the parent needs to work all day and arrives home in the evening, and they lamented not being able to check when the children had arrived home.

After a few hours it occurred to me that a simple time clock would solve her problem – each child could check-in upon arriving home, and the parent could review the check-in times later on. And thus the kid-e-log was born.

From a hardware perspective, it would be quite simple. An LCD screen, RFID reader and some tags, and a real time clock IC such as a Maxim DS1307 – all running from the ubiquitous Arduino board. After some contemplation it occurred to me that smart kids might try to mess up the hardware by pulling the power, so it also uses an EEPROM to store time data which is impervious to power loss, and the kid-e-log will not have any user buttons. After initial programming for time and RFID key data, any changes will need to be effected by the programmer (i.e. me).

If RFID is new to you, review my Arduino tutorials before moving forward.

Before jumping ahead and making something, we discussed exactly what the function would be. Each child would have an RFID tag, and when it is read the hardware will save the arrival time in memory, and display it on the LCD. The time data will be reset automatically at 0400h or by reading an RFID card belonging to the parent. There will not be any buttons, and the hardware must be power-failure resistant – therefore EEPROM memory is needed for time data and a backup battery for the real-time clock.

From a hardware perspective, the requirements are quite simple:

  • An Arduino-style board of some sort (we used the Freetronics Eleven)
  • Maxim DS1307 or DS3232 real-time clock IC
  • Microchip 24LC256 EEPROM
  • Usual 16 character, 2 line LCD with HD44780-compatible interface
  • 125kHz RFID reader with serial output, and four RFID tags (don’t get the Weigand version!)
  • Two 4.7 kilo ohm resistors (for I2C bus with EEPROM)
  • Two 0.1 uF ceramic capacitors (for power smoothing on the breadboard)
  • a solderless breadboard for prototyping
  • a nine volt DC power adaptor, rated for no less than 300 milliamps
  • And for the final product, a nice enclosure. More on that later…

The DS1307 and the EEPROM are both using the I2C bus, and the RFID reader (more information) uses Arduino digital pin zero (serial input).  The LCD is pretty straight forward as well, as described in the tutorials.

Here is the schematic for the prototype hardware:

schematicss

From a software (sketch) perspective, the design is easily broken up into distinct functions which makes programming quite easy. The sketch is a basic loop, which follows as such:

  • check to see if a tag is read by the RFID reader – if so, branch to the the reading function (which compares the read tag against those on file, and records the time matching the tag to the EEPROM)
  • display real time, date and check-in data on the LCD – another function
  • delay for a moment to stop the LCD flickering from fast updating
  • check if the time is 4am, and if so call a function to reset the check-in times

From each of those four main instructions, functions are called to handle various tasks. For example the displayData() funtion is used to read the DS1307 real time clock, and display the time and date on the top line of the LCD. Then it reads the contents of the EEPROM, and displays the check in time for each RFID tag – or a line if they have not checked in yet.

The data stored in the EEPROM is held in following order

  • tag 1 status (0 for not checked in, 1 for checked in)
  • tag 1 check-in hour
  • tag 1 check-in minute

and repeats for tag two and three. You will notice in the sketch that the RFID cards’ serial data are stored in individual arrays. You will need to read your RFID cards first with another sketch in order to learn their values. The rest of the sketch should be quite easy to follow, however if you have any questions please ask.

You can download the sketch from here. Next for the hardware. Here is our prototype, ready for action:

prototypess

And now for a short video clip of the prototype kid-e-log in operation:


Notice how removing the power does not affect the real time nor the stored check-in data. Almost child-proof. The final task was to reassemble the prototype in order to fit into a nice enclosure. Unfortunately by this stage the person concerned had moved away, so I had no need to finish this project. However I had already purchased this nice enclosure:

enclosuress

It was just large enough to accept the Eleven board, and protoshield with the EEPROM and RFID reader circuitry, and the LCD module. It is custom-designed with mounts for Arduino boards and the LCD – a perfect fit. However the use of it can wait for another day. So an important note to self – even if designing things for a friend – get a deposit!

Such is life. I hope you enjoyed reading about this small project and perhaps gained some use for it of your own or sparked some other ideas in your imagination that you can turn into reality.

In the meanwhile have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, subscribe  for email updates or RSS using the links on the right-hand column? And join our friendly Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other –  and we can all learn something.

Posted in arduino, I2C, projects, rfid, time clock, tronixstuff, tutorialComments (3)

Add a real-time clock to the Freetronics Eleven

Let’s add a DS1307 real-time clock to our Freetronics Arduino-compatible board.

Updated 18/03/2013 – this is also perfect for the Freetronics Eleven board.

Now and again I find myself making another kind of clock or timing device using the Arduino system, and each one has been making use of the Maxim DS1307 real-time clock IC. However every time another clock is being worked on, my DS1307 real-time clock shield needs to come out to play. Although in itself it is a nice shield, at the end of the day – the less you have the better. Originally I used a Freetronics TwentyTen board – which has now been superseded by their Eleven board, however they’re both identical for the purposes of this tutorial.

So what to do? As regular readers will know, my preferred board is the Freetronics Eleven, and within this we have a solution to the following problem:

problemss

The Freetronics team have thoughtfully provided a prototyping area in their board – and that will be a perfect home for the real time clock system. Being a cheapskate and a masochist – instead of  following others by using a smaller RTC module I will instead use parts already in stock (except for the battery) and install my own circuit. So, as always – we need a plan. The circuit itself is quite simple, the DS1307 data sheet has a fine example on page thirteen, and here is my interpretation:

schematicss

So the parts required for our clock circuit will be:

  • IC1 – Maxim DS1307 I2C real-time clock IC
  • 8-pin IC socket
  • R1~R3 – 10k ohm 1% metal film resistors
  • X1 – 32.768 kHz crystal
  • B1 – Panasonic CR1220 3v battery with solder pins (Farnell part number 1298944) [data sheet one and two]
  • One header pin (from those 40-way strips)
  • some thin black single-core wire

The CR1220 battery was chosen over the usual CR2032 due to the smaller diameter. According to the DS1307 data sheet, the battery should last around ten years if it has a capacity of 48 mAh. Our CR1220 is 35 mAh – which will do nicely, perhaps seven years or so. That will have to do. Don’t forget to check the voltage of the battery before installation – it should be just over three volts.

Now to get everything arranged in the prototyping area. When doing this it pays to always have the schematic in front of you as well so you can refer to it when necessary. Planning to use protoboard of any size requires a good plan as well. After spending some time considering component placement, the final layout was as follows:

layoutsss

Each square on the grid represents one hole on the board. After you see the images below, everything will make sense. Before soldering away, it will pay to give the prototyping area a quick clean with some PCB cleaner.

Now it is finally time to get soldering. The first items were the battery, crystal and the resistors. Although the battery was designed to be soldered, I am always a little wary when applying heat to them. Two seconds with the hot iron was enough.

When soldering in the crystal (or anything else), try to keep in mind what the leads will be connecting to. For example, the crystal legs will need to connect to pins 1 and 2 of the IC socket. So bend the crystal leads in the direction of the respective IC socket pins. Doing so will make creating solder joins between them much easier:

The resistors were simple enough. Keep the excess clippings to make jumpers with later. Also notice how the right hand leg of R3 was bent around and brought back up to the top row – this is to help make connections with the 5V rail link:

resisleadsss

The next item was the IC socket. Nothing to worry about there, just drop it in and solder away. Don’t forget to bridge the crystal pins to socket pins one and two, and the battery positive pin to IC socket pin three.

Next for the SQW pin. The DS1307 can also output a nice square wave at either 1Hz, 4.096 kHz, 8.192 kHz or 32.768 kHz, with the resulting signal being found on pin 7. It isn’t something really used that often, but you never know. So I soldered in one of these pins, which should make it easy enough to use later on:

Note that if you are using the SQW function, the DS1307 will merrily pulse away once it is set, until the power is cut – the square-wave generator is autonomous to the I2C bus once it has been set. And it remembers (as long as the backup battery is fine). For example, you can upload a sketch to set the SQW to 4.096 kHz, remove power, yank out the ATmega328, power up – and the SQW is still active.

Next we turn the board over, and solder in our jumper wires:

backlinkss

The lead on the top runs from the right-hand side of the pull-up resistors R1~R3 (when facing the top of the board) to the 5V pad. The bottom lead runs from pin four of the IC socket to the GND pad. The negative pin of the battery is also bent over and soldered to the GND pad. Also, connect all the resistors together as shown in the above image (below the TX pin). The next step is turn the board back over and make some more wired connections, the first being pin eight of the IC socket to the resistors and then to the 5V link on the rear:

toplinksss

The next are somewhat longer, they are the leads for the I2C bus. Run a wire from next to IC socket pin six all the way to (and through) the bottom-right hole of the TwentyTen (when facing the top); this will be the SCL line and soldered to analogue 5. Repeat again from IC socket pin five, this is the SDA line (as above) for analogue 4. The joints you have to solder them onto are not that large, however it can be done. Before soldering the wires in, heat up the existing joint to melting point then let it cool again – this makes actually soldering the wire in a lot easier:

i2css

And there we have it. At this stage, don’t plug the board in. Do some quality control: check that the soldered joints are complete; check that solder has bridged where you need it, and not where you don’t; use the continuity function (‘beeper’) of a multimeter to spot-check for shorts, and also follow the new 5V and GND lines to ensure they are connected correctly. And finally, insert the DS1307 IC into the socket.

finishedss

OK – now for some test timing. If you have not worked with the DS1307 IC before, there is a full explanation of how it works within our Arduino tutorials. Here’s a sketch you can use to test the real-time clock. Once you have uploaded that sketch, open the serial monitor box at 9600 bps, and you should have something like this:


Now let’s check the 1 Hz output from the SQW pin:

Recall that you can generate four frequencies with your DS1307, here is an example sketch that does just that:

and here is the result – measured on a freqency counter:

My frequency counter is around twenty-two years old, please be patient with it as the sampling rate is not the best.

In the meanwhile have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, subscribe  for email updates or RSS using the links on the right-hand column? And join our friendly Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other –  and we can all learn something.

Posted in arduino, clocks, ds1307, freetronics, hardware hacking, learning electronics, microcontrollers, tutorialComments (4)

Kit Review – adafruit industries DS1307 Real Time Clock breakout board kit

Hello readers

Today we are going to examine another small yet useful kit from adafruit industries – their DS1307 Real Time Clock breakout board kit. My purpose of acquiring this kit was to make life easier when prototyping my clock and timer Arduino-based projects on a breadboard. For example, blinky, or the various clock projects in the Arduino tutorials.

When breadboarding a DS1307 circuit, there are a few problems – the legs of the crystal are very fine, and break easily, and trying to mount the backup battery holder on the breadboard can be difficult due to their odd pin-spacing. That is why this breakout board is just perfect for breadboarding. Finally, (in Australia anyway) the price of the kit is less than the sum of the retail cost of the parts required. Anyhow, time to get cracking!

Again, as usual the adafruit kit packaging is simple, safe and reusable:

bagss2

And with regards to the contents within:

partsss

… no surprises here, another quality solder-masked, silk-screened PCB  that has everything you need to know printed on it. Now that you can see the crystal (above image, bottom-right) you can realise why this board is a good idea. Furthermore, the inclusion of a quality battery and not some yum-cha special is a nice touch.

Assembly is incredibly simple. The IC position is printed on the PCB, the resistors are the same, and the capacitor and crystal are not polarised. Again, no IC socket, but perhaps it is time not to worry about that anymore – my soldering skills have improved somewhat in the last twelve months. Plus the DS1307 can handle 260 degrees Celsius for ten seconds when soldering (according to the data sheet.pdf).

However if you like to read instructions (which is generally a good idea) the excellent documentation is laid out here for your perusal.

Soldering the board is quite straightforward, however when it comes time to solder in the coin cell holder, note that there are large gaps in the mounting holes:

1ss

It is important to solder the pins solidly to the PCB, without letting lots of solder flow through the hole and block the other side. If you can bend the pins slightly closer to the circumference of the hole, soldering will be a lot easier. And don’t forget to put a blob of solder on the top-facing pad between the two pin holes before soldering in the coin cell holder.

Finally, when time to solder in the header pins, mount the lot onto a breadboard, and support the gap between the PCB and the breadboard at the opposite end of the PCB. An old CD works very well:

2ss

And within ten minutes of starting, we have finished!

3ss1

Insert the backup cell (writing facing up!) in the holder and you’re ready to time. A new backup cell should last between seven to ten years, so unless you want to reset the clock completely, leave the cell in the board.

Now it is time to use the board. My only experience is with the Arduino-based systems, and even so using the DS1307 can seem quite difficult at the start. However with the right library and some basic reusable sketch modules you can do it quite successfully. The board is a standard DS1307 circuit, and is explained in great detail within the data sheet.pdf.

Don’t forget you can get a nice 1 Hz (or 4, 8 or 32 kHz) square wave from this IC – here is a sketch that allows you to control the square-wave generator:

And a video demonstration:

Well I hope you found this review interesting, and helped motivate you to expand your knowledge and work with real-time clocks, Arduino and the I2C bus.

You can purchase the kit directly from adafruit industries.

As always, thank you for reading and I look forward to your comments and so on. Furthermore, don’t be shy in pointing out errors or places that could use improvement. Please subscribe using one of the methods at the top-right of this web page to receive updates on new posts. Or join our new Google Group. High resolution images are available on flickr.

[Note - The kit was purchased by myself personally and reviewed without notifying the manufacturer or retailer]

Posted in adafruit, ds1307, kit review, microcontrollers, real time clock, tutorialComments (6)


Receive notifications of new posts by email.

The Arduino Book

Arduino Workshop

Für unsere deutschen Freunde

Dla naszych polskich przyjaciół ...

Australian Electronics!

Buy and support Silicon Chip - Australia's only Electronics Magazine.

Use of our content…

%d bloggers like this: