I managed to get it working, the thing was the switch code for the received numbers as you said it...i rewrote the code and put everything in the last case, that worked.
like this:
#include <SD.h>
#include <Wire.h>
#include "Rtc.h"
#include <DHT22.h>
const char inicionumero = '<';
const char finnumero = '>';
char temperatura[10];
char humedad[10];
char polvo[10];
char temperatura2[10];
char humedad2[10];
char polvo2[10];
char datos[100];
float dustValenvio = 0.0;
float a = 0.0;
int dustPin=0;
float dustVal=0.0;
int ledPower=2;
int delayTime=280;
int delayTime2=40;
float offTime=9680;
enum { getTemperature, getHumedad, getDust };
int whichNumber = getTemperature;
float temperature, humidity, dust;
#define DHT22_PIN 4
// Inicio de Setup DHT22
DHT22 myDHT22(DHT22_PIN);
float enviodatosT = 0;
float enviodatosH = 0;
const int chipSelect = 8;
char time[20];
char date[20];
Rtc rtc;
void setup ()
{
Serial.begin (9600);
pinMode(ledPower, OUTPUT);
pinMode(10, OUTPUT);
if (!SD.begin(chipSelect)) {
return;
}
Rtc rtc = Rtc(0,0,0,1,1,1,11,0xAA);
}
void processNumber (const long n)
{
DHT22_ERROR_t errorCode;
errorCode = myDHT22.readData();
if(errorCode == DHT_ERROR_NONE)
{
enviodatosT = myDHT22.getTemperatureC()/1.0;
enviodatosH = myDHT22.getHumidity()/1.0;
}
float x = n/100.0;
switch (whichNumber)
{
case getTemperature:
temperature = x;
dtostrf(temperature,1,2,temperatura);
strcpy(datos, temperatura);
strcat(datos, ";");
whichNumber = getHumedad;
Serial.print ("Temperature = ");
Serial.println(temperatura);
break;
case getHumedad:
humidity = x;
dtostrf(humidity,1,2,humedad);
strcat(datos, humedad);
strcat(datos, ";");
whichNumber = getDust;
Serial.print ("Humidity = ");
Serial.println(humedad);
break;
case getDust:
dust = x;
dtostrf(dust,1,2,polvo);
strcat(datos, polvo);
strcat(datos, ";");
whichNumber = getTemperature;
Serial.print ("Dust = ");
Serial.println(polvo);
dtostrf(enviodatosT,1,2,temperatura2);
dtostrf(enviodatosH,1,2,humedad2);
strcat(datos, temperatura2);
strcat(datos, ";");
strcat(datos, humedad2);
strcat(datos, ";");
digitalWrite(ledPower,LOW); // power on the LED
delayMicroseconds(delayTime);
dustVal=analogRead(dustPin); // read the dust value via pin 5 on the sensor
delayMicroseconds(delayTime2);
digitalWrite(ledPower,HIGH); // turn the LED off
delayMicroseconds(offTime);
if(dustVal<125)
{
dustValenvio = 0.0;
dtostrf(dustValenvio,1,2,polvo2);
}
else {
a=(dustVal*5)/1023;
dustValenvio=(a-0.611)/5.1720;
dtostrf(dustValenvio,1,2,polvo2);
}
strcat(datos, polvo2);
strcat(datos, ";");
rtc.GetDate();
rtc.Time(time);
rtc.Date(date);
strcat(datos, date);
strcat(datos, ";");
strcat(datos, time);
File dataFile = SD.open("datalog.csv", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
// write file
if(enviodatosT>0 && enviodatosH>0 && dustValenvio>0)
{
dataFile.println(datos);
dataFile.close();
}
}
Serial.println(datos);
delay(5000);
break;
}
}
void processInput ()
{
static float receivedNumber = 0;
static boolean negative = false;
byte c = Serial.read ();
switch (c)
{
case finnumero:
if (negative)
processNumber (- receivedNumber);
else
processNumber (receivedNumber);
// fall through to start a new number
case inicionumero:
receivedNumber = 0;
negative = false;
break;
case '0' ... '9':
receivedNumber *= 10;
receivedNumber += c - '0';
break;
case '-':
negative = true;
break;
}
}
void loop ()
{
if (Serial.available ())
{
processInput ();
}
}
So again, thanks mr. Nick, im not so experienced in this stuff, but you always come with great ideas and patience, now my project is almost finished and that could not be achieved without your help.
greetings.
Ignacio.