nrf_to_nrf - NRF52 Radio Driver v1.2.2
TMRh20 2023 - OSI Layer 2 radio driver using RF24 API
Loading...
Searching...
No Matches
examples/RF24/scanner/scanner.ino
/*
* Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
* Updated 2020 TMRh20
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*/
#include "nrf_to_nrf.h"
//
// Hardware configuration
//
// Set up nRF24L01 radio on SPI bus plus pins 7 & 8
nrf_to_nrf radio;
//
// Channel info
//
const uint8_t num_channels = 100;
uint8_t values[num_channels];
//
// Setup
//
void setup(void) {
//
// Print preamble
//
Serial.begin(115200);
Serial.println(F("\n\rRF24/examples/scanner/"));
//
// Setup and configure rf radio
//
radio.begin();
radio.setAutoAck(false);
// Get into standby mode
radio.startListening();
//radio.stopListening();
//radio.printDetails();
//delay(1000);
// Print out header, high then low digit
int i = 0;
while (i < num_channels) {
Serial.print(i >> 4, HEX);
++i;
}
Serial.println();
i = 0;
while (i < num_channels) {
Serial.print(i & 0xf, HEX);
++i;
}
Serial.println();
//delay(1000);
}
//
// Loop
//
const int num_reps = 100;
bool constCarrierMode = 0;
void loop(void) {
/****************************************/
// Send g over Serial to begin CCW output
// Configure the channel and power level below
if (Serial.available()) {
char c = Serial.read();
if (c == 'g') {
constCarrierMode = 1;
radio.stopListening();
delay(2);
Serial.println("Starting Carrier Out");
//radio.startConstCarrier(RF24_PA_LOW, 40);
} else if (c == 'e') {
constCarrierMode = 0;
//radio.stopConstCarrier();
Serial.println("Stopping Carrier Out");
}
}
/****************************************/
if (constCarrierMode == 0) {
// Clear measurement values
memset(values, 0, sizeof(values));
// Scan all channels num_reps times
int rep_counter = num_reps;
while (rep_counter--) {
int i = num_channels;
while (i--) {
// Select this channel
radio.setChannel(i);
// Listen for a little
radio.startListening();
delayMicroseconds(128);
//radio.stopListening();
// Did we get a carrier?
if (radio.testCarrier()) {
++values[i];
}
}
}
// Print out channel measurements, clamped to a single hex digit
int i = 0;
while (i < num_channels) {
if (values[i])
Serial.print(min(0xf, values[i]), HEX);
else
Serial.print(F("-"));
++i;
}
Serial.println();
} //If constCarrierMode == 0
}
Driver class for nRF52840 2.4GHz Wireless Transceiver.
Definition nrf_to_nrf.h:115
void startListening(bool resetAddresses=true)
bool testCarrier(uint8_t RSSI=65)
void setChannel(uint8_t channel)
bool begin()
void setAutoAck(bool enable)
void stopListening(bool setWritingPipe=true, bool resetAddresses=true)