<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Issues with Stepmotor Driver Module v1.1 (HR8825) Using M5Stack]]></title><description><![CDATA[<h3>Subject: Issues with Stepper Motor Control Using M5Stack and Stepmotor Driver Module</h3>
<h3>Description:</h3>
<p dir="auto">Hello,</p>
<p dir="auto">I am reaching out to seek your assistance with an issue I am experiencing with the M5Stack and the Stepmotor Driver Module. Here is a detailed description of the hardware and steps I have taken so far:</p>
<h4>Hardware:</h4>
<p dir="auto"><em>- M5Stack Core2</em><br />
<em>- Stepmotor Driver Module v1.1 (HR8825)</em><br />
<em>- NEMA 17 stepper motor</em></p>
<h4>Issue Description:</h4>
<p dir="auto">I successfully tested the stepper motor using MicroPython, but due to the limited functionality and hidden features in the MicroPython library, I decided to switch to PlatformIO with Arduino. Unfortunately, I have been unable to get the example code from your GitHub repository (<a href="https://github.com/m5stack/M5Module-Stepmotor" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/m5stack/M5Module-Stepmotor</a>) to work as expected.</p>
<h4>Steps and Code:</h4>
<ol>
<li>
<p dir="auto"><strong>MicroPython Code (Working):</strong><br />
<em>The MicroPython code initializes the stepper motor and successfully controls its movements.</em><br />
<em>Here is a snippet of the working MicroPython code:</em></p>
<pre><code>from m5stack import *
import module

Z = 2

stepmotor = module.get(module.STEPMOTORDRIVER)  # Use single argument
stepmotor.initDevice(0x27)
stepmotor.setStepPulse(500, Z)
stepmotor.setStepDir(Z, 0)
# Loop to toggle motor on and off
while True:
    stepmotor.enableMotor(0)
    time.sleep(100)
    stepmotor.enableMotor(1)
</code></pre>
</li>
<li>
<p dir="auto"><strong>Arduino Code (Not Working):</strong><br />
I tried to follow the provided example for Arduino but without success. I extended the AccelStepper class to add the methods from the "Module_Stepmotor.h" library.</p>
<p dir="auto">I use the following pins for the Z motor:</p>
<pre><code>#define STEP_PIN 15
#define DIR_PIN 0
#define MOTOR_ID 2
</code></pre>
<p dir="auto">Here is my current implementation (with lvgl GUI):</p>
<pre><code>// main.cpp

#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;unistd.h&gt;
#include "lvgl_port_m5stack.hpp"
#include "StepperMotor.h"

#define STEP_PIN 15
#define DIR_PIN 0
#define MOTOR_ID 2

StepperMotor stepperMotor(STEP_PIN, DIR_PIN, MOTOR_ID);  // Initialize stepper motor

extern void user_app(void);
M5GFX gfx;

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

    gfx.init();
    lvgl_port_init(gfx);

    stepperMotor.initMotor();

    Serial.println("Setup done");

    user_app();
}

void loop(void) {
    delay(10);

    lv_timer_handler();  // Use lv_task_handler() if lv_timer_handler() is not available
    delay(5);  // Adjust delay as needed

    if (stepperMotor.distanceToGo() != 0) {
        // Print current and target positions
        Serial.print("Current Position: ");
        Serial.print(stepperMotor.currentPosition());
        Serial.print(", Target Position: ");
        Serial.println(stepperMotor.targetPosition());

        // Execute the motor movement
        stepperMotor.run();
    }
}
</code></pre>
<pre><code class="language-cpp">// StepperMotor.cpp

#include "StepperMotor.h"
#include &lt;Wire.h&gt;

StepperMotor::StepperMotor(int step_pin, int dir_pin, uint8_t motor_id)
    : AccelStepper(AccelStepper::DRIVER, step_pin, dir_pin), motorID(motor_id) {
    setCurrentPosition(0);
    setMaxSpeed(500);
    setAcceleration(500);
}

void StepperMotor::initMotor() {
    Wire.begin(21, 22, 400000UL); // Start I2C bus
    driver.init(Wire, 0x27); // Initialize the driver with the I2C bus and address 0x27
    driver.resetMotor(motorID, 0); // Reset the motor
    setMicrostepResolution(Module_Stepmotor::kMicrosteps16);
    delay(50);
    driver.enableMotor(1);
}

void StepperMotor::enableMotor(bool enable) {
    driver.enableMotor(enable ? 1 : 0);
}

void StepperMotor::setMicrostepResolution(Module_Stepmotor::MicrostepResolution_t resolution) {
    driver.setMicrostepResolution(resolution);
}

void StepperMotor::resetMotor() {
    driver.resetMotor(motorID, 0); // Reset the motor
}
</code></pre>
</li>
</ol>
<h4>Observed Behavior:</h4>
<p dir="auto">When using <code>driver.resetMotor(motorID, 1)</code>, the motor makes a whining noise and is locked (cannot be turned by hand).<br />
If I use <code>driver.enableMotor(0)</code>, I still need to use <code>driver.resetMotor(motorID, 0)</code> to unlock the motor.<br />
The motor does not respond to movement commands as expected.</p>
<h3>Request:</h3>
<p dir="auto">I couldn't find detailed documentation for the library. Could you please provide it? Do you see any errors in my code, or is the library incomplete? I would appreciate your assistance.</p>
<p dir="auto">The fact that the MicroPython code works but the Arduino code does not raises questions for me. Why are the libraries hidden? If the implementation of the library in MicroPython were open, I could have examined it further.</p>
<p dir="auto">Best regards,</p>
<p dir="auto">Nicolas</p>
]]></description><link>https://community.m5stack.com/topic/6601/issues-with-stepmotor-driver-module-v1-1-hr8825-using-m5stack</link><generator>RSS for Node</generator><lastBuildDate>Fri, 06 Mar 2026 14:07:29 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/6601.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 01 Jul 2024 16:55:25 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Issues with Stepmotor Driver Module v1.1 (HR8825) Using M5Stack on Fri, 31 Jan 2025 08:39:45 GMT]]></title><description><![CDATA[<p dir="auto">Kind of an old thread but I wanted to respond since it may help others who are trying to get this module to work, not much out there on the Arduino coding side.</p>
<p dir="auto">I believe the issue might be the pin assignment for step and dir, it's actually printed on the PCB. For the Core2 X, Y, Z step = 13, 27, 2 and dir = 14, 19, 0 respectively. So I'm not sure why STEP_PIN is set to 15, maybe this is the legacy Core?</p>
<p dir="auto">I used the same referenced Stepmotor code (<a href="https://github.com/m5stack/M5Module-Stepmotor" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/m5stack/M5Module-Stepmotor</a>) and did get it working eventually. Here is some very basic example code that may help:</p>
<pre><code>#include &lt;M5Unified.h&gt;
#include "Module_Stepmotor.h"

// change to CORE2 if using Core2
#define CORE_S3

#ifdef CORE_S3
    static const int X_STEP_PIN = 18;
    static const int X_DIR_PIN = 17;
    static const int Y_STEP_PIN = 6;
    static const int Y_DIR_PIN = 7;
    static const int Z_STEP_PIN = 13;
    static const int Z_DIR_PIN = 0;
    
    static const int SDA_PIN = 12;
    static const int SCL_PIN = 11;
#elif defined CORE2
    static const int X_STEP_PIN = 13;
    static const int X_DIR_PIN = 14;
    static const int Y_STEP_PIN = 27;
    static const int Y_DIR_PIN = 19;
    static const int Z_STEP_PIN = 2; // Not sure about this one
    static const int Z_DIR_PIN = 0;

    static const int SDA_PIN = 21;
    static const int SCL_PIN = 22;
#endif

static Module_Stepmotor driver;

void setup() {
    Wire.begin(SDA_PIN, SCL_PIN, 400000UL);

    driver.init(Wire, 0x27);
    driver.resetMotor(0, 0);
    driver.resetMotor(1, 0);
    driver.resetMotor(2, 0);
    driver.enableMotor(1);

    // PWM, sets the speed of the stepper motor, adjust accordingly
    ledcSetup(0, 500, 8);

    // XYZ step
    ledcAttachPin(X_STEP_PIN, 0);
    ledcAttachPin(Y_STEP_PIN, 0);
    ledcAttachPin(Z_STEP_PIN, 0);

    ledcWrite(0, 127);

    // XYZ dir
    pinMode(X_DIR_PIN, OUTPUT);
    digitalWrite(X_DIR_PIN, 1);
    pinMode(Y_DIR_PIN, OUTPUT);
    digitalWrite(Y_DIR_PIN, 1);
    pinMode(Z_DIR_PIN, OUTPUT);
    digitalWrite(Z_DIR_PIN, 1);
}

void loop() {
    digitalWrite(X_DIR_PIN, 0);
    delay(2000);
    digitalWrite(X_DIR_PIN, 1);
    delay(2000);
}
</code></pre>
]]></description><link>https://community.m5stack.com/post/28073</link><guid isPermaLink="true">https://community.m5stack.com/post/28073</guid><dc:creator><![CDATA[vuhn88]]></dc:creator><pubDate>Fri, 31 Jan 2025 08:39:45 GMT</pubDate></item><item><title><![CDATA[Reply to Issues with Stepmotor Driver Module v1.1 (HR8825) Using M5Stack on Wed, 31 Jul 2024 04:01:34 GMT]]></title><description><![CDATA[<p dir="auto"><a class="mention plugin-mentions-user plugin-mentions-a" href="https://community.m5stack.com/uid/139835">@pntnut</a> Hi, the M039 and M039-V11 registers are compatible(all most), so you can still use the M039 lib to drive the StepMotor Driver 1.1 module</p>
<p dir="auto"><a href="https://github.com/m5stack/M5Module-Stepmotor" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/m5stack/M5Module-Stepmotor</a></p>
]]></description><link>https://community.m5stack.com/post/25951</link><guid isPermaLink="true">https://community.m5stack.com/post/25951</guid><dc:creator><![CDATA[Sean xiang]]></dc:creator><pubDate>Wed, 31 Jul 2024 04:01:34 GMT</pubDate></item><item><title><![CDATA[Reply to Issues with Stepmotor Driver Module v1.1 (HR8825) Using M5Stack on Tue, 23 Jul 2024 08:37:49 GMT]]></title><description><![CDATA[<p dir="auto">Another thing I just realized: The Arduino-example code is for the old module (M039, not M039-V11).</p>
]]></description><link>https://community.m5stack.com/post/25906</link><guid isPermaLink="true">https://community.m5stack.com/post/25906</guid><dc:creator><![CDATA[pntnut]]></dc:creator><pubDate>Tue, 23 Jul 2024 08:37:49 GMT</pubDate></item><item><title><![CDATA[Reply to Issues with Stepmotor Driver Module v1.1 (HR8825) Using M5Stack on Mon, 22 Jul 2024 22:06:28 GMT]]></title><description><![CDATA[<p dir="auto">I have exactly the same problem. Were you able to figure it out?</p>
]]></description><link>https://community.m5stack.com/post/25905</link><guid isPermaLink="true">https://community.m5stack.com/post/25905</guid><dc:creator><![CDATA[pntnut]]></dc:creator><pubDate>Mon, 22 Jul 2024 22:06:28 GMT</pubDate></item></channel></rss>