I am trying to make a sensor that gets temperature and humidity values from a DHT22 and send it through NRF24L01+ to a Raspberry Pi 2 Model B.
To connect NRF24L01+ to ATtiny85 and to free two pins for the DHT22, I used this link.
There is a scheme of my sensor:
There is a photo of the test board with the sensor (sorry, it is very untidy, because I remade it many times before to fix the problem):
I program the ATtiny85 with Arduino IDE (with 8 MHz clock).
I used this library and radio communication is working perfectly (it can't be an error during the radio transmission).
Here is the code of my ATtiny85:
#include <DHT.h>
#include <RF24.h>
byte currentNodeAddr[6] = "1Node"; // Address of this node
// Struct for sending measured data
struct Data {
uint16_t temp; // Temperature value
uint16_t hum; // Humidity value
int status; // DHT22 module status
} data;
RF24 radio(2,2); // Create instance of RF24 radio object
DHT dht; // Create instance of DHT22 module object
void setup() {
// Set up the radio
radio.begin();
radio.openWritingPipe(currentNodeAddr);
radio.stopListening();
dht.setup(3); // Set up the sensor on PB3 pin
}
void loop() {
// This DHT library can calculate the delay but it may be 2+ sec
delay(dht.getMinimumSamplingPeriod());
// Get values from DHT22
data.temp = dht.getTemperature();
data.hum = dht.getHumidity();
radio.write(&data, sizeof(Data)); // Send data to the Raspberry
}
But I can't the get temperature and humidity values from the DHT22. I used a lot of different libraries for DHT22 (for example, github.com/ringerc/Arduino-DHT22, github.com/nethoncho/Arduino-DHT22, github.com/jscrane/DHT22, etc.) and none of them works (they return zeros, NAN, or, generally, timeout error). And it seems that the connection with the DHT22 is correct (there were connection errors and I fixed them). I tried to use a lot of DHT22 modules, so the problem can't be a defective module.
Yes, I put a 2 second (and more) delay in between read requests. Yes, I added a 10k resistor between pin 1 and 2 of the DHT22.
Now I am thinking that the libraries work fine, but may be free pins (PB3 or PB4) of ATtiny85 can't receive data for some reason.
Tell me please where may be an error or a bug? Thank you in advance! And also many thanks to authors of all links and repositories that I have mentioned here!
EDIT (in accordance with frarugi87's answer):
At first I have grounded 3 and 4 pins of the DHT22.
When I program ATtiny at the 1 MHz, values are sent every 2 seconds (as it should be), but when I program ATtiny at 8 MHz, values are sent every 16 seconds (is it correct?).
I used the suggested code to check the radio library and it seems it works pretty well (values are being incremented and sent):
After that I used the suggested library (RobTillaart/Arduino v. 0.1.21) and at first time it returned some strange values (humidity and the status were 0 and temperature was MAX_INT value), but when I have tried to get only status value as string, the library also has returned -2 (DHTLIB_ERROR_TIMEOUT). This time I program ATTiny at 8 MHz:
Also I tried to get values without NRF24L01+ through I2C connection between the ATtiny85 and the Raspberry Pi. Result was the same (DHTLIB_ERROR_TIMEOUT):
Maybe the problem is in timings of ATtiny85 or in the program process? I used these links (1, 2, 3) to set up Arduino IDE on Raspbian.
Here is list of useful links for this project which I found to implement it (I hope the authors will not mind that I posted their links here):
Arduino/AVR DHT projects and libraries:
- Arduino Wireless Weather Station
- Mini weather station with Attiny85
- Easy IoT weather station with multiple sensors
- ATtiny84 & RFM12B wireless sensor node
- DHT11 HUMIDITY & TEMPERATURE SENSOR MODULE
- DHT22 running @ 8MHZ
- DHT22 not working with 8mhz clockspeed?
- Adafruit DHT Library and ATtiny85
- Class for DHTxx sensors
- An Arduino library for reading the DHT family of temperature and humidity sensors
- Using a RHT03 (aliases: RHT-22, DHT22, AM2302) temperature/humidity sensor from Arduino
- Arduino-library for DHT11/DHT22 sensors reading
- Efficient DHT library for Arduino
- Feuchtesensor AM2302/DHT22
- 7 Segment Digital Thermometer using ATtiny 85
- Wiring up DHT humidity sensors
- Attiny85 RF Transmitter to Arduino Uno Receiver
- Arduino library for the DHT22 humidity and temperature sensor
- Arduino library for DHT11DHT22, etc Temp & Humidity Sensors
- A simplified DHT11/DHT22/AM2302 library for use with the Trinket/Gemma
- Arduino library for the DHT22 humidity and temperature sensor
- Arduino sketch code for reading RHT03 (also known as DHT22, RHT22, and AM2302) temperature/humidity sensor
Arduino/AVR nRF24L01 projects and libraries:
- Optimized fork of nRF24L01 for Arduino and Raspberry
- Optimized Network Layer for nRF24L01(+) Radios on Arduino and Raspberry Pi
- nrf24l01+ control with 3 ATtiny85 pins
- NRF24L01 real life range test
- Optimized fork of nRF24L01 for Arduino and Raspberry Pi
- NRF24L01 SIX CHANNELS TO ONE RECEIVER
- Arduino attiny support files for nRF24L01 RF modules
- ARDUINO + RASPBERRY PI Switching light with NRF24l01+
Programming the ATtiny85 from Raspberry-Pi:
- Programming the ATtiny85 from Raspberry Pi
- Arduino IDE Installation
- Arduino for other Chips
- Tiny AVR Programmer Hookup Guide
- ATtiny85 with Arduino IDE and Gertboard
- Setting up the Arduino IDE on Raspbian
Arduino/AVR FR433 libraries:
- 433Kit is a collection of code and documentation designed to assist you in the connection and usage of RF 433MHz transmit and receive modules to/with your Arduino and Rapberry Pi
- Tiny AVR Programmer Hookup Guide
Troubleshooting: