Use DS1307 in another pins

buenos dias

disculpen estoy tratando de usar un modulo RTC DS1307 para hacer lecturas de tiempo al mismo tiempo que hago lecturas de CAN en un auto, estoy usando un sparkfun CAN BUS SHIELD con una arduino UNO y todo funciona por separado, me pide usar A5 A4 para los datos del RTC pero los pines A1 A2 A3 A4 A5 ya los estoy usando en mi programa por el joystick que viene en el shield por default, alguien tiene alguna idea de como hacerlo funcionar en los pines normales?

mi codigo es:

#include <SPI.h>
#include <SD.h>
#include <SoftwareSerial.h>
#include <Canbus.h>
//MODULO RTC
#include <Wire.h>
#include <TimeLib.h>
#include <DS1307RTC.h>

//dEFINE rtc var
int HORA, MIN, SEG, CONT;
String DIA, MES;

// Define Joystick connection pins
#define UP A1
#define DOWN A3
#define LEFT A2
//#define RIGHT A5
//#define CLICK A4

//Define LED pins
#define LED2 8
#define LED3 7

//Declare CAN variables for communication
char *EngineRPM;
char buffer[64];
char *VehicleSpeed;
char buffer1[64];
char *Throttle;
char buffer2[64];  //Data will be temporarily stored to this buffer before being written to the file

const int chipSelect = 9;  // Chip Select pin is tied to pin 9 on the SparkFun CAN-Bus Shield
int Archivo, read_len, Nuevo;
char buf[80], filename1[13];
char Conta;
String str, filename2, Contas, filename3, filename4;

File file;

void setup() {
  Serial.begin(9600);
  Serial.print("Initializing SD card...");
  pinMode(chipSelect, OUTPUT);
  CONT = 0;

  //---------------------------------------sEGEMENTO DE VERIFICACION DE TARJETA INSERTADA------------------------------------------------
  if (!SD.begin(chipSelect)) {
    Serial.println("SD Card failed, or not present");
    return;
  }
  Serial.println("SD card initialized.");
  //--------------------------------------- open file for reading----------------------------------------------------------------------
  file = SD.open("Contador.txt", FILE_READ);
  if (file) {
    int avail_len = file.available();
    read_len = file.readBytes(buf, avail_len);  // read all to buffer to buffer
    Serial.print("Length:");
    Serial.println(read_len);
    Serial.println("Content:");
    Serial.println(buf);  //Lee el archivo y envia contenido
    file.close();
  } else {
    Serial.print(F("SD Card: error on opening file"));
  }  //ESTA SECCION LEE EN EL ARCHIVO CONTADOR los datos presentes
  //---------------------------------------Agrega +1 al ultimo dato del archivo----------------------------------------------------------
  int Nuevo = read_len + 1;
  Serial.println();
  Serial.println("Agregando Lectura");
  Serial.println(Nuevo);
  //---------------------------------------Escribe el ultimo dato del archivo +1 y lo guarda---------------------------------------------
  file = SD.open("Contador.txt", FILE_WRITE);
  if (file) {
    file.write('\n');  // new line
    file.write(Nuevo);
    file.close();
  } else {
    Serial.print(F("SD Card: error on opening file arduino.txt"));
  }
  //--------------------------------------- END OF SECTION FOR FILE CONTADOR ------------------------------------------------------------
  //------------------------------------------------- CREACION DE NUEVO ARCHIVO  --------------------------------------------------------
  //DIA= myRTC.dayofmonth;
  //MES= myRTC.month; // DIA + MES +
  String Contas = String(Nuevo);
  //filename2= DIA + MES + "ACC"+ Contas + ".txt";
  //filename3= DIA + MES + "RPM"+ Contas + ".txt";
  //filename4= DIA + MES + "VEL"+ Contas + ".txt";
  filename2 = "ACC" + Contas + ".txt";
  filename3 = "RPM" + Contas + ".txt";
  filename4 = "VEL" + Contas + ".txt";
  Serial.print("ArchivoS CreadoS: ");
  Serial.println(filename2);
  Serial.println(filename3);
  Serial.println(filename4);
  //Serial.println(Conta);
  //Serial.println(Contas);
  //---------------------------------------------- FIN DE CREACION DE NUEVO ARCHIVO  ----------------------------------------------------
  //Initialize pins as necessary
  pinMode(chipSelect, OUTPUT);
  pinMode(UP, INPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);

  //Pull analog pins high to enable reading of joystick movements
  digitalWrite(UP, HIGH);

  //Write LED pins low to turn them off by default
  digitalWrite(LED2, LOW);
  digitalWrite(LED3, LOW);

  //Initialize CAN Controller
  if (Canbus.init(CANSPEED_500)) /* Initialize MCP2515 CAN controller at the specified speed */
  {
    Serial.println("CAN Init Ok");
    delay(150);
  } else {
    Serial.println("Can't init CAN");
    return;
  }
  while (digitalRead(UP) == HIGH) {
    digitalWrite(LED2, HIGH);
    digitalWrite(LED3, HIGH);  //Wait for user to click joystick to begin logging
  }
  delay(300);
}
void print2digits(int number) {
  if (number >= 0 && number < 10) {
    Serial.write('0');
  }
  Serial.print(number);
}
/*void Tiempo(){
  HORA=0; MIN=0; SEG=0;
  delay(200);
  myRTC.updateTime();
  HORA=myRTC.hours;
  MIN=myRTC.minutes;
  SEG=myRTC.seconds;
  CONT=0;
  Serial.print("LECTURA DE TIEMPOOOOOOOOOOOOOOOOOOOOOOOOO");
  
}*/

void loop() {
  //digitalWrite(LED2, LOW);
  while (digitalRead(UP) == HIGH) {

    //RTC MODULE

    Serial.println("DS1307RTC Read Test");
    Serial.println("-------------------");
    tmElements_t tm;
    if (RTC.read(tm)) {
      Serial.print("Ok, Time = ");
      print2digits(tm.Hour);
      Serial.write(':');
      print2digits(tm.Minute);
      Serial.write(':');
      print2digits(tm.Second);
      Serial.print(", Date (D/M/Y) = ");
      Serial.print(tm.Day);
      Serial.write('/');
      Serial.print(tm.Month);
      Serial.write('/');
      Serial.print(tmYearToCalendar(tm.Year));
      Serial.println();
    } else {
      if (RTC.chipPresent()) {
        Serial.println("The DS1307 is stopped.  Please run the SetTime");
        Serial.println("example to initialize the time and begin running.");
        Serial.println();
      } else {
        Serial.println("DS1307 read error!  Please check the circuitry.");
        Serial.println();
      }
    }

    digitalWrite(LED3, HIGH);  //Turn on LED to indicate CAN Bus traffic
    digitalWrite(LED2, LOW);
    //  RTC SECCION
    //  END RTC SECCION
    //------------------------------ INICIO SECCION Acelerador ----------------------------------------
    File file = SD.open(filename2, FILE_WRITE);  //Open uSD file to log data
    Serial.print("Grabando archivo: ");
    Serial.println(filename2);  //Comunicacion Serial

    Canbus.ecu_req(ENGINE_RPM, buffer);  //Request engine RPM
    EngineRPM = buffer;
    Serial.print("Acelerador: ");
    Serial.println(buffer);  //Escribe datos adquiridos en serial
    file.print("Acelerador: ");
    file.println(EngineRPM);  //graba datos a tarjeta SD
    delay(50);
    digitalWrite(LED3, HIGH);
    delay(50);
    digitalWrite(LED3, LOW);
    file.flush();
    file.close();
    
  }
  digitalWrite(LED2, HIGH);
  digitalWrite(LED3, HIGH);
  Serial.print("Logging stopped.");
  while (1)
    ;  //Stop logging if joystick is clicked
}

Su publicacion se MUEVE a su ubicacion actual ya que es mas adecuada.

A qué se refiere con moverlo? Quiero pasarlo de los pines A4 A5 a pines digitales como 10,11

Los pines del Arduino UNO usan por defecto el SDA/SCL del protocolo i2c en los pines A4 y A5, estos no son por software sino de hardware no hay manera de comunicar mediante I2C con otros módulos I2C si no es por estos pines, la solución más eficiente seria conseguir un módulo RTC que no utilice el protocolo I2C, algo como RTC DS1302, segun el esquematico de esa shield si usas todos sus componentes solo te queda libre el pin D3 del arduino

Ahora lo más práctico seria doblar los pines de la shield que van hacia el A4 Y A5 y conectarlos a otros pines que no uses perdiendo lo estetico

muchas gracias no habia comprendido esa parte del protocolo de comunicacion, tednre que buscar otro RTC u obtener por CAN la hora

Moderador:
Por favor, lee las Normas del foro
Si posteas en el foro en inglés usa idioma inglés para expresarte.
Si escribes en español debes usar el foro Arduino en español.
Este mensaje lo envío porque tu hilo fue movido del foro en inglés y por eso tenemos una respuesta anterior en ese idioma.
Edita tu título usando idioma español.
No sigas respondiendo sin hacerlo mas allá que el tema este solucionado.

El modulo ds1307 es el mas impreciso de los RTC, te recomiendo el ds3231.

Mas alla de tu problema tienes varias alternativas:
La mas barata es un NANO que tiene A6 y A7 solo como ADC extras y libera A4 y A5 para el uso de tu RTC que ya te dije que es el peor de todos los disponibles.
Además tienes el MEGA por si debes mantener compatibilidad con algun shield CAN.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.