Help with visualising DHT sensor data

Hello good people here! I’m new to processing, and attempting to read my DHT11 sensor and visualising it via Processing. I’ve taken the processing/ arduino code from an online tutorial, and adapted it for my own arduino. Seems like the Arduino (UNO) data can’t be read but I’m not sure what the issue is (code perhaps?). Have attached my code as below!

Appreciate your help! :slight_smile:

Processing Code

import meter.*;
import processing.serial.*;

Serial usbPort;
int [ ] sensors = null;
boolean firstContact = false;
String[] list;

Meter m, m2;

void setup() {
  size(950, 400);
  background(0);
  
  String portName = Serial.list()[0];//listens for serial port and names it"portName"
  usbPort = new Serial(this, "/dev/cu.SLAB_USBtoUART", 9600);

  fill(120, 50, 0);
  m = new Meter(this, 25, 100);
  // Adjust font color of meter value  
  m.setTitleFontSize(20);
  m.setTitleFontName("Arial bold");
  m.setTitle("Temperature (C)");
  m.setDisplayDigitalMeterValue(true);
  
  // Meter Scale
  String[] scaleLabelsT = {"0", "10", "20", "30", "40", "50", "60", "70", "80"};
  m.setScaleLabels(scaleLabelsT);
  m.setScaleFontSize(18);
  m.setScaleFontName("Times New Roman bold");
  m.setScaleFontColor(color(200, 30, 70));
  
  m.setArcColor(color(141, 113, 178));
  m.setArcThickness(10);
  m.setMaxScaleValue(80);
  
  m.setNeedleThickness(3);
  
  m.setMinInputSignal(0);
  m.setMaxInputSignal(80);

  // A second meter for reference
  int mx = m.getMeterX();
  int my = m.getMeterY();
  int mw = m.getMeterWidth();
  
  m2 = new Meter(this, mx + mw + 20, my);
  m2.setTitleFontSize(20);
  m2.setTitleFontName("Arial bold");
  m2.setTitle("Humidity (%)");
  m2.setDisplayDigitalMeterValue(true);
  
  String[] scaleLabelsH = {"0", "10", "20", "30", "40", "50", "60", "70", "80", "90", "100"};
  m2.setScaleLabels(scaleLabelsH);
  m2.setScaleFontSize(18);
  m2.setScaleFontName("Times New Roman bold");
  m2.setScaleFontColor(color(200, 30, 70));
  
  m2.setArcColor(color(141, 113, 178));
  m2.setArcThickness(10);
  m2.setMaxScaleValue(100);
  
  m2.setNeedleThickness(3);
  
  m2.setMinInputSignal(0);
  m2.setMaxInputSignal(100);
  
}

public void draw() {
  
  textSize(30);
  fill(0, 255, 0);
  text("Temperature and Humidity", 270, 50);
  
  if (usbPort.available() > 0) {
    String val = usbPort.readString();
    list = split(val, ',');
    float temp = float(list[0]);
    float hum = float(list[1]);
    
    println("Temperature: " + temp + " C  " + "Humidity: " + hum + " %");
    
    m.updateMeter(int(temp));
    m2.updateMeter(int(hum));
  }
}

Arduino Code (attaching original notes here)

#include <DHT.h>

// for DHT22, 
//      VCC: 5V or 3V
//      GND: GND
//      DATA: 2
int pinDHT11 = 2;
#define DHTTYPE DHT11
DHT dht(pinDHT11, DHTTYPE);

void setup() {
  Serial.begin(9600);
}

void loop() {
  // start working...
  
  // read without samples.
  // @remark We use read2 to get a float data, such as 10.1*C
  //    if user doesn't care about the accurate data, use read to get a byte data, such as 10*C.
  float temperature = dht.readTemperature();

  }
  
  Serial.print(temperature);
  Serial.print(",");
  return;
  }
  // DHT22 sampling rate is 0.5HZ.
  delay(2500);
}
1 Like

please after

use ( temporary ) a

println("arduino send: "+val);

and check if that data make any sense.

actually it might be a good idea to strip down that processing code to a 5 line thing
just for confirm the communication.


in that case a link can be good,
just imagine you start from a 10 year old code for a retired processing version, or other…

2 Likes

Just fyi the link to the tutorial is here!

1 Like