Giter Club home page Giter Club logo

mt6701's Introduction

MT6701 Magnetic Rotary Encoder Library for ESP32

The MT6701 library provides a simple and effective way to interface with the MT6701 magnetic rotary encoder using ESP32. It supports reading angular positions in radians and degrees, calculating rotational velocity in RPM, and smoothing RPM values with a moving average filter. The sensor uses I2C.

Features

  • Read angular position in radians and degrees.
  • Calculate rotational velocity (RPM).
  • Smooth RPM readings with a moving average filter.
  • Easy-to-use interface for ESP32 environments.

Installation

Manual Installation

  1. Download this library as a ZIP file.
  2. Open the Arduino IDE.
  3. Go to Sketch > Include Library > Add .ZIP Library....
  4. Choose the downloaded ZIP file.
  5. Restart the Arduino IDE.

Library Manager

  1. Open the Arduino IDE.
  2. Go to Sketch > Include Library > Manage Libraries....
  3. Search for "MT6701".

Usage

To use the library, include it in your Arduino sketch and follow the steps below.

Basic Setup

#include "MT6701.hpp"

MT6701 encoder;

void setup() {
    Serial.begin(115200);
    encoder.begin();
}

void loop() {
    float angleRadians = encoder.getAngleRadians();
    Serial.print("Angle in Radians: ");
    Serial.println(angleRadians);

    delay(1000);
}

Advanced Usage

RPM Calculation

The library can calculate the RPM of the rotary encoder. It works best with a short update interval, by using a low update interval for the constructor for ESP32 or manually calling encoder.updateCount() frequently for Arduino. Here's how you can get the RPM value:

void loop() {
    float rpm = encoder.getRPM();
    Serial.print("RPM: ");
    Serial.println(rpm);

    delay(1000);
}

Changing Update Interval

You can modify the update interval of the encoder readings (default is 50 ms) by passing the interval in milliseconds to the constructor:

MT6701 encoder(MT6701::DEFAULT_ADDRESS, 200); // Update interval set to 200 ms

Changing moving average filter size

You can modify the number of samples to average for the moving average filter (default is 10) by passing the filter size to the constructor:

MT6701 encoder(MT6701::DEFAULT_ADDRESS, MT6701::UPDATE_INTERVAL, 20); //  Filter size set to 20

API Reference

Methods:

  • begin(): Initialize the encoder and start the background task for reading data.
  • getAngleRadians(): Get the current angle in radians.
  • getAngleDegrees(): Get the current angle in degrees.
  • getAccumulator(): Get the accumulated count.
  • getRPM(): Get the current RPM.
  • getCount(): Get the raw count value from the sensor.
  • updateCount(): Update the count value from the sensor. This is only needed for Arduino environments.
  • getTurns(): Get the number of turns the shaft has made since startup.
  • getFullTurns(): Get the number of full turns the shaft has made since startup.

Constants:

  • DEFAULT_ADDRESS: Default I2C address of the MT6701 encoder.
  • RPM_FILTER_SIZE: Number of samples to average for rpm calculation.

Example Sketches

Example sketches demonstrating basic and advanced usage of the library are included in the /examples folder.

License

This library is released under the GPL-3 License.

mt6701's People

Contributors

noranraskin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

mt6701's Issues

Multi I2C bus support!

Great work,

You write a library perfect for Esp32.
We know that the esp32 can create a multi-I2C bus with it's GPIO pins. Could you tweak your source code to enable the multi-I2C bus feature?
Thank!

Reference not included in package

Hello, I tried using your library and when compiling in the arduino IDE, I was given a message stating "fatal error: atomic: No such file or directory". When checking your .hpp file there was a reference to a library #include , which I don't own.

Please let me know if I'm missing something b/c I don't know where to go from here.

I have attached a picture of the compilation error and the atomic library reference I mentioned earlier
compilationError
libraryReference

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.