|
| 1 | +/* |
| 2 | +
|
| 3 | + RF Explorer 3G+ IoT for Arduino - A Spectrum Analyzer for everyone! |
| 4 | + Copyright © 2010-17 Ariel Rocholl, www.rf-explorer.com |
| 5 | + |
| 6 | + This sketch is free software; you can redistribute it and/or |
| 7 | + modify it under the terms of the GNU Lesser General Public |
| 8 | + License as published by the Free Software Foundation; either |
| 9 | + version 3.0 of the License, or (at your option) any later version. |
| 10 | + |
| 11 | + ----------------------------------------------------------------- |
| 12 | + |
| 13 | + Example: RFE_IoT_GetPeak - Version 1.0.0 - 2016/12/01 |
| 14 | +
|
| 15 | + General Description: |
| 16 | + Simplest example with RF Explorer 3G+ IoT capturing external Signal Peak. |
| 17 | + Use the Arduino Terminal to detect results |
| 18 | + |
| 19 | + Software Description: |
| 20 | + * setup() initialize hardware and communications: |
| 21 | + * MWSUB3G module connects at 115200bps |
| 22 | + * Monitor Serial (USB debug port) remains at 57600bps |
| 23 | + * loop() continuous scan frequency range 1.180 to 1.2 GHz to detect peak signal |
| 24 | + * Everytime a new sweep scan is received, the Terminal will display frequency and power of peak signal |
| 25 | +
|
| 26 | + Circuit Description: |
| 27 | + * RF Explorer 3G+ IoT for Arduino |
| 28 | + * Arduino DUE |
| 29 | + * USB cable for programming and monitoring |
| 30 | + |
| 31 | + Support Email: contact@rf-explorer.com |
| 32 | +
|
| 33 | + See: http://www.rf-explorer.com/IoT for more information |
| 34 | +
|
| 35 | +*/ |
| 36 | + |
| 37 | +#include <RFExplorer_3GP_IoT.h> |
| 38 | + |
| 39 | +RFExplorer_3GP_IoT g_objRF; //Global 3G+ object for access to all RF Explorer IoT functionality |
| 40 | + |
| 41 | +void setup() |
| 42 | +{ |
| 43 | + digitalWrite(_RFE_GPIO2, LOW); //Set _RFE_GPIO2 as output, LOW -> Device mode to 2400bps |
| 44 | + g_objRF.resetHardware(); //Reset 3G+ board |
| 45 | + |
| 46 | + delay(5000); //Wait for 3G+ to complete initialization routines |
| 47 | + g_objRF.init(); //Initialize 3G+ library - Monitor SerialDebugger set 57600bps |
| 48 | + g_objRF.changeBaudrate(115200); //Change baudrate to 115Kbps, max reliable in Arduino DUE. |
| 49 | + delay(1000); //Wait 1sec to stablish communication |
| 50 | + digitalWrite(_RFE_GPIO2, HIGH); |
| 51 | + pinMode(_RFE_GPIO2, INPUT_PULLUP); //Set _RFE_GPIO2 as a general port, no longer needed after start completed |
| 52 | + |
| 53 | + g_objRF.requestConfig(); //Request of current configuration to 3G+ -> Device starts to send it setup and them SweepData |
| 54 | +} |
| 55 | + |
| 56 | +void loop() |
| 57 | +{ |
| 58 | + //Call to these two functions to refresh library received data. |
| 59 | + //If this function is not being called regularly, data received from 3G+ may be lost |
| 60 | + //and keep unprocessed |
| 61 | + g_objRF.updateBuffer(); |
| 62 | + unsigned short int nProcessResult = g_objRF.processReceivedString(); |
| 63 | + |
| 64 | + //If received data processing was correct, we can use it |
| 65 | + if (nProcessResult == _RFE_SUCCESS) |
| 66 | + { |
| 67 | + if ((g_objRF.getLastMessage() == _CONFIG_MESSAGE)) |
| 68 | + { |
| 69 | + //Message received is a new configuration from 3G+ |
| 70 | + //We show new Start/Stop KHZ range here from the new configuration |
| 71 | + g_objRF.getMonitorSerial().println("New Config"); |
| 72 | + g_objRF.getMonitorSerial().print("StartKHz: "); |
| 73 | + g_objRF.getMonitorSerial().println(g_objRF.getConfiguration()->getStartKHZ()); |
| 74 | + g_objRF.getMonitorSerial().print("StopKHz: "); |
| 75 | + g_objRF.getMonitorSerial().println(g_objRF.getConfiguration()->getEndKHZ()); |
| 76 | + } |
| 77 | + else if((g_objRF.getLastMessage() == _SWEEP_MESSAGE) && g_objRF.isValid()) |
| 78 | + { |
| 79 | + //Message received was actual sweep data, we can now use internal functions |
| 80 | + //to get sweep data parameters |
| 81 | + unsigned long int nFreqPeakKHZ=0; |
| 82 | + int16_t nPeakDBM=0; |
| 83 | + if (g_objRF.getPeak(&nFreqPeakKHZ, &nPeakDBM) ==_RFE_SUCCESS) |
| 84 | + { |
| 85 | + //Display frequency and amplitude of the signal peak |
| 86 | + g_objRF.getMonitorSerial().print(nFreqPeakKHZ); |
| 87 | + g_objRF.getMonitorSerial().print(" KHz to "); |
| 88 | + g_objRF.getMonitorSerial().print(nPeakDBM); |
| 89 | + g_objRF.getMonitorSerial().println(" dBm"); |
| 90 | + } |
| 91 | + } |
| 92 | + } |
| 93 | + else |
| 94 | + { |
| 95 | + //Message or Data was not received, or was wrong. Note: |
| 96 | + // _RFE_IGNORE or _RFE_NOT_MESSAGE are not errors, it just mean a new message was not available |
| 97 | + if ((nProcessResult != _RFE_IGNORE) && (nProcessResult != _RFE_NOT_MESSAGE)) |
| 98 | + { |
| 99 | + //Other error codes were received, report for information |
| 100 | + //Check library error codes for more details |
| 101 | + g_objRF.getMonitorSerial().print("Error:"); |
| 102 | + g_objRF.getMonitorSerial().println(nProcessResult); |
| 103 | + } |
| 104 | + } |
| 105 | +} |
0 commit comments