2011-05-26 05:22:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Copyright (C) 2011 James Coliz, Jr. <maniacbug@ymail.com>
|
2011-07-09 05:15:37 +00:00
|
|
|
|
2011-05-26 05:22:21 +00:00
|
|
|
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
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
|
|
|
|
//
|
|
|
|
// Hardware configuration
|
|
|
|
//
|
|
|
|
|
|
|
|
// Set up nRF24L01 radio on SPI bus plus pins 8 & 9
|
|
|
|
|
|
|
|
RF24 radio(8,9);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Channel info
|
|
|
|
//
|
|
|
|
|
|
|
|
const short num_channels = 128;
|
|
|
|
short values[num_channels];
|
|
|
|
|
|
|
|
//
|
|
|
|
// Setup
|
|
|
|
//
|
|
|
|
|
|
|
|
void setup(void)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Print preamble
|
|
|
|
//
|
2011-07-09 05:15:37 +00:00
|
|
|
|
2011-05-26 05:22:21 +00:00
|
|
|
Serial.begin(57600);
|
|
|
|
printf_begin();
|
|
|
|
printf("\n\rRF24/examples/scanner/\n\r");
|
2011-07-09 05:15:37 +00:00
|
|
|
|
2011-05-26 05:22:21 +00:00
|
|
|
//
|
|
|
|
// Setup and configure rf radio
|
|
|
|
//
|
2011-07-09 05:15:37 +00:00
|
|
|
|
2011-05-26 05:22:21 +00:00
|
|
|
radio.begin();
|
|
|
|
radio.setAutoAck(false);
|
|
|
|
|
|
|
|
// Get into standby mode
|
|
|
|
radio.startListening();
|
|
|
|
radio.stopListening();
|
|
|
|
|
2011-07-09 05:15:37 +00:00
|
|
|
// Print out header, high then low digit
|
2011-05-26 05:22:21 +00:00
|
|
|
int i = 0;
|
|
|
|
while ( i < num_channels )
|
|
|
|
{
|
|
|
|
printf("%x",i>>4);
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
printf("\n\r");
|
|
|
|
i = 0;
|
|
|
|
while ( i < num_channels )
|
|
|
|
{
|
|
|
|
printf("%x",i&0xf);
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
printf("\n\r");
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Loop
|
|
|
|
//
|
|
|
|
|
|
|
|
const short num_reps = 100;
|
|
|
|
|
|
|
|
void loop(void)
|
|
|
|
{
|
2011-07-09 05:15:37 +00:00
|
|
|
// Clear measurement values
|
2011-05-26 05:22:21 +00:00
|
|
|
memset(values,0,num_channels);
|
|
|
|
|
|
|
|
// 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() )
|
2011-07-09 05:15:37 +00:00
|
|
|
++values[i];
|
2011-05-26 05:22:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-09 05:15:37 +00:00
|
|
|
// Print out channel measurements, clamped to a single hex digit
|
2011-05-26 05:22:21 +00:00
|
|
|
int i = 0;
|
|
|
|
while ( i < num_channels )
|
|
|
|
{
|
|
|
|
printf("%x",min(0xf,values[i]&0xf));
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
printf("\n\r");
|
|
|
|
}
|
|
|
|
|
|
|
|
// vim:ai:cin:sts=2 sw=2 ft=cpp
|