123-Récepteur tout ou rien
Récepteur tout ou rien
Le principe de ce récepteur est de recevoir une commande et de renvoyer son état. Il permettra de commander l'allumage d'une LED. Par la suite on pourra envisager la commande d'un relais. Les commandes sont envoyées par le RPI. Voir article sur ma domotique.
Montage:
Programme:
/*
This is an attiny85 example code for the nRF24L01 that can communicate with RF24 library
All the support files and libraries for the attiny85 for nRF24L01 is at repo listed below
* repo : https://github.com/stanleyseow/attiny-nRF24L01
* Author : Stanley Seow
* e-mail : stanleyseow@gmail.com
* date : 11th Apr 2013
Some default values to take note when using this mirf85/spi85 library
- changed the default of CRC8 to CRC16 ( mirf85.h )
- added rf_setup to Nrf24l::config ( mirf85.cpp / mirf85.h )
- added some defines for Dynamic Payload in the header files ( nRF24L0185.h )
- 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 <avr/io.h>
#include <inttypes.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <SPI85.h>
#include <Mirf85.h>
#include <nRF24L0185.h>
#include <MirfHardwareSpiDriver85.h>
char buffer[32] = ""; //Reception
int led = 10;
int compteur = 0;
int etat=0;
#define CE 8 //ATTiny
#define CSN 7 //ATTiny
void setup(){
pinMode(led, OUTPUT);
Mirf.cePin = CE;
Mirf.csnPin = CSN;
Mirf.spi = &MirfHardwareSpi;
Mirf.init();
// 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[] = {0xe4, 0xf0, 0xf0, 0xf0, 0xf0};
byte TADDR[] = {0xe3, 0xf0, 0xf0, 0xf0, 0xf0};
Mirf.channel = 120; // Same as rpi-hub and sendto_hub canal 0
Mirf.rfsetup = 0x27; // 1Mbps, Max power
Mirf.setRADDR(RADDR);
Mirf.setTADDR(TADDR);
Mirf.payload = 32;
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] = ""; //Reception
Mirf.powerUpRx();
if (Mirf.dataReady()){
Mirf.getData((byte *) &buffer);
if (strcmp(buffer,"*ID70*ON")==0){
digitalWrite(led, HIGH);
etat=1;
delay(50);
envoi("#ID70#ON");
}
if (strcmp(buffer,"*ID70*OFF")==0){
digitalWrite(led, LOW);
etat=0;
delay(50);
envoi("#ID70#OFF");
}
}
delay(1000);
compteur ++;
if (compteur>60){
if (etat==0){
envoi("#ID70#OFF");
}
else {
envoi("#ID70#ON");
}
compteur=0;
}
} // End loop()
// Fonction envoie caractères
void envoi( char *text){
uint8_t sent = false;
Mirf.send((byte *) text);
while( Mirf.isSending() )
{
delay(10);
sent = true; // Sent success
}
}
Téléchargement du programme ici
Fonctionnement:
Il faut envoyer la commande *ID70*ON ou *ID70*OFF cela commandera la LED. Toute les 60 Sec l'état sera envoyé. #ID70#ON ou #ID70#OFF.
Mise à jour 17/03/2014
Créé avec HelpNDoc Personal Edition: Générateur gratuit de livres électroniques et documentation