This repository provides a robust and modular solution to control a Variable Frequency Drive (VFD) using Modbus RTU communication and read encoder positions with a quadrature encoder. The project is designed with best practices and features asynchronous operations for seamless performance.
-
Motor Control via VFD (CFW500):
- Start, stop, and reverse the motor with precise RPM control.
- Read motor speed (RPM) and status.
- Reset VFD faults.
-
Quadrature Encoder Integration:
- Read encoder positions in steps or degrees.
- Support for zero-calibration to set custom reference positions.
- Handle "zero position" using the encoder’s Z signal.
-
Configurable Verbose Levels:
- Control console output:
- 0: No output.
- 1: Encoder position only.
- 2: Motor actions and VFD status.
- 3: Full details (encoder and motor/VFD statuses).
- Control console output:
-
Async Event Handling:
- Non-blocking encoder reading and motor control using
uasyncio
.
- Non-blocking encoder reading and motor control using
-
Modular Structure:
cfw500_modbus.py
: VFD-related functions.encoder.py
: Encoder handling.main.py
: Main application logic.
- Raspberry Pi Pico
- Omron E6B2-CWZ6C Quadrature Encoder (2000 PPR)
- WEG CFW500 VFD with Modbus RTU
- RS485 to UART converter
- Motor compatible with VFD
Encoder Pin | Pico Pin |
---|---|
A (Black) | GPIO16 |
B (White) | GPIO17 |
Z (Orange) | GPIO18 |
+5V (Brown) | VBUS (5V) |
GND (Blue) | GND |
- Thonny IDE
- MicroPython firmware on Pico
uasyncio
library for async operations
-
Clone the Repository:
git clone https://github.com/<your-username>/<your-repo-name>.git cd <your-repo-name>
-
Prepare the Raspberry Pi Pico:
- Flash the MicroPython firmware onto the Pico.
- Ensure
uasyncio
is included (standard in MicroPython).
-
Upload Files:
- Use Thonny IDE to upload
main.py
,cfw500_modbus.py
, andencoder.py
to the Pico.
- Use Thonny IDE to upload
start [rpm]
: Start motor at the specified RPM (default: 1000 RPM).stop
: Stop the motor.reverse [rpm]
: Reverse motor at the specified RPM.set_speed [rpm]
: Update motor speed reference.reset_fault
: Reset VFD faults.
set_encoder_output [step|deg]
: Set encoder output to steps or degrees.calibrate
: Set current encoder position as zero.
set_verbose [0-3]
: Adjust verbosity level.
help
: Show command list.exit
: Exit the program.test
: Run a test sequence.
-
Start motor at 1200 RPM:
start 1200
-
Set encoder output to degrees:
set_encoder_output deg
-
Calibrate the encoder:
calibrate
-
Stop the motor:
stop
-
main.py
:- Main logic with asynchronous loops for encoder and motor control.
- Command processing and zero-endstop integration.
-
cfw500_modbus.py
:- Modbus communication for VFD operations.
- Functions for reading/writing parameters and fault handling.
-
encoder.py
:- Encoder handling with real-time position updates.
- A/B/Z signal processing and calibration support.
-
Motor does not start:
- Check VFD connections.
- Ensure Modbus parameters match
cfw500_modbus.py
. - Verify VFD power and fault status.
-
Encoder position not updating:
- Verify wiring for A, B, Z signals (GPIO16, GPIO17, GPIO18).
- Ensure encoder is powered and functional.
-
Verbose output issues:
- Adjust verbosity using
set_verbose [0-3]
.
- Adjust verbosity using
- Fork this repository.
- Create a new branch for your changes.
- Submit a pull request with a description of your updates.
This project is licensed under the MIT License.
- MicroPython development team
- Peter Hinch for encoder library contributions
- WEG for CFW500 documentation
- Omron for encoder specifications
- All contributors and testers