MENU

Fun & Interesting

Object Oriented C++ Implementation of Encoders in Arduino | ESP32 - Learn to Write Structured C++

Aleksandar Haber PhD 1,027 6 months ago
Video Not Working? Fix It Now

#arduino #encoders #halleffect #stm32 #aleksandarhaber #robotics #engineering #robotics It takes a significant amount of time and energy to create these free video tutorials. You can support my efforts in this way: - Buy me a Coffee: https://www.buymeacoffee.com/AleksandarHaber - PayPal: https://www.paypal.me/AleksandarHaber - Patreon: https://www.patreon.com/user?u=32080176&fan_landing=true - You Can also press the Thanks YouTube Dollar button In this tutorial, we explain how to write a disciplined and object oriented C++ code for interfacing Arduino or ESP32 microcontrollers with low-cost Hall-effect encoders. We explain how to embed an interrupt function for reading encoder values in a C++ class and how to read A and B phases of an encoder. We explain how to read the pulses. Here is the main motivation for creating this tutorial: In our previous tutorial whose link is given here: https://www.youtube.com/watch?v=1PJOzrXAlcg we explained how to write unstructured C Arduino code for interfacing encoders. However, this is a naive approach for writing an interface. It leads to a cumbersome and unreadable code that is difficult to debug to and to Namely, if you want to integrate an encoder in a complex project involving a number of sensors and actuators, you need to learn how to write a structured and object-oriented C++ code. In this tutorial, we will teach you precisely that. That is, how to write reusable, disciplined, and structured C++ code for interfacing encoders. As you will see later on, the main challenge was how to properly write a C++ class that will properly set the interrupt functions necessary to interface the encoders. In the next several tutorials, we will explain how to use the developed interface to develop a complete servo control system for DC motors. We are using a low cost DC motor with an integrated Hall effect sensor. There are a number of versions and designs of a DC motor and encoder. You can find these motors on Amazon, Ebay, DigiKey, and similar online stores. In this particular, in this tutorial, we are using a low cost motor with the product name: GA37-520 with AB-phase incremental Hall encoder. Since this is a low-cost product that does not come with a detailed document describing the specifications of the encoder, we only have basic information about this encoder. The main thing is the wiring diagram that we will explain later. All other parameters can be experimentally determined.

Comment