Skip to content

RFE_IoT_SweepsAndChangeConfig example

mballesteros-RFExplorer edited this page Dec 15, 2016 · 2 revisions

This is a more advanced example of using RF Explorer 3G+ IoT, based on RFE_IoT_GetPeak example.

The main limitation of RFE_IoT_GetPeak is the selection of frequency range. In that example used default configuration and not actually selected by the Arduino sketch.

What it does

This sketch configures multiple different scan start/stop frequency ranges, iteratively displaying captured peak signal result on each one of them.

The example begins with the default configuration of the analyzer, then increases the range of Span, configured by the user, to establish the analysis.

For example at the lowest possible frequency (15MHz) and, using a 10MHz span, it does a sequence of sweeps. It then increases range to the next slot (15 + 10 = 25MHz) and continue scanning. It will continue to the maximum frequency of 2700MHz, at which time it will be reconfigured to 15MHz and run the same algorithm. It is a general spectrum analysis.

How to run it

Upload the RFE_IoT_SweepsAndChangeConfig example into the Arduino DUE and see the results in the Arduino Serial Monitor.

Expected results

As depicted below, the output on the Serial Monitor includes the following information:

  • IoT Library header and version
  • A print report indicating New Config while the module is reporting current configuration
  • A couple of print details with start/stop frequency scan range as defined by the current default settings in the RF module. The default setting is set to 1.180 - 1.220 GHz.
  • Scans on this range according to the _SWEEP constant which in this case is at 2. Therefore ensures that at least two scans will be performed on this frequency range. It analyzes the received data and shows the amplitude value of the highest frequency found.
  • A reconfigured range reusing the same default start frequency (1,180GHz) but it adds 10MHz to create nStartFreqKHZ. The Span is configured by a constant of 10Mhz so scan will be now 1,190 - 1,200GHz.
  • It performs two scans, analyzes the data received and displays the maximum value.
  • New configuration, scanning, new configuration, scanning, etc. Repeat this reconfiguration scheme until it exceeds the maximum frequency of 2700 Mhz. In this case it start at 15MHz which is the lowest frequency supported.

Detailed source code description

A couple of constant #define symbols allows different configuration of the same sketch:

  • _SPAN_KHZ: span scan in MHZ to use in the code
  • _SWEEPS: Number of sweeps for each configuration

The main difference (in code) with [the simpler example] (https://github.com/RFExplorer/RFExplorer-IoT-for-Arduino/wiki/RFE_IoT_GetPeak-example) is this new if clause where we end up changing the configuration by using the g_objRF.sendNewConfig(nStartFreqKHZ, nEndFreqKHZ) function:

        if (bChangeConfig == true)
        {
            //Get configuration from RF module and add to constant defined values
            unsigned long int nStartFreqKHZ = g_objRF.getConfiguration()->getStartKHZ() + _SPAN_KHZ;
            unsigned long int nEndFreqKHZ = nStartFreqKHZ + _SPAN_KHZ;
            if (nEndFreqKHZ > g_objRF.getConfiguration()->getMaxFreqKHZ()) 
            {
                //Frequency limit, reconfigure with minimum value of RF module
                nStartFreqKHZ = g_objRF.getConfiguration()->getMinFreqKHZ();
                nEndFreqKHZ = nStartFreqKHZ + _SPAN_KHZ;
            }
            //Send Command to change RF module configuration
            g_objRF.sendNewConfig(nStartFreqKHZ, nEndFreqKHZ);
        }

Further changes

Simple code changes will allow you to make this code work in very different and useful ways:

  • Change _SPAN_KHZ to other values in valid range to suit your needs. The wider the span, the lower the resolution but the faster will the full range will be covered.
  • Change _SWEEPS to report more or less sweep scans. You may also replace with a variable to remain scanning on a particular range for longer if no signal is detected above certain threshold, etc.
  • Change the start/stop ranges, for that the line with if (nEndFreqKHZ > g_objRF.getConfiguration()->getMaxFreqKHZ()) would change to something like if (nEndFreqKHZ > nMyValue). An example on how to scan the FM broadcast range only:
        if (nEndFreqKHZ > 108000) 
        {
               //set new start frequency in FM broadcast range
               nStartFreqKHZ = 87500;
               nEndFreqKHZ = nStartFreqKHZ + _SPAN_KHZ;
        }