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. Gyroscope

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

XdkSensorHandle.h

/************************************************************
*   PositionSensor.c
************************************************************/

/* system header files */
#include <stdio.h>

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

#include "XdkSensorHandle.h"

/* own header files */

We define a function that have the propose of get the value of the sensor.

Gyroscope_XyzData_T bmg160 = {INT32_C(0), INT32_C(0), INT32_C(0)};

Gyroscope_readXyzDegreeValue(xdkGyroscope_BMG160_Handle, &bmg160);

First we need to storage a struct for every axis´ position data is declared.

The data is read by the second function and stored in a passed reference of the storage struct.

// Function that read and print the sensor data of the BMG160 to the console of the XDK-Workbench
static void readGyroscope(xTimerHandle xTimer)
{
    (void) xTimer;

    Retcode_T returnValue = RETCODE_FAILURE;

    /* read and print BMG160 gyroscope data */

    Gyroscope_XyzData_T bmg160 = {INT32_C(0), INT32_C(0), INT32_C(0)};

    returnValue = Gyroscope_readXyzDegreeValue(xdkGyroscope_BMG160_Handle, &bmg160);

    if (RETCODE_OK == returnValue)  {
        printf("BMG160 Gyro Data : x =%ld mDeg y =%ld mDeg z =%ld mDeg\n\r", (long int) bmg160.xAxisData, 
                  (long int) bmg160.yAxisData, (long int) bmg160.zAxisData);
    }
}

Then we declared the function to initialized the sensor and variable.

// Function that initializes the Gyroscope with the BMG160 handler and with additional pre settings
static void initGyroscope(void)
{
    Retcode_T returnValue = RETCODE_FAILURE;
    Retcode_T returnBandwidthValue = RETCODE_FAILURE;
    Retcode_T returnRangeValue = RETCODE_FAILURE;

    /* initialize gyroscope */

    returnValue = Gyroscope_init(xdkGyroscope_BMG160_Handle);

    if(RETCODE_OK != returnValue){
        printf("BMG160 Gyroscope initialization failed \n\r");
    }

    returnBandwidthValue = Gyroscope_setBandwidth(xdkGyroscope_BMG160_Handle,GYROSCOPE_BMG160_BANDWIDTH_116HZ);
    if (RETCODE_OK != returnBandwidthValue) {
        printf("Configuring bandwidth failed \n\r");
    }
    returnRangeValue = Gyroscope_setRange(xdkGyroscope_BMG160_Handle,GYROSCOPE_BMG160_RANGE_500s);
    if (RETCODE_OK != returnRangeValue) {
        printf("Configuring range failed \n\r");
    }
}

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.

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

    uint32_t timerBlockTime = UINT32_MAX;
    uint32_t oneSecondDelay = UINT32_C(1000);
    uint32_t timerAutoReloadOn = UINT32_C(1);

    xTimerHandle gyroscopeHandle = NULL;

    initGyroscope();

    gyroscopeHandle = xTimerCreate((const char *) "readGyroscope", oneSecondDelay,timerAutoReloadOn, NULL, readGyroscope);

    xTimerStart(gyroscopeHandle,time
PreviousGyroscopeNextMita

Last updated 5 years ago

Was this helpful?