1. Do not share user accounts! Any account that is shared by another person will be blocked and closed. This means: we will close not only the account that is shared, but also the main account of the user who uses another person's account. We have the ability to detect account sharing, so please do not try to cheat the system. This action will take place on 04/18/2023. Read all forum rules.
    Dismiss Notice
  2. For downloading SimTools plugins you need a Download Package. Get it with virtual coins that you receive for forum activity or Buy Download Package - We have a zero Spam tolerance so read our forum rules first.

    Buy Now a Download Plan!
  3. Do not try to cheat our system and do not post an unnecessary amount of useless posts only to earn credits here. We have a zero spam tolerance policy and this will cause a ban of your user account. Otherwise we wish you a pleasant stay here! Read the forum rules
  4. We have a few rules which you need to read and accept before posting anything here! Following these rules will keep the forum clean and your stay pleasant. Do not follow these rules can lead to permanent exclusion from this website: Read the forum rules.
    Are you a company? Read our company rules

ESP32 SMC3

Discussion in 'DIY Motion Simulator Projects' started by azizalfirdaus, May 23, 2025.

Tags:
  1. azizalfirdaus

    azizalfirdaus New Member

    Joined:
    Mar 29, 2025
    Messages:
    6
    Balance:
    3Coins
    Ratings:
    +6 / 0 / -0
    My Motion Simulator:
    3DOF, DC motor, Arduino
    Hello I'm from Indonesia and i excited to join this community and share my journey with motion simulation. I'm relatively new to sim racing but have been diving deep into the technical side of things.

    About 4 months ago, I purchased a 2DOF platform + Traction Loss system from my friend . I have to be honest - I'm terrible with mechanical stuff! While my friend could fabricate alumunium profile and adjust DC motre with ease, I struggled with even basic mechanical adjustments.

    The platform came with the classic Arduino UNO + SMC3 setup, and initially, everything worked great with SMC3Utils. However, as I started diving deeper into tuning and understanding the system, I began to notice some limitations of the UNO platform:
    This got me thinking: "What if we could run SMC3 on ESP32?" The ESP32 have 240MHz dual-core processor vs UNO's 16MHz, 4MB flash memory vs UNO's 32KB

    I am not good at coding, I can only make the LED turn off or on, LOL. So thanks to Claude AI, I understand a little more about what C++ is.
    But here's where the 3-month journey of frustration began...

    I started by trying to port the SMC3 code directly, thinking "ESP32 is just a faster Arduino", and immediately asked Claude AI to convert the original code, but I immediately ran into a lot of problems:
    • SMC3Utils couldn't communicate properly
    • Feedback logic is different because esp32 uses 3.3v
    • PWM signals were wrong
    • Timing was completely off
    • Direct timer manipulation: Too complex and unreliable
    • Motors behaved erratically
    • Legacy analogWrite(): Limited functionality
    • LEDC PWM: Too different from UNO's timer behavior
    • MCPWM API: Powerful but initially confusing
    The breakthrough came when I stopped trying to make ESP32 "better" than UNO and focused on making it behaviorally identical. Key realizations:
    1. Preserve UNO's 0-1023 ADC range by mapping ESP32's 12-bit to 10-bit
    2. Maintain exact 250µs loop timing that SMC3 depends on
    3. Emulate UNO timer limitations rather than "improving" them
    4. Focus on behavioral compatibility, not hardware similarity
    The Final Solution
    After 3 months of experimentation, I achieved 100% behavioral compatibility:
    • SMC3Utils works identically to UNO version
    • All existing parameter sets transfer directly
    • Same PID response characteristics
    • Drop-in replacement capability
    I now have a working ESP32 SMC3 firmware that maintains full backward compatibility. And I've only been able to test it on my specific setup (Cytron drivers in the new MODE_CYTRON).

    I need your help, please test this firmware in mode 1 or 2 and please give me feedback. or maybe you want to try to develop this firmware yourself with AI then discuss it here, because it seems like it still needs a lot of features like filters, anti-haunting, soft start, etc. 107402 2.png 3.png
  2. azizalfirdaus

    azizalfirdaus New Member

    Joined:
    Mar 29, 2025
    Messages:
    6
    Balance:
    3Coins
    Ratings:
    +6 / 0 / -0
    My Motion Simulator:
    3DOF, DC motor, Arduino
    1.png

    Attached Files:

    • Winner Winner x 4
    • Useful Useful x 1
  3. Thick8

    Thick8 Just some random guy

    Joined:
    Jan 1, 2025
    Messages:
    54
    Location:
    South Carolina USA
    Balance:
    288Coins
    Ratings:
    +16 / 0 / -0
    My Motion Simulator:
    3DOF, DC motor
    Can an ESP32 drive 3 or 6 motors at 20Khz? Or does it suffer the same issues as an Uno?
  4. Joe Cortexian

    Joe Cortexian Active Member Gold Contributor

    Joined:
    Sep 8, 2021
    Messages:
    160
    Balance:
    965Coins
    Ratings:
    +33 / 0 / -0
    My Motion Simulator:
    3DOF
    The bulk of the time in the PID loop is spent on analog input processing. Additionally, an Arduino Uno lacks sufficient pins to handle six axes, so you would need a Mega (or similar microcontroller) to provide enough I/O for six motors. This is why using two Unos for six axes is a practical solution.

    Regarding the 4 kHz loop speed, consider what this means. Assuming a geared motor (not a lead screw), let’s estimate a top speed of 60 RPM, which translates to 1024 counts per revolution × 60 revolutions per minute ÷ 60 seconds = 1024 counts per second. According to the Nyquist-Shannon sampling theorem, to accurately reconstruct a signal, you should sample at least twice its highest frequency, or 2 kHz in this case. A 4 kHz sampling rate is sufficient even if the motor runs at 120 RPM (2048 counts per second), which is likely beyond its typical operating range. Thus, a 4 kHz PID loop provides ample performance for this application.

    This is not to say that the SMC code doesn’t have issues. A bug in the PID calculation was recently resolved and if you don’t have that fix you are missing out.
  5. Thick8

    Thick8 Just some random guy

    Joined:
    Jan 1, 2025
    Messages:
    54
    Location:
    South Carolina USA
    Balance:
    288Coins
    Ratings:
    +16 / 0 / -0
    My Motion Simulator:
    3DOF, DC motor
    Thank you. This information is very helpful. So the real consideration for the PWM is noise. My wife can hear the motor whine up to 16Khz so I run them at 25Khz. It would be nice to have all 6 run at that speed on 1 board. I've ordered an ESP32 board to test this ino file on my P3 rig.
  6. Gadget999

    Gadget999 Well-Known Member

    Joined:
    Dec 27, 2015
    Messages:
    1,957
    Location:
    London
    Balance:
    11,971Coins
    Ratings:
    +484 / 10 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino, 6DOF
    it uno is fast enough for reading a potentiometer
    just use 2 or 3 for more axis
    cheap and simple
  7. azizalfirdaus

    azizalfirdaus New Member

    Joined:
    Mar 29, 2025
    Messages:
    6
    Balance:
    3Coins
    Ratings:
    +6 / 0 / -0
    My Motion Simulator:
    3DOF, DC motor, Arduino
    With a lot of resources from ESP32 I'm developing the auto tune feature to setup all parameters in smc3, so we don't have to bother to set it, whatever your platform configuration should be able to set it automatically, but this is not perfect wait for it to be really stable then I will share it here

    • Like Like x 1
  8. azizalfirdaus

    azizalfirdaus New Member

    Joined:
    Mar 29, 2025
    Messages:
    6
    Balance:
    3Coins
    Ratings:
    +6 / 0 / -0
    My Motion Simulator:
    3DOF, DC motor, Arduino
    Look at the end of the video when I close and reopen smc3utils, all parameters have changed
  9. Joe Cortexian

    Joe Cortexian Active Member Gold Contributor

    Joined:
    Sep 8, 2021
    Messages:
    160
    Balance:
    965Coins
    Ratings:
    +33 / 0 / -0
    My Motion Simulator:
    3DOF
    . Looks promising. Is there a mathematical basis for this or does it basically search for the parameters like an optometrist looking for the best prescription ?

    Maybe stick on GitHub to share it.
  10. Thick8

    Thick8 Just some random guy

    Joined:
    Jan 1, 2025
    Messages:
    54
    Location:
    South Carolina USA
    Balance:
    288Coins
    Ratings:
    +16 / 0 / -0
    My Motion Simulator:
    3DOF, DC motor
    I've downloaded your sketch to an Arduino Nano. Using a DR P3 rig with IBT-2 boards. So mode 2. I need to wire it into the control box. May be able to do it today. I'll let you know how it works. HAve you tried using Klaus Schmidinger's version 2.1 with parking and soft stop as the base for you sketch?

    EDIT: SMC3 is not seeing the Nano. I used USBDeview to verify the board is recognized. When I plug it in, USBDview shows that it's connected for a moment, then it disconnects. Thoughts?

    Attached Files:

    Last edited: Jun 15, 2025 at 19:54
  11. Joe Cortexian

    Joe Cortexian Active Member Gold Contributor

    Joined:
    Sep 8, 2021
    Messages:
    160
    Balance:
    965Coins
    Ratings:
    +33 / 0 / -0
    My Motion Simulator:
    3DOF
    Overview

    The Arduino Nano ESP32 and the classic Arduino Nano are distinct boards with different capabilities. The Nano ESP32 combines the familiar Nano form factor with the powerful ESP32-S3 chip, offering Wi-Fi and Bluetooth capabilities, more processing power, and memory compared to the classic Nano. However, the classic Nano, based on the ATmega328P, remains a simpler, more power-efficient option for basic projects and educational purposes.

    Attached Files:

  12. Thick8

    Thick8 Just some random guy

    Joined:
    Jan 1, 2025
    Messages:
    54
    Location:
    South Carolina USA
    Balance:
    288Coins
    Ratings:
    +16 / 0 / -0
    My Motion Simulator:
    3DOF, DC motor
    Oops. Guess I should have specified that I bought the Nano ESP32.
  13. azizalfirdaus

    azizalfirdaus New Member

    Joined:
    Mar 29, 2025
    Messages:
    6
    Balance:
    3Coins
    Ratings:
    +6 / 0 / -0
    My Motion Simulator:
    3DOF, DC motor, Arduino
    I am adding some features from the members here, wait until I am sure this is really stable. upload_2025-6-16_20-26-33.png
    Last edited: Jun 16, 2025 at 15:26
  14. azizalfirdaus

    azizalfirdaus New Member

    Joined:
    Mar 29, 2025
    Messages:
    6
    Balance:
    3Coins
    Ratings:
    +6 / 0 / -0
    My Motion Simulator:
    3DOF, DC motor, Arduino
    I don't have a github account, I just try to explore Claude AI, so I determine the work logic flow and Claude AI is the one who completely writes this code, then I correct it

    This is my auto tuning algorithm, so basically it analyzes the relationship between the feedback targets by defining parameter limits such as response time, overshoot, Oscillation Count, PWM Utilization Analysis.

    This is Decision Logic Flow
    Step Response Test => Calculate Metrics (Response Time, Overshoot, Oscillations, Precision) => Performance Scoring (Speed, Smoothness, Stability, Precision) => Strategy Selection (Conservative vs Aggressive) => Parameter Adjustment (Within Adaptive Bounds) => Validation & Relationship Check => Apply to Motor & Send to SMC3Utils

    Strategy Selection (Conservative vs Aggressive) has not been implemented well in this code.

    Attached Files: