Nixie clock: 3 – RTC and expander

luca 16/03/2012 11

BCD Led clock

The clock’s working is:

  • read the current time from RTC;
  • check if time read is different from time shown by Nixie tubes;
  • if so, send the new time – BCD coded – to the I/O expander and from this to Nixie drivers.

I wrote a sketch with the behavior described above; for testing purposes I’m going to use LEDs instead of Nixie tubes.

WIth RTCLib, it’s very easy to get data from DS1307 IC:

  DateTime now =;  
  byte rtc_minute = bin2bcd(now.minute());
  byte rtc_hour = bin2bcd(now.hour());

The BCD conversion is performed by the following function:

byte bin2bcd (uint8_t val) { return val + 6 * (val / 10); }

Hours and minutes, BCD coded, are sent to PCF8575 via I2C bus with the function:

void sendOutputs(byte low, byte high) {

Before sending, I “invert”  (NOT function, ~) the values because, as you remember, LEDs are connected in sink mode.

BCD value for hours is reverted with the function:

byte revert(byte in) {
  byte out = 0;
  for(int i = 0; i < 7; i++) {
    if(in & 1) out = out + 1;
    out = out << 1;     in = in >> 1;
  if(in & 1) out = out + 1;
  return out;

only because of LED position on my breadboard.

Here’s a video about this “bcd led clock”… a very geek one even if not very readable ;)

Pages: 1 2 3 4


  1. pitchoilcan 06/04/2012 at 06:19 - Reply

    I get :error:
    PCF8575_Led_rolling_Demo.cpp: In function ‘void loop()’:
    PCF8575_Led_rolling_Demo.cpp:24:8: error: ‘class TwoWire’ has no member named ‘write’
    PCF8575_Led_rolling_Demo.cpp:25:8: error: ‘class TwoWire’ has no member named ‘write’
    I able to compile by change it for
    but still now a blink from any of the LED’s. Are you using any resistor? I”ve tryed it using just the pcf8575 anf an arduino board, no RTC module. Is that doable and if so what I’m I doing wrong?

    • luca 10/04/2012 at 08:07 - Reply


      You’re probably using an older (< 1.0) version of Arduino IDE… anyway you don’t need a RTC module for this example, could you post your connections so I can check?

  2. pitchoilcan 06/04/2012 at 07:15 - Reply
  3. Fernando Garcia 25/12/2012 at 18:27 - Reply


    I’m trying to build a circuit with a RTC and a PCF8575 .

    It happens that the RTC does not tell the correct time.
    There must be some conflict.

    The code I’m using to test is this:

  4. Fernando Garcia 25/12/2012 at 18:43 - Reply

    The code does not appear correctly.

    Here’s a link to it.

    Best regards.

    • luca 11/01/2013 at 08:32 - Reply

      Hi Fernando,

      are you using an Arduino Mega?

  5. Dmitry 19/03/2015 at 09:15 - Reply

    Hello Luca.
    Thanx for your manual!

    Could you advise IO extender on 24 pins (for 6 tubes)?

    I’ve found the Tca6424rgjr but probably there is something better.

    • luca 19/03/2015 at 11:15 - Reply

      Hi Dmitry… it depends on you: on the I2C bus you can connect more than one expander, therefore you can use 3 8-pins expanders or the one you found that works fine!

  6. DRS 30/11/2015 at 11:50 - Reply

    Hi, where i can read more about power supply ?

Leave A Response »