### PlatformIO Example Execution Source: https://github.com/gin66/fastaccelstepper/blob/master/README.md Demonstrates how to build and upload an example project using PlatformIO on Linux. Ensure the correct upload port is specified. ```bash ci/build-platformio.sh ``` ```bash cd pio_dirs/StepperDemo pio run -e avr --target upload --upload-port /dev/ttyUSB0 ``` -------------------------------- ### I2S Direct Stepper Hardware Setup Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/Esp32StepperDemo/DESIGN.md Example wiring for a stepper motor using the I2S interface on an ESP32 for step signals. Includes GPIO for direction and enable pins. ```text ESP32 GPIO15 ──► I2S Data (to stepper driver step input) ESP32 GPIO18 ──► Dir Pin (GPIO) ESP32 GPIO26 ──► Enable Pin (GPIO) ``` -------------------------------- ### Basic Stepper Motor Control Example Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/doc/FastAccelStepper_API.md A fundamental example demonstrating how to initialize the FastAccelStepper engine, connect a stepper motor, configure its pins, set speed and acceleration, and move the stepper to specified positions. ```cpp FastAccelStepperEngine engine = FastAccelStepperEngine(); FastAccelStepper *stepper = NULL; #define dirPinStepper 5 #define enablePinStepper 6 #define stepPinStepper 9 void setup() { engine.init(); stepper = engine.stepperConnectToPin(stepPinStepper); if (stepper) { stepper->setDirectionPin(dirPinStepper); stepper->setEnablePin(enablePinStepper); stepper->setAutoEnable(true); stepper->setSpeedInHz(500); stepper->setAcceleration(100); stepper->moveTo(1000, true); stepper->moveTo(0, true); } } void loop() {} ``` -------------------------------- ### Basic RMT Stepper Hardware Setup Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/Esp32StepperDemo/DESIGN.md Example wiring for a basic stepper motor using the RMT peripheral on an ESP32. Connects step, direction, and enable pins. ```text ESP32 GPIO15 ──► Step Pin ESP32 GPIO18 ──► Dir Pin ESP32 GPIO26 ──► Enable Pin (active low) ``` -------------------------------- ### I2S MUX with 74HC595 Hardware Setup Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/Esp32StepperDemo/DESIGN.md Example wiring for controlling multiple steppers using an I2S interface and a 74HC595 shift register for multiplexing step and direction signals. ```text ESP32 GPIO32 ──► 74HC595 Data (DS) ESP32 GPIO33 ──► 74HC595 Clock (SH_CP) ESP32 GPIO14 ──► 74HC595 Latch (ST_CP) 74HC595 Outputs: Q0 ──► Stepper 0 Step Q1 ──► Stepper 0 Dir Q2 ──► Stepper 0 Enable Q3 ──► Stepper 1 Step Q4 ──► Stepper 1 Dir Q5 ──► Stepper 1 Enable ... ``` -------------------------------- ### Per-Architecture StepperQueue (AVR Example) Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/doc/ai_improvements/ROADMAP.md Example of a per-architecture StepperQueue class (for AVR) that inherits from StepperQueueBase. It includes architecture-specific hardware fields and method implementations. ```cpp // pd_avr/avr_queue.h class StepperQueue : public StepperQueueBase { public: // AVR-specific hardware fields volatile bool _noMoreCommands; volatile bool _isRunning; enum channels channel; // Methods have access to both hardware fields (above) // and queue fields (inherited from StepperQueueBase) inline bool isRunning() const { return _isRunning; } inline bool isReadyForCommands() const { return true; } void startQueue(); // can freely access read_idx, entry[], channel void forceStop(); void init(uint8_t queue_num, uint8_t step_pin); // hardware setup only, called by tryAllocateQueue() void _initVars(); // zero fields + set defaults, no hardware access void connect(); void disconnect(); static bool isValidStepPin(uint8_t step_pin); }; ``` -------------------------------- ### setJumpStart Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/doc/FastAccelStepper_API.md Sets the starting ramp step for standstill starts. The actual start speed is calculated based on acceleration and jump step parameters, with different formulas for linear acceleration enabled or disabled. ```APIDOC ## setJumpStart ### Description Sets the ramp step to start from standstill. The start speed is calculated based on acceleration and jump step parameters, with different formulas for linear acceleration enabled or disabled. The new value is applied after calling move/moveTo/runForward/runBackward. ### Method ```cpp void setJumpStart(uint32_t jump_step) ``` ``` -------------------------------- ### ESP32 MCPWM Timer Start (Task Context) Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/doc/ai_improvements/todo_esp32_mcpwm_migration.md Starts an MCPWM timer in a task context using the IDF5 API. ```c mcpwm_timer_start_stop(timer, MCPWM_TIMER_START_NO_STOP) ``` -------------------------------- ### Stepper Command Example: 1ms Steps Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/doc/FastAccelStepper_API.md Illustrates creating a command for 3 steps with a 1ms interval between each step, moving in the positive direction. ```cpp // Example: ticks=TICKS_PER_S/1000, steps=3, count_up=true means: // 1. Direction pin set to HIGH // 2. One step is generated // 3. Exactly 1ms after the first step, the second step // 4. Exactly 1ms after the second step, the third step // 5. The stepper waits for 1ms // 6. The next command is processed ``` -------------------------------- ### StepperDemo Commands for Ramp Calculation Example Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/doc/ramp.md These commands are generated based on the calculation example for different acceleration times. They set the acceleration (A), maximum speed (V), and total steps (R) for the stepper motor. ```text M1 A3556 V281 R32000 M1 A2000 V250 R32000 M1 A1524 V218 R32000 M1 A1333 V188 R32000 M1 A1280 V156 R32000 ``` -------------------------------- ### High-Level Stepper Control with Acceleration Source: https://github.com/gin66/fastaccelstepper/blob/master/README.md This example demonstrates setting up and controlling a stepper motor using the high-level interface of the FastAccelStepper library. It includes setting speed, acceleration, and initiating a move. Ensure necessary pin definitions and library includes are present. ```Arduino #include "FastAccelStepper.h" #include "AVRStepperPins.h" // Only required for AVR controllers #define dirPinStepper 5 #define enablePinStepper 6 #define stepPinStepper 9 // If using an AVR device use the definitons provided in AVRStepperPins // stepPinStepper1A // // or even shorter (for 2560 the correct pin on the chosen timer is selected): // stepPinStepperA FastAccelStepperEngine engine = FastAccelStepperEngine(); FastAccelStepper *stepper = NULL; void setup() { engine.init(); stepper = engine.stepperConnectToPin(stepPinStepper); if (stepper) { stepper->setDirectionPin(dirPinStepper); stepper->setEnablePin(enablePinStepper); stepper->setAutoEnable(true); stepper->setSpeedInHz(500); // 500 steps/s stepper->setAcceleration(100); // 100 steps/s² stepper->move(1000); } } void loop() { } ``` -------------------------------- ### 32-bit Integer Wrap-around Example Source: https://github.com/gin66/fastaccelstepper/blob/master/README.md Demonstrates how 32-bit signed integer arithmetic can lead to unexpected results due to overflow when calculating large differences, affecting stepper motor direction. ```c++ 2.000.000.000 - (-2.000.000.000) = 4.000.000.000 But 4.000.000.000 interpreted as signed 32bit is -294.967.296 => count down, turn anti-clockwise Means the position will count: -2.000.000.000 -2.000.000.001 -2.000.000.002 : -2.147.483.647 -2.147.483.648 2.147.483.647 2.147.483.646 2.147.483.645 : 2.000.000.000 ``` -------------------------------- ### WebSocket Subscribe Command Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/Esp32StepperDemo/DESIGN.md Example of a WebSocket command sent from the client to the server to subscribe to specific topics. ```json { "command": "subscribe", "topics": ["steppers", "pins", "sequences"] } ``` -------------------------------- ### WebSocket Sequence Progress Event Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/Esp32StepperDemo/DESIGN.md Example of a WebSocket event reporting the progress of an executing sequence. ```json { "event": "sequence_progress", "data": { "id": 0, "step": 5, "total": 10, "status": "running" } } ``` -------------------------------- ### move and moveTo Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/doc/FastAccelStepper_API.md Starts or updates a move for a specified number of steps (relative) or to an absolute position. If the stepper is already running, the current move is updated. Reversing direction during an ongoing move is ignored. ```APIDOC ## move() and moveTo() ### Description Starts/moves the stepper for a specified number of steps (relative) or to an absolute position. If the stepper is already running, the current move is updated, including any updated acceleration/speed values. The move is relative to the target position of any ongoing move. If the new move/moveTo for an ongoing command would reverse the direction, the command is silently ignored. Return values are the MOVE_... constants. ### Methods ```cpp MoveResultCode move(int32_t move, bool blocking = false); MoveResultCode moveTo(int32_t position, bool blocking = false); ``` ``` -------------------------------- ### I2S MUX Mode Worked Example: Slot 5 Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/doc/esp32_i2s_driver.md Illustrates the calculation for setting or clearing a specific bit (Slot 5) in the I2S buffer using the I2S_MUX mode mapping logic. It shows how to derive the byte index and bit mask. ```c // Worked example: Slot 5 (6th output bit) // byte_in_frame = 5 / 8 = 0 → L_hi // bit_in_byte = 7 - (5 % 8) = 2 // bit_mask = 0x04 // To set: buf[frame_index * 4 + 0] |= 0x04; // To clear: buf[frame_index * 4 + 0] &= ~0x04; ``` -------------------------------- ### ESP32 PCNT ISR Handler Setup (IDF5) Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/doc/ai_improvements/todo_esp32_mcpwm_migration.md Configures a direct ISR for PCNT events in IDF5, bypassing the standard callback mechanism. This is used to address issues where hardware counter resets prevent watch point callbacks from firing. ```c esp_intr_alloc(ETS_PCNT_INTR_SOURCE, ESP_INTR_FLAG_SHARED | ESP_INTR_FLAG_IRAM, pcnt_isr_handler, NULL, NULL) ``` -------------------------------- ### FastAccelStepperEngine Initialization with CPU Core Pinning (ESP32) Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/doc/FastAccelStepper_API.md Illustrates how to initialize the FastAccelStepperEngine on a specific CPU core for multitasking systems like ESP32. This allows for better control over task scheduling. ```cpp void init(uint8_t cpu_core = 255); #else void init(); #endif ``` -------------------------------- ### FastAccelStepperEngine Initialization Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/doc/FastAccelStepper_API.md Demonstrates the basic initialization of the FastAccelStepperEngine. This step is crucial before any stepper instances can be created or controlled. ```cpp FastAccelStepperEngine engine = FastAccelStepperEngine(); ``` -------------------------------- ### Build and Upload Demo Application Source: https://github.com/gin66/fastaccelstepper/blob/master/README.md Build and upload the PlatformIO test application for the ESP32 I2S Mux driver. After uploading, monitor the device via serial console. ```bash cd extras/Esp32StepperDemo pio run -t upload && pio device monitor ``` -------------------------------- ### Set Jump Start Step Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/doc/FastAccelStepper_API.md Sets the ramp step from which the stepper will start from standstill. The actual start speed is calculated based on acceleration and jump step parameters. ```cpp void setJumpStart(uint32_t jump_step) { _rg.setJumpStart(jump_step); } ``` -------------------------------- ### Build for ESP32 with PlatformIO Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/Esp32StepperDemo/README.md Builds the project for the ESP32 target using a specific PlatformIO environment. Ensure the environment name matches your configuration. ```bash pio run -e esp32_pioarduino_V53_03_11 ``` -------------------------------- ### Running State Detection (Flag vs. Hardware) Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/doc/driver_architecture.md Implement `isRunning()` using a simple boolean flag or by checking hardware state, such as PIO status on Pico. ```cpp // Simple flag approach bool isRunning() { return _isRunning; } ``` ```cpp // Hardware state approach (Pico PIO example) bool isRunning() { return !pio_sm_is_tx_fifo_empty(pio, sm) || pio_sm_get_pc(pio, sm) != 0; } ``` -------------------------------- ### Build and Upload to ESP32 Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/Esp32StepperDemo/README.md Builds the project and uploads it to the ESP32 development board. This command is used after successful building. ```bash pio run -e esp32_pioarduino_V53_03_11 -t upload ``` -------------------------------- ### Get Acceleration Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/doc/FastAccelStepper_API.md Retrieves the configured acceleration value for the stepper motor. ```APIDOC ## Get Acceleration ### Description Retrieves the configured acceleration value for the stepper motor. ### Method - `uint32_t getAcceleration() const;` ``` -------------------------------- ### Project File Structure Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/Esp32StepperDemo/DESIGN.md Illustrates the directory structure of the Esp32StepperDemo project, organizing source code, web assets, and configuration files. ```text examples/Esp32StepperDemo/ ├── DESIGN.md # This document ├── Esp32StepperDemo.ino # Main Arduino sketch ├── src/ │ ├── config/ │ │ ├── ConfigManager.h │ │ ├── ConfigManager.cpp │ │ ├── SystemConfig.h │ │ ├── StepperConfig.h │ │ └── SequenceConfig.h │ ├── managers/ │ │ ├── GPIOPinManager.h │ │ ├── GPIOPinManager.cpp │ │ ├── I2SExpanderManager.h │ │ └── I2SExpanderManager.cpp │ ├── stepper/ │ │ ├── StepperController.h │ │ ├── StepperController.cpp │ │ ├── SequenceExecutor.h │ │ └── SequenceExecutor.cpp │ ├── web/ │ │ ├── WebServer.h │ │ ├── WebServer.cpp │ │ ├── RestAPIHandler.h │ │ ├── RestAPIHandler.cpp │ │ ├── WebSocketHandler.h │ │ ├── WebSocketHandler.cpp │ │ └── StatusBroadcaster.h │ └── utils/ │ ├── JsonHelpers.h │ └── PinHelpers.h ├── data/ │ ├── index.html # Main HTML file │ ├── css/ │ │ ├── style.css │ │ └── dashboard.css │ ├── js/ │ │ ├── app.js │ │ ├── api.js │ │ ├── websocket.js │ │ ├── stepper-control.js │ │ ├── pin-manager.js │ │ └── sequence-editor.js │ └── assets/ │ └── esp32-pinout.svg # Pin diagram └── platformio.ini # PlatformIO configuration ``` -------------------------------- ### moveTimed() Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/doc/FastAccelStepper_API.md Executes a timed move, bypassing the ramp generator for consecutive small moves with fixed speed. It takes the number of steps and duration in ticks as parameters. An optional boolean 'start' parameter controls whether the queue starts immediately. Returns a MoveTimedResultCode indicating success or failure. ```APIDOC ## moveTimed(int16_t steps, uint32_t duration, uint32_t* actual_duration, bool start = true) ### Description Executes a timed move, bypassing the ramp generator for consecutive small moves with fixed speed. It takes the number of steps and duration in ticks as parameters. An optional boolean 'start' parameter controls whether the queue starts immediately. Returns a MoveTimedResultCode indicating success or failure. The parameters are steps (which can be 0) and duration in ticks. steps=0 makes sense in order to keep the time running and not getting out of sync. Due to integer arithmetics the actual duration may be off by a small value. That's why the actual_duration in TICKS is returned. The application should consider this for the next runTimed move. The optional parameter is a boolean called start. This allows for the first invocation to not start the queue yet. This is for managing steppers in parallel. It allows to fill all steppers' queues and then kick it off by a call to `moveTimed(0,0,NULL,true)`. Successive invocations can keep true. In order to not have another lightweight ramp generator running in background interrupt, the expecation to the application is, that this function is frequently enough called without the queue being emptied. ### Return Codes - **MOVE_TIMED_BUSY (5)**: Queue too full to append this timed move. - **MOVE_TIMED_EMPTY (6)**: Queue ran empty, but move was appended. - **MOVE_TIMED_OK (0)**: Move successfully appended. - **MOVE_TIMED_TOO_LARGE_ERROR (-4)**: Move exceeds queue capacity. Queue depth is 32 (ESP32/SAM) or 16 (AVR). Each entry emits max 255 steps. For slow speeds (>65535 ticks/step), pauses are needed, reducing capacity. Recommendation: keep duration in the range of milliseconds. ### Signature ```cpp MoveTimedResultCode moveTimed(int16_t steps, uint32_t duration, uint32_t* actual_duration, bool start = true); ``` ``` -------------------------------- ### Get Current Acceleration Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/doc/FastAccelStepper_API.md Retrieves the actual current acceleration of the stepper motor. ```APIDOC ## Get Current Acceleration ### Description Retrieves the actual current acceleration of the stepper motor. ### Method - `int32_t getCurrentAcceleration() const;` ### Return Values - `= 0`: while idle or coasting - `> 0`: while speed is changing towards positive values - `< 0`: while speed is changing towards negative values ``` -------------------------------- ### Get Direction Pin Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/doc/FastAccelStepper_API.md Retrieves the configured GPIO pin number for direction signals. ```cpp uint8_t getDirectionPin() const { return _dirPin; } ``` -------------------------------- ### Stepper Configuration Migration (C++ to JSON) Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/Esp32StepperDemo/DESIGN.md Illustrates the conversion of a C++ stepper configuration structure to a JSON format for WebUI compatibility. Useful for migrating existing projects. ```cpp // Old StepperDemo config const struct stepper_config_s stepper_config[MAX_STEPPER] = { { step : 17, enable_low_active : 26, enable_high_active : PIN_UNDEFINED, direction : 18, dir_change_delay : 0, direction_high_count_up : true, auto_enable : true, on_delay_us : 50, off_delay_ms : 1000 } }; // Converted to WebUI config (JSON) { "steppers": [ { "id": 0, "name": "Stepper 0", "driver": "RMT", "step_pin": {"source": "GPIO", "pin": 17}, "dir_pin": {"source": "GPIO", "pin": 18, "delay_us": 0}, "enable_pin_low": {"source": "GPIO", "pin": 26, "active_low": true}, "speed_us": 50, "acceleration": 10000, "auto_enable": true, "delay_to_enable_us": 50, "delay_to_disable_ms": 1000 } ] } ``` -------------------------------- ### FastAccelStepper Project Structure Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/doc/ai_improvements/README.md Illustrates the directory structure for per-architecture StepperQueue implementations, including base classes and platform-specific queues. ```text src/ fas_queue/ base.h ← StepperQueueBase (common fields) stepper_queue.h ← Architecture dispatcher pd_avr/ avr_queue.h/cpp ← AVR implementation pd_test/ test_queue.h ← PC-based test stub pd_sam/ sam_queue.h/cpp ← SAM Due implementation pd_pico/ pico_queue.h/cpp ← RP2040/RP2350 implementation pd_esp32/ esp32_queue.h/cpp ← ESP32 queue (7 driver files remain) ``` -------------------------------- ### Get Current Speed Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/doc/FastAccelStepper_API.md Retrieves the actual current speed of the stepper motor, optionally in real-time. ```APIDOC ## Get Current Speed ### Description Retrieves the actual current speed of the stepper motor. If `realtime` is true, the most actual speed from the stepper queue is derived (only works if the queue does not contain pauses). Otherwise, the speed from the ramp generator is reported, which is typically the speed a couple of milliseconds later. The default for `realtime` is true. ### Methods - `int32_t getCurrentSpeedInUs(bool realtime = true) const;` - `int32_t getCurrentSpeedInMilliHz(bool realtime = true) const;` ### Return Values - `= 0`: while not moving - `> 0`: while position counting up - `< 0`: while position counting down ``` -------------------------------- ### Configure Timer Module with Warnings (PlatformIO) Source: https://github.com/gin66/fastaccelstepper/blob/master/README.md Add this to your platformio.ini to select a specific timer module with error and warning flags enabled. ```ini build_flags = -Werror -Wall -DFAS_TIMER_MODULE=3 ``` -------------------------------- ### WebSocket Unsubscribe Command Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/Esp32StepperDemo/DESIGN.md Example of a WebSocket command sent from the client to the server to unsubscribe from a specific topic. ```json { "command": "unsubscribe", "topics": ["steppers"] } ``` -------------------------------- ### WebSocket Pin Change Event Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/Esp32StepperDemo/DESIGN.md Example of a WebSocket event indicating a change in the state of a GPIO pin. ```json { "event": "pin_change", "data": { "pin": 15, "value": 1 } } ``` -------------------------------- ### Define Architecture Header for New Microcontroller Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/doc/driver_architecture.md Create `fas_arch/your_arch.h` to define platform identification, include necessary headers, set up interrupt control, define core timing constants, configure queue parameters, and optionally define features like direct port access. ```cpp #ifndef FAS_ARCH_YOUR_ARCH_H #define FAS_ARCH_YOUR_ARCH_H // 1. Platform identification #define SUPPORT_YOUR_ARCH // 2. Include platform headers #include // or your SDK headers // 3. Interrupt control (required) #define fasDisableInterrupts() // disable interrupts #define fasEnableInterrupts() // restore interrupts // 4. Core timing constants (required) #define TICKS_PER_S 16000000L // your timer frequency #define MIN_CMD_TICKS (TICKS_PER_S / 5000) // minimum command duration #define MIN_DIR_DELAY_US 200 // direction pin setup time #define MAX_DIR_DELAY_US 4095 // maximum direction delay // 5. Queue configuration (required) #define QUEUE_LEN 32 // queue depth (power of 2) #define NUM_QUEUES 4 // number of steppers supported #define MAX_STEPPER NUM_QUEUES // usually same as NUM_QUEUES // 6. Optional features (define if supported) // - Direct port access for dir pin (if needed, declare // _dirPinPort/_dirPinMask in your StepperQueue subclass) // 7. Task management (if using RTOS) #define noop_or_wait vTaskDelay(1) // or your idle function // 8. Debug LED timing #define DEBUG_LED_HALF_PERIOD 50 // 9. Fixed queue-to-pin mapping (if hardware requires) // #define NEED_FIXED_QUEUE_TO_PIN_MAPPING #endif ``` -------------------------------- ### Get Enable Pin Status Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/doc/FastAccelStepper_API.md Retrieves the configured enable pin status (high active or low active). ```cpp uint8_t getEnablePinHighActive() const; ``` ```cpp uint8_t getEnablePinLowActive() const; ``` -------------------------------- ### FastAccelStepperEngine Initialization Call Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/doc/FastAccelStepper_API.md Shows the required call to initialize the FastAccelStepperEngine after its declaration. This prepares the engine to manage stepper instances. ```cpp void setup() { engine.init(); } ``` -------------------------------- ### System Configuration Structure Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/Esp32StepperDemo/DESIGN.md C++ struct defining the system configuration parameters, including Wi-Fi settings and port numbers. ```cpp struct SystemConfig { char wifi_ssid[32]; char wifi_password[64]; char hostname[32]; bool ap_mode; // Access Point mode if true uint16_t web_server_port; uint16_t websocket_port; uint32_t status_update_interval_ms; }; ``` -------------------------------- ### Get Queue Entries Count - C++ Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/doc/FastAccelStepper_API.md Returns the number of commands currently in the queue, including the command that is actively being processed. ```cpp uint8_t queueEntries() const; ``` -------------------------------- ### Get Speed Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/doc/FastAccelStepper_API.md Retrieves the currently set speed of the stepper motor. Note that this is the set speed, not the actual speed during movement. ```APIDOC ## Get Speed ### Description Retrieves the currently set speed of the stepper motor. Note that this is the set speed, not the actual speed during movement. ### Methods - `uint32_t getSpeedInUs() const;` - `uint32_t getSpeedInTicks() const;` - `uint32_t getSpeedInMilliHz() const;` ``` -------------------------------- ### WebSocket Stepper Status Event Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/Esp32StepperDemo/DESIGN.md Example of a WebSocket event sent from the server to the client, providing real-time status of a stepper motor. ```json { "event": "stepper_status", "data": { "id": 0, "position": 1234, "speed": 1000, "running": true, "ramp_state": "ACCELERATE" } } ``` -------------------------------- ### Get Step Pin Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/doc/FastAccelStepper_API.md Retrieves the GPIO pin number configured for step signals. This pin is defined at the creation of the stepper object. ```cpp uint8_t getStepPin() const; ``` -------------------------------- ### System Configuration Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/Esp32StepperDemo/DESIGN.md Defines network settings, WiFi credentials, and update intervals for the ESP32 system. ```json { "wifi": { "ssid": "MyNetwork", "password": "MyPassword", "hostname": "stepper-demo" }, "network": { "ap_mode": false, "port": 80, "ws_port": 81 }, "update_interval_ms": 100 } ``` -------------------------------- ### Get Ramp State - C++ Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/doc/FastAccelStepper_API.md Returns the current operational state of the high-level stepper control. The value is a bitwise OR of RAMP_STATE_ and RAMP_DIRECTION_ flags. ```cpp uint8_t rampState() const { return _rg.rampState(); } ``` -------------------------------- ### Engine Initialization with CPU Affinity Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/doc/driver_architecture.md Implement `fas_init_engine` for special architecture-specific initialization, optionally supporting CPU core assignment. ```cpp // In your .cpp file #if defined(SUPPORT_CPU_AFFINITY) void fas_init_engine(FastAccelStepperEngine* engine, uint8_t cpu_core) { // Your initialization } #else void fas_init_engine(FastAccelStepperEngine* engine) { // Your initialization } #endif ``` -------------------------------- ### Configure Timer Module for AVR ATmega2560 (PlatformIO) Source: https://github.com/gin66/fastaccelstepper/blob/master/README.md Add this to your platformio.ini to select a specific timer module for AVR ATmega2560. ```ini build_flags = -DFAS_TIMER_MODULE=3 ``` -------------------------------- ### Get Current Stepper Position Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/doc/FastAccelStepper_API.md Retrieves the current position of the stepper motor. Note that for ESP32 with RMT, this may be off by steps in an ongoing command. ```cpp int32_t getCurrentPosition() const; ``` -------------------------------- ### Ramp Helper Tool Usage Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/tests/pc_based/README.txt Use this tool to generate and dump ramp commands for specific speed and acceleration profiles. It's useful for creating test inputs by outputting commands until coasting is reached. ```bash make ramp_helper && ./ramp_helper ``` ```bash ./ramp_helper 1000 10000 1000 ``` -------------------------------- ### Sequence Executor Class Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/Esp32StepperDemo/DESIGN.md Defines the SequenceExecutor class for executing predefined movement sequences, managing sequence start, stop, pause, resume, and progress updates. ```cpp class SequenceExecutor { private: ConfigManager* config_manager; StepperController* stepper_controller; bool executing; uint8_t current_sequence_id; uint32_t last_command_time; bool executeCommand(const MoveCommand& cmd); public: void begin(ConfigManager* cfg, StepperController* ctrl); bool startSequence(uint8_t id); void stopSequence(); void pauseSequence(); void resumeSequence(); void update(); // Call from loop() bool isExecuting() { return executing; } uint8_t getCurrentSequence() { return current_sequence_id; } float getProgress(); }; ``` -------------------------------- ### Get Future Position - C++ Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/doc/FastAccelStepper_API.md Calculates and returns the stepper's position after all commands currently in the queue have been completed. This value is based on the planned future state. ```cpp int32_t getPositionAfterCommandsCompleted() const; ``` -------------------------------- ### Raspberry Pi Pico Platform Configuration Source: https://github.com/gin66/fastaccelstepper/blob/master/README.md Configuration for Raspberry Pi Pico using the custom platform. Ensure to use this for RP2040 boards. ```ini [env:rpipico] platform = https://github.com/maxgerhardt/platform-raspberrypi.git framework = arduino board = rpipico build_flags = -Wall -Wextra -D__FREERTOS=1 ``` -------------------------------- ### Get Maximum Speed Limits Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/doc/FastAccelStepper_API.md Retrieve the maximum allowed speed for the stepper device in different units. These values represent the device's physical limitations. ```cpp uint16_t getMaxSpeedInUs() const; uint16_t getMaxSpeedInTicks() const; uint32_t getMaxSpeedInHz() const; uint32_t getMaxSpeedInMilliHz() const; ``` -------------------------------- ### Enable Pin State Management Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/doc/dir_pin_refactoring.md Demonstrates how to enable stepper motor outputs, including checks for pulses in flight and handling of external enable pins. ```cpp // In FastAccelStepper.cpp bool FastAccelStepper::enableOutputs() { // For safety, check if pulses in flight if (q->hasPulsesInFlight()) { return false; } if (_enablePinLowActive != PIN_UNDEFINED) { if (_enablePinLowActive & PIN_EXTERNAL_FLAG) { return _engine->_externalCallForPin(_enablePinLowActive, HIGH) == HIGH; } else { q->setEnablePinState(HIGH); return true; } } // ... similar for high-active } ``` -------------------------------- ### Connecting Stepper in I2S_DIRECT Mode Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/doc/esp32_i2s_driver.md Connects a stepper to a pin using I2S_DIRECT mode, where each stepper gets a dedicated I2S peripheral. No engine initialization is needed beforehand. ```cpp FastAccelStepper* s = engine.stepperConnectToPin(step_pin, DRIVER_I2S_DIRECT); ``` -------------------------------- ### Create Symlink to FastAccelStepper Library Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/Esp32StepperDemo/README.md This command creates a symbolic link to the FastAccelStepper library, which is necessary for building the project. ```bash make ``` -------------------------------- ### Get Stepper Driver Type (ESP32) Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/doc/FastAccelStepper_API.md Retrieves the driver type (RMT, MCPWM_PCNT, I2S_DIRECT, I2S_MUX) used by the stepper on ESP32. This is available when multiple driver types are supported. ```cpp FasDriver driverType() const; const char* driverTypeString() const; #endif ``` -------------------------------- ### Add Stepper Command to Queue Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/doc/FastAccelStepper_API.md Adds a low-level stepper command to the queue. Use start=true to automatically restart a running queue. If the queue is not running, start=true initiates it. ```cpp AqeResultCode addQueueEntry(const struct stepper_command_s* cmd, bool start = true); ``` -------------------------------- ### Current Code Flow for addQueueEntry() Source: https://github.com/gin66/fastaccelstepper/blob/master/extras/doc/dir_pin_refactoring.md Illustrates the logic within `addQueueEntry()` for handling direction pins. It differentiates between initial commands when the queue is empty and subsequent commands that require a direction change. ```cpp addQueueEntry(): 1. Compare new dir with queue_end.dir 2. If queue is empty and not running: - Toggle direction pin directly - Update queue_end.dir 3. Else if direction change needed: - Set toggle_dir = 1 in entry - Update queue_end.dir ISR/Driver: 1. Check entry.toggle_dir 2. If set: toggle direction pin 3. Process steps ```