IOT - Bosch
  • Introduction
  • Devices
    • Bosch XDK 110
      • Introduction
      • Operating System
      • Hardware
        • Sensors
          • Accelerometer
            • C
          • Gyroscope
            • C
            • Mita
          • Magnetometer
            • C
          • Environmental
            • C
            • Mita
          • Ambient Light
            • C
            • Mita
          • Acoustic
            • C
      • Software
        • XDK WorkSpace
          • Structure
          • Debug
          • Supported languages
            • C
              • Static Library (.a)
            • XDK Live - Mita
            • MicroFlo
      • Connectivity
        • Bluetooth Low Energy (BLE)
          • Overview
          • General Info
          • Implementation
            • C
            • XDK Live
        • WI-FI
          • OverView
          • Implementation
            • C
            • XDK Live
        • WI-FI Enterprise
      • Protocols
        • CoAP
          • Overview
          • Implementation -TBD
        • HTTP
          • Overview
          • Structure and Methods
          • Implementation
            • C - Rest
            • C - Post
            • XDK Live
        • HTTPS
          • Overview
          • Implementation TBD
        • LWM2M
          • Overview
          • Implementation TBD
        • MQTT
          • Overview
          • Implementation
            • C
            • XDK Live
        • USB
          • Overview
          • Implementation TBD
      • Data Storage
      • XDK Extension Bus
      • Community
      • Applications
        • Language C
          • HomeAssitant - MQTT
            • Prerequisites
            • Server
            • Device
          • IOTA-MQTT-XDK
            • Prerequisites
            • XDK110
            • Mqtt JSON to MAM
            • SensorHub
            • Demo
        • Language XDK Live
          • MQTT
            • Hello World
            • HomeAssistant
              • Prerequisites
              • Server
              • Device
            • Docker-HomeAssistant
          • HTTP
            • Roku Remote Control
              • Roku API
              • MITA
                • Example
    • Bosch AMRA
    • Bosch GLM 100C
    • Bosch FLEXIDOME IP panoramic
    • Bosch GLM 100C
    • Bosch Rexroth Nexo
    • Bosch Rexroth PRC 7000
    • Bosch RRC / CT100
    • Bosch Rexroth IoT Gateway
  • Bosch IOT Solutions
    • Bosch IOT Projects
      • Smart Home
      • Industry 4.0
      • Smart Cities
      • Connected-mobility
    • Bosch IOT Suite
      • Bosch Analytics
      • Bosch IOT Hub
      • Bosch Iot Permission
      • IoT Remote Manager
      • IoT Rollouts
      • IoT Things
      • Demo TBD **
    • BPM and BRM
  • IOTA
    • Introduction
      • Tangle
      • Glossary
      • Differences with other tech
      • How does iota work
      • Developers
    • Qubic
      • What is Qubic?
      • Target
      • Qubic Protocol
    • Ecosystem
    • Applications
      • Python
      • XDK110
        • Prerequisites
        • XDK110
        • Mqtt JSON to MAM
        • SensorHub
    • Bosch/IOTA
  • ByteBall
    • SmartContract
    • Use Case
      • BoshCoins
Powered by GitBook
On this page

Was this helpful?

  1. Devices
  2. Bosch XDK 110
  3. Hardware
  4. Sensors
  5. Acoustic

C

This code base on language C have the propose to get information about this sensor and display it.

First part that we need to write on our code is the libraries that we are going to use. In this case we are going to use

BCDS_BSP_Mic_AKU340.h

/************************************************************
*   AcousticSensor.c
************************************************************/

/* system header files */
#include 
/* additional interface header files */
#include "FreeRTOS.h"
#include "timers.h"

#include "KnowledgebaseAcousticSensor.h"
#include "BCDS_CmdProcessor.h"
#include "BCDS_Assert.h"

Currently, the API does not provide a built-in function to convert these values from their byte representation into the representation of the output voltage of the AKU340 or the measured sound pressure. To calculate the sound pressure level, we use the next part of the code:

** First, the sound pressure to output voltage conversion ratio of the AKU340 is calculated using the math.c library into a linear value from its logarithmic data sheet specification. Afterwards, the ADC conversion ratio is calculated by with the maximal input voltage of the ADC and the 4096 representable states. Additionally the ratio is multiplied by 1000 for a presentation in milli volts.

Then, the function calcSoundPressure() is used to calculate the sound pressure representation in milli pascal by using the previous calculated conversion ratios for the ADC and the AKU340 and the passed measured raw value read from the acoustic sensor.

/* own header files */
#include "BCDS_BSP_Mic_AKU340.h"
#include "math.h"

const float aku340ConversionRatio = pow(10,(-38/20));

const float adcConversionRatio = 2.5*1000/4096;

// Function to calculate the sound pressure representation from the read acoustic sensor values
float calcSoundPressure(uint32_t acousticRawValue){
    return ((acousticRawValue/aku340ConversionRatio)*adcConversionRatio);
}

BSP_Mic_AKU340_Sense() is used and data can be read as follows from the acoustic sensor.

// Timer function to read out the acoustic sensor
void readAcousticSensor(xTimerHandle xTimer){

    BCDS_UNUSED(xTimer);

    int32_t microphoneSample;

    microphoneSample = BSP_Mic_AKU340_Sense();

    printf("Sound pressure: %f \r\n", calcSoundPressure(microphoneSample));
}

// Function to initialize the acoustic sensor

void initAcousticSensor(void){
    BSP_Mic_AKU340_Connect();
    BSP_Mic_AKU340_Enable();
}

Finally we declared the main part of the program where we need to call all the function that we previously defined. Also define the timers.

Acoustic sensor requires a timer or operating task, which runs on a very short sampling period, such as 1 to 10 ms approximately to produce appropriate results, when measuring ambient noise.

void appInitSystem(void * CmdProcessorHandle, uint32_t param2)
{
    if (CmdProcessorHandle == NULL)
    {
        printf("Command processor handle is null \n\r");
        assert(false);
    }
    BCDS_UNUSED(param2);

    initAcousticSensor();

    uint32_t timerBlockTime = UINT32_MAX;
    uint32_t timerAutoReloadOn = UINT32_C(1);
    uint32_t timerPeriod = UINT32_C(100) / portTICK_RATE_MS;

    xTimerHandle TimerHandle = xTimerCreate(
                (const char* const) "TimerFunc",
                timerPeriod,
                timerAutoReloadOn,
                (void*) NULL,
                readAcousticSensor);

    xTimerStart(TimerHandle, timerBlockTime);
}
PreviousAcousticNextSoftware

Last updated 5 years ago

Was this helpful?