Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 2 of 2

Thread: Ham radio monitor

  1. #1
    Junior Member
    Join Date
    May 2016
    Posts
    8

    Ham radio monitor

    Ok folks, I have been trying to get something working off and on for a very very long time.
    Iíve been stubborn up till now and because of that, havenít requested the help previously.

    Here is the hardware I am attempting to work with.
    Teensy 3.2
    Teensy audio board with optional memory chip
    BC-127 (for initial programming I intended to use a purple tooth jamboree board, then switch to just the BC-127, however over the years I have tried both ways without success)

    My desired process is to have 2 audio channels from my ham radio fed in to the audio board via analog in.
    The audio would simultaneously be sent to a delay buffer of (guessing) 1.5s, as well as fed to a peak detect or possibly RMS(not sure what would be best to detect if the squelch has been broken)
    Upon detecting audio, the bc127 board should 1)send an incoming call signal, 2) answer call signal, and 3) send the delay buffer to the bc127 via i2s.

    It should remain in that state for at least 8-10 seconds after the audio has gone silent before sending the terminate call signal.


    The purpose of this is so that while I am out with friends, I can listen to the stereo at whatever volume I want, and when someone tries to talk, it will automatically cut off the music and switch to the Ham.


    I have at times gotten some basic feedback from the peak detect, then trying to move forward would somehow lose it. I would then step back to what was working and find that it no longer functioned...

    I know some of you will want some code to review, hopefully I can dig some up in the morning. With all the revisions over the years it will take some time to remember what the last one that functioned at all was.

    Thanks
    Nathan

  2. #2
    Junior Member
    Join Date
    May 2016
    Posts
    8
    Here is one of my last attempts.

    Code:
    const int debug = 1;
    const int debugstatus = 1;
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    #include <microsmooth.h>
    #include <SparkFunbc127.h>
    
    // GUItool: begin automatically generated code
    AudioInputI2S            i2s1;           //xy=129,204
    AudioMixer4              mixer1;         //xy=318,204
    AudioEffectDelayExternal delayExt1(AUDIO_MEMORY_23LC1024, 700);     //xy=326,302
    AudioEffectDelayExternal delayExt2(AUDIO_MEMORY_23LC1024, 700);     //xy=328,107
    AudioAnalyzePeak         peak1;          //xy=483,185
    AudioAnalyzeRMS          rms1;           //xy=485,220
    AudioOutputI2S           i2s2;           //xy=695,232
    AudioConnection          patchCord1(i2s1, 0, delayExt1, 0);
    AudioConnection          patchCord2(i2s1, 0, mixer1, 0);
    AudioConnection          patchCord3(i2s1, 1, delayExt2, 0);
    AudioConnection          patchCord4(i2s1, 1, mixer1, 1);
    AudioConnection          patchCord5(mixer1, peak1);
    AudioConnection          patchCord6(mixer1, rms1);
    AudioConnection          patchCord7(delayExt2, 0, i2s2, 1);
    AudioConnection          patchCord8(delayExt1, 0, i2s2, 0);
    AudioControlSGTL5000     audioShield;    //xy=202,108
    
    const int myInput = AUDIO_INPUT_LINEIN;
    
    #define HWSerial Serial3
    BC127 BTModu(&HWSerial);
    
    uint16_t *history = ms_init(SMA);
    int activeSession;
    
    
    
    
    void setup() {
      pinMode(13, OUTPUT);
      digitalWrite(13, HIGH);
    
      // put your setup code here, to run once:
      SerialUSB.begin(115200);
      AudioMemory(20);
      delayExt1.delay(0, 500);
      delayExt2.delay(0, 500);
      //  audioShield.setAddress(LOW);
      audioShield.enable();
      audioShield.inputSelect(myInput);
      audioShield.volume(0.5);
    
      HWSerial.begin(115200);
    
      if (history == NULL) SerialUSB.println("No memory");
      /* BC127 Config area */
      if (debug == 1) {
        SerialUSB.println(BTModu.autoconfig());
        delay(600);
        SerialUSB.println(BTModu.writeConfig());
        delay(600);
        SerialUSB.println(BTModu.reset());
        delay(600);
        int sessionid;
        String parsing;
        int connectionResult = 0;
        SerialUSB.print("Inquiry result: "); SerialUSB.println(BTModu.inquiry(10));
        String address;
        for (byte i = 0; i < 5; i++)
        {
          if (BTModu.getAddress(i, address))
          {
            SerialUSB.print("BT device found at address ");
            SerialUSB.println(address);
    
            SerialUSB.print("Connect result: ");
            connectionResult = BTModu.connect(i, BC127::AGHFP, sessionid, parsing);
            SerialUSB.println(connectionResult);
    //        break;
    
          }
        }
        if (connectionResult == 0) SerialUSB.println("Connection Attempt Failed!");
        else
        {
          if (connectionResult == 1)
          {
            activeSession = sessionid;
          }
        }
    
      }
    
    
    delay(5000);
    BTModu.makeCallandAnswer(12, 1, "3101231234");
    }
    
    
    unsigned long triggerStart;
    unsigned long lastTrigger;
    unsigned long lastDetected;
    long lastlevel;
    int lastpeak;
    long currentLevel;
    int threshold = 10;
    int delayTime = 30000; //*in ms
    int detectFlag = 0;
    unsigned long triggerTimeout;
    
    
    elapsedMillis fps;
    //elapsedMillis speedtest;
    //int outerloopcnt=0;
    //int innerloopcnt=0;
    
    void loop() {
      //  outerloopcnt++;
      // put your main code here, to run repeatedly:
    
      if (fps > 20) {
        if (peak1.available() /*| peak2.available()*/) {
          fps = 0;
          int monoPeak1 = peak1.read() * 30.0;
          if (debugstatus == 1 && lastpeak != monoPeak1) {
            lastpeak=monoPeak1;
            SerialUSB.print("RawLevel - ");
            SerialUSB.println(monoPeak1);
          }
    
          currentLevel = sma_filter(monoPeak1, history);
          if (debugstatus == 1 && lastlevel != currentLevel) {
            lastlevel=currentLevel;
    
            SerialUSB.print("CurrLevel - ");
            SerialUSB.println(currentLevel);
          }
          if (currentLevel >= threshold && detectFlag == 0) {
            detectFlag = 1;
            lastDetected = millis();
            muteStereo();
          }
          else if (currentLevel >= threshold && detectFlag == 1) {
            SerialUSB.print("Last Quiet Duration - " + String(lastDetected - triggerStart));
    
    
            triggerStart = millis();
            lastDetected = millis();
            triggerTimeout = millis() + delayTime;
            detectFlag = 2;
          }
          else if (currentLevel >= threshold && detectFlag == 2) {
            lastDetected = millis();
            triggerTimeout = millis() + delayTime;
          }
          if (currentLevel < threshold && triggerTimeout < millis() && detectFlag == 2) {
            detectFlag = 0;
            SerialUSB.print("Last Trigger Duration - " + String(millis() - lastDetected));
            unMuteStereo();
          }
        }
    
    
    
    
    
    
    
        //      if (debug) {
        //        if (speedtest>=1000) {
        //          SerialUSB.print("outer/inner/time:");
        //          SerialUSB.println(String(innerloopcnt)+"/"+String(speedtest));
        //          outerloopcnt=0;
        //          innerloopcnt=0;
        //          speedtest=0;
        //        }
        //        SerialUSB.print(" | ");
        //        SerialUSB.print("Peak: ");
        //        SerialUSB.print(monoPeak1);
        //        SerialUSB.print(" | ");
        //        SerialUSB.print(monoPeak2);
        //  //      int monoRMS1 = rms1.read() * 30.0;
        //  //      int monoRMS2 = rms2.read() * 30.0;
        //  //      SerialUSB.print("  RMS: ");
        //  //      SerialUSB.print(monoRMS1);
        //  //      SerialUSB.print(" | ");
        //  //      SerialUSB.println(monoRMS2);
        //        innerloopcnt++;
    
      }
    }
    
    void muteStereo() {
      BTModu.makeCallandAnswer(12, 1, "3101231234");
    
    }
    
    void unMuteStereo() {
      BTModu.endCall(12);
    
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •