Saturday, March 11, 2017

Setting up LinuxCNC for Arduino & Extruder Controller

I will be using an Arduino to control the heaters on my 3020 3D Printer. LinuxCNC will send commands to the Arduino through the USB port and heater temperatures will be set on the LinuxCNC GUI. I did this using LinuxCNC 2.5.0 and 2.6.4, but it should work with most versions.

This work was originally done by Sam Wong using an older version back when it was called EMC. So some things have changed slightly. Here are the steps!

1) Install pyserial 2.7.13 (I have not tried 3.6.0, let me know if it works okay)
https://pypi.python.org/pypi/pyserial
- Extract to your user folder
- Open the terminal to the pyserial folder
- Then "sudo python setup.py instlall"

2) Install the files. Copy to a folder inside "/linuxcnc". I used "/linuxcnc/scripts".
https://github.com/sam0737/hrepstrap

3) Make sure all the scripts are executable:
chmod a+x *.pl *.py *.sh

4) Edit your machine's ini file (usually in "/linuxcnc/configs/your-machines-name/your-machines-name.ini"). Add a new line at the bottom of [DISPLAY]:
"PYVCP = /home/username/linuxcnc/scripts/repstrap-extruder.pyvcp"

and under [FILTER]:
"PROGRAM_EXTENSION = .skf Skeinforge Output
skf = /home/username/linuxcnc/scripts/skeinforge2emc.pl"

under [HAL] make sure there is a:
"POSTGUI_HALFILE = custom_postgui.hal"

5) The easiest way to add halui is to add the following to the [HAL] section of the ini file.
HALUI = halui
6) Open "repstrap-extruder.hal" inside "linuxcnc/scripts" folder. Change the 3rd line to point to the correct directory. Mine was:
"loadusr -Wn rs-extruder /home/username/linuxcnc/scripts/repstrap-extruder.py"

and comment out the following lines by adding a "#" at the beginning. It should look like this:

#net motor1.spindle <= motion.spindle-speed-out => rs-extruder.motor1.spindle
#net motor1.spindle.on <= motion.spindle-on => rs-extruder.motor1.spindle.on

I'm not 100% sure why this is a problem, but I had to comment the lines to get my setup to load without error.

7) Execute "softlink-mcode-inject.sh" to have the softlinks needed created.

When you're all done you should be able to load Linux CNC like so:


Let me know if you have issues and we'll try and sort them out together. I know I had tons of issues the first AND second time I did this, so that's what I wrote a post on it.

Jorge Pinto (casainho) from Portugal also did some work on this, but it was lost when google code was shut down. Original thread here:
http://www.cnczone.com/forums/linuxcnc-formerly-emc2-/95045-cnc-software.html

A separate tutorial just on connecting an Arduino to Linux CNC by some Russian professor:
http://rkmiit.ru/main/all/students/educational/tutorials/arduinolinuxcnc_en.html