Ci dessous un pseudo tuto pour mes confrères qui comme moi découvre l'arduino.
Votre sonde a base de dht11, dht22 ds18b20 seras reconnu comme un sonde Oregon.
L'article du Pro:
-dht11 + attiny85 (script oregon) + rf433 => http://labalec.fr/erwan/?p=1534
-DS18B20 + attiny85 (script oregon) +rf433 =>http://labalec.fr/erwan/?p=1520
Commande:
A prendre une fois:
-UNO R3 MEGA328P ATMEGA16U2 for Arduino Compatible env 7$ sur aliexpress
A prendre pour une sonde:
-Attiny 85 env 1,15$
-Sonde pas chère env 1,5$
-Un support pile 1.28$ (qui prendra je l'espère 3 piles et le circuit)

La base:
1-Télécharger et installer le logiciel Arduino
http://arduino.cc/download.php?f=/ardui ... indows.exe
2-Brancher l'arduino
3-Vérifier dans le gestionnaire de périphérique que l'arduino est bien reconnu
=>Si non reconnu installer le driver et allez pointer sur le dossier fraichement installé dans le dossier driver (c:program files/arduino/drivers)
=>Vous pouvez en profiter pour regarder le port com de l'arduino (dans Ports(com et LPT))
4-Débrancher / redemarrer
5-Pour que la carte Arduino Uno soit capable de programmer un Attiny il faut le lui dire.
- Branchez la carte Arduino Uno au port USB de votre ordinateur
- Lancer le programme Arduino
- Allez dans ( outils/port série) sélectionnez le port COM sur le quel est connecté la carte Arduino.
- Allez dans ( Fichier/exemple) et cliquez sur ( ArduinoISP )
- Dans la nouvelle fenetre allez dans ( Outils/Type de carte) cliquez sur ( Arduino Uno )
- Allez dans ( Fichier ) cliquez sur Téléverser
=>Téléversement terminé
- Fermer les deux fenetres
__________________________________________________________________________________________
DTH11
1-Copier le script http://labalec.fr/erwan/wp-content/uplo ... _dht11.txt
Code : Tout sélectionner
/*
* connectingStuff, Oregon Scientific v2.1 Emitter
* http://connectingstuff.net/blog/encodage-protocoles-oregon-scientific-sur-arduino/
*
* Copyright (C) 2013 olivier.lebrun@gmail.com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <avr/sleep.h>
#include <avr/wdt.h>
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
volatile boolean f_wdt = 1;
#include <dht11.h>
#define DHT11PIN PB1
dht11 DHT11;
#include <SoftwareSerial.h>
#define SERIAL_RX PB3 //pin 2 //INPUT
#define SERIAL_TX PB4 //pin 3 //OUTPUT
SoftwareSerial TinySerial(SERIAL_RX, SERIAL_TX); // RX, TX
//#define THN132N
const byte TX_PIN = 0;
const unsigned long TIME = 512;
const unsigned long TWOTIME = TIME*2;
#define SEND_HIGH() digitalWrite(TX_PIN, HIGH)
#define SEND_LOW() digitalWrite(TX_PIN, LOW)
// Buffer for Oregon message
#ifdef THN132N
byte OregonMessageBuffer[8];
#else
byte OregonMessageBuffer[9];
#endif
/**
* \brief Send logical "0" over RF
* \details azero bit be represented by an off-to-on transition
* \ of the RF signal at the middle of a clock period.
* \ Remenber, the Oregon v2.1 protocol add an inverted bit first
*/
inline void sendZero(void)
{
SEND_HIGH();
delayMicroseconds(TIME);
SEND_LOW();
delayMicroseconds(TWOTIME);
SEND_HIGH();
delayMicroseconds(TIME);
}
/**
* \brief Send logical "1" over RF
* \details a one bit be represented by an on-to-off transition
* \ of the RF signal at the middle of a clock period.
* \ Remenber, the Oregon v2.1 protocol add an inverted bit first
*/
inline void sendOne(void)
{
SEND_LOW();
delayMicroseconds(TIME);
SEND_HIGH();
delayMicroseconds(TWOTIME);
SEND_LOW();
delayMicroseconds(TIME);
}
/**
* Send a bits quarter (4 bits = MSB from 8 bits value) over RF
*
* @param data Source data to process and sent
*/
/**
* \brief Send a bits quarter (4 bits = MSB from 8 bits value) over RF
* \param data Data to send
*/
inline void sendQuarterMSB(const byte data)
{
(bitRead(data, 4)) ? sendOne() : sendZero();
(bitRead(data, 5)) ? sendOne() : sendZero();
(bitRead(data, 6)) ? sendOne() : sendZero();
(bitRead(data, 7)) ? sendOne() : sendZero();
}
/**
* \brief Send a bits quarter (4 bits = LSB from 8 bits value) over RF
* \param data Data to send
*/
inline void sendQuarterLSB(const byte data)
{
(bitRead(data, 0)) ? sendOne() : sendZero();
(bitRead(data, 1)) ? sendOne() : sendZero();
(bitRead(data, 2)) ? sendOne() : sendZero();
(bitRead(data, 3)) ? sendOne() : sendZero();
}
/******************************************************************/
/******************************************************************/
/******************************************************************/
/**
* \brief Send a buffer over RF
* \param data Data to send
* \param size size of data to send
*/
void sendData(byte *data, byte size)
{
for(byte i = 0; i < size; ++i)
{
sendQuarterLSB(data[i]);
sendQuarterMSB(data[i]);
}
}
/**
* \brief Send an Oregon message
* \param data The Oregon message
*/
void sendOregon(byte *data, byte size)
{
sendPreamble();
//sendSync();
sendData(data, size);
sendPostamble();
}
/**
* \brief Send preamble
* \details The preamble consists of 16 "1" bits
*/
inline void sendPreamble(void)
{
byte PREAMBLE[]={0xFF,0xFF};
sendData(PREAMBLE, 2);
}
/**
* \brief Send postamble
* \details The postamble consists of 8 "0" bits
*/
inline void sendPostamble(void)
{
#ifdef THN132N
sendQuarterLSB(0x00);
#else
byte POSTAMBLE[]={0x00};
sendData(POSTAMBLE, 1);
#endif
}
/**
* \brief Send sync nibble
* \details The sync is 0xA. It is not use in this version since the sync nibble
* \ is include in the Oregon message to send.
*/
inline void sendSync(void)
{
sendQuarterLSB(0xA);
}
/******************************************************************/
/******************************************************************/
/******************************************************************/
/**
* \brief Set the sensor type
* \param data Oregon message
* \param type Sensor type
*/
inline void setType(byte *data, byte* type)
{
data[0] = type[0];
data[1] = type[1];
}
/**
* \brief Set the sensor channel
* \param data Oregon message
* \param channel Sensor channel (0x10, 0x20, 0x30)
*/
inline void setChannel(byte *data, byte channel)
{
data[2] = channel;
}
/**
* \brief Set the sensor ID
* \param data Oregon message
* \param ID Sensor unique ID
*/
inline void setId(byte *data, byte ID)
{
data[3] = ID;
}
/**
* \brief Set the sensor battery level
* \param data Oregon message
* \param level Battery level (0 = low, 1 = high)
*/
void setBatteryLevel(byte *data, byte level)
{
if(!level) data[4] = 0x0C;
else data[4] = 0x00;
}
/**
* \brief Set the sensor temperature
* \param data Oregon message
* \param temp the temperature
*/
void setTemperature(byte *data, float temp)
{
// Set temperature sign
if(temp < 0)
{
data[6] = 0x08;
temp *= -1;
}
else
{
data[6] = 0x00;
}
// Determine decimal and float part
int tempInt = (int)temp;
int td = (int)(tempInt / 10);
int tf = (int)round((float)((float)tempInt/10 - (float)td) * 10);
int tempFloat = (int)round((float)(temp - (float)tempInt) * 10);
// Set temperature decimal part
data[5] = (td << 4);
data[5] |= tf;
// Set temperature float part
data[4] |= (tempFloat << 4);
}
/**
* \brief Set the sensor humidity
* \param data Oregon message
* \param hum the humidity
*/
void setHumidity(byte* data, byte hum)
{
data[7] = (hum/10);
data[6] |= (hum - data[7]*10) << 4;
}
/**
* \brief Sum data for checksum
* \param count number of bit to sum
* \param data Oregon message
*/
int Sum(byte count, const byte* data)
{
int s = 0;
for(byte i = 0; i<count;i++)
{
s += (data[i]&0xF0) >> 4;
s += (data[i]&0xF);
}
if(int(count) != count)
s += (data[count]&0xF0) >> 4;
return s;
}
/**
* \brief Calculate checksum
* \param data Oregon message
*/
void calculateAndSetChecksum(byte* data)
{
#ifdef THN132N
int s = ((Sum(6, data) + (data[6]&0xF) - 0xa) & 0xff);
data[6] |= (s&0x0F) << 4; data[7] = (s&0xF0) >> 4;
#else
data[8] = ((Sum(8, data) - 0xa) & 0xFF);
#endif
}
/******************************************************************/
void setup()
{
setup_watchdog(9);
//pinMode(PB3, OUTPUT);
//digitalWrite(PB3,HIGH);delay(500);
//digitalWrite(PB3,LOW);delay(500);
//digitalWrite(PB3,HIGH);
pinMode(TX_PIN, OUTPUT);
pinMode(PB4, OUTPUT); //tx
TinySerial.begin(9600);
TinySerial.println("\n[Oregon V2.1 encoder]");
SEND_LOW();
#ifdef THN132N
// Create the Oregon message for a temperature only sensor (TNHN132N)
byte ID[] = {0xEA,0x4C};
#else
// Create the Oregon message for a temperature/humidity sensor (THGR2228N)
byte ID[] = {0x1A,0x2D};
#endif
setType(OregonMessageBuffer, ID);
setChannel(OregonMessageBuffer, 0x20);
setId(OregonMessageBuffer, 0xEE);
}
// set system into the sleep state
// system wakes up when wtchdog is timed out
void system_sleep() {
cbi(ADCSRA,ADEN); // switch Analog to Digitalconverter OFF
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here
sleep_enable();
sleep_mode(); // System sleeps here
sleep_disable(); // System continues execution here when watchdog timed out
sbi(ADCSRA,ADEN); // switch Analog to Digitalconverter ON
}
// 0=16ms, 1=32ms,2=64ms,3=128ms,4=250ms,5=500ms
// 6=1 sec,7=2 sec, 8=4 sec, 9= 8sec
void setup_watchdog(int ii) {
byte bb;
int ww;
if (ii > 9 ) ii=9;
bb=ii & 7;
if (ii > 7) bb|= (1<<5);
bb|= (1<<WDCE);
ww=bb;
MCUSR &= ~(1<<WDRF);
// start timed sequence
WDTCR |= (1<<WDCE) | (1<<WDE);
// set new watchdog timeout value
WDTCR = bb;
WDTCR |= _BV(WDIE);
}
// Watchdog Interrupt Service / is executed when watchdog timed out
ISR(WDT_vect) {
f_wdt=1; // set global flag
}
void loop()
{
int chk = DHT11.read(DHT11PIN);
switch (chk)
{
case DHTLIB_OK:
TinySerial.println("OK");
break;
case DHTLIB_ERROR_CHECKSUM:
TinySerial.println("Checksum error");
break;
case DHTLIB_ERROR_TIMEOUT:
TinySerial.println("Time out error");
break;
default:
TinySerial.println("Unknown error");
break;
}
TinySerial.print("Temperature : ");TinySerial.print(DHT11.temperature);TinySerial.write(176); // caractère °
TinySerial.write('C'); TinySerial.println();
TinySerial.print("Humidity : ");TinySerial.print(DHT11.humidity);
TinySerial.write('%'); TinySerial.println();
// (ie: 1wire DS18B20 for température, ...)
setBatteryLevel(OregonMessageBuffer, 0); // 0 : low, 1 : high
setTemperature(OregonMessageBuffer, DHT11.temperature);
#ifndef THN132N
// Set Humidity
setHumidity(OregonMessageBuffer, DHT11.humidity);
#endif
// Calculate the checksum
calculateAndSetChecksum(OregonMessageBuffer);
// Show the Oregon Message
for (byte i = 0; i < sizeof(OregonMessageBuffer); ++i) {
//TinySerial.print(OregonMessageBuffer[i] >> 4, HEX);
//TinySerial.print(OregonMessageBuffer[i] & 0x0F, HEX);
}
// Send the Message over RF
sendOregon(OregonMessageBuffer, sizeof(OregonMessageBuffer));
// Send a "pause"
SEND_LOW();
delayMicroseconds(TWOTIME*8);
// Send a copie of the first message. The v2.1 protocol send the
// message two time
sendOregon(OregonMessageBuffer, sizeof(OregonMessageBuffer));
// Wait for 30 seconds before send a new message
SEND_LOW();
//
//9 secs * 6 = 54 secs
system_sleep();
system_sleep();
system_sleep();
system_sleep();
system_sleep();
system_sleep();
//
//delay(30000);
}
3-faire un fichier enregistrer sous mes documents/arduino/rf433_sendOOK_at85_dht11.ino
4-Dans mes documents/arduino/libraries cree un dossier dht11
5-Dans dht11 cree 2 fichier txt dht11h.txt et un dht11cpp.txt
6-Dans dht11h.txt coller le script du meme nom trouvé ici http://playground.arduino.cc/Main/DHT11Lib ou ci dessous puis enregistrer et le renommer en dht11.h
Code : Tout sélectionner
//
// FILE: dht11.h
// VERSION: 0.4.1
// PURPOSE: DHT11 Temperature & Humidity Sensor library for Arduino
// LICENSE: GPL v3 (http://www.gnu.org/licenses/gpl.html)
//
// DATASHEET: http://www.micro4you.com/files/sensor/DHT11.pdf
//
// URL: http://playground.arduino.cc/Main/DHT11Lib
//
// HISTORY:
// George Hadjikyriacou - Original version
// see dht.cpp file
//
#ifndef dht11_h
#define dht11_h
#if defined(ARDUINO) && (ARDUINO >= 100)
#include <Arduino.h>
#else
#include <WProgram.h>
#endif
#define DHT11LIB_VERSION "0.4.1"
#define DHTLIB_OK 0
#define DHTLIB_ERROR_CHECKSUM -1
#define DHTLIB_ERROR_TIMEOUT -2
class dht11
{
public:
int read(int pin);
int humidity;
int temperature;
};
#endif
//
// END OF FILE
//8-Meme chose pour le cpp
Code : Tout sélectionner
//
// FILE: dht11.cpp
// VERSION: 0.4.1
// PURPOSE: DHT11 Temperature & Humidity Sensor library for Arduino
// LICENSE: GPL v3 (http://www.gnu.org/licenses/gpl.html)
//
// DATASHEET: http://www.micro4you.com/files/sensor/DHT11.pdf
//
// HISTORY:
// George Hadjikyriacou - Original version (??)
// Mod by SimKard - Version 0.2 (24/11/2010)
// Mod by Rob Tillaart - Version 0.3 (28/03/2011)
// + added comments
// + removed all non DHT11 specific code
// + added references
// Mod by Rob Tillaart - Version 0.4 (17/03/2012)
// + added 1.0 support
// Mod by Rob Tillaart - Version 0.4.1 (19/05/2012)
// + added error codes
//
#include "dht11.h"
// Return values:
// DHTLIB_OK
// DHTLIB_ERROR_CHECKSUM
// DHTLIB_ERROR_TIMEOUT
int dht11::read(int pin)
{
// BUFFER TO RECEIVE
uint8_t bits[5];
uint8_t cnt = 7;
uint8_t idx = 0;
// EMPTY BUFFER
for (int i=0; i< 5; i++) bits[i] = 0;
// REQUEST SAMPLE
pinMode(pin, OUTPUT);
digitalWrite(pin, LOW);
delay(18);
digitalWrite(pin, HIGH);
delayMicroseconds(40);
pinMode(pin, INPUT);
// ACKNOWLEDGE or TIMEOUT
unsigned int loopCnt = 10000;
while(digitalRead(pin) == LOW)
if (loopCnt-- == 0) return DHTLIB_ERROR_TIMEOUT;
loopCnt = 10000;
while(digitalRead(pin) == HIGH)
if (loopCnt-- == 0) return DHTLIB_ERROR_TIMEOUT;
// READ OUTPUT - 40 BITS => 5 BYTES or TIMEOUT
for (int i=0; i<40; i++)
{
loopCnt = 10000;
while(digitalRead(pin) == LOW)
if (loopCnt-- == 0) return DHTLIB_ERROR_TIMEOUT;
unsigned long t = micros();
loopCnt = 10000;
while(digitalRead(pin) == HIGH)
if (loopCnt-- == 0) return DHTLIB_ERROR_TIMEOUT;
if ((micros() - t) > 40) bits[idx] |= (1 << cnt);
if (cnt == 0) // next byte?
{
cnt = 7; // restart at MSB
idx++; // next byte!
}
else cnt--;
}
// WRITE TO RIGHT VARS
// as bits[1] and bits[3] are allways zero they are omitted in formulas.
humidity = bits[0];
temperature = bits[2];
uint8_t sum = bits[0] + bits[2];
if (bits[4] != sum) return DHTLIB_ERROR_CHECKSUM;
return DHTLIB_OK;
}
//
// END OF FILE
//
10-Pour que ca fonctionne j'ai eu besoin de télécharger et d'installer tiny8x pcrel patch.zip récupéréhttp://forum.arduino.cc/index.php?topic=116674.0 ou en direct http://forum.arduino.cc/index.php?actio ... tach=22984
(pour l'installation il suiffit de coller le fichier a la fin de l'arborescence (vérifier que la date de modification est bien changer))
Message d'erreur si non installé:
Code : Tout sélectionner
This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
Arduino: 1.0.6 (Windows XP), Board: "ATtiny85 (internal 8 MHz clock)"
c:/program files/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn85.o:(.init9+0x2): relocation truncated to fit: R_AVR_13_PCREL against symbol `exit' defined in .fini9 section in c:/program files/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/avr25\libgcc.a(_exit.o)
rf433_sendOOK_at85_dht11.cpp.o: In function `setHumidity(unsigned char*, unsigned char)':
C:\Program Files\Arduino/rf433_sendOOK_at85_dht11.ino:277: relocation truncated to fit: R_AVR_13_PCREL against symbol `__udivmodqi4' defined in .text.libgcc section in c:/program files/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/avr25\libgcc.a(_udivmodqi4.o)
C:\Program Files\Arduino/rf433_sendOOK_at85_dht11.ino:278: relocation truncated to fit: R_AVR_13_PCREL against symbol `__mulhi3' defined in .text.libgcc section in c:/program files/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/avr25\libgcc.a(_mulhi3.o)
rf433_sendOOK_at85_dht11.cpp.o: In function `setTemperature(unsigned char*, float)':
C:\Program Files\Arduino/rf433_sendOOK_at85_dht11.ino:256: relocation truncated to fit: R_AVR_13_PCREL against symbol `__fixsfsi' defined in .text.fplib section in c:/program files/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25\libm.a(fixsfsi.o)
C:\Program Files\Arduino/rf433_sendOOK_at85_dht11.ino:257: relocation truncated to fit: R_AVR_13_PCREL against symbol `__divmodhi4' defined in .text.libgcc section in c:/program files/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/avr25\libgcc.a(_divmodhi4.o)
C:\Program Files\Arduino/rf433_sendOOK_at85_dht11.ino:258: relocation truncated to fit: R_AVR_13_PCREL against symbol `__floatsisf' defined in .text.fplib section in c:/program files/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25\libm.a(floatsisf.o)
C:\Program Files\Arduino/rf433_sendOOK_at85_dht11.ino:258: relocation truncated to fit: R_AVR_13_PCREL against symbol `__floatsisf' defined in .text.fplib section in c:/program files/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25\libm.a(floatsisf.o)
C:\Program Files\Arduino/rf433_sendOOK_at85_dht11.ino:258: relocation truncated to fit: R_AVR_13_PCREL against symbol `__mulsf3' defined in .text.fplib section in c:/program files/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25\libm.a(mulsf3.o)
C:\Program Files\Arduino/rf433_sendOOK_at85_dht11.ino:258: relocation truncated to fit: R_AVR_13_PCREL against symbol `round' defined in .text.fplib section in c:/program files/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25\libm.a(round.o)
C:\Program Files\Arduino/rf433_sendOOK_at85_dht11.ino:260: relocation truncated to fit: R_AVR_13_PCREL against symbol `__mulsf3' defined in .text.fplib section in c:/program files/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25\libm.a(mulsf3.o)
C:\Program Files\Arduino/rf433_sendOOK_at85_dht11.ino:260: additional relocation overflows omitted from the output-télécharger le fichier de paramétrage de l'attiny http://labalec.fr/erwan/wp-content/uplo ... attiny.zip et l'installer dans Documents\Arduino\hardware (soit au final Documents\Arduino\hardware\attiny\variants...)
-et la mettre dans Documents\Arduino\ (il y aura donc dans arduino 5 dossiers + 4 fichiers)
-Démarrer le soft Arduino
-faire fichier/exemples/arduinoisp
-Ouvrir votre script "rf433_sendOOK_at85_dht11.ino"
- dans outils/programmateur faire « arduino as isp »
- dans outils\type de carte choisir « attiny85 (8mhz) »
-Faire compiler
-Puis outils/graver la séquence d'initialisation
-Apparation d'un pseudo message d'erreur
-Puis téléverser.
-Apparation d'un pseudo message d'erreur
-Fermer
-Réaliser le branchement qui va bien http://labalec.fr/erwan/?p=1534
-enjoy
__________________________________________________________________________
DTH22
1-Copier le script de traveled
Code : Tout sélectionner
/*
* connectingStuff, Oregon Scientific v2.1 Emitter
* http://connectingstuff.net/blog/encodage-protocoles-oregon-scientific-sur-arduino/
*
* Copyright (C) 2013 olivier.lebrun@gmail.com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <avr/sleep.h>
#include <avr/wdt.h>
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
volatile boolean f_wdt = 1;
#include <dht.h>
dht DHT;
#define DHT22_PIN 1
//#include <SoftwareSerial.h>
//#define SERIAL_RX PB3 //pin 2 //INPUT
//#define SERIAL_TX PB4 //pin 3 //OUTPUT
//SoftwareSerial TinySerial(SERIAL_RX, SERIAL_TX); // RX, TX
const byte TX_PIN = 0;
const unsigned long TIME = 512;
const unsigned long TWOTIME = TIME*2;
#define SEND_HIGH() digitalWrite(TX_PIN, HIGH)
#define SEND_LOW() digitalWrite(TX_PIN, LOW)
// Buffer for Oregon message
byte OregonMessageBuffer[9];
/**
* \brief Send logical "0" over RF
* \details azero bit be represented by an off-to-on transition
* \ of the RF signal at the middle of a clock period.
* \ Remenber, the Oregon v2.1 protocol add an inverted bit first
*/
inline void sendZero(void)
{
SEND_HIGH();
delayMicroseconds(TIME);
SEND_LOW();
delayMicroseconds(TWOTIME);
SEND_HIGH();
delayMicroseconds(TIME);
}
/**
* \brief Send logical "1" over RF
* \details a one bit be represented by an on-to-off transition
* \ of the RF signal at the middle of a clock period.
* \ Remenber, the Oregon v2.1 protocol add an inverted bit first
*/
inline void sendOne(void)
{
SEND_LOW();
delayMicroseconds(TIME);
SEND_HIGH();
delayMicroseconds(TWOTIME);
SEND_LOW();
delayMicroseconds(TIME);
}
/**
* Send a bits quarter (4 bits = MSB from 8 bits value) over RF
*
* @param data Source data to process and sent
*/
/**
* \brief Send a bits quarter (4 bits = MSB from 8 bits value) over RF
* \param data Data to send
*/
inline void sendQuarterMSB(const byte data)
{
(bitRead(data, 4)) ? sendOne() : sendZero();
(bitRead(data, 5)) ? sendOne() : sendZero();
(bitRead(data, 6)) ? sendOne() : sendZero();
(bitRead(data, 7)) ? sendOne() : sendZero();
}
/**
* \brief Send a bits quarter (4 bits = LSB from 8 bits value) over RF
* \param data Data to send
*/
inline void sendQuarterLSB(const byte data)
{
(bitRead(data, 0)) ? sendOne() : sendZero();
(bitRead(data, 1)) ? sendOne() : sendZero();
(bitRead(data, 2)) ? sendOne() : sendZero();
(bitRead(data, 3)) ? sendOne() : sendZero();
}
/******************************************************************/
/******************************************************************/
/******************************************************************/
/**
* \brief Send a buffer over RF
* \param data Data to send
* \param size size of data to send
*/
void sendData(byte *data, byte size)
{
for(byte i = 0; i < size; ++i)
{
sendQuarterLSB(data[i]);
sendQuarterMSB(data[i]);
}
}
/**
* \brief Send an Oregon message
* \param data The Oregon message
*/
void sendOregon(byte *data, byte size)
{
sendPreamble();
//sendSync();
sendData(data, size);
sendPostamble();
}
/**
* \brief Send preamble
* \details The preamble consists of 16 "1" bits
*/
inline void sendPreamble(void)
{
byte PREAMBLE[]={0xFF,0xFF};
sendData(PREAMBLE, 2);
}
/**
* \brief Send postamble
* \details The postamble consists of 8 "0" bits
*/
inline void sendPostamble(void)
{
byte POSTAMBLE[]={0x00};
sendData(POSTAMBLE, 1);
}
/**
* \brief Send sync nibble
* \details The sync is 0xA. It is not use in this version since the sync nibble
* \ is include in the Oregon message to send.
*/
inline void sendSync(void)
{
sendQuarterLSB(0xA);
}
/******************************************************************/
/******************************************************************/
/******************************************************************/
/**
* \brief Set the sensor type
* \param data Oregon message
* \param type Sensor type
*/
inline void setType(byte *data, byte* type)
{
data[0] = type[0];
data[1] = type[1];
}
/**
* \brief Set the sensor channel
* \param data Oregon message
* \param channel Sensor channel (0x10, 0x20, 0x30)
*/
inline void setChannel(byte *data, byte channel)
{
data[2] = channel;
}
/**
* \brief Set the sensor ID
* \param data Oregon message
* \param ID Sensor unique ID
*/
inline void setId(byte *data, byte ID)
{
data[3] = ID;
}
/**
* \brief Set the sensor battery level
* \param data Oregon message
* \param level Battery level (0 = low, 1 = high)
*/
void setBatteryLevel(byte *data, byte level)
{
if(!level) data[4] = 0x0C;
else data[4] = 0x00;
}
/**
* \brief Set the sensor temperature
* \param data Oregon message
* \param temp the temperature
*/
void setTemperature(byte *data, float temp)
{
// Set temperature sign
if(temp < 0)
{
data[6] = 0x08;
temp *= -1;
}
else
{
data[6] = 0x00;
}
// Determine decimal and float part
int tempInt = (int)temp;
int td = (int)(tempInt / 10);
int tf = (int)round((float)((float)tempInt/10 - (float)td) * 10);
int tempFloat = (int)round((float)(temp - (float)tempInt) * 10);
// Set temperature decimal part
data[5] = (td << 4);
data[5] |= tf;
// Set temperature float part
data[4] |= (tempFloat << 4);
}
/**
* \brief Set the sensor humidity
* \param data Oregon message
* \param hum the humidity
*/
void setHumidity(byte* data, byte hum)
{
data[7] = (hum/10);
data[6] |= (hum - data[7]*10) << 4;
}
/**
* \brief Sum data for checksum
* \param count number of bit to sum
* \param data Oregon message
*/
int Sum(byte count, const byte* data)
{
int s = 0;
for(byte i = 0; i<count;i++)
{
s += (data[i]&0xF0) >> 4;
s += (data[i]&0xF);
}
if(int(count) != count)
s += (data[count]&0xF0) >> 4;
return s;
}
/**
* \brief Calculate checksum
* \param data Oregon message
*/
void calculateAndSetChecksum(byte* data)
{
data[8] = ((Sum(8, data) - 0xa) & 0xFF);
}
/******************************************************************/
void setup()
{
setup_watchdog(9);
//pinMode(PB3, OUTPUT);
//digitalWrite(PB3,HIGH);delay(500);
//digitalWrite(PB3,LOW);delay(500);
//digitalWrite(PB3,HIGH);
//pinMode(TX_PIN, OUTPUT);
// pinMode(PB4, OUTPUT); //tx
// TinySerial.begin(9600);
// TinySerial.println("\n[Oregon V2.1 encoder]");
SEND_LOW();
// Create the Oregon message for a temperature/humidity sensor (THGR2228N)
byte ID[] = {0x1A,0x2D};
setType(OregonMessageBuffer, ID);
setChannel(OregonMessageBuffer, 0x20);
setId(OregonMessageBuffer, 0xBB);
}
// set system into the sleep state
// system wakes up when wtchdog is timed out
void system_sleep() {
cbi(ADCSRA,ADEN); // switch Analog to Digitalconverter OFF
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here
sleep_enable();
sleep_mode(); // System sleeps here
sleep_disable(); // System continues execution here when watchdog timed out
sbi(ADCSRA,ADEN); // switch Analog to Digitalconverter ON
}
// 0=16ms, 1=32ms,2=64ms,3=128ms,4=250ms,5=500ms
// 6=1 sec,7=2 sec, 8=4 sec, 9= 8sec
void setup_watchdog(int ii) {
byte bb;
int ww;
if (ii > 9 ) ii=9;
bb=ii & 7;
if (ii > 7) bb|= (1<<5);
bb|= (1<<WDCE);
ww=bb;
MCUSR &= ~(1<<WDRF);
// start timed sequence
WDTCR |= (1<<WDCE) | (1<<WDE);
// set new watchdog timeout value
WDTCR = bb;
WDTCR |= _BV(WDIE);
}
// Watchdog Interrupt Service / is executed when watchdog timed out
ISR(WDT_vect) {
f_wdt=1; // set global flag
}
void loop()
{
int chk = DHT.read22(DHT22_PIN);
setBatteryLevel(OregonMessageBuffer, 1); // 0 : low, 1 : high
setTemperature(OregonMessageBuffer, DHT.temperature);
setHumidity(OregonMessageBuffer, DHT.humidity);
// Calculate the checksum
calculateAndSetChecksum(OregonMessageBuffer);
// Show the Oregon Message
for (byte i = 0; i < sizeof(OregonMessageBuffer); ++i) {
}
// Send the Message over RF
sendOregon(OregonMessageBuffer, sizeof(OregonMessageBuffer));
// Send a "pause"
SEND_LOW();
delayMicroseconds(TWOTIME*8);
// Send a copie of the first message. The v2.1 protocol send the
// message two time
sendOregon(OregonMessageBuffer, sizeof(OregonMessageBuffer));
SEND_LOW();
//
//9 secs * 6 = 54 secs
system_sleep();
system_sleep();
system_sleep();
system_sleep();
system_sleep();
system_sleep();
//
//delay(30000);
}
3-faire un fichier enregistrer sous mes documents/arduino/rf433_sendOOK_at85_dht22.ino
4-Dans mes documents/arduino/libraries cree un dossier dht
5-Dans dht cree 2 fichier txt dhth.txt et un dhtcpp.txt
6-Dans dhth.txt coller le script du meme nom trouvé ici http://playground.arduino.cc/Main/DHTLib ou ci dessous puis enregistrer et le renommer en dht.h
Code : Tout sélectionner
//
// FILE: dht.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.14
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino
// URL: http://arduino.cc/playground/Main/DHTLib
//
// HISTORY:
// see dht.cpp file
//
#ifndef dht_h
#define dht_h
#if ARDUINO < 100
#include <WProgram.h>
#else
#include <Arduino.h>
#endif
#define DHT_LIB_VERSION "0.1.14"
#define DHTLIB_OK 0
#define DHTLIB_ERROR_CHECKSUM -1
#define DHTLIB_ERROR_TIMEOUT -2
#define DHTLIB_INVALID_VALUE -999
#define DHTLIB_DHT11_WAKEUP 18
#define DHTLIB_DHT_WAKEUP 1
// max timeout is 100 usec.
// For a 16 Mhz proc 100 usec is 1600 clock cycles
// loops using DHTLIB_TIMEOUT use at least 4 clock cycli
// so 100 us takes max 400 loops
// so by dividing F_CPU by 40000 we "fail" as fast as possible
#define DHTLIB_TIMEOUT (F_CPU/40000)
class dht
{
public:
// return values:
// DHTLIB_OK
// DHTLIB_ERROR_CHECKSUM
// DHTLIB_ERROR_TIMEOUT
int read11(uint8_t pin);
int read(uint8_t pin);
inline int read21(uint8_t pin) { return read(pin); };
inline int read22(uint8_t pin) { return read(pin); };
inline int read33(uint8_t pin) { return read(pin); };
inline int read44(uint8_t pin) { return read(pin); };
double humidity;
double temperature;
private:
uint8_t bits[5]; // buffer to receive data
int _readSensor(uint8_t pin, uint8_t wakeupDelay);
};
#endif
//
// END OF FILE
//
Code : Tout sélectionner
//
// FILE: dht.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.14
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino
// URL: http://arduino.cc/playground/Main/DHTLib
//
// HISTORY:
// 0.1.14 replace digital read with faster (~3x) code => more robust low MHz machines.
// 0.1.13 fix negative temperature
// 0.1.12 support DHT33 and DHT44 initial version
// 0.1.11 renamed DHTLIB_TIMEOUT
// 0.1.10 optimized faster WAKEUP + TIMEOUT
// 0.1.09 optimize size: timeout check + use of mask
// 0.1.08 added formula for timeout based upon clockspeed
// 0.1.07 added support for DHT21
// 0.1.06 minimize footprint (2012-12-27)
// 0.1.05 fixed negative temperature bug (thanks to Roseman)
// 0.1.04 improved readability of code using DHTLIB_OK in code
// 0.1.03 added error values for temp and humidity when read failed
// 0.1.02 added error codes
// 0.1.01 added support for Arduino 1.0, fixed typos (31/12/2011)
// 0.1.00 by Rob Tillaart (01/04/2011)
//
// inspired by DHT11 library
//
// Released to the public domain
//
#include "dht.h"
/////////////////////////////////////////////////////
//
// PUBLIC
//
// return values:
// DHTLIB_OK
// DHTLIB_ERROR_CHECKSUM
// DHTLIB_ERROR_TIMEOUT
int dht::read11(uint8_t pin)
{
// READ VALUES
int rv = _readSensor(pin, DHTLIB_DHT11_WAKEUP);
if (rv != DHTLIB_OK)
{
humidity = DHTLIB_INVALID_VALUE; // invalid value, or is NaN prefered?
temperature = DHTLIB_INVALID_VALUE; // invalid value
return rv;
}
// CONVERT AND STORE
humidity = bits[0]; // bits[1] == 0;
temperature = bits[2]; // bits[3] == 0;
// TEST CHECKSUM
// bits[1] && bits[3] both 0
uint8_t sum = bits[0] + bits[2];
if (bits[4] != sum) return DHTLIB_ERROR_CHECKSUM;
return DHTLIB_OK;
}
// return values:
// DHTLIB_OK
// DHTLIB_ERROR_CHECKSUM
// DHTLIB_ERROR_TIMEOUT
int dht::read(uint8_t pin)
{
// READ VALUES
int rv = _readSensor(pin, DHTLIB_DHT_WAKEUP);
if (rv != DHTLIB_OK)
{
humidity = DHTLIB_INVALID_VALUE; // invalid value, or is NaN prefered?
temperature = DHTLIB_INVALID_VALUE; // invalid value
return rv; // propagate error value
}
// CONVERT AND STORE
humidity = word(bits[0], bits[1]) * 0.1;
temperature = word(bits[2] & 0x7F, bits[3]) * 0.1;
if (bits[2] & 0x80) // negative temperature
{
temperature = -temperature;
}
// TEST CHECKSUM
uint8_t sum = bits[0] + bits[1] + bits[2] + bits[3];
if (bits[4] != sum)
{
return DHTLIB_ERROR_CHECKSUM;
}
return DHTLIB_OK;
}
/////////////////////////////////////////////////////
//
// PRIVATE
//
// return values:
// DHTLIB_OK
// DHTLIB_ERROR_TIMEOUT
int dht::_readSensor(uint8_t pin, uint8_t wakeupDelay)
{
// INIT BUFFERVAR TO RECEIVE DATA
uint8_t mask = 128;
uint8_t idx = 0;
// replace digitalRead() with Direct Port Reads.
// reduces footprint ~100 bytes => portability issue?
// direct port read is about 3x faster
uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
volatile uint8_t *PIR = portInputRegister(port);
// EMPTY BUFFER
for (uint8_t i = 0; i < 5; i++) bits[i] = 0;
// REQUEST SAMPLE
pinMode(pin, OUTPUT);
digitalWrite(pin, LOW); // T-be
delay(wakeupDelay);
digitalWrite(pin, HIGH); // T-go
delayMicroseconds(40);
pinMode(pin, INPUT);
// GET ACKNOWLEDGE or TIMEOUT
uint16_t loopCntLOW = DHTLIB_TIMEOUT;
while ((*PIR & bit) == LOW ) // T-rel
{
if (--loopCntLOW == 0) return DHTLIB_ERROR_TIMEOUT;
}
uint16_t loopCntHIGH = DHTLIB_TIMEOUT;
while ((*PIR & bit) != LOW ) // T-reh
{
if (--loopCntHIGH == 0) return DHTLIB_ERROR_TIMEOUT;
}
// READ THE OUTPUT - 40 BITS => 5 BYTES
for (uint8_t i = 40; i != 0; i--)
{
loopCntLOW = DHTLIB_TIMEOUT;
while ((*PIR & bit) == LOW )
{
if (--loopCntLOW == 0) return DHTLIB_ERROR_TIMEOUT;
}
uint32_t t = micros();
loopCntHIGH = DHTLIB_TIMEOUT;
while ((*PIR & bit) != LOW )
{
if (--loopCntHIGH == 0) return DHTLIB_ERROR_TIMEOUT;
}
if ((micros() - t) > 40)
{
bits[idx] |= mask;
}
mask >>= 1;
if (mask == 0) // next byte?
{
mask = 128;
idx++;
}
}
pinMode(pin, OUTPUT);
digitalWrite(pin, HIGH);
return DHTLIB_OK;
}
//
// END OF FILE
//
10-Pour que ca fonctionne j'ai eu besoin de télécharger et d'installer tiny8x pcrel patch.zip récupéréhttp://forum.arduino.cc/index.php?topic=116674.0 ou en direct http://forum.arduino.cc/index.php?actio ... tach=22984
(pour l'installation il suiffit de coller le fichier a la fin de l'arborescence (vérifier que la date de modification est bien changer))
Message d'erreur si non installé:
Code : Tout sélectionner
This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
Arduino: 1.0.6 (Windows XP), Board: "ATtiny85 (internal 8 MHz clock)"
c:/program files/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn85.o:(.init9+0x2): relocation truncated to fit: R_AVR_13_PCREL against symbol `exit' defined in .fini9 section in c:/program files/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/avr25\libgcc.a(_exit.o)
rf433_sendOOK_at85_dht11.cpp.o: In function `setHumidity(unsigned char*, unsigned char)':
C:\Program Files\Arduino/rf433_sendOOK_at85_dht11.ino:277: relocation truncated to fit: R_AVR_13_PCREL against symbol `__udivmodqi4' defined in .text.libgcc section in c:/program files/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/avr25\libgcc.a(_udivmodqi4.o)
C:\Program Files\Arduino/rf433_sendOOK_at85_dht11.ino:278: relocation truncated to fit: R_AVR_13_PCREL against symbol `__mulhi3' defined in .text.libgcc section in c:/program files/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/avr25\libgcc.a(_mulhi3.o)
rf433_sendOOK_at85_dht11.cpp.o: In function `setTemperature(unsigned char*, float)':
C:\Program Files\Arduino/rf433_sendOOK_at85_dht11.ino:256: relocation truncated to fit: R_AVR_13_PCREL against symbol `__fixsfsi' defined in .text.fplib section in c:/program files/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25\libm.a(fixsfsi.o)
C:\Program Files\Arduino/rf433_sendOOK_at85_dht11.ino:257: relocation truncated to fit: R_AVR_13_PCREL against symbol `__divmodhi4' defined in .text.libgcc section in c:/program files/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/avr25\libgcc.a(_divmodhi4.o)
C:\Program Files\Arduino/rf433_sendOOK_at85_dht11.ino:258: relocation truncated to fit: R_AVR_13_PCREL against symbol `__floatsisf' defined in .text.fplib section in c:/program files/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25\libm.a(floatsisf.o)
C:\Program Files\Arduino/rf433_sendOOK_at85_dht11.ino:258: relocation truncated to fit: R_AVR_13_PCREL against symbol `__floatsisf' defined in .text.fplib section in c:/program files/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25\libm.a(floatsisf.o)
C:\Program Files\Arduino/rf433_sendOOK_at85_dht11.ino:258: relocation truncated to fit: R_AVR_13_PCREL against symbol `__mulsf3' defined in .text.fplib section in c:/program files/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25\libm.a(mulsf3.o)
C:\Program Files\Arduino/rf433_sendOOK_at85_dht11.ino:258: relocation truncated to fit: R_AVR_13_PCREL against symbol `round' defined in .text.fplib section in c:/program files/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25\libm.a(round.o)
C:\Program Files\Arduino/rf433_sendOOK_at85_dht11.ino:260: relocation truncated to fit: R_AVR_13_PCREL against symbol `__mulsf3' defined in .text.fplib section in c:/program files/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25\libm.a(mulsf3.o)
C:\Program Files\Arduino/rf433_sendOOK_at85_dht11.ino:260: additional relocation overflows omitted from the output-télécharger le fichier de paramétrage de l'attiny http://labalec.fr/erwan/wp-content/uplo ... attiny.zip et l'installer dans Documents\Arduino\hardware (soit au final Documents\Arduino\hardware\attiny\variants...)
-et la mettre dans Documents\Arduino\ (il y aura donc dans arduino 5 dossiers + 4 fichiers)
-Démarrer le soft Arduino
-faire fichier/exemples/arduinoisp
-Ouvrir votre script "rf433_sendOOK_at85_dht11.ino"
- dans outils/programmateur faire « arduino as isp »
- dans outils\type de carte choisir « attiny85 (8mhz) »
-Faire compiler
-Puis outils/graver la séquence d'initialisation
-Apparation d'un pseudo message d'erreur
-Puis téléverser.
-Apparation d'un pseudo message d'erreur
-Fermer
-Réaliser le branchement qui va bien http://labalec.fr/erwan/?p=1534
-enjoy
__________________________________________________________________________
DS18B20 en dessous







