Uncategorized

Use M5Stack core to control potentiometer-based servo motors


At its core, M5Stack is a modular, stackable and programmable development module designed for building IoT projects and creating prototypes quickly and easily. This module is based on the ESP32 microcontroller and is equipped with various sensors, inputs, outputs and a color liquid crystal display (LCD). In addition, the M5Stack core package is a rectangular module with dimensions of 54 x 54 x 18 mm and has a 2-inch thin film transistor (TFT) LCD.

As mentioned, the device has multiple input and output options, such as three buttons, a speaker, and a microSD card slot. Figure 1 shows the M5Stack core.

M5Stack core.

figure 1. M5Stack core.Image provided by M5Stack

One of the most unique features at the heart of M5Stack is its modular design ecosystem. This module can be easily stacked with other M5Stack modules, allowing users to add additional functionality and expand the functionality of their projects. The M5Stack modular ecosystem has a variety of available modules, such as camera, GPS and battery module units.

In this article, we will explore the angle sensor and servo motor unit with M5Stack core. The result of this implementation project was the construction of a potentiometer-based servo motor controller with an M5Stack core TFT display.

Project Overview – Understanding Human-Computer Interaction (HCI)

The servo motor controller project based on the M5Stack core potentiometer will demonstrate the versatility and ease of use of building human-computer interaction (HCI) devices using off-the-shelf electronics and software. The purpose of this project is to illustrate how to use a small controller based on ESP32 to realize human-computer interaction concepts such as human-computer interaction. The ESP32-based platform will conduct human-machine computing interactions with electromechanical objects. This project will let readers understand how to use the M5Stack core TFT LCD display and obtain interactive data from electromechanical systems. This data can be used to explore machine learning concepts for cyber-physical systems (CPS) using programming languages ​​such as Python, PyTorch, and Pandas.

As the key technology source for this project, it is recommended to refer to the M5Stack electronic blueprint book. More specifically, Chapter 2, “M5Stack Unit in Practice,” provides technical insights into the electronic circuitry and settings of the ESP32 modular controller and programmable sensing and control unit. The book also includes practical projects and interactive quizzes to engage readers. Basically, you can think of this project as an extension of this book; therefore, detailed software setup instructions will not be explained in this project.

BOM of servo motor control based on M5Stack potentiometer

Below is a list of electronic parts to build and assist in exploring a servo motor controller project based on the M5Stack Core Potentiometer.

Bill of Materials (BOM):

The M5Go IoT Starter Kit features various sensors, jumpers, RGB LEDs, and USB C cables. Angle sensor included in the kit. In this project, a 10 KΩ potentiometer and a 1 KΩ resistor will be used to build a homemade version of the M5Stack angle sensor. Chapter 2 details the electrical wiring of electronic parts on a solderless breadboard and connecting homemade sensors to the M5Stack core controller.

Configuring the M5Stack core

The overall concept of this project is to demonstrate the prototyping of a small servo motor controller using the M5Stack core as the main ESP32 embedded platform. The initial setup for this project is to add an external potentiometer to control the servo motor. The potentiometer will provide rotation information to the M5Stack core. The M5Stack core then converts the analog voltage voltage data into an equivalent pulse width modulation (PWM) control signal to operate the wired servo motor. Figure 2 shows the prototype system block diagram.

Block diagram of servo motor control system based on M5Stack core potentiometer.

figure 2. Block diagram of servo motor control system based on M5Stack core potentiometer.

Next, connect the potentiometer circuit to the ESP32 microcontroller at the heart of the M5Stack using the same internal electronics as the angle sensor. The M5Stack angle sensor is composed of a 1 KΩ resistor and a 10 KΩ potentiometer in series. This circuit configuration provides a voltage divider function that allows a range of discrete analog signal values ​​to appear on designated ESP32 analog-to-digital general-purpose input and output (GPIO) pins. Figure 3 shows the M5Stack angle sensor.

M5Stack angle sensor unit.

image 3. M5Stack angle sensor unit.Image provided by M5Stack

Additionally, this circuit approach allows the potentiometer to have a maximum output voltage of +3.3V relative to ground, and the ESP32 microcontroller’s GPIO pins comply with the +3.3V standard. Therefore, the maximum output voltage of the voltage divider circuit +3.3V will not damage the ESP32 single chip. The electronic circuit schematic diagram of the homemade angle sensor is shown in Figure 4.

Homemade angle sensor electronic circuit schematic.

Figure 4. Homemade angle sensor electronic circuit schematic.

Note that the J1 reference designator represents the four-pin female connector soldered to the angle sensor PCB.

From here, you can connect the electronic circuitry on a solderless breadboard to connect the homemade angle sensor to the M5Stack core, using the electrical wiring diagram shown in Figure 5 as a reference.

Homemade angle sensor without soldering breadboard diagram.

Figure 5. Homemade angle sensor without soldering breadboard diagram.

Keep in mind that the TFT LCD layout at the heart of the M5Stack can be designed using UiFlow software – we’ll cover this in the next section.

Next, you will use Dupont wire to build an extension harness between the M5Stack core and the homemade angle sensor solderless breadboard circuit. Insert the three DuPont wires (shown in Figure 5) into the white four-pin female connector to electrically connect the circuit to the M5Stack core controller. Figure 6 illustrates this electrical wiring interface connection and attachment method.

Solderless breadboard wiring of the potentiometer to the M5Stack core.

Figure 6. Solderless breadboard wiring of the potentiometer to the M5Stack core.

UiFlow software introduction

For this project, I used a program called UiFlow. UiFlow is a software development platform designed to simplify the programming and prototyping process of M5Stack products for controllers, modules, sensors and units. The software provides a graphical user interface (GUI) for programming the M5Stack core ESP32 microcontroller. Developers can drag and drop blocks of code and create logic code to program ESP32 microcontrollers. UiFlow allows coding using an online editor or a desktop downloadable package.

The UiFlow online editor is available from the M5Stack website at the following URL. There is also a desktop version for Windows, Apple, and Linux-based computers.

The layout design of the M5Stack core TFT LCD that displays potentiometer rotation data is shown in Figure 7.

Configure M5Stack Core TFT LCD to display potentiometer angle information.

Figure 7. Configure M5Stack Core TFT LCD to display potentiometer angle information.

To learn more about UiFlow, you can go to Chapter 2 of the M5Stack Electronic Blue Book for more information.

Display potentiometer reading

After connecting the potentiometer to the M5Stack core, software is required to display the rotation value of the electrical component. The UiFlow software will be used to display the angle of rotation of the potentiometer in degrees, and the code block consists of three main operations of the servo motor controller.

Guidance code block features include:

  • Read the raw data of the potentiometer into a variable
  • Provides appropriate variable scaling factors to ensure correct angular display
  • Display angle in degrees

The UiFlow code block is shown in Figure 8.

UiFlow potentiometer angle display code block.

Figure 8. UiFlow potentiometer angle display code block.

In addition to code blocks, the code block palette also includes servo and angle sensor units. These units will have a new set of code blocks added to allow for correct operation of these devices throughout the controller prototype. As shown in Figure 8, “servo_0, servo_0 rotation angle” and “get angle_0 value” are new unit instructions added to the code block palette. You can include these code blocks by selecting the Units plus button. Selecting servo and angle units from the equipment list will add the required blocks of code to the palette to complete the code build for the project controller. By selecting the RUN button on the software IDE control panel, the UiFlow code block will be executed on the M5Stack core.

Use UiFlow to control servo motors

In addition to displaying the angle of rotation of the potentiometer, the UiFlow code block (shown in Figure 8) also controls the servo motor. Connecting the servo motor to the M5Stack core requires the same electrical wiring techniques as the potentiometer. A partial electronic circuit schematic is shown in Figure 9, illustrating the electrical wiring of the servo motor connected to the GPIO13 pin of the M5Stack core ESP32.

Partial electronic circuit schematic: servo motor attached to M5Stack core ESP32 microcontroller.

Figure 9. Partial electronic circuit schematic: servo motor attached to M5Stack core ESP32 microcontroller.

The J2_A connector on the electronic schematic represents the A port on the M5Stack core. The J2_B reference designator represents the wire jumper harness pin that plugs into the servo motor’s black three-pin female connector.

The electrical wiring between M5Stack Core and servo motor is shown in Figure 10.

The servo motors are electrically connected to the M5Stack core.

Figure 10. The servo motors are electrically connected to the M5Stack core.

The completed prototype of the servo motor controller based on the M5Stack core potentiometer is shown in Figure 11.

Finally, a servo motor controller prototype based on M5Stack core potentiometer was built.

Figure 11. Finally, a servo motor controller prototype based on M5Stack core potentiometer was built.

As a final reference for this project, Figure 12 shows the complete electronic circuit schematic of the M5Stack core potentiometer-based servo motor controller.

Schematic diagram of the electronic circuit of the servo motor controller based on the M5Stack core potentiometer.

Figure 12. Schematic diagram of the electronic circuit of the servo motor controller based on the M5Stack core potentiometer.

Adjusting the potentiometer will cause the servo motor to rotate to the angular position displayed on the TFT LCD at the heart of the M5Stack. Since the rotational scan range of the servo motor is 0°–180°, the TFT LCD will allow the use of a potentiometer to dial in such angles and display accordingly. A brief video clip is provided showing the operation of the servo motor controller. To see the prototype servo motor controller in action, you can watch the video here or watch it below.

Prototyping made easy

The purpose of this project is to demonstrate a unique and innovative approach to creating an HCI servo motor controller using the ESP32 platform. At its core, M5Stack is an ESP32-based modular IoT ecosystem that allows for easy prototyping of various CPS devices using off-the-shelf electronic components and units. This project illustrates how Visual Programming Language (VPL) can help developers quickly create functional prototypes in minutes. The M5Stack Core’s small form factor enables the development and deployment of small wearable controllers and human-machine interfaces (HMI) in areas such as automation, robotics, smart home and education technology development.



Source link

LEAVE A RESPONSE

Your email address will not be published. Required fields are marked *