element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Safe and Sound
  • Challenges & Projects
  • Design Challenges
  • Safe and Sound
  • More
  • Cancel
Safe and Sound
Blog Safe and Sound Wearables- Hearing Guard System #5: Audio Circuit - Part Deux
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: jomoenginer
  • Date Created: 13 Mar 2017 6:06 AM Date Created
  • Views 504 views
  • Likes 4 likes
  • Comments 5 comments
  • msp432 430boost-sharp96 energia
Related
Recommended

Safe and Sound Wearables- Hearing Guard System #5: Audio Circuit - Part Deux

jomoenginer
jomoenginer
13 Mar 2017

This is another example of the Audio Circuit for my Hearing Guard System using the  MSP-EXP432P401RMSP-EXP432P401R with the  430BOOST-SHARP96430BOOST-SHARP96 LCD showing the audio input I'm using TI Energia MT for MSP432 to prototype the display output but will use Code Composer Studio with TI-RTOS for the final code

Energia is TI's take on the Arduino IDE and works pretty much the same as the Arduino version but is only supported with the TI MSP432, MSP430, Tiva C (TM4C123, TM4C129) and CC1310 and CC1350 Launchpads.  There are a number of examples that carry over from the Arduino examples and it is fairly simple to take an existing Arduino Example and port it over to a TI device in Energia.  One cool feature of Energia MT is that is offers Multitasking capabilities for the MSP432 by way of TI-RTOS.  With this, separate tasks can be created to handle different parts of the code such as LCD, ADC input, and GPIO processing. For my example, I created a separate task for the Sharp96 LCD, the Audio Input, and for the LED Bar Graph. Each of these run at different intervals with the Audio input running more frequently than the others.

 

For example, the initial tab in my Energia project is left blank so there is no over all managing task:

/*
 * Hear Guard System
 * Demo of Audio Input with Sharp96 LCD output using multitasking
 * 
 * 
 */

 

Then, I have a separate tab for the Audio Input Task:

 

/*
 * Add shared libraries
 */
 #include "MultiAnalogInput.h"


const int audioInput = 33;    // select the input pin for the potentiometer
uint16_t audioValue = 0;  // variable to store the value coming from the sensor


void setupAnalog2() {
  Serial.begin(115200);
}


void loopAnalog() {
  // read the value from the sensor:
  audioValue = analogRead(audioInput);
  Serial.print("Value read by audio task: ");
  Serial.println(audioValue);
  delay(10);  
}

 

 

There is a separate task to handle the LED output (NOTE: This will eventually control the RGB LED color)

 

/*
 * LEDOutput.ino
 * Output to LED Bar Graph
 */


//const int ledPin = 40; // the code will flash the LED connected to pin 13


const uint16_t threshold = 500;  // mic threshold sound level
const uint8_t ledCount = 10; // The number of LEDs in the bar graph
uint16_t ledPins[] = {23, 24, 25, 26, 27, 28, 29, 30, 31, 32}; // an array of pin numbers




void setupLEDOutput() {
    Serial.begin(115200);  
    for (int thisLed = 0; thisLed < ledCount; thisLed++) {
        pinMode(ledPins[thisLed], OUTPUT);
    }
    
}


void loopLEDOutput() {
      int ledLevel = map(audioValue, 500, 1023, 0, ledCount);
      Serial.print("LED Output = ");
      Serial.println(ledLevel);  // print out the data read in  
        
      for (int thisLed = 0; thisLed < ledCount; thisLed++) {
          // if the array element's index is less than ledLevel,
          // turn the pin for this element on:
          if (thisLed < ledLevel) { 
              digitalWrite(ledPins[thisLed], HIGH);
          } else { // turn off all pins higher than the ledLevel
              digitalWrite(ledPins[thisLed], LOW);
          }


     }
     for (uint8_t i=0; i<2; i++) delay(20);
}

 

And a separate task for the Sharp96 LCD

 

// Include application, user and local libraries
#include "SPI.h"
#include "OneMsTaskTimer.h"
#include "LCD_SharpBoosterPack_SPI.h"


#include "MultiAnalogInput.h"

LCD_SharpBoosterPack_SPI myScreen;


const int ledPin = 40; // the code will flash the LED connected to pin 40
const int maxVal = 1023;
int maxAudioVal = 0;


void setup() {

    pinMode(ledPin, OUTPUT);  // sets digital pin 40 as output
    Serial.begin(115200);  


    myScreen.begin();
    myScreen.clearBuffer();


    myScreen.setFont(1);
    myScreen.text(10, 10, "Hello!");
    myScreen.flush();
    
    for (uint8_t i=0; i<20; i++) delay(100);
    
}




void loop() {


    Serial.print("Sample = ");
    Serial.println(audioValue);  // print out the data read in


    myScreen.clearBuffer();
    myScreen.setFont(0);
    myScreen.text(15, 10, "READ AUDIO", LCDWrapNone);
    myScreen.setFont(0);
    myScreen.setCharXY(10, 40);
    myScreen.text(10, 40, "Sample = ");
    myScreen.setCharXY(60, 40);
    myScreen.println(audioValue, DEC);


    if (maxAudioVal < audioValue && audioValue != maxVal)
    {
      maxAudioVal = audioValue;
    }
    myScreen.setFont(0);
    myScreen.text(10, 60, "MaxVal = ");
    myScreen.setCharXY(60, 60);
    myScreen.println(maxAudioVal, DEC);
    
    myScreen.flush();
   
    for (uint8_t i=0; i<2; i++) delay(100);
}

 

 

I had to include a header file to handle the shared variables otherwise the code would not compile:

 

/*
 * Header file to share sensor and sensor pin variables
 */
#include <stdint.h>
 extern const int audioInput;
 extern uint16_t audioValue;

 

When this is running, the Serial output can be used to view how often the tasks are running:

Value read by audio task: 462

Value read by audio task: 485

Value read by audio task: 484

Sample = 484

LED Output = 0

 

 

To see an example of this running, here be a link to a vid of this:

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

  • Sign in to reply

Top Comments

  • DAB
    DAB over 9 years ago in reply to jomoenginer +1
    Sorry, I suffer from ADD, so you probably said that and I just did not retain the information. I was just asking if you needed to do more than just record the raw data levels from the circuit A/D input…
  • jomoenginer
    jomoenginer over 9 years ago in reply to DAB +1
    DAB, Yeah, the plan is to be able to detect dB levels based on a user selectable threshold and then both display this value as well as light an RGB accordingly. I have been working with a few formulas…
  • DAB
    DAB over 9 years ago in reply to jomoenginer +1
    Yes, I was curious how it would perform. Still, starting with a simple circuit is best until you see how it performs. Then you can look at adding filters, noise reduction circuits or just put all of the…
  • DAB
    DAB over 9 years ago in reply to jomoenginer

    Yes, I was curious how it would perform.

     

    Still, starting with a simple circuit is best until you see how it performs.

     

    Then you can look at adding filters, noise reduction circuits or just put all of the clean up in software.

     

    That is the beauty of a challenge, you start at one point and learn along the way.

     

    If you have some time, you might want to look at adaptive algorithms for processing the data.  They would allow you to implement a variable threshold depending upon the background noise.

     

    DAB

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • jomoenginer
    jomoenginer over 9 years ago in reply to DAB

    DAB,

     

    Yeah, the plan is to be able to detect dB levels based on a user selectable threshold and then both display this value as well as light an RGB accordingly.  I have been working with a few formulas to convert the values read in from the audio circuit but that will take some more time to iron out. Also, I am not completely sold on the audio circuit that I have and may look at more efficient ones and other OP AMPs.

     

    Thanks,

     

    Jon

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 9 years ago in reply to jomoenginer

    Sorry, I suffer from ADD, so you probably said that and I just did not retain the information.

     

    I was just asking if you needed to do more than just record the raw data levels from the circuit A/D input.

     

    Depending upon your needs, you may decide to just go with threshold levels based upon relative background levels.

     

    DAB

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • jomoenginer
    jomoenginer over 9 years ago in reply to DAB

    Uh, I do believe the intent of the project is to detect dB levels, so I assume yes would be appropriate.

    However, I am not clear with the intent of your question though.

     

    Jon

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 9 years ago

    Nice update.

     

    Are you planning to do any calibration of your audio circuit to actual db levels?

     

    DAB

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube