Trying to figure out how to send/receive info to my
H100 VFD (Page 79). I have cheap a RS485 attached to both my RaspberryPi (USB) and my VFD (Twisted pair). I am able to get some basic communication, I think, using the
mbpoll Linux command. My goal is to figure out 3 commands. On/Off, Set RPM, Current RPM. Any help would be wonderful. Modbus is beyond my current skill set.
geometry dash lite
Code:
$ mbpoll -a 1 -b 19200 -t 3 -r 1 -c 4 /dev/serial/by-id/usb-1a86_USB2.0-Serial-if00-port0
Protocol configuration: Modbus RTU
Slave configuration...: address = [1]
start reference = 1, count = 4
Communication.........: /dev/serial/by-id/usb-1a86_USB2.0-Serial-if00-port0, 19200-8E1
t/o 1.00 s, poll rate 1000 ms
Data type.............: 16-bit register, input register table
-- Polling slave 1... Ctrl-C to stop)
[1]: 0
[2]: 0
[3]: 0
[4]: 0
Hello, I think you should use the pymodbus library in Python. Here's an example code snippet that demonstrates how to achieve your goals of turning the VFD on/off, setting the RPM, and reading the current RPM:
Code:
python
from pymodbus.client.sync import ModbusSerialClient
# Configure the Modbus client
client = ModbusSerialClient(method='rtu', port='/dev/serial/by-id/usb-1a86_USB2.0-Serial-if00-port0', baudrate=19200, parity='E', stopbits=1, bytesize=8, timeout=1)
# Connect to the Modbus device
client.connect()
# Function to turn the VFD on/off
def set_vfd_state(state):
# Write to coil address 0 to turn the VFD on or off (assuming coil address 0 controls the VFD state)
client.write_coil(0, state)
# Function to set the RPM
def set_rpm(rpm):
# Write the desired RPM to holding register address 0 (assuming register address 0 is used to set the RPM)
client.write_register(0, rpm)
# Function to read the current RPM
def get_current_rpm():
# Read the value from input register address 0 (assuming register address 0 holds the current RPM)
result = client.read_input_registers(0, 1)
if result.isError():
return None
else:
return result.registers[0]
# Example usage
set_vfd_state(True) # Turn the VFD on
set_rpm(1000) # Set the RPM to 1000
current_rpm = get_current_rpm() # Read the current RPM
print("Current RPM:", current_rpm)
# Disconnect from the Modbus device
client.close()
Make sure you have the pymodbus library installed (pip install pymodbus) before running this code. Adjust the coil and register addresses according to the documentation of your specific VFD model (Page 79).