Arduino - invalid operands of types 'double' and 'double' to Binary 'Operator'

Asked

Viewed 397 times

0

#include <DHT.h>
#include <math.h>
#include <stdlib.h>
#include <stdafx.h>
#include <iostream>

#define DHT1PIN 2
#define DHT2PIN 3
#define DHT3PIN 4
#define DHT4PIN 5
#define DHT5PIN 6
#define DHT6PIN 7

#define DHT1TYPE DHT11 // DHT 11
#define DHT2TYPE DHT11
#define DHT3TYPE DHT11
#define DHT4TYPE DHT11
#define DHT5TYPE DHT11
#define DHT6TYPE DHT11


DHT dht1(DHT1PIN, DHT1TYPE); 
DHT dht2(DHT2PIN, DHT2TYPE);
DHT dht3(DHT3PIN, DHT3TYPE);
DHT dht4(DHT4PIN, DHT4TYPE);
DHT dht5(DHT5PIN, DHT5TYPE);
DHT dht6(DHT6PIN, DHT6TYPE);

void setup();
void loop();

void setup(){
  Serial.begin(9600);
  Serial.println("DHT11 + MPX5050DP");

  dht1.begin();
  dht2.begin();
  dht3.begin();
  dht4.begin();
  dht5.begin();
  dht6.begin();
}

void loop() {

  //MDPX5050 DP
  int reading = analogRead(1);
  float Pressure = 11.11 * reading - 2.2226;
  Serial.print(Pressure);

  float h1 = dht1.readHumidity();
  float t1 = dht1.readTemperature();

  float h2 = dht2.readHumidity();
  float t2 = dht2.readTemperature();

  float h3 = dht3.readHumidity();
  float t3 = dht3.readTemperature();

  float h4 = dht4.readHumidity();
  float t4 = dht4.readTemperature();

  float h5 = dht5.readHumidity();
  float t5 = dht5.readTemperature();

  float h6 = dht6.readHumidity();
  float t6 = dht6.readTemperature();


  if (isnan(t1) || isnan(h1)) {
  Serial.println("Failed to read from DHT #1");
  } else { 
    Serial.print("Humidity 1: "); 
    Serial.print(h1); 
    Serial.print(" %\t") ; 
    Serial.print("Temperature 1: "); 
    Serial.print(t1); 
    Serial.println(" *C");
   delay(1000);
  }


   if (isnan(t2) || isnan(h2)) { 
    Serial.println("Failed to read from DHT #2");
  } else { 
    Serial.print("Humidity 2: "); 
    Serial.print(h2);
    Serial.print(" %\t"); 
    Serial.print("Temperature 2: "); 
    Serial.print(t2); 
    Serial.println(" *C");
   delay(1000); 
  } 


   if (isnan(t3) || isnan(h3)) { 
    Serial.println("Failed to read from DHT #3");
  } else { 
    Serial.print("Humidity 3: "); 
    Serial.print(h3);
    Serial.print(" %\t"); 
    Serial.print("Temperature 3: "); 
    Serial.print(t3); 
    Serial.println(" *C");
   delay(1000); 
  } 


   if (isnan(t4) || isnan(h4)) { 
    Serial.println("Failed to read from DHT #4");
  } else { 
    Serial.print("Humidity 4: "); 
    Serial.print(h4);
    Serial.print(" %\t"); 
    Serial.print("Temperature 4: "); 
    Serial.print(t4); 
    Serial.println(" *C");
   delay(1000); 
  } 


   if (isnan(t5) || isnan(h5)) { 
    Serial.println("Failed to read from DHT #5");
  } else { 
    Serial.print("Humidity 5: "); 
    Serial.print(h5);
    Serial.print(" %\t"); 
    Serial.print("Temperature 5: "); 
    Serial.print(t5); 
    Serial.println(" *C");
   delay(1000); 
  } 

   if (isnan(t6) || isnan(h6)) { 
    Serial.println("Failed to read from DHT #6");
  } else { 
    Serial.print("Humidity 6: "); 
    Serial.print(h6);
    Serial.print(" %\t"); 
    Serial.print("Temperature 6: "); 
    Serial.print(t6); 
    Serial.println(" *C");
   delay(1000); 
  }




float tambiente,twb,Va,Entalpia_do_ar,Hv,Lv,Tpo,Pfi,x,Pb,Pa,Pv,Uabs,Vv,Hesp,c, Pvs;
//float tambiente2,twb2,Va2,Entalpia_do_ar2,Hv2,Lv2,Tpo2,Pfi2,x2,Pb2,Pa2,Pv2,Uabs2,Vv2,Hesp2,c2, Pvs2;
//float tambiente3,twb3,Va3,Entalpia_do_ar3,Hv3,Lv3,Tpo3,Pfi3,x3,Pb3,Pa3,Pv3,Uabs3,Vv3,Hesp3,c3, Pvs3;
//float tambiente4,twb4,Va4,Entalpia_do_ar4,Hv4,Lv4,Tpo4,Pfi4,x4,Pb4,Pa4,Pv4,Uabs4,Vv4,Hesp4,c4, Pvs4;
//float tambiente5,twb5,Va5,Entalpia_do_ar5,Hv5,Lv5,Tpo5,Pfi5,x5,Pb5,Pa5,Pv5,Uabs5,Vv5,Hesp5,c5, Pvs5;
//float tambiente6,twb6,Va6,Entalpia_do_ar6,Hv6,Lv6,Tpo6,Pfi6,x6,Pb6,Pa6,Pv6,Uabs6,Vv6,Hesp6,c6, Pvs6;


{   Serial.println ("Ponto 1");
    tambiente=t1+273.15;
  twb= t1*(atan[0.151977*(h1+8.313659)^0.5 ])+(atan(t1+h1))- (atan(h1-1.676331)+0.00391838*((h1)^3/2))*(atan(0.023101*h1)-4.686035);
  Entalpia_do_ar=1.01*t1;
  Lv=2538.2+2.91*t1;
  Hv=Lv+1,88*t1;
  Pfi=(1-3*(t1-twb)/(t1+18))*100;
  x=(-27405.526+97.5413*tambiente-0.146244*(tambiente*tambiente)+0.00012558*(tambiente*tambiente*tambiente)-0.000000048502*(tambiente*tambiente*tambiente*tambiente))/(4.34903*tambiente-0.0039381*tambiente*tambiente);
  Pvs=22105649.25*exp(x)/1000;
  Pv=Pfi*Pvs/100;
  Pa=101,325-Pv;
  Va=((287,05*(tambiente))/Pa)/1000;
  Uabs=0.6219*Pv/(Pb-Pv);
  Vv=(461,52*tambiente)/(Pv*100)/1000;
  Tpo=(31.685*log10(Pv*1000/613.34))/(1-0.1311*log10(Pv*1000/613.34));
  Hesp=4.1868*(0.24*t1+(597.3+0.441*t1)*Uabs);

  Serial.print("\n Volume Especifico Ar            =  %.3f    [m3/kg]"); Serial.print(Va);
  Serial.print("\n Volume Especifico Vapor         =  %.3f    [m3/kg]"); Serial.print(Vv);
  Serial.print("\n Entalpia do Ar                  =  %.2f    [kJ/kg]"); Serial.print(Entalpia_do_ar);
  Serial.print("\n Entalpia do Vapor               =  %.2f    [kJ/kg]"); Serial.print(Hv);
  Serial.print("\n Entalpia Especifica             =  %.2f    [kJ/kg]"); Serial.print(Hesp);
  Serial.print("\n Umidade Relativa                =  %.2f    [%]");     Serial.print(Pfi);
  Serial.print("\n Pressao de Vapor Saturado       =  %.2f    [KPa]");   Serial.print(Pvs);
  Serial.print("\n Pressao de Vapor                =  %.2f    [KPa]");   Serial.print(Pv);
  Serial.print("\n Pressao de Ar seco              =  %.2f    [Kpa]");   Serial.print(Pa);
  Serial.print("\n Umidade Absoluta                =  %.4f    [Kg/Kg]"); Serial.print(Uabs);
  Serial.print("\n Temperatura de Ponto de Orvalho =  %.1f    [C]");     Serial.print(Tpo); }
}

Here follows the code, I still have to repeat it for at least 5 times, for 5 different inputs of humidity and temperature, I’m sure the problem occurs in this equation.

twb= t1*(atan[0.151977*(h1+8.313659)^0.5 ])+(atan(t1+h1))- (atan(h1-1.676331)+0.00391838*((h1)^3/2))*(atan(0.023101*h1)-4.686035);

But I have no idea how to get around it, someone might give me a hand ?

Mistakes:

error: invalid operands of types 'double' and 'double' to Binary 'Operator ' error: invalid operands of types 'float' and 'int' to Binary 'Operator^'

  • thanks for editing in formatting bfavaretto, I’m hitting myself here.

  • 1

    You wouldn’t happen to be using the operator hoping it’s potent, would you? I say this because this operator is an XOR binary operator in C/C++ and some other languages.

  • that was the intention, exponential... Uch, with his comment, consulted the internet, I saw the use of such a 'Pow ()' I will test to see if it meets my need, I appreciate the contribution.

  • twb= t1*(atan[0.151977*variavel1])+(atan(t1+h1))- atan(h1-1.676331)+0.00391838*variavel2*(atan(0.023101*h1)-4.686035); 'variavel1 = Pow(H1+8.313659,0.5);&#xA;&#xA;variavel2 = Pow(H1,3/2);` the error returned this time being 'error: invalid types 'double ()(double)[double]' for subscript array'

  • 1

    Exchange straight parentheses for curved parentheses.

1 answer

1

In Arduino you add the Math. h library to use:

pow(base, expoente)

Utilize:

twb= t1*(atan(0.151977*pow(h1+8.313659, 0.5) )+(atan(t1+h1))- (atan(h1-1.676331)+0.00391838*(pow(h1, 3/2 ))*(atan(0.023101*h1)-4.686035);

After the sign of - (less) you have to close the parentheses which is opened before the atan, otherwise it will also give error.

C supports conversion of types to perform the operation and then the variable (which received the casting) back to the original type:

float soma, num1;
int num2;

soma = num1 + (float) num2;

And if you’re going to use that formula more than once, it’s worth turning into a function:

float twb( float a, float b ) {
  float primeiro = atan( 0.151977 * pow( b + 8.313659, 0.5 );
  float segundo = atan( b - 1.676331 ) + 0.00391838 * ( pow( b, 3/2 );
  float terceiro = atan( 0.023101 * b) - 4.686035) ;

  return ( a * primeiro + atan( a + b ) - segundo * terceiro );
}

This will help you when you need to change some part of it, automatically changes every time the function is used.

If the formula is too large to divide it, either in the middle of the code or within a function, this makes it easier to detect errors.

To use:

twb( 7.0, 5.4);

twb( <primeiro numero>, <segundo numero> );

Browser other questions tagged

You are not signed in. Login or sign up in order to post.