The PrintNC project strongly recommends using your Huanyang VFD with RS485, which runs on a modified modbus. This allows you to control and get feedback from your spindle in your GUI.
Before trying software control from LinuxCNC, make sure the VFD works perfectly when controlled manually via the panel of the VFD - start, stop, forward, reverse, RPM control and feedback. Then move on to the following instructions.
1) Wiring
Connecting the RS485-USB adapter to the VFD is pretty straight forward: using a twisted pair of cable (e.g. CAT5 Ethernet cable), connect the RS485-USB adapter (+) and (-) to the VFD's RS+ and RS-, respectively. If your RS485-USB adapter does not have a (+) and (-) label, connect any to the VFD for now.
2) VFD Settings
*To start take a look at this guide here: https://cdn.discordapp.com/attachments/769339226213974046/819426216884043786/Spindle_Settings.pdf*
The following PD settings need to be changed to use the VFD with RS485. It is also assumed you've put all the settings in and wired it according to /en/electronics/vfd/config
PD001 = 2
#source of run commands = external terminal
PD002 = 2
#source of operation frequency = external terminal
PD163 = 1
#communication address for inverter = 01
PD164 = 1
#BaudRate = 9600
PD165 = 3
#Communication Data = 8N1
3) Verifying that Linux is communicating with the RS485-USB adapter
In order for Linux to communicate with the RS485-USB adapter, one must verify first that the logged in user has the required privileges. For this, type the following command in a terminal window:
$ getent group dialout
If the logged in user appears as below, you are good to go,
dialout:x:20:<your_username>
If not, it must be added to the "dialout" list using:
$ sudo adduser $USER dialout
Next, one need to find out what name Linux gave to the RS485-USB adapter. In the case below, the RS485-USB adapter name is ttyUSB0. You may unplug and re-plug the USB dongle and look for which name is added to the list. It is this name that will need to be entered in the VFD.hal under "loadusr -Wn vfd hy_vfd -n vfd -d /dev/ttyUSB0 -p none -r 9600". Note that Linux may change the name of the RS485-USB adapter if you unplugged and re-plug it in the future (even in the same USB port). In doubt, run the command above again to find out the new name of the RS485-USB adapter.
$ ls /dev/tty*
/dev/tty /dev/tty19 /dev/tty3 /dev/tty40 /dev/tty51 /dev/tty62
/dev/tty0 /dev/tty2 /dev/tty30 /dev/tty41 /dev/tty52 /dev/tty63
/dev/tty1 /dev/tty20 /dev/tty31 /dev/tty42 /dev/tty53 /dev/tty7
/dev/tty10 /dev/tty21 /dev/tty32 /dev/tty43 /dev/tty54 /dev/tty8
/dev/tty11 /dev/tty22 /dev/tty33 /dev/tty44 /dev/tty55 /dev/tty9
/dev/tty12 /dev/tty23 /dev/tty34 /dev/tty45 /dev/tty56 /dev/ttyS0
/dev/tty13 /dev/tty24 /dev/tty35 /dev/tty46 /dev/tty57 /dev/ttyS1
/dev/tty14 /dev/tty25 /dev/tty36 /dev/tty47 /dev/tty58 /dev/ttyS2
/dev/tty15 /dev/tty26 /dev/tty37 /dev/tty48 /dev/tty59 /dev/ttyS3
/dev/tty16 /dev/tty27 /dev/tty38 /dev/tty49 /dev/tty6 /dev/ttyUSB0
/dev/tty17 /dev/tty28 /dev/tty39 /dev/tty5 /dev/tty60
/dev/tty18 /dev/tty29 /dev/tty4 /dev/tty50 /dev/tty61
To verify that Linux communicates with the VFD, enter the following command (make sure to update your ttyUSB* name).
$ sudo chmod 666 /dev/ttyUSB0
$ halrun
halcmd: loadusr -W hy_vfd -d /dev/ttyUSB0
halcmd: show pin
You should see a list of entry related to the VFD (hy_vfd, freq, spindle...etc.). If not try to switch the (+) and (-) wires at the RS485-USB adapter and run the "show pin" command again.
Component Pins:
Owner Type Dir Value Name
4 float OUT 0 hy_vfd.ACV
...
4 float OUT 0 hy_vfd.freq-lower-limit
...
4 bit IN FALSE hy_vfd.spindle-on
4 bit IN FALSE hy_vfd.spindle-reverse
4 float OUT 0 hy_vfd.spindle-speed-fb
4) Add the following to a vfd.hal in your configuration folder for LinuxCNC
loadusr -Wn vfd hy_vfd -n vfd -d /dev/ttyUSB0 -p none -S24000 -r 9600 -s 1
# Replace ttyUSB0 with the address of your adapter
setp vfd.enable 1 # This enables the VFD in the driver
net spindle-speed spindle.0.speed-out => vfd.speed-command
net spindle-cw spindle.0.forward => vfd.spindle-forward
net spindle-ccw spindle.0.reverse => vfd.spindle-reverse
net spindle-on spindle.0.on => vfd.spindle-on
net spindle-speed-fb => vfd.spindle-speed-fb
net spindle-current <= vfd.OutA
net spindle-comm-ok <= vfd.hycomm-ok
net spindle-at-speed => vfd.spindle-at-speed
net spindle-at-speed <= spindle.0.at-speed
5) In your INI file add the following in your [HAL] section
HALFILE = vfd.hal
6) In custom_postgui.hal add the following for gmocappy
net spindle-speed-fb <= gmoccapy.spindle_feedback_bar
net spindle-at-speed <= gmoccapy.spindle_at_speed_led
7) If the custom_postgui.hal reference is missing from the [HAL] section in your INI file, you'll need to add it
POSTGUI_HALFILE = custom_postgui.hal