Tuesday, December 2, 2014

YetAnotherGCodeSender, a C++ software for TinyG and ShapeOko2.

Hi. I’m working on a C++ program that connects to the TinyG and configures it for the ShapeOko2 machine. It will, soon, also be able to deliver the gcode files to the machine, line by line.

If you are interested, the sources can be found here. They include a Makefile so you should be able to compile them in a linux machine just by typing ‘make’ and <ENTER>. The only required library is libxml2, which is available on most linux distributions and can be installed by conventional package managers:

- apt-get install libxml2 on RaspberryPi, Debian, etc;

- port install libxml2 on Mac OS;

- yum install libxml2 on Fedora, etc;

- cd /usr/ports/textproc/libxml2; make; make install on FreeBSD.

The chances that you have it already installed in your system are very big. Please read your linux distribution manual to learn how to install it if it is not your case.

To download the code you can access the link I gave or checkout it using Mercurial, which is a version control system available on almost all systems (including Raspberry Pi). You can learn how to use Mercurial here or, if you already have it installed in your linux (or MacOS) system, type this in a terminal:

$ mkdir YetAnotherGCodeSender

$ cd YetAnotherGCodeSender

$ hg init

$ hg pull -U https://xp-dev.com/hg/YetAnotherGCodeSender

The Mercurial version control system can also be installed using available package managers (yum, apt-get, ports, macports etc) or via an excellent software called SourceTree which is available for Mac and Windows systems. This software handles all the checkouts and updates graphically and can make your life easier if you do not like the command line interface.

For my program (YetAnotherGCodeSender), all the machine configuration parameters are written inside a XML file that is easy to be changed. The parameters include the communications port. The file looks like this:

<config>

<attribute key="serial_port_device">/dev/tty.usbserial-DA00XWU7</attribute>

<attribute key="serial_port_data_bits">8</attribute>

<attribute key="serial_port_parity">0</attribute>

<attribute key="serial_port_stop_bits">1</attribute>

<attribute key="serial_port_baud_rate">115200</attribute>

<attribute key="serial_port_flow_control">XONXOFF</attribute>

<!-- Global system settings -->

<!-- Junction acceleration: Global cornering acceleration value -->

<setup key="JUNCTION_ACCELERATION" command="$ja">2000000</setup>

<!-- Chordal tolerance: Sets precision of arc drawing. Trades off precision for max arc draw rate-->

<setup key="CHORDAL_TOLERANCE" command="$ct"></setup>

<!-- Switch type: 0=NO, 1=NC -->

<setup key="SWITCH_TYPE" command="$st">1</setup>

<!-- Motor disable timeout: Number of seconds before motor power is automatically released. Maximum value is 40 million. -->

<setup key="MOTOR_DISABLE_TIMEOUT" command="$mt">10</setup>

<!-- Communications settings -->

<!-- Enable JSON mode: 0=text mode, 1=JSON mode -->

<setup key="ENABLE_JSON_MODE" command="$ej">0</setup>

<!-- JSON verbosity: 0=silent ... 5=verbose (see details) -->

<setup key="JSON_VERBOSITY" command="$jv">3</setup>

<!-- JSON syntax: 0=relaxed, 1=strict -->

<setup key="JSON_SYNTAX" command="$js">0</setup>

...

<!-- Status report interval: in milliseconds (50 ms minimum interval) -->

<setup key="STATUS_REPORT_INTERVAL_MS" command="$si">50</setup>

<!-- Enable CR on TX: 0=send LF line termination on TX, 1= send both LF and CR termination -->

<setup key="ENABLE_CR_ON_TX" command="$ec">0</setup>

<!-- Enable character echo: 0=off, 1=enabled -->

<setup key="ENABLE_CHARACTER_ECHO" command="$ee">0</setup>

<!-- Enable flow control: 0=off, 1=XON/XOFF enabled, 2=RTS/CTS enabled -->

<setup key="ENABLE_FLOW_CONTROL" command="$ex">1</setup>

<!-- Baud rate: 1=9600, 2=19200, 3=38400, 4=57600, 5=115200, 6=230400. 115200 is default-->

<setup key="BAUD_RATE" command="$baud">5</setup>

...

<!-- Motor 1 settings --

<!-- Motor mapping to axis: Configures the axis to which this motor is connected (for Cartesian machines) Typically: $1ma=0, $2ma=1, $3ma=2, $4ma=3 to map motors 1-4 to X,Y,Z,A, respectively-->

<setup key="M1_MOTOR_MAP" command="$1ma">0</setup>

<!-- Step angle: Motor parameter indicating the angle traveled per whole step. Typical setting is $1sa=1.8 for 1.8 degrees per step (200 steps per revolution) -->

<setup key="M1_STEP_ANGLE" command="$1sa">1.8</setup>

...

</config>

In principle you just need to run the main program and it will read the XML file, send it to TinyG and configure your machine. More advanced functions will include spindle warm up and other tasks which are not available now.

The current code is able to send the configuration parameters to TinyG with success. I’m working on the functions that read the GCode file and send them line-by-line to the controller, so if an emergency happens (crash, break etc) you can stop the task by killing the program.

I almost forgot this: the program outputs a log file with details of the communication between it and the TinyG. You can find there all the commands and the answers from the controller.

 

 

The files are licensed as follows:

/************************************************************************

*

* This file is part of YetAnotherGCodeSender

* Copyright (C) 2014 Eduardo Novaes Hering

*

* YetAnotherGCodeSender is free software: you can redistribute

* it and/or modify it under the terms of the GNU General Public

* License as published by the Free Software Foundation, either

* version 3 of the License, or(at your option) any later version.

*

* This program is distributed in the hope that it will be useful,

* but WITHOUT ANY WARRANTY; without even the implied warranty of

* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

* GNU General Public License for more details.

*

* You should have received a copy of the GNU General Public License

* along with this program. If not, see <http://www.gnu.org/licenses/>

*

************************************************************************/

This code is still immature. If you decide to use it, take all the necessary safety precautions before trying. As written in the license, this program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

 

Limit switches for the ShapeOko2.

Yesterday I have finished installing limit switches on the ShapeOko2 I have.

I bought these switches at RS.com and fixed them to the machine using nylon cable ties. For the Z axis I used also these pieces bought from Inventables.com plus a few M5 screws, washers and nuts. Please see the pictures below.

The switches were wired in the NC position.

 

_0EH4896-2014-12-2-17-46.jpg

 

_0EH4898-2014-12-2-17-46.jpg

_0EH4899-2014-12-2-17-46.jpg

_0EH4900-2014-12-2-17-46.jpg

_0EH4901-2014-12-2-17-46.jpg

_0EH4902-2014-12-2-17-46.jpg

 

 

 

 

 

 

 

 

 

Saturday, November 29, 2014

Laser for ShapeOko2.

I have been thinking a lot about how to install a laser in the ShapeOko2 machine I assembled a few weeks ago.

In my mind, it should be capable of delivering enough power to the focal point to impress a photoresist coated PCB or even evaporate the ink from a black, hand painted PCB. Maybe it will also work with black wax coating too.

The list below converged after many days of EBay browsing. Keep in mind that there are many suppliers for each item. I tried to select the ones that looked better and cheaper for me without compromising quality but I may be wrong and only the tests will tell if I succeeded. Also do not forget that there are laser diodes and laser diodes. They look pretty the same, but their quality can vary a lot.

If you ever want to start a new hobby and it involves lasers like this, YOU MUST READ ABOUT LASER SAFETY. The most important thing to know and always remember is that YOU CAN GET PERMANENTLY BLIND IN A FRACTION OF A SECOND. My masters advisor always remembered the students that WE HAVE ONLY TWO EYES and WE CAN BURN BOTH IN A SIMPLE, STUPID, ACT LIKE LOOKING AT THE REFLEXION OF A LASER BEAM IN A METALLIC OBJECT. In laser science, research labs avoid reflexive materials and scientists are advised to keep the laser beams in a very definite plane and to keep their eyes far from that plane.

You must also wear protective equipment every time you enter a room with a free propagating laser beam. Special goggles are made to absorb all the light from the laser that you are working with. This means that, different laser colours may require different safety equipment. And this rule includes far-infrared (CO2), infrared and ultra-violet lasers. The fact that you do not see the laser beam, or that it looks faint to your eyes, does not mean that they are safer. It is the contrary. They are much more dangerous. INFRARED AND ULTRAVIOLET LASERS CAN BURN YOUR EYES TOO. THEY ARE VERY, VERY DANGEROUS.

So, think twice before starting this new hobby. Enforce safety on the working environment punishing who enters it without protection with a one day entrance denial, or a many day one in case of recurrent behaviour. Remember all the beautiful scenes that the people will miss in their future if they loose their vision if you need motivation for this.

Before continuing read the information on this link and on this link too.

One last call to safety: if you look at the sun your eye hurts, right? The sun delivers to our planet around 1.4kW per square meter. This means 1400W per 1000mm x 1000mm area, or 1.4mW/mm^2. A typical, low power, cheap, red laser pointer delivers 1mW per square mm. It has roughly the same intensity as the sun but it is even worse for your eyes to look at a laser beam than to look at the sun. Check this link to see why.

I hope you understood that you should not keep reading this post before reading all you can about laser safety. And that YOU SHOULD NEVER POINT A LASER TO ANOTHER LIVING CREATURE WITH EYES. You can blind your cat, your dog, your neighbour or somebody you love in a fraction of a second.

Now let me share with you what I just bought on EBay. The list includes power supplies, drivers with TTL port, 405nm and 808 diode lasers, copper laser housings, a heat sink and lenses for both wavelengths. The power I chose for the diodes was 120mW (405nm) and 500mW (808nm). Both are very powerful lasers that should do a lot of damage when focused to a 0.1mm spot.

Let me start by the laser diodes. As said before, I chose two wavelengths. The first, 405nm is the peak of absorption of photoresist materials that coat PCB boards. The second, 808nm, is the peak of absorption of copper. Above the selected powers the prices seem to increase a lot so I selected the best relation power/price for me.

808nm 500mW 5.6mm TO-18 Infrared IR Laser Diode No PD        $6,54 USD

New 405nm-410nm 120mW TO18 5.6mm Sony Laser Diode/Violet Laser Diode 1

PCS         $7,99 USD

These diodes must work at around 25 degrees Celsius. If their temperature increases, their lifetime decreases abruptly. They need the operation heat to be flowed out very efficiently, so I selected housings made of copper, that seems to be of good quality:

3 pack 12 x 30mm Copper 5.6mm Laser Diode Mount Blank Module & Diode

Press Tool         $28,00 USD

After being assembled on the housings you have what they call a laser module on EBay sellers language. The module needs to be inside a heat sink. The higher the laser power, the better must be the heat sink. Some of the heat sinks even accept fans. So I selected this:

New TYPE Professional Cooling Heatsink/ Heat Sink for 12mm Laser Diode

Module         $5,99 USD

You also need lenses to collect the light emitted from the diode and collimate it to a beam. As you may not know, the diode does not emit light in a straight line. It is more like a cone. The lens must be placed with its focal point positioned over the diode output and it must be transparent to the light emitted by the diode. If possible, it should have an anti-reflective coating to avoid loosing power by backward reflection. I selected two lenses, one for each wavelength:

For the 405nm (purple, UV) laser:

445nm 405nm Three Element Glass Lens for Aixiz Module        $10,95 USD

808nm 3 layer Glass Laser Collimation Lens with M9P05*10mm Frame        $4,99 USD

The laser diodes requires constant current supply at a specific voltage. The parameters vary with the emitted wavelength and there are ready made circuits to drive them. I chose drivers that can be tuned, hoping that I can decrease the emitted power to a minimum while learning how things work. My options were:

405nm 50mw-400mw Violet/Blue Laser Module Power Supply Driver 12V with

TTL         $14,23 USD

Professional Laser Diode Driver for 808nm&532nm +660nm with TTL        $14,39 USD

Finally I ordered two power adapters to feed the drivers:

Power Supply AC 100-240V To DC 12V 2A Adapter for 3528 5050 LED Strip

Light EU         $4,39 USD

AC Converter Adapter DC 5V 3A Power Supply Charger EU plug 3000mA MICRO

USB 15W         $5,49 USD

 

This post was long. I will share my results here as soon as the parts arrive and I assemble them.

Thanks for reading.

Wednesday, November 26, 2014

MMS on Raspberry Pi.

Good news. I could compile today the Multi Measurement System (MMS) on a Raspberry Pi. MMS is a system, which I have been developing for a long time, that enables you to write simple programs to control scientific instruments, automate data acquisition and process it afterwards. It is meant to be free, ‘easy to use’ and to replace that expensive drawing application that infests science labs all around the world. And now you can run MMS on a Raspberry Pi, a less than 50 USD computer that fits in the palm of your hand.

The MMS code is still immature, but works. You can find it here.

Monday, November 3, 2014

Testing.

The Shapeoko2 first tests were a success.

The electronics had already been tested before assembling the machine, as suggested by the instructions, so I expected all the motors to rotate and the communications between the computer and the Arduino controller to work fine.

After assembling, it was important to test if both Y motors were rotating in the same sense, so I connected them one at a time and used the Universal G-Code sender software to check them.

It is important to remember that the electronics that comes with the Shapeoko2 kit will burn if turned on without the motors connected. You must verify all the connections before turning on the machine. At least this is what the instructions say. I believed.

The first carving attempts worked almost fine. For 2D tests the workflow is simple. You can use easel (www.easel.com) that is developed by Instructables and works fine. I could draw something at Easel and send it to the machine but I used a piece of pine to carve on and this material is not on Easel list of materials. The machine went too fast inside it and also tried to move faster than it could carve, so many steps were lost and the result was not consistent. You can change the parameters on the software, but you have to guess them first. My second guess is to divide everything there by two.

But the mystery really started when I tried to do 3D carving. There are many pieces of tutorials around trying to explain how to get from a cad drawing to a set of instructions for the carving machine, usually written in G-Code. After a lot of search I learnt the following:

1) OpenSCAD is free and can produce STL files. You use this software to do your 3D project;

2) You need something to translate from STL to G-Code. This something can be paid (like MeshCAM) or free (like PyCAM). MeshCAM works fine but is not cheap. I’m trying to install PyCAM now and will tell you about it later;

3) The software you need to use cannot be made for 3D printers. Those ones build something by adding material. You need to remove material, which is the inverse operation.

4) After you load your STL into the software, you need to tell it how to carve and which tool you are using. There are many, many options. I tried the standard ones, with a 1/8” flat end bit and only roughing passes. The 3D object I tried to carve was a fairly simple one but the generated G-Code had, like, 5000 lines.

5) Having the file with G-Code, you must load it to Universal G-Code something, home the machine (lower left corner, almost touching the material) and hit SEND;

6) If something goes wrong, you must be able to abort the operation, but the only option that works is the pause button. The STOP option does not stop the machine 3D movement. This is a real problem. The solution I found was to unplug the USB cable.

7) The machine needs limit switches. They do not come on the kit, but are really important. I will buy some and try to install them. Hot glue will be the fixing option, probably. But where to connect them is another mystery. The Shapeoko forums probably have a lot of information on that.

8) You must read this: http://lcamtuf.coredump.cx/gcnc/ There is a lot of information on this webpage on CNC milling. Useful information.

Shapeoko2 wiring.

Before actually testing the Shapeoko2 machine I did a complete rewiring. The cables that came with it weren’t the most flexible ones and I was afraid they were going to interfere with micro stepping. Maybe nonsense, but I did it. I changed everything for a microphone, two pair, shielded cable and also increased their length, giving some space between the machine and the electronics.

 

_0EH4483-2014-11-3-09-13.jpg

 

_0EH4485-2014-11-3-09-13.jpg

 

The pictures show a solution I found for the cable management system. It seems to work and uses only the mechanical parts that came with the full kit option (the plastic guide and 2 endings). I divided the guide in two parts and connected the ends in a way that it could be used for X and Y axis.

 

_0EH4484-2014-11-3-09-13.jpg

 

I also used a wire termination that is very convenient and easy to use. It made the assembly very clean. Before clamping the terminations I have put some solder in the wire ends. This solder is not visible as the tubes were clamped over them.

You can find those ferroules here.

 

_0EH4487-2014-11-3-09-13.jpg

Wednesday, October 29, 2014

Shapeoko2, assembled and almost ready for testing.

This is the Shapeoko2. A desktop CNC kit that transforms your computer into a small factory! It took me the spare time of a few days to assemble it and figure out how to route the wiring.

 

_0EH4473-2014-10-29-10-40.jpg

 

 

_0EH4474-2014-10-29-10-40.jpg