Frequency Hopping with NRF24l01+

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

IMG_20170319_144328.jpg

Advertisements

4 thoughts on “Frequency Hopping with NRF24l01+

  1. Pingback: Ask Hackaday: Frequency Hopping on the nRF24l01+? | Hackaday

  2. Pingback: Ask Hackaday: Frequency Hopping on the nRF24l01+?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s