Nixie clock: 3 – RTC and expander

luca 16/03/2012 13


The first sketch is about how to control PCF8575 PINs.

I connected a LED to each PIN to show its state. This IC can’t provide (source mode) enougth current to power on a LED, you need to connect the LED in sink mode, with current flowing from Vcc into the PIN:

With this connection, the LED will be on when IC PIN is connected to ground, that is logical level 0.

Let me show you how to control PIN states:

  1. write, starting from P7 to P0, the required logical stage (0 or 1), for example: 10110000;
  2. do the same for PINs from P17 to P10: 10110000 01011101;
  3. (for convenience) convert the two numbers in hexadecimal: B0 5D;
  4. send the two values to the expander.

I2C bus allows to connect more than two devices: when you send commands on the bus, you have to specify the target’s address. Every I2C device has a builtin address; for PCF8575 that address is 0x20 (decimal 32). If you connect to ground or Vcc PINs A0, A1 e A2 you can change its address:

For example, if you connect A0 to ground and A1, A2 to Vcc, the resulting address is 0100110 = 0x26. If you change the builtin address, you can connect more than one IC of the same type on the same I2C bus.

After having set the address, you can send commands and data with the following code:

#include <Wire.h>
#define PCF8575_ADDRESS  0x20

I wrote a simple sketch to light up 16 LEDs with a rolling animation:

In the next page, an Arduino working with both modules…

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 ?

  7. Mauro 06/09/2016 at 10:07 - Reply

    Ciao Luca,
    non riesco a compilare NESSUN esempio che utilizza il pcf8575!
    Ho scaricato le librerie da github le istallo ma gli esempi Blinkled non si compilano . dice che manca il file PCG8575.h.
    Dove sbaglio ?

  8. Mauro 19/10/2016 at 14:57 - Reply

    Devo usare tre 8575 in I2C e collegare ai pin digitali 2 e 3 di Arduino Nano il modulo Bluetooth HC-06 .
    Le librerie 8575.h e SoftwareSerial.h sembra che non possano convivere assieme.
    Con qualsiasi IDE con cui cerco di compilare mi da sempre:

    SoftwareSerial\SoftwareSerial.cpp.o: In function `__vector_3′:
    \\Srv01\dati\Comune\Arduino\IDE_ARDUINO\arduino-1.5.8\hardware\arduino\avr\libraries\SoftwareSerial/SoftwareSerial.cpp:306: multiple definition of `__vector_3′
    PCF8575\PCF8575.cpp.o:\\Srv01\dati\Comune\Arduino\IDE_ARDUINO\arduino-1.5.8\libraries\PCF8575/PCint.h:104: first defined here
    SoftwareSerial\SoftwareSerial.cpp.o: In function `__vector_4′:
    \\Srv01\dati\Comune\Arduino\IDE_ARDUINO\arduino-1.5.8\hardware\arduino\avr\libraries\SoftwareSerial/SoftwareSerial.cpp:313: multiple definition of `__vector_4′
    PCF8575\PCF8575.cpp.o:\\Srv01\dati\Comune\Arduino\IDE_ARDUINO\arduino-1.5.8\libraries\PCF8575/PCint.h:107: first defined here
    SoftwareSerial\SoftwareSerial.cpp.o: In function `__vector_5′:
    \\Srv01\dati\Comune\Arduino\IDE_ARDUINO\arduino-1.5.8\hardware\arduino\avr\libraries\SoftwareSerial/SoftwareSerial.cpp:320: multiple definition of `__vector_5′
    PCF8575\PCF8575.cpp.o:\\Srv01\dati\Comune\Arduino\IDE_ARDUINO\arduino-1.5.8\libraries\PCF8575/PCint.h:110: first defined here
    collect2: error: ld returned 1 exit status
    Errore durante la compilazione

Leave A Response »

Click here to cancel reply.

This website uses cookies to ensure you get the best experience on our website maggiori informazioni

Questo sito utilizza i cookie per fonire la migliore esperienza di navigazione possibile. Continuando a utilizzare questo sito senza modificare le impostazioni dei cookie o clicchi su "Accetta" permetti al loro utilizzo.