Skip to content

Commit

Permalink
Add CCW to scanner example
Browse files Browse the repository at this point in the history
- Add feature to output a CCW on a specified channel and power level to the scanner example per #609
- Changed scanner example to use Serial prints instead of printf
- Removed unneeded delays
  • Loading branch information
TMRh20 committed Jul 20, 2020
1 parent 0eada50 commit 92b15c7
Showing 1 changed file with 64 additions and 37 deletions.
101 changes: 64 additions & 37 deletions examples/scanner/scanner.ino
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
/*
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.
*/

/**
* 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 <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"

Expand Down Expand Up @@ -61,67 +64,91 @@ 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);
}

//
// Loop
//

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

0 comments on commit 92b15c7

Please sign in to comment.