Giter Club home page Giter Club logo

mpu6050-sensor-library-cpp's Introduction

MPU6050 Sensor Library Cpp

About the Library

This library is made to create a simple interface in C++ for the MPU6050 sensor over I2C. The library initially made for Raspberry Pi 4 but it allows users to port the library to other architectures easily. Additionally, the library currently contains example applications made for RaspberryPi 4 and ESP32 Wroom boards.

How to Use

Since the I2C related methods (such as initialization, read, write, etc.) may differ for every architecture, the library is using an interface class called I2C_Interface (see i2c_interface.h source file) in order to keep the library flexible to port to other architectures. The user should create its own class from the I2C_Interface base class and implement only 3 methods to make it work for its architecture. Methods to be implemented by the user are the following:

  • virtual i2c_status_t Init_I2C(uint32_t baudrate = 100000)
  • virtual uint8_t ReadRegister(uint8_t slaveAddress, uint8_t regAddress, i2c_status_t *status)
  • virtual i2c_status_t WriteRegister(uint8_t slaveAddress, uint8_t regAddress, uint8_t data)

Requirements

For RaspberryPi 4 Examples

For ESP32 Examples

  • ESP-IDF (applications made with ESP-IDF v5.0-dev-1295-gfaf0f61cdb)

About the Example Applications

1) Raspberry Pi 4

There is currently 2 example applications for RPi4. Both example applications doing the same basic reading from the sensor to show the features of the driver and how to port the driver to other libraries if needed. One of the example is using bcm2835 library and other one is using the wiringPi library to access the I2C port.

Connection

  • SDA -> GPIO2
  • SCL -> GPIO3
  • VCC -> 3V3 Power
  • ADD -> GND
  • GND -> GND :)

Important: Pin connections are same for both applications! Check this link for RaspberryPi pinout: https://www.raspberrypi.org/documentation/usage/gpio/

Build and Run

In order to build the example application, make sure that the requirements are fulfilled (check requirements above) and move into one of the examples folder by using terminal then type make all. If everything is ok, it will create the executable inside the example applications /build folder.

After the build process you can run the application by moving into /build folder with terminal and type sudo ./example_rpi4_bcm2835 or sudo ./example_rpi4_wiringPi.

Important: You should use sudo (super user permissions) keyword to run the bcm2835 library example application!

2) ESP32 - Wroom

Connection

  • SDA -> IO21
  • SCL -> IO22
  • VCC -> 3V3 Power
  • ADD -> GND
  • GND -> GND :)

Build and Run

In order to build and run the ESP32 application, just use the ESP-IDF toolchain.

Build the application with:

  • idf.py build

After the build flash the application to ESP32 with:

  • idf.py -p <portNum> -b 115200 flash

Once the application is running on the MCU, use following command to monitor the sensor readings:

  • idf.py -p <portNum> monitor

mpu6050-sensor-library-cpp's People

Contributors

batu92k avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

mpu6050-sensor-library-cpp's Issues

Tidy-Up Repository Example Applications

There are common interface files used in multiple example applications for each platform. Put them in a folder called interfaces instead of having copies of the files in each example.

Update Readme File for New Example Applications

Description

Now there are new example applications for Rpi4 WiringPi library and ESP32 microcontroller. Describe how to use the example applications and platforms they were developed in the readme.

STM32 Example Application

Description

  • Add an example application for stm32 series mcu (most common ones like stm32f407 etc.) with Cube-IDE or KEIL
  • Implement the I2C interface for chosen stm32 mcu

Use Namescapes for Scoping

Description

Since we use C++, use namespaces (maybe nested namespaces) to scope the sensor class and constant variables.

DMP Firmware Support

Description

Add support for Digital Motion Processor (DMP) Firmware. Get the DMP firmware binaries as an array and implement the necessary methods to configure and upload the DMP firmware when needed.
Check this link for more info: https://invensense.tdk.com/developers/

Make All Driver Constants Scoped

Description

Enums are available for the whole program, this may create confusion in the future when we use this sensor driver in other projects. So scope all the driver constants into appropriate scopes to make them accessible more specifically. We can use the enum classes but since we need the values of the constants as integer it requires to type static cast for all instances. So use something else.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.