### Initialize HamShield Radio Object Source: https://github.com/enhancedradiodevices/hamshield/wiki/HamShield-Quick-Start-Guide Include the required library and instantiate the radio object globally before setup and loop functions. ```cpp /* My Awesome New HAM Radio Idea */ #include HamShield radio; ``` -------------------------------- ### Control HamShield Frequency Source: https://context7.com/enhancedradiodevices/hamshield/llms.txt Demonstrates setting and getting the operating frequency in kilohertz using both integer and float values. Includes functions for setting preset channels (GMRS, FRS, MURS, WX) and scanning for active weather channels. Also shows how to enable/disable frequency restrictions. ```cpp #include HamShield radio; void setup() { radio.initialize(); // Set frequency in kHz (432.100 MHz = 432100 kHz) radio.frequency(432100); // 70cm calling frequency // Alternative for float frequencies radio.frequency_float(446.000); // FRS channel 1 // Get current frequency uint32_t freq_khz = radio.getFrequency(); float freq_float = radio.getFrequency_float(); Serial.print("Current frequency: "); Serial.print(freq_khz); Serial.println(" kHz"); // Preset channel functions radio.setGMRSChannel(1); // GMRS channel 1-8 radio.setFRSChannel(1); // FRS channel 1-14 radio.setMURSChannel(1); // MURS channel 1-5 radio.setWXChannel(1); // NOAA Weather channel 1-7 // Scan for active weather channel uint8_t active_wx = radio.scanWXChannel(); if (active_wx > 0) { Serial.print("Active weather channel: "); Serial.println(active_wx); } // Disable frequency restrictions (requires license!) radio.dangerMode(); // Allows any frequency in band radio.safeMode(); // Re-enable restrictions } ``` -------------------------------- ### Get Current TX Audio Source Source: https://github.com/enhancedradiodevices/hamshield/wiki/HamShield-Library-Reference Retrieves the current audio source selection for transmission, returned as a uint16_t. ```cpp radio.getTxSource(); ``` -------------------------------- ### Get Current Channel Mode Source: https://github.com/enhancedradiodevices/hamshield/wiki/HamShield-Library-Reference Retrieves the current channel mode setting, returned as a uint16_t. ```cpp radio.getChanMode(); ``` -------------------------------- ### Get Current Radio Frequency Source: https://github.com/enhancedradiodevices/hamshield/wiki/HamShield-Library-Reference Retrieves the current tuned frequency of the radio, returned as an unsigned 32-bit integer in KHz. ```cpp radio.getFrequency() ``` -------------------------------- ### Initialization and Connection Source: https://github.com/enhancedradiodevices/hamshield/wiki/HamShield-Library-Reference Methods for initializing the radio object and verifying hardware connectivity. ```APIDOC ## HamShield radio() ### Description Creates the HamShield radio object. Must be called outside of loop() and setup(). ## HamShield radio(ncs_pin, clk_pin, dat_pin, mic_pin) ### Description Creates the HamShield radio object with custom pin assignments. ## radio.initalize() ### Description Performs basic initialization steps and sets the radio to default configuration (446.000MHz, 100% Volume, Receive Mode, Squelch On). ## radio.testConnection() ### Description Tests the connection to the radio and returns when detected. ``` -------------------------------- ### Initialize HamShield Radio Source: https://context7.com/enhancedradiodevices/hamshield/llms.txt Includes necessary headers, defines pins, creates a HamShield object, and initializes the radio transceiver with default settings. Verifies connection and prints status. ```cpp #include #define MIC_PIN 3 #define RESET_PIN A3 #define SWITCH_PIN 2 HamShield radio; // Or with custom pins: HamShield radio(ncs_pin, clk_pin, dat_pin, mic_pin); void setup() { // Hold MIC pin low when not using PWM output to avoid TX noise pinMode(MIC_PIN, OUTPUT); digitalWrite(MIC_PIN, LOW); // Set up reset control pin (no effect on HamShieldMini) pinMode(RESET_PIN, OUTPUT); digitalWrite(RESET_PIN, HIGH); delay(5); // Wait for device to come up Serial.begin(9600); // Verify connection to radio Serial.print("Radio status: "); int result = radio.testConnection(); Serial.println(result ? "Connected" : "Failed"); // Initialize radio (defaults to 12.5kHz narrowband) radio.initialize(); // Narrowband (12.5kHz) // radio.initialize(false); // Wideband (25kHz) Serial.println("Radio initialized successfully"); } ``` -------------------------------- ### Configure Audio Filters for HamShield Source: https://context7.com/enhancedradiodevices/hamshield/llms.txt Sets up pre-emphasis, de-emphasis, voice high-pass/low-pass filters, VOX filters, and FM deviation settings. ```cpp #include HamShield radio; void setup() { radio.initialize(); radio.frequency(432100); // Pre-emphasis and de-emphasis filters radio.usePreDeEmph(); // Enable pre/de-emphasis (default) // radio.bypassPreDeEmph(); // Bypass for flat audio bool predeemph = radio.getPreDeEmphEnabled(); Serial.print("Pre/De-emphasis: "); Serial.println(predeemph ? "Enabled" : "Bypassed"); // Voice high-pass filter (removes low frequency rumble) radio.useVoiceHpf(); // Enable voice HPF // radio.bypassVoiceHpf(); // Bypass voice HPF // Voice low-pass filter (removes high frequency noise) radio.useVoiceLpf(); // Enable voice LPF // radio.bypassVoiceLpf(); // Bypass voice LPF // VOX filters radio.useVoxHpf(); // Enable VOX HPF radio.useVoxLpf(); // Enable VOX LPF // FM deviation settings radio.setFMVoiceCssDeviation(0x1C); // Voice + CTCSS deviation radio.setFMCssDeviation(0x1E); // CTCSS only deviation radio.setModeReceive(); } ``` -------------------------------- ### Initialize HamShield with Non-Standard Pins Source: https://github.com/enhancedradiodevices/hamshield/wiki/HamShield-Library-Reference Allows the use of non-standard pins for the HamShield by passing the pin numbers during object creation. Ensure these pins are correctly defined. ```cpp HamShield radio(ncs_pin, clk_pin, dat_pin, mic_pin); ``` -------------------------------- ### Initialize HamShield Radio IC Source: https://github.com/enhancedradiodevices/hamshield/wiki/HamShield-Library-Reference Performs basic initialization steps on the HamShield, including required radio IC commands and setting the radio to its default configuration. ```cpp radio.initalize(); ``` -------------------------------- ### Implement Serial Command Interface for HamShield Source: https://context7.com/enhancedradiodevices/hamshield/llms.txt Provides a command-based interface to control frequency, power, squelch, and Morse code transmission via Serial input. ```cpp #include HamShield radio; long freq = 432100; int pwr = 0; bool repeater = false; long tx_freq = 0; void setup() { Serial.begin(9600); radio.initialize(); radio.frequency(freq); radio.setVolume1(0xF); radio.setVolume2(0xF); radio.setModeReceive(); radio.setTxSourceMic(); radio.setRfPower(pwr); radio.setSQLoThresh(-80); radio.setSQHiThresh(-70); radio.setSQOn(); Serial.println("*START;"); } void loop() { if (Serial.available()) { char cmd = Serial.read(); switch (cmd) { case ' ': // Transmit while space received if (repeater && tx_freq != 0) { radio.frequency(tx_freq); } radio.setModeTransmit(); Serial.println("#TX,ON;"); break; case '?': // Query RSSI Serial.print(":"); Serial.print(radio.readRSSI()); Serial.println(";"); break; case 'F': // Set frequency: F432100; freq = Serial.parseInt(); if (radio.frequency(freq)) { Serial.println("!;"); } else { Serial.println("X1;"); } break; case 'P': // Set power: P8; pwr = Serial.parseInt(); radio.setRfPower(pwr); Serial.println("!;"); break; case 'S': // Set squelch: S-80; int sq = Serial.parseInt(); radio.setSQLoThresh(sq); radio.setSQHiThresh(sq + 2); Serial.println("!;"); break; case 'M': // Morse out: MCQCQ; { char buf[32]; int i = 0; while (Serial.available() && i < 31) { char c = Serial.read(); if (c == ';') break; buf[i++] = c; } buf[i] = '\0'; radio.setModeTransmit(); delay(300); radio.morseOut(buf); radio.setModeReceive(); Serial.println("!;"); } break; default: // Return to receive if not transmitting radio.setModeReceive(); if (repeater) radio.frequency(freq); Serial.println("#TX,OFF;"); break; } } } ``` -------------------------------- ### Implement Frequency and Channel Scanning Source: https://context7.com/enhancedradiodevices/hamshield/llms.txt Provides methods for scanning frequency ranges, checking specific preset channels, and identifying clear frequencies for transmission. ```cpp #include HamShield radio; void setup() { radio.initialize(); radio.setModeReceive(); Serial.println("Scanner ready"); } void loop() { // Scan frequency range // Parameters: start_freq, stop_freq, speed, step, threshold uint32_t found = radio.scanMode( 430000, // Start frequency (kHz) 440000, // Stop frequency (kHz) 10, // Dwell time per step 25, // Step size (kHz) -100 // RSSI threshold (dBm) ); if (found > 0) { Serial.print("Signal found at: "); Serial.print(found); Serial.println(" kHz"); // Stay on frequency while signal present radio.frequency(found); while (radio.readRSSI() > -100) { delay(100); } } } void scanPresetChannels() { // Define channel list uint32_t channels[] = {446000, 446500, 462562, 462587, 462612}; uint8_t num_channels = 5; // Scan channel array // Returns first channel with signal above threshold uint32_t active = radio.scanChannels(channels, num_channels, 10, -90); if (active > 0) { Serial.print("Active channel: "); Serial.println(active); } } void findWhitespace() { // Find clear frequency for transmission uint32_t clear_freq = radio.findWhitespace( 432000, // Start frequency 434000, // Stop frequency 20, // Dwell time 25, // Step size -110 // Threshold (must be below this) ); if (clear_freq > 0) { Serial.print("Clear frequency: "); Serial.println(clear_freq); } } ``` -------------------------------- ### Monitor Channel Activity with waitForChannel Source: https://github.com/enhancedradiodevices/hamshield/wiki/HamShield-Best-Practices-Guide Use waitForChannel to ensure the frequency is clear before transmitting. The optional arguments define the maximum wait time for a clear channel and the duration of silence required. ```cpp if(radio.waitForChannel(30000,2000)) { setModeTransmit(); // do something setModeReceive(); } ``` -------------------------------- ### Set HamShield Audio Levels Source: https://github.com/enhancedradiodevices/hamshield/wiki/HamShield-Advanced-Hacks-and-Tricks Use this method to adjust audio output to line level, preventing distortion when connecting to a computer. ```cpp .audioLineLevel() ``` -------------------------------- ### Test HamShield Connection Source: https://github.com/enhancedradiodevices/hamshield/wiki/HamShield-Library-Reference Tests the connection to the radio and waits if necessary. The function returns once the radio is detected. ```cpp radio.testConnection() ``` -------------------------------- ### Set TX Audio Source to GPIO Code Input Source: https://github.com/enhancedradiodevices/hamshield/wiki/HamShield-Library-Reference Configures the radio IC chip's audio path to receive audio from the GPIO1 code_in pin. The exact function of this input is not specified. ```cpp radio.setTXSourceCode(); ``` -------------------------------- ### Frequency and Channel Management Source: https://github.com/enhancedradiodevices/hamshield/wiki/HamShield-Library-Reference Methods for setting and retrieving radio frequency and channel bandwidth settings. ```APIDOC ## radio.frequency(frequency) ### Description Sets the radio frequency in KHz. ### Parameters #### Request Body - **frequency** (uint32_t) - Required - Valid values: 134000-174000, 200000-260000, 400000-520000 ## radio.getFrequency() ### Description Returns the current tuned frequency in KHz. ## radio.setChanMode(channel_width) ### Description Sets the channel bandwidth. ### Parameters #### Request Body - **channel_width** (string) - Required - Options: 25KHZ, 12.5KHZ ## radio.getChanMode() ### Description Returns the current channel mode as a uint16_t. ``` -------------------------------- ### HamShield API Function Definitions Source: https://github.com/enhancedradiodevices/hamshield/wiki/HamShield-Library-Reference A collection of function signatures for controlling radio features, audio processing, and hardware interfaces. ```cpp void disableCtcssCdcss(); // Ctcss_sel // 1 = ctcss_cmp/cdcss_cmp out via gpio // 0 = ctcss/cdcss sdo out vio gpio void setCtcssSel(bool cmp_nsdo); bool getCtcssSel(); // Cdcss_sel // 1 = long (24 bit) code // 0 = short(23 bit) code void setCdcssSel(bool long_nshort); bool getCdcssSel(); // Cdcss neg_det_en void enableCdcssNegDet(); void disableCdcssNegDet(); bool getCdcssNegDetEnabled(); // Cdcss pos_det_en void enableCdcssPosDet(); void disableCdcssPosDet(); bool getCdcssPosDetEnabled(); // css_det_en void enableCssDet(); void disableCssDet(); bool getCssDetEnabled(); // ctcss freq void setCtcss(float freq); void setCtcssFreq(uint16_t freq); uint16_t getCtcssFreq(); void setCtcssFreqToStandard(); // freq must be 134.4Hz for standard cdcss mode // cdcss codes void setCdcssCode(uint16_t code); uint16_t getCdcssCode(); // SQ void setSQOn(); void setSQOff(); bool getSQState(); // SQ threshold void setSQHiThresh(uint16_t sq_hi_threshold); // Sq detect high th, rssi_cmp will be 1 when rssi>th_h_sq, unit 1/8dB uint16_t getSQHiThresh(); void setSQLoThresh(uint16_t sq_lo_threshold); // Sq detect low th, rssi_cmp will be 0 when rssi th_h_vox, then vox will be 1(unit mV ) uint16_t getVoxOpenThresh(); void setVoxShutThresh(uint16_t vox_shut_thresh); // When vssi < th_l_vox && time delay meet, then vox will be 0 (unit mV ) uint16_t getVoxShutThresh(); // Tail Noise void enableTailNoiseElim(); void disableTailNoiseElim(); bool getTailNoiseElimEnabled(); // tail noise shift select // Select ctcss phase shift when use tail eliminating function when TX // 00 = 120 degree shift // 01 = 180 degree shift // 10 = 240 degree shift // 11 = reserved void setShiftSelect(uint16_t shift_sel); uint16_t getShiftSelect(); // DTMF void setDTMFC0(uint16_t freq); uint16_t getDTMFC0(); void setDTMFC1(uint16_t freq); uint16_t getDTMFC1(); void setDTMFC2(uint16_t freq); uint16_t getDTMFC2(); void setDTMFC3(uint16_t freq); uint16_t getDTMFC3(); void setDTMFC4(uint16_t freq); uint16_t getDTMFC4(); void setDTMFC5(uint16_t freq); uint16_t getDTMFC5(); void setDTMFC6(uint16_t freq); uint16_t getDTMFC6(); void setDTMFC7(uint16_t freq); uint16_t getDTMFC7(); // TX FM deviation void setFMVoiceCssDeviation(uint16_t deviation); uint16_t getFMVoiceCssDeviation(); void setFMCssDeviation(uint16_t deviation); uint16_t getFMCssDeviation(); // RX voice range void setVolume1(uint16_t volume); uint16_t getVolume1(); void setVolume2(uint16_t volume); uint16_t getVolume2(); // GPIO void setGpioMode(uint16_t gpio, uint16_t mode); void setGpioHiZ(uint16_t gpio); void setGpioFcn(uint16_t gpio); void setGpioLow(uint16_t gpio); void setGpioHi(uint16_t gpio); uint16_t getGpioMode(uint16_t gpio); // Int void enableInterrupt(uint16_t interrupt); void disableInterrupt(uint16_t interrupt); bool getInterruptEnabled(uint16_t interrupt); // ST mode void setStMode(uint16_t mode); uint16_t getStMode(); void setStFullAuto(); void setStRxAutoTxManu(); void setStFullManu(); // Pre-emphasis, De-emphasis filter void bypassPreDeEmph(); void usePreDeEmph(); bool getPreDeEmphEnabled(); // Read Only Status Registers int16_t readRSSI(); uint16_t readVSSI(); uint16_t readDTMFIndex(); // may want to split this into two (index1 and index2) uint16_t readDTMFCode(); // set output power of radio void setRfPower(uint8_t pwr); // channel helper functions bool setGMRSChannel(uint8_t channel); bool setFRSChannel(uint8_t channel); bool setMURSChannel(uint8_t channel); bool setWXChannel(uint8_t channel); uint8_t scanWXChannel(); // restrictions control void dangerMode(); void safeMode(); // utilities uint32_t scanMode(uint32_t start,uint32_t stop, uint8_t speed, uint16_t step, uint16_t threshold); uint32_t findWhitespace(uint32_t start,uint32_t stop, uint8_t dwell, uint16_t step, uint16_t threshold); uint32_t scanChannels(uint32_t buffer[],uint8_t buffsize, uint8_t speed, uint16_t threshold); uint32_t findWhitespaceChannels(uint32_t buffer[],uint8_t buffsize, uint8_t dwell, uint16_t threshold); void buttonMode(uint8_t mode); void isr_ptt(); void isr_reset(); void morseOut(char buffer[HAMSHIELD_MORSE_BUFFER_SIZE]); char morseLookup(char letter); bool waitForChannel(long timeout, long breakwindow); void SSTVVISCode(int code); void SSTVTestPattern(int code); ``` -------------------------------- ### Set TX Audio Source to Microphone/Headset Source: https://github.com/enhancedradiodevices/hamshield/wiki/HamShield-Library-Reference Configures the radio IC's audio path to use input from the Arduino or the Headset jack. ```cpp radio.setTXSourceMic(); ``` -------------------------------- ### HamShield Serial Commands Source: https://github.com/enhancedradiodevices/hamshield/wiki/HamShield-Serial-Mode A comprehensive list of serial commands to configure and control the HamShield radio. ```APIDOC ## HamShield Serial Commands ### Description Commands to control the HamShield radio via serial interface. Commands are terminated with a semicolon (;) unless otherwise noted. ### Commands - **Transmit** (Spacebar) - Transmit mode, must be received every 500ms. - **CTCSS In** (A[tone];) - Set CTCSS receive tone (0 disables). - **CTCSS Out** (B[tone];) - Set CTCSS transmit tone (0 disables). - **CTCSS Enable** (C[state];) - Enable (1) or disable (0) CTCSS. - **CDCSS Enable** (D[state];) - Enable (1) or disable (0) CDCSS. - **Bandwidth** (E[mode];) - 0 for 12.5KHz, 1 for 25KHz. - **Frequency** (F[freq];) - Set frequency in KHz. - **CDCSS In** (G[code];) - Set CDCSS input code. - **CDCSS Out** (H[code];) - Set CDCSS output code. - **Print Config** (I) - Print configuration in comma-delimited format. - **Power Level** (P[level];) - Set power level (0-15). - **Enable Offset** (R[state];) - Enable (1) or disable (0) repeater offset. - **Squelch** (S[level];) - Set squelch level. - **TX Offset** (T[freq];) - Set repeater offset transmit frequency in KHz. - **Volume** (V[level];) - Set receiver volume. - **Reset** (X) - Reset to default settings. - **Sleep** (Z) - Put radio to sleep. - **Filters** (@[state];) - Set filter bits (0: pre/de-emphasis, 1: high pass, 2: low pass). - **Vox mode** ($[state];) - 0 = off, >=1 = sensitivity. - **Mic Channel** (*[state];) - 0 = mic/arduino, 1 = internal tone generator. - **RSSI** (?) - Get receive level in -dBm. - **Tone Gen** (%[notes]) - Send single tone, dual tone, or DTMF. - **Voice Level** (^) - Get current voice level (VSSI). ``` -------------------------------- ### Configure and Use Morse Code with HamShield Source: https://context7.com/enhancedradiodevices/hamshield/llms.txt Set up Morse code parameters including tone frequency and dot duration. Transmit Morse code messages by sending text via serial input after checking channel availability. ```cpp #include #define MORSE_FREQ 600 #define MORSE_DOT 150 // Dot duration in milliseconds HamShield radio; void setup() { radio.initialize(); radio.frequency(432100); radio.setRfPower(0); // Configure morse code parameters radio.setMorseFreq(MORSE_FREQ); // Tone frequency in Hz radio.setMorseDotMillis(MORSE_DOT); // Dot duration (dash = 3x dot) // Set up morse code receiver radio.lookForTone(MORSE_FREQ); radio.setupMorseRx(); radio.setModeReceive(); Serial.println("Morse transceiver ready"); } void loop() { // Receive morse code char rx_char = radio.morseRxLoop(); if (rx_char != 0) { Serial.print(rx_char); } // Transmit morse from serial input if (Serial.available()) { transmitMorse(); } } void transmitMorse() { // Wait for clear channel before transmitting Serial.println("Checking channel..."); if (radio.waitForChannel(30000, 2000, -5)) { Serial.println("Channel clear, transmitting..."); // Build message from serial input char morse_buf[128]; int idx = 0; morse_buf[idx++] = ' '; // Leading space for PA warmup while (Serial.available() && idx < 127) { morse_buf[idx++] = Serial.read(); } morse_buf[idx] = '\0'; // Transmit radio.setModeTransmit(); radio.morseOut(morse_buf); radio.setModeReceive(); // Resume listening radio.lookForTone(MORSE_FREQ); Serial.println("Transmission complete"); } else { Serial.print("Channel busy, RSSI: "); Serial.println(radio.readRSSI()); } } ``` -------------------------------- ### Configure and Use DTMF Tones with HamShield Source: https://context7.com/enhancedradiodevices/hamshield/llms.txt Set up DTMF timing parameters and enable DTMF reception. Transmit DTMF tones by sending characters via serial input. ```cpp #include HamShield radio; void setup() { radio.initialize(); radio.frequency(432100); // Configure DTMF timing (units are 2.5ms) radio.setDTMFDetectTime(24); // Detection time: 60ms radio.setDTMFIdleTime(50); // Time between tones: 125ms radio.setDTMFTxTime(60); // Tone duration: 150ms // Enable DTMF receiver radio.enableDTMFReceive(); // Set lower volume to reduce false positives radio.setVolume1(6); radio.setVolume2(0); radio.setModeReceive(); Serial.println("DTMF receiver ready"); } void loop() { // Poll for received DTMF tones char dtmf = radio.DTMFRxLoop(); if (dtmf != 0) { Serial.print("DTMF received: "); Serial.println(dtmf); } // Transmit DTMF from serial input if (Serial.available()) { transmitDTMF(); } } void transmitDTMF() { // Get first character char c = Serial.read(); uint8_t code = radio.DTMFchar2code(c); // Configure for tone transmission radio.setDTMFCode(code); radio.setTxSourceTones(); radio.setModeTransmit(); delay(300); // Wait for TX to reach full power // Send additional characters while (Serial.available()) { // Wait for current tone to complete while (radio.getDTMFTxActive() != 1) { delay(10); } c = Serial.read(); code = radio.DTMFchar2code(c); if (code == 255) code = 0xE; // Default to * for invalid radio.setDTMFCode(code); while (radio.getDTMFTxActive() != 0) { delay(10); } } // Return to receive mode radio.setModeReceive(); radio.setTxSourceMic(); Serial.println("DTMF transmission complete"); } ``` -------------------------------- ### Manage Radio Transmit and Receive Modes Source: https://context7.com/enhancedradiodevices/hamshield/llms.txt Controls radio operating states and transmission audio sources. Requires initialization of the HamShield object and frequency setting before mode switching. ```cpp #include HamShield radio; bool currently_tx = false; void setup() { radio.initialize(); radio.frequency(432100); radio.setRfPower(0); // Set TX power level (0-15, 0=lowest) radio.setModeReceive(); currently_tx = false; } void loop() { // Read RSSI in receive mode if (!currently_tx) { int16_t rssi = radio.readRSSI(); Serial.print("RSSI: "); Serial.print(rssi); Serial.println(" dBm"); } // Check for PTT button press if (digitalRead(SWITCH_PIN) == LOW && !currently_tx) { // Switch to transmit mode radio.setModeTransmit(); currently_tx = true; Serial.println("TX ON"); } else if (digitalRead(SWITCH_PIN) == HIGH && currently_tx) { // Switch back to receive mode radio.setModeReceive(); currently_tx = false; Serial.println("TX OFF"); } delay(100); } // TX source options void configureTxSource() { radio.setTxSourceMic(); // Audio from microphone/Arduino radio.setTxSourceTone1(); // Internal tone generator 1 radio.setTxSourceTone2(); // Internal tone generator 2 radio.setTxSourceTones(); // Both tone generators (for DTMF) radio.setTxSourceNone(); // Silent carrier } // Power down mode void powerSave() { radio.setModeOff(); // Turn off both TX and RX, enter power-down } ``` -------------------------------- ### Manage HamShield Band Restrictions Source: https://github.com/enhancedradiodevices/hamshield/wiki/HamShield-Advanced-Hacks-and-Tricks Use these methods to toggle transmission restrictions. .dangerMode() disables restrictions, while .safeMode() restores them. ```cpp .dangerMode() ``` ```cpp .safeMode() ``` -------------------------------- ### Utilities and Advanced Functions Source: https://github.com/enhancedradiodevices/hamshield/wiki/HamShield-Library-Reference Utility functions for scanning, whitespace detection, button modes, Morse code output, and SSTV. ```APIDOC ## Utilities and Advanced Functions ### scanMode(uint32_t start, uint32_t stop, uint8_t speed, uint16_t step, uint16_t threshold) Performs a scan within a specified frequency range. - `start` (uint32_t): The starting frequency. - `stop` (uint32_t): The stopping frequency. - `speed` (uint8_t): The scan speed. - `step` (uint16_t): The frequency step. - `threshold` (uint16_t): The detection threshold. Returns: `uint32_t` - The frequency where the scan stopped. ### findWhitespace(uint32_t start, uint32_t stop, uint8_t dwell, uint16_t step, uint16_t threshold) Searches for whitespace within a specified frequency range. - `start` (uint32_t): The starting frequency. - `stop` (uint32_t): The stopping frequency. - `dwell` (uint8_t): The dwell time. - `step` (uint16_t): The frequency step. - `threshold` (uint16_t): The detection threshold. Returns: `uint32_t` - The frequency where whitespace was found. ### scanChannels(uint32_t buffer[], uint8_t buffsize, uint8_t speed, uint16_t threshold) Scans channels and stores found frequencies in a buffer. - `buffer` (uint32_t[]): An array to store the found frequencies. - `buffsize` (uint8_t): The size of the buffer. - `speed` (uint8_t): The scan speed. - `threshold` (uint16_t): The detection threshold. Returns: `uint32_t` - The number of channels found. ### findWhitespaceChannels(uint32_t buffer[], uint8_t buffsize, uint8_t dwell, uint16_t threshold) Finds whitespace channels and stores their frequencies in a buffer. - `buffer` (uint32_t[]): An array to store the found frequencies. - `buffsize` (uint8_t): The size of the buffer. - `dwell` (uint8_t): The dwell time. - `threshold` (uint16_t): The detection threshold. Returns: `uint32_t` - The number of whitespace channels found. ### buttonMode(uint8_t mode) Sets the mode for button operations. - `mode` (uint8_t): The desired button mode. ### isr_ptt() Interrupt service routine for Push-To-Talk (PTT). ### isr_reset() Interrupt service routine for reset. ### morseOut(char buffer[HAMSHIELD_MORSE_BUFFER_SIZE]) Outputs a string as Morse code. - `buffer` (char[]): The null-terminated string to be converted to Morse code. The size is defined by `HAMSHIELD_MORSE_BUFFER_SIZE`. ### morseLookup(char letter) Looks up the Morse code representation for a given letter. - `letter` (char): The character to look up. Returns: `char` - The Morse code representation (or a placeholder if not found). ### waitForChannel(long timeout, long breakwindow) Waits for a channel activity with specified timeout and break window. - `timeout` (long): The maximum time to wait. - `breakwindow` (long): The break window duration. Returns: `bool` - True if channel activity detected, false otherwise. ### SSTVVISCode(int code) Sets a VIS code for Slow-Scan Television (SSTV). - `code` (int): The VIS code to set. ### SSTVTestPattern(int code) Activates a test pattern for SSTV. - `code` (int): The test pattern code. ``` -------------------------------- ### Transmit Station Identification with morseOut Source: https://github.com/enhancedradiodevices/hamshield/wiki/HamShield-Best-Practices-Guide Use morseOut to send station identification in Morse code. Adjust the morse_dot_millis value in HamShield.cpp to control the transmission speed. ```cpp radio.morseOut("MY CALLSIGN IS ZZ6EXAMPL."); ``` -------------------------------- ### Set TX Audio Source to Internal Sine Generator Source: https://github.com/enhancedradiodevices/hamshield/wiki/HamShield-Library-Reference Sets the radio IC chip's audio path to utilize its internal audio signal generator. ```cpp radio.setTXSourceSine(); ``` -------------------------------- ### Set Channel Bandwidth Source: https://github.com/enhancedradiodevices/hamshield/wiki/HamShield-Library-Reference Sets the channel bandwidth to either 25KHZ or 12.5KHZ. This setting is case-sensitive. ```cpp radio.setChanMode(25KHZ); ``` ```cpp radio.setChanMode(12.5KHZ); ``` -------------------------------- ### RX Volume Control Source: https://github.com/enhancedradiodevices/hamshield/wiki/HamShield-Library-Reference Functions to set the receive audio volume levels. ```APIDOC ## RX Volume Control ### setVolume1(uint16_t volume) Sets the first receive volume level. - `volume` (uint16_t): The volume level. ### getVolume1() Returns the first receive volume level. ### setVolume2(uint16_t volume) Sets the second receive volume level. - `volume` (uint16_t): The volume level. ### getVolume2() Returns the second receive volume level. ``` -------------------------------- ### Configure Tail Noise Elimination Source: https://context7.com/enhancedradiodevices/hamshield/llms.txt Enables CTCSS phase shift to eliminate squelch tail noise at the end of transmissions. ```cpp #include HamShield radio; void setup() { radio.initialize(); radio.frequency(432100); // Enable tail noise elimination radio.enableTailNoiseElim(); // Set phase shift for tail elimination // 0 = 120 degrees // 1 = 180 degrees // 2 = 240 degrees radio.setShiftSelect(1); // 180 degree shift // Verify settings if (radio.getTailNoiseElimEnabled()) { Serial.print("Tail noise elimination enabled, shift: "); Serial.println(radio.getShiftSelect()); } radio.setModeReceive(); } void disableTailElim() { radio.disableTailNoiseElim(); } ``` -------------------------------- ### Channel Management Source: https://github.com/enhancedradiodevices/hamshield/wiki/HamShield-Library-Reference Helper functions for setting and scanning radio channels for various services. ```APIDOC ## Channel Management ### setGMRSChannel(uint8_t channel) Sets the radio to a specific GMRS channel. - `channel` (uint8_t): The GMRS channel number. Returns: `bool` - True if successful, false otherwise. ### setFRSChannel(uint8_t channel) Sets the radio to a specific FRS channel. - `channel` (uint8_t): The FRS channel number. Returns: `bool` - True if successful, false otherwise. ### setMURSChannel(uint8_t channel) Sets the radio to a specific MURS channel. - `channel` (uint8_t): The MURS channel number. Returns: `bool` - True if successful, false otherwise. ### setWXChannel(uint8_t channel) Sets the radio to a specific Weather (WX) channel. - `channel` (uint8_t): The WX channel number. Returns: `bool` - True if successful, false otherwise. ### scanWXChannel() Scans for the next available Weather (WX) channel. Returns: `uint8_t` - The WX channel number found. ``` -------------------------------- ### GPIO Control Source: https://github.com/enhancedradiodevices/hamshield/wiki/HamShield-Library-Reference Functions for configuring and controlling General Purpose Input/Output (GPIO) pins. ```APIDOC ## GPIO Control ### setGpioMode(uint16_t gpio, uint16_t mode) Sets the mode for a specific GPIO pin. - `gpio` (uint16_t): The GPIO pin number. - `mode` (uint16_t): The desired mode for the GPIO pin. ### setGpioHiZ(uint16_t gpio) Sets a GPIO pin to high impedance state. - `gpio` (uint16_t): The GPIO pin number. ### setGpioFcn(uint16_t gpio) Sets a GPIO pin to function mode. - `gpio` (uint16_t): The GPIO pin number. ### setGpioLow(uint16_t gpio) Sets a GPIO pin to low state. - `gpio` (uint16_t): The GPIO pin number. ### setGpioHi(uint16_t gpio) Sets a GPIO pin to high state. - `gpio` (uint16_t): The GPIO pin number. ### getGpioMode(uint16_t gpio) Returns the current mode of a specific GPIO pin. - `gpio` (uint16_t): The GPIO pin number. ``` -------------------------------- ### Tone Generation Functions Source: https://github.com/enhancedradiodevices/hamshield/wiki/HamShield-Library-Reference Functions to generate tones with a specified frequency and duration. ```APIDOC ## toneWait ### Description Generates a tone with the specified frequency for the given duration (in milliseconds). ### Method N/A (Function Signature) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ## toneWaitU ### Description Generates a tone with the specified frequency for the given duration (in microseconds). ### Method N/A (Function Signature) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Configure Squelch Thresholds Source: https://context7.com/enhancedradiodevices/hamshield/llms.txt Sets RSSI thresholds to mute the receiver when no signal is present. Uses hysteresis where the high threshold opens the squelch and the low threshold closes it. ```cpp #include HamShield radio; void setup() { radio.initialize(); radio.frequency(432100); radio.setModeReceive(); // Configure squelch thresholds in dBm radio.setSQHiThresh(-70); // Squelch opens when RSSI > -70 dBm radio.setSQLoThresh(-80); // Squelch closes when RSSI < -80 dBm // Enable/disable squelch radio.setSQOn(); // Enable squelch // radio.setSQOff(); // Disable squelch (always open) // Check squelch state bool sq_enabled = radio.getSQState(); Serial.print("Squelch enabled: "); Serial.println(sq_enabled ? "Yes" : "No"); } void loop() { // Check if squelch is open (signal present) if (!radio.getSquelching()) { Serial.print("Signal detected! RSSI: "); Serial.println(radio.readRSSI()); } delay(100); } ``` -------------------------------- ### Control Volume and Mute Audio with HamShield Source: https://context7.com/enhancedradiodevices/hamshield/llms.txt Set receiver volume levels independently for two channels and mute or unmute audio output. Volume can be adjusted via serial input. ```cpp #include HamShield radio; void setup() { radio.initialize(); radio.frequency(432100); radio.setModeReceive(); // Set volume levels (0-15, where 15 is maximum) radio.setVolume1(0xF); // Volume 1 control radio.setVolume2(0xF); // Volume 2 control // Read current volume settings uint16_t vol1 = radio.getVolume1(); uint16_t vol2 = radio.getVolume2(); Serial.print("Volume 1: "); Serial.println(vol1); Serial.print("Volume 2: "); Serial.println(vol2); // Mute/unmute audio output radio.setMute(); // Mute audio radio.setUnmute(); // Unmute audio } void loop() { // Adjust volume via serial commands if (Serial.available()) { int vol = Serial.parseInt(); if (vol >= 0 && vol <= 15) { radio.setVolume1(vol); radio.setVolume2(vol); Serial.print("Volume set to: "); Serial.println(vol); } } delay(100); } ``` -------------------------------- ### Configure VOX Transmission Source: https://context7.com/enhancedradiodevices/hamshield/llms.txt Sets up voice-activated transmission thresholds and provides methods to enable or disable the feature. ```cpp #include HamShield radio; void setup() { radio.initialize(); radio.frequency(432100); radio.setRfPower(0); // Configure VOX thresholds (in mV) radio.setVoxOpenThresh(200); // Threshold to activate TX radio.setVoxShutThresh(100); // Threshold to deactivate TX // Enable VOX radio.setVoxOn(); // Verify VOX is enabled if (radio.getVoxOn()) { Serial.println("VOX enabled"); Serial.print("Open threshold: "); Serial.println(radio.getVoxOpenThresh()); Serial.print("Shut threshold: "); Serial.println(radio.getVoxShutThresh()); } radio.setModeReceive(); } void loop() { // VOX operates automatically via hardware // Read VSSI (Voice Signal Strength Indicator) when transmitting uint16_t vssi = radio.readVSSI(); uint16_t mssi = radio.readMSSI(); // Mic signal strength delay(500); } void disableVox() { radio.setVoxOff(); } ``` -------------------------------- ### Transmission and Mode Control Source: https://github.com/enhancedradiodevices/hamshield/wiki/HamShield-Library-Reference Methods for controlling transmission power, operating modes, and audio sources. ```APIDOC ## radio.setRfPower(power) ### Description Sets the output power for TX. ### Parameters #### Request Body - **power** (int) - Required - Range: 0 (lowest) to 15 (highest) ## radio.setModeTransmit() ### Description Turns on the transmitter. ## radio.setModeReceive() ### Description Turns on the receiver. ## radio.setModeOff() ### Description Turns off transmit and receive, placing the IC into powerdown state. ## radio.setTXSourceMic() ### Description Sets audio path to Arduino and Headset jack. ## radio.setTXSourceSine() ### Description Sets audio path to internal audio generator. ## radio.setTXSourceCode() ### Description Sets audio path to tx code from GPIO1. ## radio.setTXSourceNone() ### Description Sets audio path to nothing (silent carrier). ``` -------------------------------- ### Tail Noise and Shift Control Source: https://github.com/enhancedradiodevices/hamshield/wiki/HamShield-Library-Reference Functions for managing tail noise elimination and phase shift selection during transmission. ```APIDOC ## Tail Noise and Shift Control ### enableTailNoiseElim() Enables tail noise elimination. ### disableTailNoiseElim() Disables tail noise elimination. ### getTailNoiseElimEnabled() Returns the status of tail noise elimination. ### setShiftSelect(uint16_t shift_sel) Sets the phase shift selection for tail noise elimination during TX. - `shift_sel` (uint16_t): Selects the phase shift: 00 = 120 degrees, 01 = 180 degrees, 10 = 240 degrees, 11 = reserved. ### getShiftSelect() Returns the current phase shift selection. ``` -------------------------------- ### Wait for Clear Channel Before Transmitting Source: https://context7.com/enhancedradiodevices/hamshield/llms.txt Ensures the radio frequency is clear before transmitting to maintain amateur radio courtesy. Waits up to 30 seconds for the channel to be clear, requiring 2 seconds of continuous clear signal, and considers the channel clear if RSSI is below -5 dBm. ```cpp #include HamShield radio; void setup() { radio.initialize(); radio.frequency(432100); radio.setRfPower(0); radio.setModeReceive(); } void transmitMessage(const char* message) { Serial.println("Waiting for clear channel..."); // Wait up to 30 seconds for channel to be clear // Require 2 seconds of continuous clear before transmitting // Consider clear when RSSI < -5 dBm (relative to threshold) if (radio.waitForChannel(30000, 2000, -5)) { Serial.print("Channel clear, RSSI: "); Serial.println(radio.readRSSI()); // Transmit radio.setModeTransmit(); delay(250); // Allow PA to stabilize radio.morseOut(message); radio.setModeReceive(); Serial.println("Transmission complete"); } else { Serial.print("Channel busy after timeout, RSSI: "); Serial.println(radio.readRSSI()); } } void loop() { if (Serial.available()) { char buf[80]; int len = Serial.readBytesUntil('\n', buf, 79); buf[len] = '\0'; transmitMessage(buf); } delay(100); } ``` -------------------------------- ### Stereo Mode Control Source: https://github.com/enhancedradiodevices/hamshield/wiki/HamShield-Library-Reference Functions for setting and managing stereo (ST) modes. ```APIDOC ## Stereo Mode Control ### setStMode(uint16_t mode) Sets the stereo mode. - `mode` (uint16_t): The desired stereo mode. ### getStMode() Returns the current stereo mode. ### setStFullAuto() Sets the stereo mode to Full Auto. ### setStRxAutoTxManu() Sets the stereo mode to RX Auto / TX Manual. ### setStFullManu() Sets the stereo mode to Full Manual. ``` -------------------------------- ### Set TX Audio Source to None (Silent Carrier) Source: https://github.com/enhancedradiodevices/hamshield/wiki/HamShield-Library-Reference Disables any audio input to the transmitter, resulting in a silent carrier wave transmission. ```cpp radio.setTXSourceNone(); ``` -------------------------------- ### Enable CTCSS Tone for Transmitted Audio Source: https://github.com/enhancedradiodevices/hamshield/wiki/HamShield-Library-Reference Activates the configured Continuous Tone-Coded Squelch System (CTCSS) for transmitted audio signals. ```cpp setOuterCtcssMode(); ``` -------------------------------- ### Pre-emphasis/De-emphasis Filter Control Source: https://github.com/enhancedradiodevices/hamshield/wiki/HamShield-Library-Reference Functions to control the pre-emphasis and de-emphasis filters. ```APIDOC ## Pre-emphasis/De-emphasis Filter Control ### bypassPreDeEmph() Bypasses the pre-emphasis and de-emphasis filters. ### usePreDeEmph() Enables the use of pre-emphasis and de-emphasis filters. ### getPreDeEmphEnabled() Returns the enabled status of the pre-emphasis/de-emphasis filters. ``` -------------------------------- ### Set Radio Frequency Source: https://github.com/enhancedradiodevices/hamshield/wiki/HamShield-Library-Reference Sets the radio frequency in KHz. Valid frequency ranges are 134000-174000, 200000-260000, and 400000-520000. ```cpp radio.frequency(frequency in KHz) ``` -------------------------------- ### Enable CTCSS Tone for Received Audio Source: https://github.com/enhancedradiodevices/hamshield/wiki/HamShield-Library-Reference Activates the configured Continuous Tone-Coded Squelch System (CTCSS) for processing received audio signals. ```cpp radio.setInnerCtcssMode() ```