Control Huanyang VFD with LinuxCNC

This is a brief post to record some notes for my own reference on the steps I had to follow to be able to control my 2.2kW water cooled spindle with Linux CNC via a Huanyang VFD (Variable Frequency Drive)

I had to set the following menus on the huanyang VFD

PD001: 2 (Accept RS485 commands)
PD002: 2 (Accept freq commands)
PD163: (1 RS485 Slave address :1)
PD164: 1 (RS485 Baud Rate: 9600)
PD165: 3 (8 bit, no parity, 1 stop)

In Stepconf Wizard on LinuxCNC

If necessary set spindle pins to unused i.e. Pin14 and Pin 16

Select spindle speed display to activate the spindle speed display on LinuxCNC

Edit custom.hal

First you will need to find the port that the usb-RS485 dongle is using. In my case it is /dev/ttyUSB0

Then edit the custom.hal script found in the config/setup folder of LinuxCNCand add the following 5 lines. Remember to change your usb port to what is relevant for your setup.

1
2
3
4
5
loadusr -Wn vfd hy_vfd -n vfd -d /dev/ttyUSB0 -p none -r 9600
net spindle-cmd-rpm-abs => vfd.speed-command
net spindle-cw motion.spindle-forward => vfd.spindle-forward
net spindle-ccw motion.spindle-reverse => vfd.spindle-reverse
net on motion.spindle-on => vfd.spindle

Edit custom_postgui.hal

Change line:

sets spindle-at-speed true

to

net spindle-at-speed => vfd.spindle-at-speed

add the following line to the bottom of the file.

setp vfd.enable 1

^