j'ai un projet de faire une sonnette sans fils avec un module RFM69,
j'ai trouvé quelques codes que j'ai essayé de modifier mais sans succes.
je voudrais envoyé un mot "sonnette" et si le récepteur reçois "sonnette" l'arduino déclencherai la sonnette.
si quelqu'un a deja fait un code permettant ce genre de chose je suis preneur.
merci
#include <RFM69.h>
#include <SPI.h>
#define NETWORKID 0 // Must be the same for all nodes
#define MYNODEID 2 // My node ID
#define TONODEID 1 // Destination node ID
#define FREQUENCY RF69_868MHZ
#define ENCRYPT true // Set to "true" to use encryption
#define ENCRYPTKEY "TOPSECRETPASSWRD" // Use the same 16-byte key on all nodes
#define USEACK true // Request ACKs or not
RFM69 radio;
void setup()
{
pinMode(5, INPUT_PULLUP);
Serial.begin(9600); Serial.print("Node "); Serial.print(MYNODEID, DEC); Serial.println(" ready");
radio.initialize(FREQUENCY, MYNODEID, NETWORKID);
radio.setHighPower(); // Always use this for RFM69HCW
if (ENCRYPT)
radio.encrypt(ENCRYPTKEY);
}
void loop()
{
if(digitalRead(5) == LOW)
{
static char sendbuffer[62];
static int sendlength = 0;
radio.send(TONODEID, "azerty", 10); <==== cette ligne s'execute et apres l'arduino plante
sendlength = 0; // reset the packet
}
}
#include <string.h>
#include <RFM69.h>
#include <SPI.h>
char mot;
#define NETWORKID 0 // Must be the same for all nodes
#define MYNODEID 1 // My node ID
#define TONODEID 2 // Destination node ID
// RFM69 frequency, uncomment the frequency of your module:
//#define FREQUENCY RF69_433MHZ
#define FREQUENCY RF69_868MHZ
// AES encryption (or not):
#define ENCRYPT true // Set to "true" to use encryption
#define ENCRYPTKEY "TOPSECRETPASSWRD" // Use the same 16-byte key on all nodes
// Use ACKnowledge when sending messages (or not):
#define USEACK true // Request ACKs or not
RFM69 radio;
void setup()
{
radio.initialize(FREQUENCY, MYNODEID, NETWORKID);
radio.setHighPower(); // Always use this for RFM69HCW
if (ENCRYPT)
radio.encrypt(ENCRYPTKEY);
}
void loop()
{
char message[6];
static char sendbuffer[62];
static int sendlength = 0;
if (radio.receiveDone()) // Got one!
{
Serial.print("received from node ");
Serial.print(radio.SENDERID, DEC);
Serial.print(", message [");
for (byte i = 0; i < radio.DATALEN; i++)
{ Serial.print((char)radio.DATA[i]); message[i] = (char)radio.DATA[i];}
if(strcmp(message, "azerty"))
{digitalWrite(8, HIGH);delay(1000); digitalWrite(8, LOW); delay(200);}
//===> LE IF ne fonctionne pas dès qu'un message est recu la LED s'allume
if (radio.ACKRequested())
{
radio.sendACK();
Serial.println("ACK sent");
}
}
}
Sans être entré dans le détail du code, je dirais que la boucle "loop()" s'exécute trop vite (pas de delay()).
De plus, lorsque "digitalRead(5) == LOW", il ne faut émettre qu'une seule fois.
Il faut que tu testes la changement d'état de l'entrée. Pour cela il faut mémoriser l'état précédent et comparer par rapport à cet état précédent.
Mais pour essayer tu peux mettre un délai de qq centaines de ms