Hi,
I'm far newer to the forum than to Arduino and I usually find my answers without annoying other people with questions like this
I nearly gave up in trying to understand this and I can't let that happen. So i reach out to you and hope, someone can explain me why I get this behaviour.
I'm currently working on a small weather station project -> AtTiny85 reporting DHT22 data through 433MHz transmitter to an UNO which itself has a DHT22 Sensor and additional 2x16 LCD to display both readings.
Details to be found here: diy-funk-wetterstation-mit-dht22-attiny85-und-radiohead
I got it working but something is puzzling me and I fail to get the AHA experience.
On the receiver side (UNO)
If I define the DHT_Pin like so: [#define DHT_PIN 9] I won't get any readings. However, if I use [#define DHT_PIN PB1] it works like a charm.
From AtTiny85 I'm used to "strange" pin names. But not on the UNO...
The strange thing about it is: The Pins for the receiver module and the LCD Module are defined with the pin number and they work fine this way.
On this Forum I found a hint regarding the file hardware\arduino\avr\variants\standard\pins_arduino.h but I don't see anything wrong with it. (pin 9 is only mentioned once as declaration for a digital pwm pin on row 35)
Any Ideas why I cant access the DHT Sensor through pin 9?
IDE v1.8.9, target board Arduino/Genuino UNO
// source https://git.cryhost.de/crycode/attiny85-radiohead-dht22-weather-sensor/snippets/19
#define SERVER_ADDRESS 0x01
#define RH_SPEED 2000
#define RH_RX_PIN 5
#define LED_PIN 13
#define DHT_PIN PB1 //pin 9
#define RH_BUF_LEN 9
uint8_t rh_buf[RH_BUF_LEN];
#define RH_ASK_MAX_MESSAGE_LEN RH_BUF_LEN
#include <RHDatagram.h>
#include <RH_ASK.h>
//LCD Stuff
#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 6, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
#include "dht22.h"
dht22 dht;
RH_ASK driver(RH_SPEED, RH_RX_PIN);
RHDatagram manager(driver, SERVER_ADDRESS);
float t = 0;
float h = 0;
uint8_t bat_percent = 0;
uint8_t bat_raw = 0;
void setup() {
 lcd.begin(16, 2);
 Serial.begin(9600);
 if (!manager.init()) {
  Serial.println("init failed");
  lcd.print("init failed");
 } else {
  Serial.println("init done");
  lcd.print("init ok...");
  lcd.setCursor(0, 1);
  lcd.print("wait for input");
 }
 dht_init(&dht, DHT_PIN);
 pinMode(LED_PIN, OUTPUT);
}
void loop() {
 if (manager.available()) {
  uint8_t len = sizeof(rh_buf);
  uint8_t from;
  if (manager.recvfrom(rh_buf, &len, &from)) {
   lcd.clear();
   digitalWrite(LED_PIN, HIGH);
   //Serial.print("got message from : 0x");
   //Serial.println(from, HEX);
   switch (rh_buf[0]) {
    case 0x00:
     // start message
     Serial.println("0x00 start");
     break;
    case 0x01:
     // DHT data
     //Serial.println("0x01 DHT data");
     memcpy(&t, &rh_buf[1], 4);
     memcpy(&h, &rh_buf[5], 4);
     Serial.print(t);
     Serial.print("°C - ");
     Serial.print(h);
     Serial.println("%");
     String lcddata = "O: " + String(t, 1) + char(223) + "C, " + String(h, 1) + "%";
     lcd.setCursor(0, 0);
     lcd.print(lcddata);
     readInsideTemp();
     break;
    case 0x02:
     // battery data
     //Serial.println("0x02 battery data");
     bat_percent = rh_buf[1];
     bat_raw = rh_buf[2];
     Serial.print(bat_percent);
     Serial.print("% Batery - ADC: ");
     Serial.println(bat_raw);
     break;
    case 0xee:
     // error
     Serial.println("0xEE error");
     break;
    default:
     // should never happen
     break;
   }
   digitalWrite(LED_PIN, LOW);
  }
 }
}
void readInsideTemp() {
 float tin = 0;
 float hin = 0;
 String lcddata;
 if (dht_read_data(&dht, &tin, &hin) == 1) {
  lcddata = "I: " + String(tin, 1) + char(223) + "C, " + String(hin, 1) + "%";
 } else {
  lcddata = "I: DHT NOK!";
 }
 lcd.setCursor(0, 1);
 lcd.print(lcddata);
}
Solution:
The Problem is related to the used Fast dht22 library by Sergey Denisov aka LittleBuster GitHub - LittleBuster/avr-dht22: DHT22 library C-language
The library is hardcoded to Port B which played a trick on me.
hence DHT_PIN 1 is equal to Port B Pin 1 which refers to arduino pin 9
2 -> PB2 -> arduino pin 10 etc.