Hi .
Anybody have idea how to translate this to arduino code . I´m trying but always errors.
is as follow
Td =(K1/100)(Ta -K2/10)+(K3/100)(Exp(K4/1000*Ta))^(K5/100)+T67
Exp(n)= e (the base of natural logarithms) raised to the power of n.
and this
If Abs((K2 / 10 - Ta)) < 1 Then T67 =Sgn(K6)Sgn(Ta -K2/10)Abs((K2/10-Ta))
Else T67 =K6/10Sgn(Ta -K2/10)(Log(Abs((K2/10-Ta)))/Log(10)+K7/100)
End If
where Sgn( x ) = function that returns the sign of x
Log( x ) = function that returns the natural logarithm of x
Abs( x ) = function that returns the absolute value of x
for this last one I make this but I lost with the Sgn that i don´t know what fuction use
Also I don´t know in this last one if the log is really the fuction that give the logarithm of K9.
Also I try to use the fuction pow , but my arduine ide seens like not recognice pow , any idea.?
I think most of those function exist in the Arduino's C/C++ compiler but the names are all lower case. e.g. Exp should be exp, and Abs should be abs, etc.
// not the ultimate implementation (IEEE754 also has 0.0 and -0.0) , but it will probably be good enough
float sign(float n)
{
if (n < 0) return -1;
return 1;
}
// not the ultimate implementation (IEEE754 also has 0.0 and -0.0) , but it will probably be good enough
float sign(float n)
{
if (n < 0) return -1;
return 1;
}
I modify for somethink like this
// not the ultimate implementation (IEEE754 also has 0.0 and -0.0) , but it will probably be good enough
float sign(float temp2);
if (temp2 < 0) {return -1;} else
{return 1;}
but also some is wrong because the compiler say me this error
returning 'void'
CloudDetectorFinal:90: error: return-statement with a value, in function returning 'void'
// not the ultimate implementation (IEEE754 also has 0.0 and -0.0) , but it will probably be good enough
float sign(float n)
{
if (n < 0) return -1;
return 1;
}
What does not work? can you give an example value for which the code fails?
I modify for somethink like this
// not the ultimate implementation (IEEE754 also has 0.0 and -0.0) , but it will probably be good enough
float sign(float temp2);
if (temp2 < 0) {return -1;} else
{return 1;}
but also some is wrong because the compiler say me this error
returning 'void'
CloudDetectorFinal:90: error: return-statement with a value, in function returning 'void'
any idea
The ; after the function declaration is incorrect.
cvdarias:
I put the complete code to see what is going wrong
float Tsky;
float Tir;
float Td;
float Tamb;
int K1;
int K2;
int K3;
int K4;
int K5;
int K6;
int K7;
float T67;
// extracted common sub expression
float temp1 = K2/10 -Tamb;
float temp2 = abs(temp1);
// not the ultimate implementation (IEEE754 also has 0.0 and -0.0) , but it will probably be good enough
float sign(float temp2);
Hi , well the complete program is this , but have a lot of thing that in the final version not go because first I want to see what I se in the serial and after go to a little display, for this reason some of the code are in // and almost of the serial.print will be delated.
#include <math.h>
#include <dht.h>
#include <Wire.h>
#include <Adafruit_MLX90614.h>
#define DHT11_PIN 4
#define _Digole_Serial_UART_
#include <DigoleSerial.h>
#if defined(_Digole_Serial_UART_)
DigoleSerialDisp mydisp(&Serial, 38400); //UART:Arduino UNO: Pin 1(TX)on arduino to RX on module
#endif
#define SC_W 96 //screen width in pixels
#define SC_H 64 //screen Hight in pixels
#include "detectornubes.h"
dht DHT;
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
int inputPin = 3; // Connect push button to input pin 3
void setup(){
pinMode(inputPin, INPUT);// declara el boton como una entrada
pinMode(6, OUTPUT);//piezo buzzer
mlx.begin();
mydisp.begin();
//mydisp.setColor(224);
//mydisp.clearScreen(); //CLear screen
//mydisp.setFont(fonts[2]);
//mydisp.setMode('C'); //set graphic Drawing Mode to COPY
//mydisp.displayStartScreen1
Serial.begin(9600);
Serial.println("DHT TEST PROGRAM ");
Serial.print("LIBRARY VERSION: ");
Serial.println(DHT_LIB_VERSION);
Serial.println();
Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)");
Serial.println("Adafruit MLX90614 test");
delay (3000);
}
void loop(){
// READ DATA
//mydisp.clearScreen();
Serial.print("DHT11, \t");
DHT.read11(DHT11_PIN);
//mydisp.print("Temperatura = ")
//mydisp.print(DHT.temperature,1)
//mydisp.print("Humedad = "
//mydisp.print(DHT.humidity,1)
// DISPLAT DATA
Serial.print(DHT.humidity,1);
Serial.print(",\t");
Serial.println(DHT.temperature,1);
Serial.print("Ambient = ");
Serial.print(mlx.readAmbientTempC());
Serial.print("*C\tObject = ");
Serial.print(mlx.readObjectTempC());
Serial.println("*C");
Serial.print("Ambient = ");
Serial.print(mlx.readAmbientTempF());
Serial.print("*F\tObject = ");
Serial.print(mlx.readObjectTempF());
Serial.println("*F");
float Tsky;
float Tir;
float Td;
float Tamb;
int K1;
int K2;
int K3;
int K4;
int K5;
int K6;
int K7;
float T67;
float temp1;
float temp2;
// extracted common sub expression
temp1 = K2/10 -Tamb;
temp2 = abs(temp1);
if (temp2 < 1)
{
T67 = (K6) * (-temp1) * temp2;
}
else
{
T67 = K6/10 * (-temp1) * (log( temp2 )/log(10) + K7/100 );
}
Td = (K1/100) * ( Tamb -K2/10) + (K3/100) * pow( exp(K4/1000*Tamb), (K5/100) ) + T67;
Tir = (mlx.readObjectTempC());
Tsky=Tir-Td;
//if(Tsky>=0)
//{
//mydisp.drawBitmap256(39,30,70,44,nubes);
//}
//if(Tsky < 0 && Tsky > -10)
//{
//mydisp.drawBitmap(39,30,70,40,nubesluna);
//}
//if(Tsky <= -10)
//{
//mydisp.drawBitmap(39,30,70,40,luna);
//}
int val = digitalRead(inputPin); // read input value
if (val == HIGH) { mydisp.backLightOff(); } //turn display off
else {mydisp.backLightOn();} //turn display on
//Hace sonar el buzzer cuando la humedad es igual o superior a 90
int humedad = (DHT.humidity,1);
if (humedad>=90) { digitalWrite(6, HIGH);}
else { digitalWrite(6, LOW);}
delay(1000);
}
now look better , no ;-), well this version is compiled ok but without the " sight"
Without extensive tests, I'm never sure exactly what a C/C++ compiler does in cases like the above but it seems very likely that if K3 is of type int, then (K3/1000) will be evaluated as an int (truncating the remainder) and then converting to floating point for multiplication with pow(). In any case, you should carefully test the finished program to make sure that the results of the calculation are correct. If not, try declaring K1, K2, etc. to be of type float.
well , no problem I think ,m the K1K2K3K4K5 variables havesa fixes value that is not a float number , this is why I declare like int, I read in some place that use float can make errors in same case if the number is not a float number , them