From 92b15c74f0790a89554229eae4a86e0d10578037 Mon Sep 17 00:00:00 2001 From: TMRh20 Date: Mon, 20 Jul 2020 17:21:01 -0600 Subject: [PATCH] Add CCW to scanner example - Add feature to output a CCW on a specified channel and power level to the scanner example per https://github.com/nRF24/RF24/pull/609 - Changed scanner example to use Serial prints instead of printf - Removed unneeded delays --- examples/scanner/scanner.ino | 101 ++++++++++++++++++++++------------- 1 file changed, 64 insertions(+), 37 deletions(-) diff --git a/examples/scanner/scanner.ino b/examples/scanner/scanner.ino index fec9a2791..722486304 100644 --- a/examples/scanner/scanner.ino +++ b/examples/scanner/scanner.ino @@ -1,5 +1,6 @@ /* Copyright (C) 2011 J. Coliz + 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 @@ -7,18 +8,20 @@ */ /** - * Channel scanner + * Channel scanner and Continuous Carrier Wave Output * * Example to detect interference on the various channels available. * This is a good diagnostic tool to check whether you're picking a * good channel for your application. + * + * Run this sketch on two devices. On one device, start CCW output by sending a 'g' + * character over Serial. The other device scanning should detect the output of the sending + * device on the given channel. Adjust channel and output power of CCW below. * * Inspired by cpixip. * See http://arduino.cc/forum/index.php/topic,54795.0.html */ -#include -#include "nRF24L01.h" #include "RF24.h" #include "printf.h" @@ -61,24 +64,25 @@ void setup(void) // 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 ) { - printf("%x",i>>4); + Serial.print(i>>4,HEX); ++i; } Serial.println(); i = 0; while ( i < num_channels ) { - printf("%x",i&0xf); + Serial.print(i&0xf,HEX); ++i; } Serial.println(); + //delay(1000); } // @@ -86,42 +90,65 @@ void setup(void) // const int num_reps = 100; +bool constCarrierMode = 0; void loop(void) { - // 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); + /****************************************/ + // 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(); - - // Did we get a carrier? - if ( radio.testCarrier() ){ - ++values[i]; - } + 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 ) - { - printf("%x",min(0xf,values[i])); - ++i; - } - Serial.println(); + // Print out channel measurements, clamped to a single hex digit + int i = 0; + while ( i < num_channels ) + { + Serial.print(min(0xf,values[i]),HEX); + ++i; + } + Serial.println(); + + }//If constCarrierMode == 0 } - -// vim:ai:cin:sts=2 sw=2 ft=cpp