Hi Guys,
I'm fresh new in programming Arduinoa and I was trying to use some codes for my education and practice using Tmp/Humidity Sensor and read it with Processing but I'm getting wrong string, It's like reading the first 2 digits of the Temp and than reading again the full value and continue with (,) and humidity.
what could be the problem??? I'm thinking is related to the delay but not sure.
Thank you for helping
this is the code for Arduino:
#include <SimpleDHT.h>
int pinDHT11 = 2;
SimpleDHT11 dht11;
void setup() {
Serial.begin(9600);
delay(500);
}
void loop() {
// start working...
// read without samples.
// @remark We use read2 to get a float data, such as 10.1C
// if user doesn't care about the accurate data, use read to get a byte data, such as 10C.
float temperature = 0;
float humidity = 0;
int err = SimpleDHTErrSuccess;
if ((err = dht11.read2(pinDHT11, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
Serial.print("Read DHT22 failed, err="); Serial.println(err);delay(2000);
return;
}
Serial.print((float)temperature);
Serial.print(",");
Serial.println((float)humidity);
// DHT22 sampling rate is 0.5HZ.
delay(2500);
}
and this if for Processing
import processing.serial.*;
Serial port; // Define a port
void setup(){
port = new Serial(this, "COM5", 9600);
}
void draw(){
if (port.available() > 0){
String val = port.readString(); // read incoming string on serial port
// First we need to separate temperature and humidity values
print(val);
}
}
this is what I get in processing when I run it:
27.27.00,58.00
27.00,58.00
27.00,58.00
27.00,59.00