Category Archives: Useful tools

Eclipse with avr eclipse plugin

Eclipse can be used for Arduino and avr embedded development with avr-gcc. There is a nice plugin for it: http://avr-eclipse.sourceforge.net/

The plugin parses the output of some command line program to provide some properties and settings in eclipse. When the system local is not english, this cannot be parsed correctly. The simple fix is to run eclipse with the english locale.

Just create a script with:

#!/bin/bash
LC_MESSAGES=C eclipse

valgrind error – profiling timer expired

Nothing new and nothing surprising, but it still was painful to find out:
Do not use valgrind or helgrind in combination with the c++ compiler options -p and -pg for profiling.

This gave me some strange behavior of my app with sleeps not sleeping. I only had a crashing application, no clue what might be wrong with my code and the error message “Profiling timer expired”.

Just switch off the profiling options and everything was find, except the errors that I wanted valgrind to find for me.

G-code from svg files

Again I spent some time searching for free tools to improve my cnc toolchain. I stumbled upon two simple but helpful flash programs for handling g-code files:

  1. Makercam (http://www.makercam.com/)
    This tool loads svg files and generates g-code toolpaths from it. I can create programs for drilling, pockets, outlines and follow path operations. There are only two things to keep in mind when using it:

    • The svg file may only contain a single path. However this is not a big problem, because you can create such svg files easily using inkscape. Just combine all paths and then save it.
    • Makercam assumes a resolution of 72 dpi when importing a svg file. Inkscape produces files, that have 90 dpi. To fix this open the preferences of Makercam and replace 72 by 90 dpi before loading any svg.
  2. G-code viewer (http://www.buildlog.net/gview/index.html)
    This tool offers a quick way to inspect your g-code files before sending them to a cnc mill. Just drag the g-code file onto the browser window. All rendering is done locally without transferring your file to a server.

Measuring execution times in .NET

C#

var watch = Stopwatch.StartNew();
// the code that you want to measure comes here
watch.Stop();
var elapsedMs = watch.ElapsedMilliseconds;

Taken from: http://stackoverflow.com/questions/14019510/calculate-the-execution-time-of-a-method

Merge multiple pdfs into a single file

Ubuntu brings a nice package called “pdftk” for editing pdfs using the command line. This command joins multiple pdfs into a single pdf:

pdftk 1.pdf 2.pdf 3.pdf cat output 123.pdf

Here is another way to join pdf files, that only requires ghostscript:

gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=123.pdf 1.pdf 2.pdf 3.pdf

Using the commandline editor “sed” for batch renaming of files

Given a set of files, that all end with “.png.jpg”. We want to remove the “.png” from the filename. This can be done using the linux shell pipes and the commandline editor “sed”.

Examine this command: ls * | sed ‘s/\(.*\)png\.\(.*jpg\)/mv & \1\2/’ | sh

The interesting part here is of course sed ‘s/\(.*\)png\.\(.*jpg\)/mv & \1\2/’. The general syntax is “sed ‘s/patternToSubstitue/SubstituteBy/'”.

  • s means “substitute”
  • \(.*\)png\.\(.*jpg\) This splits the given string into a segment of arbitrary content \(.*\), another segment containing the fixed string “png.” and a third segment \(.*jpg\) consisting of a string with arbitrary content ending with “jpg”. The first and third part are dynamically created, so sed allows to reference them using \1 and \2
  • mv & \1\2 This part constructs a command that can be executed by the shell. The “&” references the original string passed into sed, the parts \1 and \2 are generated above and concatenated.

The result of this command is, that the substring “png.” is removed from all filenames in the current directory. Files that don’t match this pattern are not changed, because the mv command gets the same name as source and target file.