Jump to content
 
N9WXU

Playing with Teensy for Audio

Recommended Posts

I am building an integrated audio interface for a Baofeng UV-5R hand-held radio.  Primarily this is to get a packet radio APRS system up and running.  Traditionally, this seems to be accomplished with a crazy collection of adapters and hand crafted interface cables.

As I was looking for a better solution, I discovered the Teensy family of ARM microcontrollers.  (actually Arduino high performance ARM's built on NXP Cortex M4's)  The important part is actually the library support.  Out of the box I was able to get a USB Audio device up and map the ADC and DAC to the input and output.  This could all be configured with some simple "patch cord" wiring.

 

image.png

So I created the "program" above.  This combines the 2 audio channels from USB into a single DAC and also passes the data to an RMS block.  This causes the audio to play on the DAC at 44.1khz.  It also keeps a running RMS value available for your own code.  More on this later.  Next the ADC data is duplicated into both channels back through USB and on to the PC (Raspberry Pi).  Again an RMS block is present here as well.

Now pressing EXPORT produces this little block of "code"

image.png

Which gets pasted into the Arduino IDE at the beginning of the program (before your setup & main.

/*
 * A simple hardware test which receives audio on the A2 analog pin
 * and sends it to the PWM (pin 3) output and DAC (A14 pin) output.
 *
 * This example code is in the public domain.
 */

#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioInputUSB            usb1;           //xy=91,73.00001907348633
AudioInputAnalog         adc1;           //xy=153.00000381469727,215.00003242492676
AudioMixer4              mixer1;         //xy=257.00000762939453,72.00002670288086
AudioAnalyzeRMS          rms2;           //xy=427.0000114440918,266.000036239624
AudioOutputUSB           usb2;           //xy=430.00001525878906,217.00003242492676
AudioOutputAnalog        dac1;           //xy=498.00009536743164,72.00002670288086
AudioAnalyzeRMS          rms1;           //xy=498.00001525878906,129.0000295639038
AudioConnection          patchCord1(usb1, 0, mixer1, 0);
AudioConnection          patchCord2(usb1, 1, mixer1, 1);
AudioConnection          patchCord3(adc1, 0, usb2, 0);
AudioConnection          patchCord4(adc1, 0, usb2, 1);
AudioConnection          patchCord5(adc1, rms2);
AudioConnection          patchCord6(mixer1, dac1);
AudioConnection          patchCord7(mixer1, rms1);
// GUItool: end automatically generated code

const int LED = 13;

void setup() {
  // Audio connections require memory to work.  For more
  // detailed information, see the MemoryAndCpuUsage example
  AudioMemory(12);
  pinMode(LED,OUTPUT);
}

void loop() {
  // Do nothing here.  The Audio flows automatically
  if(rms1.available())
  {
    if(rms1.read() > 0.25)
    {
      digitalWrite(LED,HIGH);
    }
    else
    {
      digitalWrite(LED,LOW);
    }
  }
  // When AudioInputAnalog is running, analogRead() must NOT be used.
}

And Viola!.  The PC sees this as an audio device and the LED blinks when the audio starts.  PERFECT.

Now, the LED will be replaced with the push to talk (PTT) circuit and the audio I/O will connect to the Baofeng through some filters.  A single board interface to the radio from a Raspberry Pi that does not require 6 custom cables, and a 3 trips to E-BAY.  Now I am waiting for my PCB's from dirtypcb.com

This entire bit of work is for my radio system that is being installed on the side of my house.  Here is the box:

IMG_0897.jpeg

Inside is a Raspberry Pi 3, a Baofeng UV-5R for 2M work, 3 RTL dongles for receiving 1090MHz ADS-B, 978MHz ADS-B, 137MHz Satellite weather, GPS and 1 LoRaWAN 8 channel Gateway.  I will write more about the configuration later if there is any interest.

Good Luck.

 

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


 


×
×
  • Create New...