Hello everyone, this is my first time using both processing and arduino and I’m having a bit of trouble with receiving data in processing.
I have a DHT11 temperature and humidity sensor I’m using with my Arduino and I’m sending the temperature (as a float) and the humidity (as an int) through the serial port. I want those two values to be written inside two different boxes but I’m having some problems on the receiving end:
a) The values I receive have a letter at the beginning of them that I need to remove in processing, since I use that letter as identification in another program
b) The temperature has  between the value and “°C”, which I think it’s because the temperature value is a float (the humidity value is received just fine)
c) I can’t figure out how to maintain the values I receive (they disappear after they’ve been received) and separate them into different strings (since I want to print the “%” and the “°C” as well) in processing so I can print them separately into the different text boxes
I have the Arduino code here:
#include <DHT.h>
#define DHTPIN 12
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin();
}
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
int H = h;
Serial.print("t");
Serial.print(t);
Serial.print("°C");
Serial.println("\n");
Serial.print("H");
Serial.print(H);
Serial.print("%");
Serial.println("\n");
delay(2000);
}
And I have the processing code here (please ignore the oddly shaped thermometer on the right, that’s something else I’ll try to figure out later):
import processing.serial.*;
Serial myport;
String h;
String t;
int lf = 10;
void setup() {
size(1920, 1080);
String portname = Serial.list()[1];
myport = new Serial(this, portname, 9600); }
void draw() {
rectMode(CENTER);
noStroke();
fill(255);
rect(1460, 680, 150, 400);
ellipse(1460, 880, 150, 150);
ellipse(1460, 400, 300, 300);
stroke(0);
rect(960, 100 , 1000, 160);
rect(270, 400, 400, 200);
rect(270, 650, 400, 200);
rect(720, 400, 400, 200);
rect(720, 650, 400, 200);
String s = "BT DHT11 Temperature Sensor";
fill(0);
textSize(50);
text(s, 600, 120);
textSize(25);
text("Temperature is", 180, 400);
text("Humidity is", 200, 650);
while (myport.available()>0) {
h = myport.readStringUntil(lf);
t = myport.readStringUntil(lf);
text(h, 700, 400);
text(t, 700, 650);
}
delay(100);
}
I appreciate all the help, thank you in advance!