I can't save data on SD

The problem comes when mixing scripts, it might be because in one script i am using 9600 bits per second and other value in the other script

#include <Arduino.h>

#include <SPI.h>
#include <SD.h>

#include "calidad_aire.h"
#include "hora.h"

//SD
const int chipSelect = 4;  // Pin CS del módulo lector de tarjetas microSD

File dataAire;
File dataMetano;

//Calidad Aire
int calidad_aire;

//Reloj
String hora;
String fecha;

void datos_setup() {
  delay(300);
  Serial.begin(9600);
  
  // Inicializar la comunicación con la tarjeta microSD
  if (!SD.begin(chipSelect)) {
    Serial.println("¡Error al inicializar la tarjeta microSD!");
    return;
  }

  Serial.println("Tarjeta microSD inicializada correctamente.");
}

void datos_loop(){
  calidad_aire = CalidadAire();

  dataAire = SD.open("calidad_aire.txt", FILE_WRITE);

  hora = getCurrentTime();
  fecha = getCurrentDate();

  if(!dataAire){
    Serial.println("Error en apertura de archivo");
    dataAire.close();
  }else{
        dataAire.print(hora + ", ");
    dataAire.print(fecha + ", ");
    dataAire.println(calidad_aire);
    dataAire.close();
    Serial.println("Dato guardado");
  }
}

What is the issue with the code?

Have you confirmed the wiring to the SDCard module is correct and if so, have you confirmed the module even works using the example sketch (if it has one)?

Your sketch has neither of the required functions: setup() nor loop() Rename your datos_setup() and datos_loop() to setup() and loop()

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