start:arduino:nrf24l01
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
start:arduino:nrf24l01 [2022/05/20 10:59] – [Utilisation du module nRF24L01+ avec l’Arduino] gerardadmin | start:arduino:nrf24l01 [2023/01/27 16:08] (Version actuelle) – modification externe 127.0.0.1 | ||
---|---|---|---|
Ligne 3: | Ligne 3: | ||
{{ : | {{ : | ||
- | {{ : | ||
{{ : | {{ : | ||
Ligne 17: | Ligne 16: | ||
{{ : | {{ : | ||
+ | [[https:// | ||
=== Utilisation du module nRF24L01+ avec l’Arduino === | === Utilisation du module nRF24L01+ avec l’Arduino === | ||
Ligne 22: | Ligne 22: | ||
[[http:// | [[http:// | ||
+ | |||
+ | |||
+ | [[https:// | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | [[start: | ||
+ | |||
+ | [[https:// | ||
=== Utilisation du module nRF24L01+ avec un ESP32 === | === Utilisation du module nRF24L01+ avec un ESP32 === | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | Branchement | ||
+ | |||
+ | *GND du nRF24L01 - GND de l' | ||
+ | *VCC du nRF24L01 - 3V3 de l' | ||
+ | *CE du nRF24L01 - D4 de l' | ||
+ | *CSN du nRF24L01 - D5 de l' | ||
+ | *SCK du nRF24L01 - D18 de l' | ||
+ | *MOSI du nRF24L01 - D23 de l' | ||
+ | *MISO du nRF24L01 - D19 de l' | ||
+ | *IRQ du nRF24L01 - Pas branché | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | == Programmes Exemple == | ||
+ | |||
+ | <code c Esp32_NRF24L01_Emmission_001.ino> | ||
+ | / | ||
+ | | ||
+ | | ||
+ | |||
+ | ********************************************************************/ | ||
+ | |||
+ | #include < | ||
+ | #include " | ||
+ | #include " | ||
+ | |||
+ | int compteur = 0; | ||
+ | |||
+ | RF24 radio(4, 5); | ||
+ | const uint64_t addresse = 0x1111111111; | ||
+ | const int taille = 32; | ||
+ | char message[taille + 1]; | ||
+ | |||
+ | void setup(void) | ||
+ | { | ||
+ | Serial.begin(115200); | ||
+ | Serial.println(" | ||
+ | radio.begin(); | ||
+ | radio.openWritingPipe(addresse); | ||
+ | } | ||
+ | |||
+ | void loop(void) | ||
+ | { | ||
+ | compteur++; | ||
+ | itoa(compteur, | ||
+ | Serial.print(" | ||
+ | Serial.println(message); | ||
+ | |||
+ | radio.write( message, taille ); // émission du message via nRF24L01 | ||
+ | |||
+ | delay(1000); | ||
+ | |||
+ | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | <code c Esp32_NRF24L01_Reception001.ino> | ||
+ | / | ||
+ | |||
+ | Sketch permettant à un ESP32 ou un ESP8266 de recevoir des messages | ||
+ | en provenance d'un autre microcontrôleur par l' | ||
+ | module nRF24L01. | ||
+ | Les messages reçus sont affichés dans le moniteur série. | ||
+ | |||
+ | *************************************************************/ | ||
+ | |||
+ | #include < | ||
+ | #include " | ||
+ | #include " | ||
+ | |||
+ | RF24 radio(4, 5); | ||
+ | |||
+ | const uint64_t adresse = 0x1111111111; | ||
+ | const int taille = 32; | ||
+ | char message[taille + 1]; | ||
+ | |||
+ | void setup(void) | ||
+ | { | ||
+ | Serial.begin(115200); | ||
+ | Serial.println(" | ||
+ | radio.begin(); | ||
+ | radio.openReadingPipe(1, | ||
+ | radio.startListening(); | ||
+ | } | ||
+ | |||
+ | void loop(void) | ||
+ | { | ||
+ | while ( radio.available() ) | ||
+ | { | ||
+ | radio.read( message, taille ); | ||
+ | Serial.print(" | ||
+ | Serial.println(message); | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | ===== Maquette | ||
+ | <code c ESP32_BP_NRF24L01_Emission002_GL.ino> | ||
+ | #include < | ||
+ | |||
+ | #include < | ||
+ | #include " | ||
+ | #include " | ||
+ | |||
+ | // | ||
+ | #define tunnel1 " | ||
+ | #define tunnel2 " | ||
+ | #define tunnel3 " | ||
+ | #define tunnel4 " | ||
+ | #define tunnel5 " | ||
+ | #define tunnel6 " | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | DFRobot_MCP23017 mcp(Wire, /*addr =*/ | ||
+ | #define Led0 mcp.eGPB0 | ||
+ | #define Led1 mcp.eGPB1 | ||
+ | #define Bp0 mcp.eGPA0 | ||
+ | #define Bp1 mcp.eGPA1 | ||
+ | |||
+ | int MemLed0 =0; | ||
+ | int MemBp0 =0; | ||
+ | int tempo0 =50; | ||
+ | |||
+ | int MemLed1 =0; | ||
+ | int MemBp1 =0; | ||
+ | int tempo1 =50; | ||
+ | |||
+ | int compteur = 0; | ||
+ | |||
+ | RF24 radio(4, 5); | ||
+ | const byte adresses[][6] = {tunnel1, tunnel2, tunnel3, tunnel4, tunnel5, tunnel6}; | ||
+ | const int taille = 32; | ||
+ | char message[taille + 1]; | ||
+ | char messageACK[taille +1]; | ||
+ | |||
+ | |||
+ | |||
+ | void DebugVar(int nb, int valBP0) { | ||
+ | Serial.print(" | ||
+ | Serial.print(" | ||
+ | Serial.print(" | ||
+ | Serial.print(" | ||
+ | Serial.print(" | ||
+ | delay(250); | ||
+ | } | ||
+ | int LectBp0() { | ||
+ | // Bouton O -- Led0 | ||
+ | |||
+ | int valeurBp0 = mcp.digitalRead(mcp.eGPA0); | ||
+ | |||
+ | | ||
+ | //Temps 0 | ||
+ | if(valeurBp0== 0 && MemBp0 == 0 && MemLed0 == 0){ | ||
+ | | ||
+ | // | ||
+ | } | ||
+ | // | ||
+ | if (valeurBp0 == 1 && MemBp0 ==0 && MemLed0 == 0) { | ||
+ | mcp.digitalWrite(mcp.eGPB0, | ||
+ | // | ||
+ | } | ||
+ | //Temps 2 | ||
+ | if (valeurBp0 == 0 && MemBp0 ==1 && MemLed0 == 1) { | ||
+ | mcp.digitalWrite(mcp.eGPB0, | ||
+ | // | ||
+ | } | ||
+ | //Temps 3 | ||
+ | if (valeurBp0 == 1 && MemBp0 ==0 && MemLed0 == 1) { | ||
+ | mcp.digitalWrite(mcp.eGPB0, | ||
+ | // | ||
+ | } | ||
+ | //Temps 4 | ||
+ | if (valeurBp0 == 0 && MemBp0 ==1 && MemLed0 == 0) { | ||
+ | mcp.digitalWrite(mcp.eGPB0, | ||
+ | // | ||
+ | } | ||
+ | delay(20); | ||
+ | return(!valeurBp0); | ||
+ | | ||
+ | } | ||
+ | |||
+ | int LectBp1(){ | ||
+ | // Bouton 1 -- Led1 | ||
+ | |||
+ | uint8_t valeurBp1 = mcp.digitalRead(mcp.eGPA1); | ||
+ | | ||
+ | | ||
+ | //Temps 0 | ||
+ | if(valeurBp1== 0 && MemBp1 == 0 && MemLed1 == 0){ | ||
+ | | ||
+ | // | ||
+ | } | ||
+ | // | ||
+ | if (valeurBp1 == 1 && MemBp1 ==0 && MemLed1 == 0) { | ||
+ | mcp.digitalWrite(mcp.eGPB1, | ||
+ | // | ||
+ | } | ||
+ | //Temps 2 | ||
+ | if (valeurBp1 == 0 && MemBp1 ==1 && MemLed1 == 1) { | ||
+ | mcp.digitalWrite(mcp.eGPB1, | ||
+ | // | ||
+ | } | ||
+ | //Temps 3 | ||
+ | if (valeurBp1 == 1 && MemBp1 ==0 && MemLed1 == 1) { | ||
+ | mcp.digitalWrite(mcp.eGPB1, | ||
+ | // | ||
+ | } | ||
+ | //Temps 4 | ||
+ | if (valeurBp1 == 0 && MemBp1 ==1 && MemLed1 == 0) { | ||
+ | mcp.digitalWrite(mcp.eGPB1, | ||
+ | // | ||
+ | } | ||
+ | return(valeurBp1); | ||
+ | } | ||
+ | |||
+ | void setup() { | ||
+ | Serial.begin(115200); | ||
+ | |||
+ | | ||
+ | Serial.println(" | ||
+ | radio.begin(); | ||
+ | radio.setChannel(125); | ||
+ | radio.setPALevel(RF24_PA_MIN); | ||
+ | radio.setDataRate(RF24_250KBPS); | ||
+ | radio.openWritingPipe(adresses[0]); | ||
+ | // | ||
+ | radio.openReadingPipe(1, | ||
+ | radio.openReadingPipe(2, | ||
+ | radio.openReadingPipe(3, | ||
+ | radio.openReadingPipe(4, | ||
+ | radio.openReadingPipe(5, | ||
+ | |||
+ | | ||
+ | |||
+ | | ||
+ | | ||
+ | | ||
+ | while(mcp.begin() != 0){ | ||
+ | Serial.println(" | ||
+ | delay(1000); | ||
+ | } | ||
+ | | ||
+ | mcp.pinMode(Bp0, | ||
+ | mcp.pinMode(Bp1, | ||
+ | mcp.pinMode(mcp.eGPB0, | ||
+ | mcp.pinMode(Led0, | ||
+ | mcp.digitalWrite(mcp.eGPB0, | ||
+ | mcp.digitalWrite(Led1, | ||
+ | | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | |||
+ | |||
+ | //Lecture Boutons poussoir | ||
+ | LectBp0(); | ||
+ | // | ||
+ | // | ||
+ | |||
+ | |||
+ | compteur | ||
+ | // | ||
+ | // | ||
+ | // envoie message | ||
+ | if (compteur == 1 ){ | ||
+ | radio.stopListening(); | ||
+ | itoa(compteur, | ||
+ | Serial.print(" | ||
+ | Serial.println(message);// | ||
+ | radio.write( message, taille ); // émission du message via nRF24L01 | ||
+ | delay(200); | ||
+ | compteur = 0; | ||
+ | } | ||
+ | |||
+ | radio.startListening(); | ||
+ | if(radio.available()){ | ||
+ | | ||
+ | while ( radio.available() ) | ||
+ | { | ||
+ | radio.read( messageACK, taille ); | ||
+ | Serial.print(" | ||
+ | Serial.println(messageACK); | ||
+ | } | ||
+ | delay(20); | ||
+ | } | ||
+ | | ||
+ | |||
+ | |||
+ | } | ||
+ | </ | ||
+ | |||
+ | <code c ESP32_BP_NRF24L01_Reception002_GL.ino> | ||
+ | #include < | ||
+ | |||
+ | #include < | ||
+ | #include " | ||
+ | #include " | ||
+ | |||
+ | |||
+ | |||
+ | DFRobot_MCP23017 mcp(Wire, /*addr =*/ | ||
+ | #define Led0 mcp.eGPB0 | ||
+ | #define Led1 mcp.eGPB1 | ||
+ | #define Bp0 mcp.eGPA0 | ||
+ | #define Bp1 mcp.eGPA1 | ||
+ | |||
+ | int MemLed0 =0; | ||
+ | int MemBp0 =0; | ||
+ | int tempo0 =50; | ||
+ | int MMentier = 0; | ||
+ | |||
+ | int MemLed1 =0; | ||
+ | int MemBp1 =0; | ||
+ | int tempo1 =50; | ||
+ | |||
+ | int compteur = 0; | ||
+ | |||
+ | |||
+ | // | ||
+ | #define tunnel1 " | ||
+ | #define tunnel2 " | ||
+ | #define tunnel3 " | ||
+ | #define tunnel4 " | ||
+ | #define tunnel5 " | ||
+ | #define tunnel6 " | ||
+ | |||
+ | RF24 radio(4, 5); | ||
+ | const byte adresses[][6] = {tunnel1, tunnel2, tunnel3, tunnel4, tunnel5, tunnel6}; | ||
+ | const int taille = 32; | ||
+ | char message[taille + 1]; | ||
+ | char messageACK[taille +1]; | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | int LectBp0(int ValMessage) { | ||
+ | // Bouton O -- Led0 | ||
+ | |||
+ | //int valeurBp0 = mcp.digitalRead(mcp.eGPA0); | ||
+ | int valeurBp0 = ValMessage; | ||
+ | |||
+ | | ||
+ | //Temps 0 | ||
+ | if(valeurBp0== 0 && MemBp0 == 0 && MemLed0 == 0){ | ||
+ | | ||
+ | // | ||
+ | } | ||
+ | // | ||
+ | if (valeurBp0 == 1 && MemBp0 ==0 && MemLed0 == 0) { | ||
+ | mcp.digitalWrite(mcp.eGPB0, | ||
+ | // | ||
+ | } | ||
+ | //Temps 2 | ||
+ | if (valeurBp0 == 0 && MemBp0 ==1 && MemLed0 == 1) { | ||
+ | mcp.digitalWrite(mcp.eGPB0, | ||
+ | // | ||
+ | } | ||
+ | //Temps 3 | ||
+ | if (valeurBp0 == 1 && MemBp0 ==0 && MemLed0 == 1) { | ||
+ | mcp.digitalWrite(mcp.eGPB0, | ||
+ | // | ||
+ | } | ||
+ | //Temps 4 | ||
+ | if (valeurBp0 == 0 && MemBp0 ==1 && MemLed0 == 0) { | ||
+ | mcp.digitalWrite(mcp.eGPB0, | ||
+ | // | ||
+ | } | ||
+ | |||
+ | return(valeurBp0); | ||
+ | | ||
+ | } | ||
+ | |||
+ | int LectBp1(){ | ||
+ | // Bouton 1 -- Led1 | ||
+ | |||
+ | uint8_t valeurBp1 = mcp.digitalRead(mcp.eGPA1); | ||
+ | //uint8_t valeurBp1 = ); | ||
+ | | ||
+ | //Temps 0 | ||
+ | if(valeurBp1== 0 && MemBp1 == 0 && MemLed1 == 0){ | ||
+ | | ||
+ | // | ||
+ | } | ||
+ | // | ||
+ | if (valeurBp1 == 1 && MemBp1 ==0 && MemLed1 == 0) { | ||
+ | mcp.digitalWrite(mcp.eGPB1, | ||
+ | // | ||
+ | } | ||
+ | //Temps 2 | ||
+ | if (valeurBp1 == 0 && MemBp1 ==1 && MemLed1 == 1) { | ||
+ | mcp.digitalWrite(mcp.eGPB1, | ||
+ | // | ||
+ | } | ||
+ | //Temps 3 | ||
+ | if (valeurBp1 == 1 && MemBp1 ==0 && MemLed1 == 1) { | ||
+ | mcp.digitalWrite(mcp.eGPB1, | ||
+ | // | ||
+ | } | ||
+ | //Temps 4 | ||
+ | if (valeurBp1 == 0 && MemBp1 ==1 && MemLed1 == 0) { | ||
+ | mcp.digitalWrite(mcp.eGPB1, | ||
+ | // | ||
+ | } | ||
+ | return(valeurBp1); | ||
+ | } | ||
+ | |||
+ | |||
+ | void envoiemessage1(){ | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | |||
+ | void envoiemessage2(){ | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | void setup() { | ||
+ | Serial.begin(115200); | ||
+ | |||
+ | | ||
+ | Serial.println(" | ||
+ | radio.begin(); | ||
+ | radio.setChannel(125); | ||
+ | radio.setPALevel(RF24_PA_MIN); | ||
+ | radio.setDataRate(RF24_250KBPS); | ||
+ | radio.openWritingPipe(adresses[0]); | ||
+ | radio.openReadingPipe(1, | ||
+ | radio.openReadingPipe(2, | ||
+ | radio.openReadingPipe(3, | ||
+ | radio.openReadingPipe(4, | ||
+ | radio.openReadingPipe(5, | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | while(mcp.begin() != 0){ | ||
+ | Serial.println(" | ||
+ | delay(1000); | ||
+ | } | ||
+ | | ||
+ | mcp.pinMode(Bp0, | ||
+ | mcp.pinMode(Bp1, | ||
+ | mcp.pinMode(mcp.eGPB0, | ||
+ | mcp.pinMode(Led0, | ||
+ | mcp.digitalWrite(mcp.eGPB0, | ||
+ | mcp.digitalWrite(Led1, | ||
+ | | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | | ||
+ | //Reception Message | ||
+ | radio.startListening(); | ||
+ | if (radio.available()){ | ||
+ | while ( radio.available() ) | ||
+ | { | ||
+ | radio.read( message, taille ); | ||
+ | Serial.print(" | ||
+ | Serial.println(message); | ||
+ | } | ||
+ | delay(20); | ||
+ | } | ||
+ | delay(5); | ||
+ | |||
+ | int Mentier = atoi(message); | ||
+ | |||
+ | if ( Mentier == 0 && MMentier == 0 ) { | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | if ( Mentier == 1 && MMentier == 0 ) { | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | if ( Mentier == 1 && MMentier == 1 ) { | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | </ | ||
=== L' | === L' |
/home/chanteri/www/fablab37110/data/attic/start/arduino/nrf24l01.1653037167.txt.gz · Dernière modification : 2023/01/27 16:08 (modification externe)