Category Archives: Programming

K40 Whisperer Error

K40 Whisperer – Input SVG File Errors

K40 Whisperer is a bit finicky about the SVG files that it will accept.  If you are importing files from sources other than a recent version of Inkscape (v.91 or v.92) you will likely be confronted with an error indicating that the SVG scale cannot be determined (i.e. “Cannot determine SVG scale.”).  This error or an error indicating that the  “Units not set in SVG File” is displayed when K40 Whisperer does not have enough information to conclusively determine the intended physical size of the design in the SVG file. K40 Whisperer attempts to provide some guidance to assist in getting the SVG file into a format with the needed information. However, the information provided is sometimes incomplete.  I am working toward making K40 Whisperer more flexible with respect to the file formats it will accept but until that task is completed here are a couple of procedures to make your SVG files work with K40 Whisperer.

Procedure Option A:

    1. Open a new SVG file in Inkscape V.91 or newer.
    2. Select “File”-“Import” to import the SVG design you want to use.
    3. Format the page size as needed (usually done by selecting “File”-“Document Properties”-“Resize page to drawing or selection”)
    4. Verify the “Units” are set to “mm” or “inches” in the “Custom Size” section of the “Page” Tab in the Document properties
    5. Save the new SVG file.

Procedure Option B:

    1. Open the SVG file you want to use in Inkscape V.92 or newer
    2. Selecting “File”-“Documents Properties”
    3. On the “Page” tab locate the “Scale x:” value and note the value.  Change the value to another number and press enter.  The new value can be anything.  (Increasing the value by a small number like .001 makes it easy to change it back in the next step.)
    4. Change the “Scale x:” value back to the original value and press enter.
    5. Verify the “Units” are set to “mm” or “inches” in the “Custom Size” section of the “Page” Tab in the Document properties.
    6. Save the SVG file.

These procedures will each result in an SVG file that contains the necessary information to indicate the real physical size intended for the SVG file. This information is partially encoded in the viewbox attribute which is added to the SVG file when either of these procedures are followed.

Color and Text

K40 Whisperer – Vector Colors and Text

In K40 Whisperer the red and blue vector paths in SVG files are converted to vector cut and vector engrave paths respectively.  A few people have experienced problems getting the red and blue lines to come into K40 Whisperer properly.  Here are a few of the common pitfalls that people encounter when reading SVG files into K40 Whisperer.

1. Blue and red colors in images are not converted to vectors.

If there is an image in the SVG file that contains blue or red the colors in the image are not recognized as a vector cut or engrave feature because the colored portion of an image is raster data not SVG path data.  K40 Whisperer does not convert raster images to paths. If you want to convert a raster image to vector engrave or cut paths you can use the bitmap trace feature in Inkscape  to convert bitmap image to paths before sending the SVG file to K40 Whisperer.  The trace bitmap feature in Inkscape is located in the menu bar under “Path”-“Trace Bitmap”.

2. Fill colors are not interpreted as vectors; only the stroke colors for objects are converted to vector cut/engrave paths.

Shapes/lines in SVG files have fill colors and stroke colors.  Only the stroke colors are interpreted as vector cut/engrave features.  K40 Whisperer does not try to convert the filled portion of a shape to a vector path.

3. Text is a special kind of object usually defined by fill color.  Text stroke color needs to be set in order to be interpreted as vector data.

Although text may look like strokes (depending on the font) generally standard fonts consist of outlines that are filled with a color.  So if you want to vector cut/engrave a standard font you need to change the stroke color for the font, then you can vector cut/engrave the outline of the font.   If you don’t want to cut/engrave the outline of characters you will need to use a special font that consists of strokes not outlines, these fonts are commonly referred to as stick fonts.  There are a variety of stick fonts available in the Inkscape Extension for Hershey Text.  To access the Hershey Text fonts in Inkscape go to “Extensions”-“Render”-“Hershey Text…”.  You can use the dialog that opens to create the text then change the stroke color to red/blue to engrave/cut.

K40 Whisperer will convert text to paths for you when the design is loaded.  However if the font used in a design is not installed on the computer running K40 Whisperer.  The intended font may be swapped out for another font automatically.  This can dramatically change a design in some cases.  To avoid the possibility of the design changing when it is brought to a new computer you can convert the text to paths in Inkscape.  To convert the text to paths in Inkscape use the menu options “Path”-“Object to Path”.  After the text is converted to paths the font will no longer be referenced and the design will be defined by the shape of the original font.

k40whisperer_thumb

K40 Whisperer– K40 (Cheap Chinese Laser) Control Software

After months of reverse engineering I am happy to announce that the initial version of K40 Whisperer is available for download under the GPL License.  K40 Whisperer is software written to interpret SVG and DXF data and in turn communicate the design information to the K40 Laser Cutter (using the stock M2 Nano Controller board).  This software is essentially a replacement for the Laser Draw (LaserDRW) software that comes with the stock K40 laser.  When using K40 Whisperer the USB key that is required for Laser Draw is not required.  The initial release only supports the M2 version of the K40 controller board.  If I can get other K40 owners to test with other versions of the controller board future versions will support more board versions.

K40 Whisperer has been tested with Windows (XP, Vista and 10) and Linux.  It should also work on a modern MAC computer, although this has not been tested.  Full instructions for setting up K40 Whisperer are available on the K40 Whisperer web page.  Linux instructions have not yet been written.

K40 Whisperer attempts to solve some of the basic problems with Laser Draw such as the difficulty with properly scaling designs and combining engraving and cutting on one work piece.  A previous attempt at solving these problems was the Laser Draw Inkscape Extension which allows users to send data from Inkscape to Laser Draw.  This Inkscape extension is also available on the Scorch Works web page.

Below is a screen video providing an overview of the operation of K40 Whisperer.

Laser Draw Inkscape Extension for K40 Laser Cutters

A couple of months ago I wrote an Inkscape extension that allows users to save LYZ files that are compatible with Laser Draw (LaserDRW).  Laser Draw is the software that comes with many of the cheap chinese laser cutters.  The Inkscape extension makes it easier for users to get consistently scaled output.  This is especially helpful when doing multiple operations on a single work piece (i.e. raster engraving, vector engraving and cutting).

The Inkscape Extension is free and open source (GPL).  The extension is available for download on its web page: Laser Draw Inkscape Extension.

On the ScorchWorks YouTube Channel there are a couple of relevant videos.  The first video talks about the extension and goes through making a design from scratch in Inkscape.

The second video walks through modifying an existing design for use with the Inkscape extension.

ScorchCAD Version .04

ScorchCAD_444

After a summer break from ScorchCAD development I am back at it.  The latest version of ScorchCAD is available on Google Play.  ScorchCAD is also now available on the Amazon App Store.

Here are the highlights of the new features:

  • Hull
  • Multmatrix
  • 2D shapes (circle, square, polygon)
  • 2D boolean operations
  • Resize
  • Intersection_for
  • Nested for loops (i.e. for(i=[1:5],j=[1:5]) )
  • Polyhedron
  • norm
  • cross
  • min
  • max

Additionally there are some usability changes.  ScorchCAD will now backup the current data in the code editor when the compile button is pressed.  This data is reloaded when a new session of ScorchCAD is started.  This will allow for data recovery in the event of a crash.  Additionally ScorchCAD is now associated with *.scad, *.stl, and *.dxf file extensions.  So from a file manager you can click on one of these files and ScorchCAD will show up in the available programs to open the file.  File associativity also works for *.scad files in e-mail attachments.

 

A Much Faster F-Engrave (V1.40)

F-Engrave

The latest version of F-Engrave includes major improvements to the v-carve calculation speed.  The first is based on input from geo01005.  He shared his work on his BLOG and in this YouTube Video.  The added code that breaks up the design area into a grid and stores the grid locations that are within the tool diameter.  The v-carve algorithm uses this data to skip over line segments that are farther than the max tool diameter from the current line segment.  F-Engrave had previously skipped some segments but geo01005’s implementation was significantly (2 to 3 times) faster.

In addition to the code changes geo01005 also showed that using Psyco with F-Engrave was of great benefit.  Psyco is no longer supported and is not compatible with the latest (or most commonly used) Python distributions.  However, the speed improvements were significant enough (3 to 4 times faster) to convince me to downgrade to Python 2.5 for the windows executable distribution.  I am sticking with Psyco rather than another JIT compiler (pypy, Jython, IronPython, etc.) because Psyco is easy to implement and compatible with Py2exe.  I use Py2exe to generate the windows executable files.

The final speed improvement, which is turning off plotting, has been available for some time in F-Engrave.  I have not pushed the use of this feature because the savings has only been a small percentage of the total v-carve time (depending on the design).   With the other improvements included in V1.40 plotting has become a significant player in the total calculation time.   Now turning off plotting can make the v-carve calculation 2 to 3 times faster (or significantly more depending on the design).  I have added a check button to the calculation window so the plotting can be turned on/off, on the fly, during the v-carve calculation.

So if you are paying close attention you can see that all of these increases in speed build on each other (multiply not add) and result in a v-carve calculation 12 to 36 times faster than in the previous versions of F-Engrave.

I have also been digging into the code and fixing various minor bugs and adding some features to make aligning multiple v-carve files easier.  Here are the highlights of the other changes:

  • Changed Default Origin behavior (for DXF/Image files) to be the origin of the DXF file or lower left corner of the input image. (“Bot-Left” still provides the same functionality of the old “Default” setting)
  • Added automatic scaling of all linear dimensions values when changing between units (in/mm)
  • Fixed bug in clean up function in the v-carve menu. (the bug resulted in excessive Z motions in some cases)
  • Fixed bug resulting in the last step of v-carving for any given loop to be skipped/incorrect.

ScorchCad Preview (Update 1)

ScorchCAD Demo ScorchCAD Snowman ScorchCAD Lego

This is a quick update of my progress on ScorchCAD (A clone of OpenSCAD for Android devices).  I am slowly adding features.  So far I these are the items that are working:

  • Basic shapes (cube, sphere and cylinder)
  • Basic boolean operations
  • Colors
  • OpenSCAD file opening and saving using file dialogs
  • Support for variables is partially complete (I need to make set at compile time as are in OpenSCAD)

The pictures above are small models that I made using ScorchCAD while I was waiting for my kids hockey games to start.

Simple File Dialog For Android Applications

Since there isn’t a built in file dialog interface for android development I have been searching for one that I could use without starting from scratch. I did eventually find a Simple Directory Chooser with a very lenient license (The Code Project Open License (CPOL) 1.02). The directory chooser I found uses a dialog interface so there is no need to create an additional activity to use it.

The directory chooser was great but I needed a file dialog for choosing files for opening and saving not a directory chooser. To get the file dialog I needed I modified the original directory chooser adding to it as needed to create a Simple File Dialog for my own use. I thought I would post my modified version here for others to use or build on.

The file dialog code consists of a single file and uses standard Android resources. This file dialog code should be very portable and easily inserted into any project to add menu driven file selection within Android.  Screen shots of the three file dialog modes (Open, Save, and Folder Select) are shown below. The “Save” and “Folder Select” modes include a button for adding a new folder to the file structure.

Open Dialog save folder

The code can be downloaded here: SimpleFileDialog.java and MainActivity.java

Bare Bones Application Using the Simple File Dialog

This is a very bare bones application with three buttons that call the Simple File Dialog in all three modes (Save, Open and Folder Select). To make this application I just started a new Android Application Project in Eclipse. Edited the Layout to add three buttons and edited the MainActivity.java file. The finished MainActivity.java file is shown below.

Demo Screen

//MainActivity.java
package com.scorchworks.demo;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;

import android.widget.Button;
import android.view.View.OnClickListener;
import android.widget.Toast;

//import android.view.View;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		//Button1
		Button dirChooserButton1 = (Button) findViewById(R.id.button1);
		dirChooserButton1.setOnClickListener(new OnClickListener() 
		{
			String m_chosen;
			@Override
			public void onClick(View v) {
				/////////////////////////////////////////////////////////////////////////////////////////////////
				//Create FileOpenDialog and register a callback
				/////////////////////////////////////////////////////////////////////////////////////////////////
				SimpleFileDialog FileOpenDialog =  new SimpleFileDialog(MainActivity.this, "FileOpen",
						new SimpleFileDialog.SimpleFileDialogListener()
				{
					@Override
					public void onChosenDir(String chosenDir) 
					{
						// The code in this function will be executed when the dialog OK button is pushed 
						m_chosen = chosenDir;
						Toast.makeText(MainActivity.this, "Chosen FileOpenDialog File: " + 
								m_chosen, Toast.LENGTH_LONG).show();
					}
				});

				//You can change the default filename using the public variable "Default_File_Name"
				FileOpenDialog.Default_File_Name = "";
				FileOpenDialog.chooseFile_or_Dir();

				/////////////////////////////////////////////////////////////////////////////////////////////////

			}
		});

		//Button2
		Button dirChooserButton2 = (Button) findViewById(R.id.button2);
		dirChooserButton2.setOnClickListener(new OnClickListener() 
		{
			String m_chosen;
			@Override
			public void onClick(View v) {
				/////////////////////////////////////////////////////////////////////////////////////////////////
				//Create FileSaveDialog and register a callback
				/////////////////////////////////////////////////////////////////////////////////////////////////
				SimpleFileDialog FileSaveDialog =  new SimpleFileDialog(MainActivity.this, "FileSave",
						new SimpleFileDialog.SimpleFileDialogListener()
				{
					@Override
					public void onChosenDir(String chosenDir) 
					{
						// The code in this function will be executed when the dialog OK button is pushed
						m_chosen = chosenDir;
						Toast.makeText(MainActivity.this, "Chosen FileOpenDialog File: " + 
								m_chosen, Toast.LENGTH_LONG).show();
					}
				});

				//You can change the default filename using the public variable "Default_File_Name"
				FileSaveDialog.Default_File_Name = "my_default.txt";
				FileSaveDialog.chooseFile_or_Dir();

				/////////////////////////////////////////////////////////////////////////////////////////////////

			}
		});

		//Button3
		Button dirChooserButton3 = (Button) findViewById(R.id.button3);
		dirChooserButton3.setOnClickListener(new OnClickListener() 
		{
			String m_chosen;
			@Override
			public void onClick(View v) {

				/////////////////////////////////////////////////////////////////////////////////////////////////
				//Create FileOpenDialog and register a callback
				/////////////////////////////////////////////////////////////////////////////////////////////////
				SimpleFileDialog FolderChooseDialog =  new SimpleFileDialog(MainActivity.this, "FolderChoose",
						new SimpleFileDialog.SimpleFileDialogListener()
				{
					@Override
					public void onChosenDir(String chosenDir) 
					{
						// The code in this function will be executed when the dialog OK button is pushed
						m_chosen = chosenDir;
						Toast.makeText(MainActivity.this, "Chosen FileOpenDialog File: " + 
								m_chosen, Toast.LENGTH_LONG).show();
					}
				});

				FolderChooseDialog.chooseFile_or_Dir();

				/////////////////////////////////////////////////////////////////////////////////////////////////

			}
		});

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
//

For the New Folder button to actually create a new folder in the demo you need to include the following line in the Manifest file to give the app permission to write to the SD Card.

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

None of this code would have been possible without the jump start I got from the Simple Directory Chooser

Simon Hack a Day’ing

Simon
Hack a Day is having another contest.  This time it is a microcontroller based contest.  The entries need to hide hackaday.com in a microcontroller project as an Easter egg.  The extent of my experience with microcontrollers was soldering together at a Simon project at a Maker Faire a few years back.  I have been meaning to buy an FTDI board to program the Simon for a while now but never seemed to get around to it.  When the Hack a Day contest launched I decided now was the time to give it a shot.

A few days later with the FTDI in hand it was time to start creating my Easter egg.  I downloaded the original source code for the Simon (available on the Sparkfun web site) and started adding my own code to incorporate the Hack a Day URL.  What I came up with is a fully functional Simon game with a couple of minor twists.  The first change is that when Simon is playing the sequence of buttons for the player to repeat.  The sequence is played by Simon in an irregular pattern which is actually Morse code for “hackaday.com”.  When playing the game it is clear that the timing is a little off but it hard to tell it s Morse code because the tones change with the different colored buttons.  The video below shows the Simon playing with the modified program.

Game Play Video: Game Play Video Direct Link

Since I am not great at playing the Simon game I added another method to generate the full Morse code for “hackaday.com”.  Usually to start the Simon game the player needs to push one of the buttons to initiate the beginning of a new game.  I modified the program to detect if two buttons are pressed rather than one.  With the modified program when two buttons are pressed at the same time the Morse code it pulsed out prior to the game starting.  The video below shows the full Hack a Day URL being played by Simon.

Two Button Press Video: Two Button Press Video Direct Link

I have uploaded my modified code here: Simon_Game_Code_with_morse_code.ino. I included all of the letter codes in my look-up function so the Morse code message can easily be changed.  The length of the game is automatically adjusted to the length of the string entered in the egg array.