Nixie clock: 3 – RTC and expander

luca 16/03/2012 8

Arduino

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 0×20 (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 = 0×26. 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
...
Wire.beginTransmission(PCF8575_ADDRESS);
Wire.write(0xB0);
Wire.write(0x5D);
Wire.endTransmission();

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

8 Comments »

  1. pitchoilcan 06/04/2012 at 06:17 - 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
    Wire.write(low);
    Wire.write(high);
    to

    Wire.send(low);
    Wire.send(high);

    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 wring?

  2. 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
    Wire.write(low);
    Wire.write(high);
    to
    Wire.send(low);
    Wire.send(high);
    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

      Hi

      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?

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

    Hello!

    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:

    #include // Librarie from Henning Karlsen
    #include

    DS1307 rtc(20, 21); // Indica em quais pinos o RTC está conectado.
    static byte tabela1[] = {1,2,4,8,16,32,64,128};
    static byte tabela2[] = {128,64,32,16,8,4,2,1};

    long millis_antes = 0;
    void set(byte b0,byte b1)
    {
    Wire.beginTransmission(0×20);
    Wire.write(b0);
    Wire.write(b1);
    Wire.endTransmission();
    }

    void setup()
    {
    Serial.begin(38400);
    rtc.halt(false); // Inicia o funcionamento do RTC.
    Wire.begin();
    //Todos os pinos OFF
    set(0,0);
    }

    void loop()
    {
    if(millis() – millis_antes > 5000)
    {
    millis_antes = millis();
    Serial.print(“Horario: “);
    Serial.println(rtc.getTimeStr(FORMAT_LONG));
    }

    for(int i = 0; i 0; i–)
    {
    set(tabela1[i],tabela2[i]); // Apenas o pino 1 ON.
    delay(100);
    }
    set(255,255); // Todos os pinos ON
    delay(200);
    }

    The LEDs blink correctly, but the time printed on the serial monitor is:

    Horario: 27:85:85

    I have tested your code and the same thing occurs.

    Any suggestions on what might cause the problem?

    Tank you.

    Fernando Garcia

    Sorry for english.

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

    The code does not appear correctly.

    Here’s a link to it.

    https://gist.github.com/21dfdc057cfbd1cc44a9/5e7c42002b4025b9d48a21896d81c9a6bd74cbba

    Best regards.

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

      Hi Fernando,

      are you using an Arduino Mega?

Leave A Response »