2011-05-26 05:22:21 +00:00
|
|
|
/*
|
2011-12-24 18:07:16 +00:00
|
|
|
Copyright (C) 2011 J. Coliz <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
|
|
|
|
//
|
|
|
|
|
2011-12-20 23:45:25 +00:00
|
|
|
// Set up nRF24L01 radio on SPI bus plus pins 9 & 10
|
2011-05-26 05:22:21 +00:00
|
|
|
|
2011-11-29 05:23:38 +00:00
|
|
|
RF24 radio(9,10);
|
2011-05-26 05:22:21 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Channel info
|
|
|
|
//
|
|
|
|
|
2011-11-29 05:23:38 +00:00
|
|
|
const uint8_t num_channels = 128;
|
|
|
|
uint8_t values[num_channels];
|
2011-05-26 05:22:21 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
//
|
|
|
|
|
2011-11-29 05:23:38 +00:00
|
|
|
const int num_reps = 100;
|
2011-05-26 05:22:21 +00:00
|
|
|
|
|
|
|
void loop(void)
|
|
|
|
{
|
2011-07-09 05:15:37 +00:00
|
|
|
// Clear measurement values
|
2011-11-29 05:23:38 +00:00
|
|
|
memset(values,0,sizeof(values));
|
2011-05-26 05:22:21 +00:00
|
|
|
|
|
|
|
// 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
|