SENSOR PROGRAM SAVED IN SD

Thank you for reading my question, I am trying to make my 2 sensors the distances that they measure keep it in a micro sd. Below I leave my code and could you please tell me if this is the case?

#include "Adafruit_VL53L0X.h"
#include <SPI.h> // incluye libreria interfaz SPI
#include <SD.h> // incluye libreria para tarjetas SD

// address we will assign if dual sensor is present
#define LOX1_ADDRESS 0x30
#define LOX2_ADDRESS 0x29

// set the pins to shutdown
#define SHT_LOX1 13
#define SHT_LOX2 12

// objects for the vl53l0x
Adafruit_VL53L0X lox1 = Adafruit_VL53L0X();
Adafruit_VL53L0X lox2 = Adafruit_VL53L0X();

//Sensors
#define SENSOR 11 // constante SENSOR en pin digital 4 (senal de DHT11)
int HORIZONTAL; // variable para almacenar valor de temperatura

int horizontal;
int Flecha;

#define SSpin 10 // Slave Select en pin digital 10
File archivo; // objeto archivo del tipo File
Adafruit_VL53L0X dht(SENSOR,Adafruit_VL53L0X);

// this holds the measurement
VL53L0X_RangingMeasurementData_t measure1;
VL53L0X_RangingMeasurementData_t measure2;

/*
Reset all sensors by setting all of their XSHUT pins low for delay(10), then set all XSHUT high to bring out of reset
Keep sensor #1 awake by keeping XSHUT pin high
Put all other sensors into shutdown by pulling XSHUT pins low
Initialize sensor #1 with lox.begin(new_i2c_address) Pick any number but 0x29 and it must be under 0x7F. Going with 0x30 to 0x3F is probably OK.
Keep sensor #1 awake, and now bring sensor #2 out of reset by setting its XSHUT pin high.
Initialize sensor #2 with lox.begin(new_i2c_address) Pick any number but 0x29 and whatever you set the first sensor to
*/
void setID() {
// all reset
digitalWrite(SHT_LOX1, LOW);
digitalWrite(SHT_LOX2, LOW);
delay(10);
// all unreset
digitalWrite(SHT_LOX1, HIGH);
digitalWrite(SHT_LOX2, HIGH);
delay(10);

// activating LOX1 and reseting LOX2
digitalWrite(SHT_LOX1, HIGH);
digitalWrite(SHT_LOX2, LOW);

// initing LOX1
if(!lox1.begin(LOX1_ADDRESS)) {
Serial.println(F("Failed to boot first VL53L0X"));
while(1);
}
delay(10);

// activating LOX2
digitalWrite(SHT_LOX2, HIGH);
delay(10);

//initing LOX2
if(!lox2.begin(LOX2_ADDRESS)) {
Serial.println(F("Failed to boot second VL53L0X"));
while(1);
}
}

void read_dual_sensors() {

lox1.rangingTest(&measure1, false); // pass in 'true' to get debug data printout!
lox2.rangingTest(&measure2, false); // pass in 'true' to get debug data printout!

// print sensor one reading
Serial.print("1: ");
if(measure1.RangeStatus != 4) { // if not out of range
Serial.print(measure1.RangeMilliMeter);
} else {
Serial.print("Out of range");
}

Serial.print(" ");

// print sensor two reading
Serial.print("2: ");
if(measure2.RangeStatus != 4) {
Serial.print(measure2.RangeMilliMeter);
} else {
Serial.print("Out of range");
}

Serial.println();
}

void setup() {

Serial.println("Inicializando tarjeta ..."); // texto en ventana de monitor
if (!SD.begin(SSpin)) { // inicializacion de tarjeta SD
Serial.println("fallo en inicializacion !");// si falla se muestra texto correspondiente y
return; // se sale del setup() para finalizar el programa
}
Serial.println("inicializacion correcta"); // texto de inicializacion correcta
archivo = SD.open("datos.txt", FILE_WRITE); // apertura para lectura/escritura de archivo datos.txt

if (archivo) {
for (int i=1; i < 31; i++){ // bucle repite 30 veces
Flecha = measure1.RangeMilliMeter; // almacena en variable valor leido de temperatura

archivo.print(i); // escribe en tarjeta el valor del indice
archivo.print(","); // escribe en tarjeta una coma
archivo.print(Flecha); // escribe en tarjeta el valor de temperatura

Serial.print(i); // escribe en monitor el valor del indice
Serial.print(","); // escribe en monitor una coma
Serial.print(Flecha); // escribe en monitor el valor de temperatura

delay(1000); // demora de 1 segundo
}
archivo.close(); // cierre de archivo
Serial.println("escritura correcta"); // texto de escritura correcta en monitor serie
} else {
Serial.println("error en apertura de datos.txt"); // texto de falla en apertura de archivo
}
Serial.begin(9600);

// wait until serial port opens for native USB devices
while (! Serial) { delay(1); }

pinMode(SHT_LOX1, OUTPUT);
pinMode(SHT_LOX2, OUTPUT);

Serial.println("Shutdown pins inited...");

digitalWrite(SHT_LOX1, LOW);
digitalWrite(SHT_LOX2, LOW);

Serial.println("Both in reset mode...(pins are low)");

Serial.println("Starting...");
setID();

}

void loop() {

read_dual_sensors();
delay(100);
}

sensores modulo sd.txt (4.69 KB)

0Avendano:
Thank you for reading my question, I am trying to make my 2 sensors the distances that they measure keep it in a micro sd. Below I leave my code and could you please tell me if this is the case?

I think you can answer your own question by looking at what is written (or not) on your MicroSD card.

UNO ?? Then keep sensors away from SPI-interface (pins 10..13)