Since I couldn’t find any frequency hopping example online, I tried one on my own and it works.
For those who don’t know what is Frequency Hopping see this Frequency Hopping .It is a nice feature for secure communication.FHSS is unhackable (though it also depends on how randomly you change the frequencies )
I have tried Frequency (Channel) Hopping with the Auto Acknowledgement feature of nrf24l01 so that I can change the frequencies on both Tx and Rx devices in synchronism. Sometimes there is a loss of synchronism (possible “different” latencies of the mcus [atmega328p] ).In that case, I manually set them using Serial of Arduino IDE.
In the given example I am sending a 32-byte array of data and hopping linearly between channels 90 and 125 (back and forth with an increment of 2 ) each new array of data is Transmitted on a different channel (frequency).
Transmitter Code
void loop() /****** LOOP: RUNS CONSTANTLY ******/ { if ( myRadio1.write( &tx, sizeof(tx) )) { if (myRadio1.isAckPayloadAvailable()) { myRadio1.read(&ack, sizeof(ack)); Serial.print(" Transmitted & Ack Recevied for data: "); for (int j = 0; j < 32; j++) { Serial.print(ack[j]); Serial.print(" "); } } for (int j = 0; j < 32; j++) tx[j]++; if (flag == 0) { i += 2; } else { i -= 2; } if ((i > 124) && (flag == 0)) { flag = 1; } else if ((i < 90) && (flag == 1)) { flag = 0; } myRadio1.setChannel(i); Serial.print(" New Channel "); Serial.println(i); } if (Serial.available()) { i = Serial.parseInt(); myRadio1.setChannel(i); } }
Receiver Code
void loop() { if (myRadio2.available()) { myRadio2.read( &rx, sizeof(rx)); myRadio2.writeAckPayload(1, &rx, sizeof(rx)); Serial.print(" Data received & Ack sent for data = "); for (int j = 0; j < 32; j++) { Serial.print(rx[j]); Serial.print(" "); } if (flag == 0) { i += 2; } else { i -= 2; } if ((i > 124) && (flag == 0)) { flag = 1; } else if ((i < 90) && (flag == 1)) { flag = 0; } myRadio2.setChannel(i); Serial.print(" New Channel "); Serial.println(i); } if (Serial.available()) { i = Serial.parseInt(); myRadio2.setChannel(i); } }
The codes are still not very good. Just an example of FH with Nrf24l01+. Find the full code (not refined ..still works ) here .Github Here is the demo video : Youtube
Pingback: Ask Hackaday: Frequency Hopping on the nRF24l01+? | Hackaday
Pingback: Ask Hackaday: Frequency Hopping on the nRF24l01+?
Nice, job Paul. It’s neat and clear!
LikeLiked by 1 person
Thanks bhaiya
LikeLike
If you are interested :
https://github.com/Max-62/nRF24L01-Frequency-Hopping-FHSS
LikeLiked by 1 person
How can i change the transmitting and receiving frequencies of transceiver.?
LikeLike
The frequency can be changed by setting RF_CH register
𝐹0 = 2400 + 𝑅𝐹_𝐶𝐻
LikeLike