Reloj Nixie con DS1307

¿Has creado algún proyecto genial con una Raspberry Pi? Este es tu lugar.
Wirry
Pi Newbie
Pi Newbie
Mensajes: 1
Registrado: 18 Nov 2017, 02:53
Agradecido: 0
Agradecimiento recibido: 0

Hola,

Estoy empezando con el mundo de la Raspberry (ya empece con los PIC).

Estoy intentando hacer un reloj RTC con el integrado DS1307 que se comunica con I2C, puedo leer los datos del reloj y mostrarlos en el terminal de la Raspberry, pero me gustaría sacar esos valores por las salidas GPIO y no se como hacerlo.
Estoy programando con Python 3 (soy novato con el programa)

Código:

Código: Seleccionar todo

import RPi.GPIO as GPIO
import smbus
import time
bus = smbus.SMBus(1)
address = 0x68

class DS1307():
    _REG_SECONDS = 0x00
    _REG_MINUTES = 0x01
    _REG_HOURS = 0x02
    _REG_DAY = 0x03
    _REG_DATE = 0x04
    _REG_MONTH = 0x05
    _REG_YEAR = 0x06
    _REG_CONTROL = 0x07


def BCD2BINARY(x):

        binary = ((x & 0xF0 )>>4 ) * 10 + (x & 0x0F)
        return (binary)

def getSecond(address):
       return BCD2BINARY(bus.read_byte_data(address,0x00))

def getMinutes(address):
       return BCD2BINARY(bus.read_byte_data(address,0x01))
      
def getHours(address):
        d = bus.read_byte_data(address,0x02)
        if d & 0x40:
            return BCD2BINARY(d & 0x3F)
        else:
            h = BCD2BINARY(d & 0x1F)
            if d & 0x20:
                h += 11  # Convertir 12h to 24h
            elif h == 12:
                h = 0
            return h

def getDay(address):
        return BCD2BINARY(bus.read_byte_data(address,0x03))


def getDate(address):
        return BCD2BINARY(bus.read_byte_data(address,0x04))


def getMonth(address):
        return BCD2BINARY(bus.read_byte_data(address,0x05))


def getYear(address):
        return BCD2BINARY(bus.read_byte_data(address,0x06))
 
while 1: 
  

        print (getDay(address), getDate(address), getMonth(address), getYear(address), getHours(address), getMinutes(address), getSecond(address))
        
        time.sleep(1)
Muchas gracias de antemano.
Responder