122-Mesure de Temp et Hygro DHT22
Mesure de Température et Hygrométrie DHT22
Caractéristiques:

DHT22:
Faible coût
Alimentation de 3 à 5V .
Consommation 2,5 mA usage courant max lors de la conversion.
Échelle de 0-100% d'humidité relative, avec 2-5% de précision
Échelle de -40 à 125 ° C avec ± 0,5 ° C Précision
Pas plus de 0,5 taux d'échantillonnage Hz (une fois toutes les 2 secondes)
La taille du corps 15.1mm x 25mm x 7.7mm
4 broches avec espacement de 0,1 Pouce
Raccordement:
Le module nRF24L01+ doit être alimenté avec une tension inférieure à 3,6V.

Installer la bibliothèque suivante DHT22. Téléchargement ici
Mon programme envoie deux ID différents pour la température et pour l'humidité. Et fonctionne en mode LowPower. C'est à dire basse consommation.
Charger le programme dans l'Attiny:
/*
This is an attiny84 example code for the nRF24L01 that can communicate with RF24 library
All the support files and libraries for the attiny for nRF24L01 is at repo listed below
* repo : https://github.com/stanleyseow/arduino-nrf24l01/
* Author : Stanley Seow
* e-mail : stanleyseow@gmail.com
* date : 8 Aug 2013
Some default values to take note when using this mirf/spi85 library
Uses Mirf forked library from https://github.com/xdarklight/arduino-nrf24l01
- node addressing is similar to RF24 libs but the bytes are flipped
byte TADDR[] = {0xe3, 0xf0, 0xf0, 0xf0, 0xf0}; will matches receiver node of RF24 below
const uint64_t pipes[2] = { 0x7365727631LL, 0xF0F0F0F0E3LL };
The repo for the RF24 lib is at https://github.com/stanleyseow/RF24/
Added TinyDebugSerial to the codes for TX only serial debugging
https://code.google.com/p/arduino-tiny/
*/
//Modifier par Christophe CARON
//www.caron.ws
#include <SPI85.h>
#include <Mirf85.h>
#include <nRF24L0185.h>
#include <MirfHardwareSpiDriver85.h>
#include <DHT22.h>
#include <Narcoleptic.h> // https://code.google.com/p/narcoleptic/
// This USI was defined in SPI85.cpp
// Not to be confused with SPI (MOSI/MISO) used by ICSP pins
// Refer to page 61 of attiny84 datahseet
//
//#define USI-DO 5
//#define USI-DI 4
//#define USCK 6
#define CE 8
#define CSN 7
// ATMEL ATTINY84 / ARDUINO
//
// +-\/-+
// VCC 1| |14 GND
// SerialTx (D 0) PB0 2| |13 AREF (D 10)
// (D 1) PB1 3| |12 PA1 (D 9)
// RESET PB3 4| |11 PA2 (D 8)
// PWM INT0 (D 2) PB2 5| |10 PA3 (D 7) CE
// SS/CSN (D 3) PA7 6| |9 PA4 (D 6) USCK
// USI-DI (D 4) PA6 7| |8 PA5 (D 5) USI-DO
// +----+
#define DHT22_PIN 10 // Raccordement de l'entrée de communication
#define DTH22_POWER 0 // Raccordement de l'alimentation
// Setup a DHT22 instance
DHT22 myDHT22(DHT22_PIN);
void setup(){
pinMode(DTH22_POWER, OUTPUT);
Mirf.cePin = CE;
Mirf.csnPin = CSN;
Mirf.spi = &MirfHardwareSpi;
Mirf.init();
Mirf.payload = 32;
// This address is compatible with my example of rpi-hub or nRF24_Arduino_as_hub
// at repo https://github.com/stanleyseow/RF24/examples/
//byte RADDR[] = {0xe7, 0xde, 0xde, 0xde, 0xde};
byte TADDR[] = {0xe2, 0xf0, 0xf0, 0xf0, 0xf0}; // Ardresse du raspberry . Lecture en sens inverse
Mirf.channel = 0x0; // Same as rpi-hub and sendto_hub ( channel 0 )
Mirf.rfsetup = 0x06; // 1Mbps, Max power
//Mirf.setRADDR(RADDR);
Mirf.setTADDR(TADDR);
Mirf.config();
// Enable dynamic payload on the other side
Mirf.configRegister( FEATURE, 1<<EN_DPL );
Mirf.configRegister( DYNPD, 1<<DPL_P0 | 1<<DPL_P1 | 1<<DPL_P2 | 1<<DPL_P3 | 1<<DPL_P4 | 1<<DPL_P5 );
delay(100);
}
void loop(){
char buffer[32] = ""; //texte à envoyer
char buffer1[32] = "#ID61#"; //ID Node choix
digitalWrite(DTH22_POWER, HIGH); // turn DS18B20 sensor on
float temp;
float hygro;
delay(2000);
DHT22_ERROR_t errorCode;
errorCode = myDHT22.readData(); // read data from sensor
if (errorCode == DHT_ERROR_NONE) { // data is good
temp = (myDHT22.getTemperatureC()); // Lecture de la température
hygro = (myDHT22.getHumidity()); // Lecture de l'hygrométrie
dtostrf(temp, 5, 2, buffer);
strcat (buffer1,buffer); // Ajout de ID node
envoi(buffer1); // envoie
buffer[32] = 0;
char buffer1[32] = "#ID62#"; //ID Node choix
sleep(1); // Mise en vielle pour 2 secondes
dtostrf(hygro, 5, 2, buffer);
strcat (buffer1,buffer); // Ajout de ID node
envoi(buffer1); // envoie
buffer[32] = 0;
}
digitalWrite(DTH22_POWER, LOW); // Arrêt de l'alimentation du DTH22
Mirf.powerDown(); // Mise en vielle du module RF
sleep(31); // Mise en vielle pour 60 secondes
} // End loop()
// Fonction envoie caractères
void envoi( char *text){
uint8_t sent = false;
Mirf.send((byte *) text);
while( Mirf.isSending() )
{
delay(1);
sent = true; // Sent success
}
}
// Fonction mise en veille
void sleep(int tempo){
int a=0; // variable boucle
while(a < tempo){ //60Sec
Narcoleptic.delay(2000); // enter low power mode for 60 seconds, valid range 16-32000 ms with standard Narcoleptic lib
// change variable for delay from int to unsigned int in Narcoleptic.cpp and Narcoleptic.h
// to extend range up to 65000 ms
a++;
}
}
Téléchargement du programme ici
Maintenant votre Attiny envoie la température et l'hygrométrie toute les 60 Sec. Pour les voir sur le Raspberry aller dans le chapitre ici

Mise à jour 25/12/2013
Créé avec HelpNDoc Personal Edition: Sites web iPhone faciles