Page 1 of 1

SD Datalogging

Posted: Fri Sep 15, 2017 4:54 pm
by gigioiqq
Dear People.

Im a newbie on this kind of technologies, and i need help with the script that im doing for capturing data and save it en a sd card. I have a couple of sensors and im using two readings from the waspmote board, but i need to format this data for excel importing to save in the SD card. I already have read the sdcard-programming_guide, but i didnt understand much. Im a chemical engineer and i have little experience on C programming.

Thanks and Regards

Jorge

PS: the script is follow

#include <SoftwareTX.h> // Librería para configuración de la comunicación serial traída desde Arduino
#include <SoftwareTxLCD.h> // Librería para utilizar el display LCD traída desde Arduino

int SENSOR_A1A2;
int SENSOR_A2A3;
int presion1;
int presion2;
int SENSOR_BATERIA;
int voltaje;
char* filename="logger.txt";


void setup() {
//USB.ON();
SD.ON();
// Delete file
if(SD.del(filename))
{
USB.println(F("file deleted"));
}
else
{
USB.println(F("file NOT deleted"));
}

// Create file
if(SD.create(filename))
{
USB.println(F("file created"));
}
else
{
USB.println(F("file NOT created"));
}




RTC.ON();
stxLCD.begin20x4();
stxLCD.backlight(20);
stxLCD.cursorOff();
stxLCD.clear();


pinMode(DIGITAL5, OUTPUT); // ENERGIZACION "SENSORES A"
digitalWrite(DIGITAL5, LOW); // ENERGIZACION "SENSORES A"

// encabezados impresos al inicio, solamente 1 vez
//stxLCD.setPosition20x4(1, 1); stxLCD.print("P-1 KPa:");
//stxLCD.setPosition20x4(2, 1); stxLCD.print("P-2 KPa:");
//stxLCD.setPosition20x4(3, 1); stxLCD.print("Temp. C:");
//stxLCD.setPosition20x4(4, 1); stxLCD.print("Voltaje:");
}

void loop() {

stxLCD.displayOn();
stxLCD.backlight(20);
stxLCD.setPosition20x4(1, 1); stxLCD.print("P-1 KPa:");
stxLCD.setPosition20x4(2, 1); stxLCD.print("P-2 KPa:");
stxLCD.setPosition20x4(3, 1); stxLCD.print("Temp. C:");
stxLCD.setPosition20x4(4, 1); stxLCD.print("Voltaje:");
digitalWrite(DIGITAL5, HIGH); // ENERGIZACION "SENSORES A"
delay(500);
SENSOR_A1A2 = analogRead(ANALOG1);
digitalWrite(DIGITAL5, LOW); // ENERGIZACION "SENSORES A"

presion1 = 1000*SENSOR_A1A2/815 - 1000*204/815;

// como el intervalo de presion es [0, 1000]
// reservo 4 espacios para el numero
// estas son las posiciones 17, 18, 19 y 20
stxLCD.setPosition20x4(1, 17);

if(presion1 < 10){
stxLCD.print("000");
stxLCD.print(presion1);
}
else if(presion1 >= 10 && presion1 < 100){
stxLCD.print("00");
stxLCD.print(presion1);
}
else if(presion1 >= 100 && presion1 < 1000){
stxLCD.print("0");
stxLCD.print(presion1);
} else{
stxLCD.print(presion1);
}
digitalWrite(DIGITAL5, HIGH); // ENERGIZACION "SENSORES A"
delay(500);
SENSOR_A2A3 = analogRead(ANALOG2);
digitalWrite(DIGITAL5, LOW); // ENERGIZACION "SENSORES A"

//digitalWrite(DIGITAL5, LOW); // ENERGIZACION "SENSORES A"

presion2 = 1000*SENSOR_A2A3/815 - 1000*204/815;

// como el intervalo de presion es [0, 1000]
// reservo 4 espacios para el numero
// estas son las posiciones 17, 18, 19 y 20
stxLCD.setPosition20x4(2, 17);

if(presion2 < 10){
stxLCD.print("000");
stxLCD.print(presion2);
}
else if(presion2 >= 10 && presion2 < 100){
stxLCD.print("00");
stxLCD.print(presion2);
}
else if(presion2 >= 100 && presion2 < 1000){
stxLCD.print("0");
stxLCD.print(presion2);
} else{
stxLCD.print(presion2);
}

stxLCD.setPosition20x4(3, 17);
int temperatura = RTC.getTemperature();
stxLCD.print(temperatura);

stxLCD.setPosition20x4(4, 17);
SENSOR_BATERIA = analogRead(ANALOG7);
voltaje = 6*SENSOR_BATERIA/45 - 6*820/45 + 120;
stxLCD.print(voltaje);
delay(5000);
stxLCD.displayOff();
stxLCD.backlight(0);
PWR.deepSleep("00:00:00:20",RTC_OFFSET,RTC_ALM1_MODE1,ALL_OFF);
}

Re: SD Datalogging

Posted: Mon Sep 18, 2017 9:32 am
by libelium-dev
Hi,

You can use the next example code to to store formatted frames in SD file.
http://www.libelium.com/development/was ... atalogger/

And here you can see more examples to use the SD card
http://www.libelium.com/development/was ... &subcat=sd

Regards