INFO: Dieses Forum nutzt Cookies...
Cookies sind für den Betrieb des Forums unverzichtbar. Mit der Nutzung des Forums erklärst Du dich damit einverstanden, dass wir Cookies verwenden.

Es wird in jedem Fall ein Cookie gesetzt um diesen Hinweis nicht mehr zu erhalten. Desweiteren setzen wir Google Adsense und Google Analytics ein.

Antwort schreiben 
 
Themabewertung:
  • 0 Bewertungen - 0 im Durchschnitt
  • 1
  • 2
  • 3
  • 4
  • 5
EZO- HUM- Sensor
08.01.2021, 16:31 (Dieser Beitrag wurde zuletzt bearbeitet: 08.01.2021 17:29 von Leonardo.)
Beitrag #1
EZO- HUM- Sensor
Hallo liebe community,

Ich will mit dem EZO-HUM Embedded Humidity Sensor die Luftfeuchtigkeit (HUM), die Lufttemperatur (Air TMP) und den Taupunkt (DEW) messen.

Der serielle Monitor zeigt mir aber nur einen Wert für die Luftfeuchtigkeit an. So erscheint es im seriellen Monitor:

HUM:51.37
Air TMP:
DEW:


Kann mir bitte jemand helfen und mir sagen, was ich am Sketch verändern muss damit mir auch ein Wert für Air TMP und DEW angezeigt wird?

Im Anhang befindet sich das Setup. Hier ist der Sketch:

Code:
//This code was written to be easy to understand.
//Modify this code as you see fit.
//This code will output data to the Arduino serial monitor.
//Type commands into the Arduino serial monitor to control the humidity sensor.
//This code was written in the Arduino 1.8.13 IDE
//An Arduino UNO was used to test this code.
//This code was last tested 8/2020


#include <SoftwareSerial.h>                           //we have to include the SoftwareSerial library, or else we can't use it
#define rx 2                                          //define what pin rx is going to be
#define tx 3                                          //define what pin tx is going to be

SoftwareSerial myserial(rx, tx);                      //define how the soft serial port is going to work


String inputstring = "";                              //a string to hold incoming data from the PC
String sensorstring = "";                             //a string to hold the data from the Atlas Scientific product
boolean input_string_complete = false;                //have we recived all the data from the PC
boolean sensor_string_complete = false;               //have we recived all the data from the Atlas Scientific product




void setup() {                                        //set up the hardware
  Serial.begin(9600);                                 //set baud rate for the hardware serial port_0 to 9600
  myserial.begin(9600);                               //set baud rate for the software serial port to 9600
  inputstring.reserve(10);                            //set aside some bytes for reciving data from the PC
  sensorstring.reserve(30);                           //set aside some bytes for reciving data from Atlas Scientific product
}


void serialEvent() {                                  //if the hardware serial port_0 recives a char
  inputstring = Serial.readStringUntil(13);           //read the string until we see a <CR>
  input_string_complete = true;                       //set the flag used to tell if we have recived a completed string from the PC
}


void loop() {                                         //here we go...

  if (input_string_complete == true) {                //if a string from the PC has been recived in its entirety
    myserial.print(inputstring);                      //send that string to the Atlas Scientific product
    myserial.print('\r');                             //add a <CR> to the end of the string
    inputstring = "";                                 //clear the string
    input_string_complete = false;                    //reset the flag used to tell if we have recived a completed string from the PC
  }

  if (myserial.available() > 0) {                     //if we see that the Atlas Scientific product has sent a character
    char inchar = (char)myserial.read();              //get the char we just recived
    sensorstring += inchar;                           //add the char to the var called sensorstring
    if (inchar == '\r') {                             //if the incoming character is a <CR>
      sensor_string_complete = true;                  //set the flag
    }
  }


  if (sensor_string_complete == true) {               //if a string from the Atlas Scientific product has been recived in its entirety
    if (isdigit(sensorstring[0]) == false) {          //if the first character in the string is a digit
      Serial.println(sensorstring);                   //send that string to the PC's serial monitor
    }
    else                                              //if the first character in the string is NOT a digit
    {
      print_Humidity_data();                          //then call this function
    }
    sensorstring = "";                                //clear the string
    sensor_string_complete = false;                   //reset the flag used to tell if we have recived a completed string from the Atlas Scientific product
  }
}



void print_Humidity_data(void) {                      //this function will pars the string  

  char sensorstring_array[30];                        //we make a char array
  char *HUM;                                          //char pointer used in string parsing.
  char *TMP;                                          //char pointer used in string parsing.
  char *NUL;                                          //char pointer used in string parsing (the sensor outputs some text that we don't need).
  char *DEW;                                          //char pointer used in string parsing.

float HUM_float;                                      //float var used to hold the float value of the humidity.
float TMP_float;                                      //float var used to hold the float value of the temperatur.
float DEW_float;                                      //float var used to hold the float value of the dew point.
  
  sensorstring.toCharArray(sensorstring_array, 30);   //convert the string to a char array
  HUM = strtok(sensorstring_array, ",");              //let's pars the array at each comma
  TMP = strtok(NULL, ",");                            //let's pars the array at each comma
  NUL = strtok(NULL, ",");                            //let's pars the array at each comma (the sensor outputs the word "DEW" in the string, we dont need it)
  DEW = strtok(NULL, ",");                            //let's pars the array at each comma

  Serial.println();                                   //this just makes the output easier to read by adding an extra blank line.

  Serial.print("HUM:");                               //we now print each value we parsed separately.
  Serial.println(HUM);                                //this is the humidity value.

  Serial.print("Air TMP:");                           //we now print each value we parsed separately.
  Serial.println(TMP);                                //this is the air temperatur value.

  Serial.print("DEW:");                               //we now print each value we parsed separately.
  Serial.println(DEW);                                //this is the dew point.
  Serial.println();                                   //this just makes the output easier to read by adding an extra blank line.
    
  //uncomment this section if you want to take the values and convert them into floating point number.
  /*
    HUM_float=atof(HUM);
    TMP_float=atof(TMP);
    DEW_float=atof(DEW);
  */
}



Herzliche Grüße Leonardo


Angehängte Datei(en) Thumbnail(s)
   
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
08.01.2021, 16:49
Beitrag #2
Titel ist zu lang.
Dann poste bitte mal einen Link des Sensors, den du verwendest.

Gruß Dieter

I2C = weniger ist mehr: weniger Kabel, mehr Probleme. Cool
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
08.01.2021, 17:13
Beitrag #3
Luftfeuchtigkeit, Temperatur und Taupunkt messen mit EZO-HUM Embedded Humidity Sensor
Hier ist der Link zum Sensor:
https://www.exp-tech.de/sensoren/wasserf...ity-sensor
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
08.01.2021, 17:25
Beitrag #4
Der Titel ist immer noch zu lang.
Hast du dir den Inhalt von Sensorstring_aray mal auf dem seriellen Monitor mal anzeigen lassen ?

Ich vermute, dass deine loop zu schnell durchläuft, um den Sensor richtig auszulesen.
Setze da am Ende mal ein delay(1000); rein.

Kürze bitte mal deinen Titel, der ist zu lang.

Gruß Dieter

I2C = weniger ist mehr: weniger Kabel, mehr Probleme. Cool
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
08.01.2021, 17:35
Beitrag #5
RE: EZO- HUM- Sensor
Vielen Dank für den Tipp, hat aber leider nichts gebracht. Fällt Dir noch was ein?

Code:
//This code was written to be easy to understand.
//Modify this code as you see fit.
//This code will output data to the Arduino serial monitor.
//Type commands into the Arduino serial monitor to control the humidity sensor.
//This code was written in the Arduino 1.8.13 IDE
//An Arduino UNO was used to test this code.
//This code was last tested 8/2020


#include <SoftwareSerial.h>                           //we have to include the SoftwareSerial library, or else we can't use it
#define rx 2                                          //define what pin rx is going to be
#define tx 3                                          //define what pin tx is going to be

SoftwareSerial myserial(rx, tx);                      //define how the soft serial port is going to work


String inputstring = "";                              //a string to hold incoming data from the PC
String sensorstring = "";                             //a string to hold the data from the Atlas Scientific product
boolean input_string_complete = false;                //have we recived all the data from the PC
boolean sensor_string_complete = false;               //have we recived all the data from the Atlas Scientific product




void setup() {                                        //set up the hardware
  Serial.begin(9600);                                 //set baud rate for the hardware serial port_0 to 9600
  myserial.begin(9600);                               //set baud rate for the software serial port to 9600
  inputstring.reserve(10);                            //set aside some bytes for reciving data from the PC
  sensorstring.reserve(30);                           //set aside some bytes for reciving data from Atlas Scientific product
}


void serialEvent() {                                  //if the hardware serial port_0 recives a char
  inputstring = Serial.readStringUntil(13);           //read the string until we see a <CR>
  input_string_complete = true;                       //set the flag used to tell if we have recived a completed string from the PC
}


void loop() {                                         //here we go...

  if (input_string_complete == true) {                //if a string from the PC has been recived in its entirety
    myserial.print(inputstring);                      //send that string to the Atlas Scientific product
    myserial.print('\r');                             //add a <CR> to the end of the string
    inputstring = "";                                 //clear the string
    input_string_complete = false;                    //reset the flag used to tell if we have recived a completed string from the PC
  }

  if (myserial.available() > 0) {                     //if we see that the Atlas Scientific product has sent a character
    char inchar = (char)myserial.read();              //get the char we just recived
    sensorstring += inchar;                           //add the char to the var called sensorstring
    if (inchar == '\r') {                             //if the incoming character is a <CR>
      sensor_string_complete = true;                  //set the flag
    }
  }


  if (sensor_string_complete == true) {               //if a string from the Atlas Scientific product has been recived in its entirety
    if (isdigit(sensorstring[0]) == false) {          //if the first character in the string is a digit
      Serial.println(sensorstring);                   //send that string to the PC's serial monitor
    }
    else                                              //if the first character in the string is NOT a digit
    {
      print_Humidity_data();                          //then call this function
    }
    sensorstring = "";                                //clear the string
    sensor_string_complete = false;                   //reset the flag used to tell if we have recived a completed string from the Atlas Scientific product
  }
}



void print_Humidity_data(void) {                      //this function will pars the string  

  char sensorstring_array[30];                        //we make a char array
  char *HUM;                                          //char pointer used in string parsing.
  char *TMP;                                          //char pointer used in string parsing.
  char *NUL;                                          //char pointer used in string parsing (the sensor outputs some text that we don't need).
  char *DEW;                                          //char pointer used in string parsing.

float HUM_float;                                      //float var used to hold the float value of the humidity.
float TMP_float;                                      //float var used to hold the float value of the temperatur.
float DEW_float;                                      //float var used to hold the float value of the dew point.
  
  sensorstring.toCharArray(sensorstring_array, 30);   //convert the string to a char array
  HUM = strtok(sensorstring_array, ",");              //let's pars the array at each comma
  TMP = strtok(NULL, ",");                            //let's pars the array at each comma
  NUL = strtok(NULL, ",");                            //let's pars the array at each comma (the sensor outputs the word "DEW" in the string, we dont need it)
  DEW = strtok(NULL, ",");                            //let's pars the array at each comma

  Serial.println();                                   //this just makes the output easier to read by adding an extra blank line.

  Serial.print("HUM:");                               //we now print each value we parsed separately.
  Serial.println(HUM);                                //this is the humidity value.

  Serial.print("Air TMP:");                           //we now print each value we parsed separately.
  Serial.println(TMP);                                //this is the air temperatur value.

  Serial.print("DEW:");                               //we now print each value we parsed separately.
  Serial.println(DEW);                                //this is the dew point.
  Serial.println();                                   //this just makes the output easier to read by adding an extra blank line.
    
  //uncomment this section if you want to take the values and convert them into floating point number.
  /*
    HUM_float=atof(HUM);
    TMP_float=atof(TMP);
    DEW_float=atof(DEW);
  */
  delay(1000);
}
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
08.01.2021, 17:41
Beitrag #6
RE: EZO- HUM- Sensor
Und was zeigt der serielle Monitor an ?

Gruß Dieter

I2C = weniger ist mehr: weniger Kabel, mehr Probleme. Cool
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
08.01.2021, 17:48 (Dieser Beitrag wurde zuletzt bearbeitet: 08.01.2021 17:49 von Tommy56.)
Beitrag #7
RE: EZO- HUM- Sensor
Warum gehst Du den Umweg über senssorString und schreibst nicht gleich in ein Char-Array? Was sagt die von hotsystems vorgeschlagene Ausgabe von Sensorstring_aray (am Besten auch als HEX, damit man Steuerzeichen sieht)?

Auch aus Serial kannst Du mit readBytesUntil in ein char-Array lesen.

Gruß Tommy

"Wer den schnellen Erfolg sucht, sollte nicht programmieren, sondern Holz hacken." (Quelle unbekannt)
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
08.01.2021, 18:57
Beitrag #8
RE: EZO- HUM- Sensor
@TO,
in deinem Sketch hast du vergessen den Sensor zu initialisieren und die Funktionen T und DEW freizuschalten. Einfach mal das Datenblatt auf Seite 19 lesen...Big Grin
lgbk


An alle Neuankömmlinge hier, wenn ihr Code(Sketch) hier posten wollt dann liest euch bitte diese Anleitung durch.

Ich spreche fließend Schwäbisch, Deutsch das Notwendigste und für die Begriffsstutzigen erprobtes Tacheles mit direkten Hinweisen ohne Schnörkel...

1+1 = 10 Angel ...und ich bin hier nicht der Suchmaschinen-Ersatz Dodgy...nur mal so als genereller Tipp..
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
Antwort schreiben 


Möglicherweise verwandte Themen...
Thema: Verfasser Antworten: Ansichten: Letzter Beitrag
  Sensor-Adressdaten mittels json von Webserver einlesen und hinterlegen MLuhmann 7 615 22.02.2021 18:56
Letzter Beitrag: Tommy56
  LED als lichtempfindlicher Sensor daja64 7 743 23.12.2020 01:18
Letzter Beitrag: daja64
  Arduino als Enocean Aktor/Sensor hr3 2 1.092 08.02.2020 20:53
Letzter Beitrag: Bitklopfer
  Fehlermeldung (wegen BME 280 Sensor?) Schneggl 3 1.110 26.10.2019 09:28
Letzter Beitrag: Tommy56
  Grove-GSR Sensor frala 22 4.940 09.10.2018 22:11
Letzter Beitrag: Bitklopfer
  Sensor mit 10 Hz auslesen Olafson Larson 7 2.979 05.07.2018 15:59
Letzter Beitrag: Tommy56
Exclamation Sound Sensor KY-038 Jack 6 3.573 16.05.2018 23:46
Letzter Beitrag: georg01
Question IR Sensor - Tastendruck oneill86 2 1.966 21.03.2018 18:22
Letzter Beitrag: oneill86
  DS18s20 Temperatur Sensor georg01 9 4.783 25.02.2018 16:03
Letzter Beitrag: georg01
  Lichtschrankensensor / Line Tracker Sensor Hitikatus 5 3.435 13.07.2017 15:21
Letzter Beitrag: RCudino

Gehe zu:


Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste