Bonjour à tous
J'essaie de transmettre une structure entre un ESP32 et un Arduino Nano via une connexion radio nRF24. A la réception, les données sont changées!
Si je fais la même chose, mais entre 2 Arduino Nano, avec les mêmes programmes, tout fonctionne très bien?
Voici le programme de l'émetteur
Ici le programme du récepteur.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63 #include <SPI.h> #include "nRF24L01.h" #include "RF24.h" //===================================== RF24 #define rf24CePin 9 // Nano #define rf24CsnPin 10 //#define rf24CePin 16 // ESP32 Rev1 //#define rf24CsnPin 17 RF24 radioRF24(rf24CePin, rf24CsnPin); const uint64_t rf24PipeAddressTx = 0xFDB975468ACE0000LL; // Pipes addresses. const uint64_t rf24PipeAddressRx = 0xFDB975468ACE0001LL; unsigned long rf24TempoTimer = millis(); //------------------------------------- RF24 packet definition struct rf24PacketDef {int packetIndex; long packetPayloadLong; float packetPayloadFloat; char packetPayloadStr[25];}; rf24PacketDef rf24PackTx; void setup() { Serial.begin(115200); radioRF24.begin(); radioRF24.setPALevel(2); radioRF24.setChannel(112); radioRF24.setPayloadSize(sizeof(rf24PackTx)+2); radioRF24.setDataRate(RF24_250KBPS); radioRF24.openWritingPipe(rf24PipeAddressTx); // Both radios listen on the same pipes by default, and switch when writing radioRF24.openReadingPipe(1,rf24PipeAddressRx); radioRF24.startListening(); } void loop() { if (millis()-rf24TempoTimer > 1000) { rf24PackTx.packetIndex ++; Serial.println("\nSent Structure #" + String(rf24PackTx.packetIndex)); rf24PackTx.packetPayloadLong = 32768 - rf24PackTx.packetIndex; rf24PackTx.packetPayloadFloat = (float)rf24PackTx.packetIndex/3.14; String messagePLstr = "PlStr packet #" + String(rf24PackTx.packetIndex); messagePLstr.toCharArray(rf24PackTx.packetPayloadStr, sizeof(rf24PackTx.packetPayloadStr)); radioRF24.stopListening(); radioRF24.write( &rf24PackTx, sizeof(rf24PackTx) ); radioRF24.startListening(); Serial.print("Packet Index =\t"); Serial.println(rf24PackTx.packetIndex); Serial.print("Payload Long =\t"); Serial.println(rf24PackTx.packetPayloadLong); Serial.print("Payload Float =\t"); Serial.println(rf24PackTx.packetPayloadFloat); Serial.print("Payload Str =\t"); Serial.println(rf24PackTx.packetPayloadStr); rf24TempoTimer = millis(); } }
Les traces de l'émission et de la réception.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52 #include <SPI.h> #include "nRF24L01.h" #include "RF24.h" //===================================== RF24 #define rf24CePin 9 // Nano #define rf24CsnPin 10 //#define rf24CePin 16 // ESP32 Rev1 //#define rf24CsnPin 17 RF24 radioRF24(rf24CePin, rf24CsnPin); const uint64_t rf24PipeAddressTx = 0xFDB975468ACE0000LL; // Pipes addresses base. const uint64_t rf24PipeAddressRx = 0xFDB975468ACE0001LL; // Pipes addresses base. unsigned long rf24TempoTimer = millis(); //------------------------------------- RF24 packet definition struct rf24PacketDef {int packetIndex; long packetPayloadLong; float packetPayloadFloat; char packetPayloadStr[25];}; rf24PacketDef rf24PackRx; void setup() { Serial.begin(115200); radioRF24.begin(); radioRF24.setPALevel(2); radioRF24.setChannel(112); radioRF24.setPayloadSize(sizeof(rf24PackRx)+2); radioRF24.setDataRate(RF24_250KBPS); radioRF24.openWritingPipe(rf24PipeAddressRx); // Both radios listen on the same pipes by default, and switch when writing radioRF24.openReadingPipe(1,rf24PipeAddressTx); radioRF24.startListening(); // Now, continue listening } void loop() { if( radioRF24.available()) { Serial.println("\nReceives structure "); radioRF24.read( &rf24PackRx, sizeof(rf24PackRx) ); Serial.print("Packet Index =\t"); Serial.println(rf24PackRx.packetIndex); Serial.print("Payload Long =\t"); Serial.println(rf24PackRx.packetPayloadLong); Serial.print("Payload Float =\t"); Serial.println(rf24PackRx.packetPayloadFloat); Serial.print("Payload Str =\t"); Serial.println(rf24PackRx.packetPayloadStr); } }
Merci par avance de votre aide.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98 //------------------------------------- Envoyé depuis un Arduino Nano ou ESP32 Sent Structure #1 Packet Index = 1 Payload Long = 32767 Payload Float = 0.32 Payload Str = PlStr packet #1 Sent Structure #2 Packet Index = 2 Payload Long = 32766 Payload Float = 0.64 Payload Str = PlStr packet #2 Sent Structure #3 Packet Index = 3 Payload Long = 32765 Payload Float = 0.96 Payload Str = PlStr packet #3 Sent Structure #4 Packet Index = 4 Payload Long = 32764 Payload Float = 1.27 Payload Str = PlStr packet #4 Sent Structure #5 Packet Index = 5 Payload Long = 32763 Payload Float = 1.59 Payload Str = PlStr packet #5 //------------------------------------- Reçus avec un Arduino Nano à l'émission Receives structure Packet Index = 1 Payload Long = 32767 Payload Float = 0.32 Payload Str = PlStr packet #1 Receives structure Packet Index = 2 Payload Long = 32766 Payload Float = 0.64 Payload Str = PlStr packet #2 Receives structure Packet Index = 3 Payload Long = 32765 Payload Float = 0.96 Payload Str = PlStr packet #3 Receives structure Packet Index = 4 Payload Long = 32764 Payload Float = 1.27 Payload Str = PlStr packet #4 Receives structure Packet Index = 5 Payload Long = 32763 Payload Float = 1.59 Payload Str = PlStr packet #5 Receives structure Packet Index = 6 Payload Long = 32762 Payload Float = 1.91 Payload Str = PlStr packet #6 //------------------------------------- Reçus avec un ESP32 à l'émission Receives structure Packet Index = 1 Payload Long = 2147418112 Payload Float = 0.00 Payload Str = ?>PlStr packet #1 Receives structure Packet Index = 2 Payload Long = 2147352576 Payload Float = 0.00 Payload Str = #?PlStr packet #2 Receives structure Packet Index = 3 Payload Long = 2147287040 Payload Float = -0.00 Payload Str = t?PlStr packet #3 Receives structure Packet Index = 4 Payload Long = 2147221504 Payload Float = 0.00 Payload Str = ??PlStr packet #4 Receives structure Packet Index = 5 Payload Long = 2147155968 Payload Float = ovf Payload Str = ??PlStr packet #5
Cordialement
jpbbricole
Partager