0

i recently purchased a DHT22's and tried to get it to work using Adafruit's DHT library on Github. When i compile it with a Arduino DUE, it gives me the following error:

C:\Users\Moz\Documents\Arduino\libraries\DHT-sensor-library-master\DHT.cpp: In constructor 'DHT::DHT(uint8_t, uint8_t, uint8_t)':
C:\Users\Moz\Documents\Arduino\libraries\DHT-sensor-library-master\DHT.cpp:14:9: error: invalid conversion from 'Pio*' to 'uint8_t {aka unsigned char}' [-fpermissive]
   _port = digitalPinToPort(pin);
         ^
Error compiling.

It compiles on a Arduino Uno but not on the DUE.

What is the reason for this?

Edit: Below is the example code i use

#include "DHT.h"

#define DHTPIN 2     // what pin we're connected to

#define DHTTYPE DHT22   // DHT 22  (AM2302)

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  Serial.println("DHTxx test!");
  dht.begin();
}

void loop() {

  delay(2000);
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  float f = dht.readTemperature(true);

  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  // Compute heat index in Fahrenheit (the default)
  float hif = dht.computeHeatIndex(f, h);
  // Compute heat index in Celsius (isFahreheit = false)
  float hic = dht.computeHeatIndex(t, h, false);

  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.print(" *C ");
  Serial.print(f);
  Serial.print(" *F\t");
  Serial.print("Heat index: ");
  Serial.print(hic);
  Serial.print(" *C ");
  Serial.print(hif);
  Serial.println(" *F");
}
1

That library uses direct pin manipulation to make things faster. However the Due is a completely different architecture to the Uno, so direct pin manipulation is done differently.

The library would have to be written specifically to do it in the two different ways and select between them depending on which board is chosen for the compilation. This hasn't been done, and it's unlikely it would ever be done.

This is exactly why digitalWrite(), shiftIn(), shiftOut() et al exists, so that you don't get these kind of problems. By choosing not to use them Adafruit have basically decided that their library will never work on a Due.

  • Thank you for your quick answer. I am aware that the port names on the DUE are completely different to the UNO.This might be a stupid question but, would it be enough for me to change the port name in the library manually to the DUE's port name? – Darellon Aug 6 '15 at 12:04
  • @Darellon The whole way the ports work on the Due is completely different. You would need to write completely different code to do the port manipulation. – Majenko Aug 6 '15 at 12:28
  • I suggest you post on the Adafruit forum, asking for an update to their library, or suggestions about how to fix it to work on the Due. – Nick Gammon Aug 7 '15 at 3:31
2

There are several Arduino libraries for reading DHT22 and related DHT sensors. The Adafruit DHT library does not compile for the Due since it uses AVR specific functions not available on ARM (Due).

For the Arduino Due use Rob Tillaart's DHTstable library available from his github page where you can download a zip file. Note that his project also has a "DHTlib" library which does not support the Due. There exists yet more DHT libraries which Rob has listed on the DHTLib page on arduino.cc.

0

The same library works with the Due if you use the older version 1.1.13 from the same Github repo, which is the last version that officially supported the Due.

Here are the changelog entries that show the relevant changes:

update: 0.1.13 added support for DHT33 and DHT44 - LAST DUE VERSION

update: 0.1.14 replaced digitalRead with faster code (AVR ONLY!!! better support for lower Mhz devices)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.