DHT22 issues on Portenta Machine Control

Hello,

This board has presented quite the learning curve. I have a project where I need the use of a humidity sensor and the whole project is driven by the Machine Control board. I'm running 5v analog out to the DHT22 and running the output to digital_input channel 00. However when I upload my sketch and open the serial monitor the board hangs after "Serial.println("read humidity")" in the loop. I've dug the interwebs for anything, unfortunately there seems to be very limited information for sensors and the Portenta MC. I've also tried the MC.h library's digital_inputs.read(DIN_READ_CH_PIN_00), as seen in the built-in example. I've been stuck on this for days. I've tried a couple other STM32 libraries for DHT22 but don't know if I'm having a library issue or a circuit issue. I've also ran a very similar basic sketch on my MKR Wifi 1010 without issues.

Libraries I'm using:
Arduino_MachineControl.h
DHT sensor library by Adafruit

I've been I've limited my sketch down to just the DHT circuit for ease of viewing. Any help is greatly appreciated, as this will also help with other digital inputs I am planning with this board.

#include <Arduino_MachineControl.h>
#include "Wire.h"
#include <DHT.h>

using namespace machinecontrol;

#define DHTPIN DIN_READ_CH_PIN_00
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

//Variables
float hum;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  digital_inputs.init()
  Wire.begin();
  dht.begin();
  analog_out.period_ms(0, 4);
}

void loop() {
  analog_out.write(0, 5);
  Serial.println("read humidity");
  hum = dht.readHumidity();
  Serial.print("Humidity: ");
  Serial.print(hum);

  delay(1000);
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.