I always forget how to make a poster using ghostscript.

the command is ‘poster’

sample usage:

poster -v -mletter -c5% -s1 input.ps -o output.ps

This will enlarge the original and put crop marks on the resulting pages.

 

I created a LibreOffice cheat sheet to help me quickly learn and recall the syntax.

It covers some very useful things:

 

Getting the Sheet

Getting A Cell

Iterate over a range of cells:

Getting Form Elements
Set a Cell to current timestamp

HTTP Method GET call and store data
Reading And Writing A File

 

Trying out a new category: Snippets

These will be tiny shell scripts or pieces of code.

The first one is how to have linux convert GPS NMEA text files to kml format.

 

#!/bin/sh
gpsbabel -i NMEA -f $1 -o openoffice -F test.csv
gpsbabel -i openoffice -f ./test.csv -o kml -F test.kml

 

Im sure there is a better way…but this one works and gives a .csv file as an intermediate.

 

 

Now that we live in he age of the Internet-of-Things (IOT), I find that these ‘things’ have to communicate to a normal web server at some point.

The problem of course is how best to send data to the server and make sure what was sent is what was received. My preferred method is to use ‘Method GET’ which means that the data is encoded in the URL. It is easy to implement on just about any platform from Arduino UNOs to Arm Cortex processors. Every platform that supports 802.11 or 802.3 will have an example of using ‘Method GET’ to fetch a URL. Which means that the opportunity to send data is as easy as getting a URL.

The next problem is how to send binary data. Since the URL schema has special characters like, ‘”/?& that have meaning you cant just send binary data in the url. To be completely safe in a 7bit ASCII world, one needs to encode that data into some format.

For example if you wanted to send a number of 0x31EAA5 via a URL you could do http://127.0.0.1/?q=3271333 easily enough. That would be converting the number to a integer represented by ASCII characters. This method becomes cumbersome when there are multiple values to send: ?q1=555&q2=444&q3=333&q2=222

My preferred method of late is to send the data as a byte stream. Doing this requires some sort of ASCII armor, such as BASE64 or UUENCODING. Originally I started using base64 which creates GET URLs like: ?q=SSBhbSBEQVRBCg== which decoded on the receiving server would be ‘I am DATA’. But for whatever reason the encoding uses special characters for some data. Namely / and + characters. So a few variants of base64 have sprung up to change these characters to more friendly to URL or other standards.

Not wanting to deal with the hassles of base64. I decided to give base 16 a try as the encoding. This has worked out rather well. Base16 encoding is easy to implement in any language. And many have built in encoders/decoders.

So in the above example of the data being ‘I am DATA’ it would render as

?q=4920616D2044415441

It uses exactly twice as many bytes as the original data, but is perfectly safe to transport binary data. So the sacrifice is size vs safety and ease of implementation. I will almost always chose ease of implementation over any other factor.

On to the code:
Full Examples

Arduino code snippet

char base16[16]={ '0','1','2','3','4', '5','6','7','8', '9','A','B','C', 'D','E','F' };
// this expects byte theData[len] and byte theEncodedData[len*2]
void base16encode()
{
  char b1,b2; // bytes 1 and 2 of the encoded data
  byte ev; // the value to encode
  for (int lop=0; lop<theDataLength; lop++)
  {
    ev=theData[lop]; 
    b1=base16[( (ev>>4) & 0x0F)];
    b2=base16[( (ev) & 0x0F)];
    theEncodedData[(lop*2)]=b1;
    theEncodedData[(lop*2)+1]=b2;
  }
}

PHP snippet

function base16decode($data)
{
  $retv="";
  $base16str="0123456789ABCDEF";
  for ($lop=0; $lop<strlen($data); $lop+=2)
  {
    $oneByte=$data[$lop];
    $twoByte=$data[$lop+1];
    $v1=strpos($base16str,$oneByte);
    $v2=strpos($base16str,$twoByte);
    $theValue=($v1*16)+$v2;
    $av=chr($theValue);
    //echo "ob[$oneByte]tb[$twoByte] v1[$v1]v2[$v2] tv[$theValue] av[$av]| \n";
    $retv.=$av;
  }
  return $retv;
}

These code examples are written with the goal of being easy to read and understand rather than being examples of a good coding style.

Over the last few days I have been Tweeting photos with location but I am unhappy with how the maps are displayed.  So I made a bookmarklet to extract the map links.

Grab the GPSCoords bookmarklet by following the link then dragging and dropping it from there.

This is the first project that I am putting up using the Teensy 2.0 from PJRC

I am quickly becoming a super fan of the Teensy.  What used to take me days of coding and many hours of reading I can now do in minutes thanks to the work that PJRC has done with Teensydunio.

This is only the first of many projects that I will share based on the Teensy.

USB MIDI Servo Control In 23 Lines Of Code

I just put up my first alpha version of BasicToGCode.
basictogcode allows scripting of of RS274D g-code directly into EMC2 using BASIC (Beginner’s All-Purpose Symbolic Instruction Code).

It allows you to draw geometric shapes programmatically.

Today I wanted to see all the URLs I had visited in Firefox. I tell it keep my history for a very long time. I grow tired of bookmarking and managing those bookmars. I want to be able to do something like say: “What was that site I visited a few days ago that sold Widget X”.

Firefox3 stores its history in a file called places.sqlite which is in sqlite3 format. So with sqlite3 installed this is the command I used to export my history to a text file.

echo "SELECT datetime(moz_historyvisits.visit_date/1000000,'unixepoch'), moz_places.url,moz_places.title,moz_places.visit_count FROM moz_places, moz_historyvisits WHERE moz_places.id = moz_historyvisits.place_id ORDER by moz_historyvisits.visit_date; " | sqlite3 ./places.sqlite

Now I can add a grep to the end of that and find what I was looking for.

Why not just use the built in search for finding stuff? Well the simple reason is that I can add more complex searches easily using regex.

Plus I wanted to be able to export and save my history to a file where I can search it later. Without having to install some firefox extension.

If you wanted to get really adventurous you could do some php like this:


<table>
<?
$todo=”SELECT datetime(moz_historyvisits.visit_date/1000000,’unixepoch’), moz_places.url,moz_places.title,moz_places.visit_count FROM moz_places, moz_historyvisits WHERE moz_places.id = moz_historyvisits.place_id ORDER by moz_historyvisits.visit_date;”;
$dbh = new PDO(‘sqlite:places.sqlite’);
foreach ($dbh->query($todo) as $row)
{
//print_r($row);
echo “<tr>\n”;
echo “<td>”.$row[0].”</td>\n”;
echo “<td><a href=\”".$row['url'].”\”>”.$row['title'].”</a></td>\n”;
echo “</tr>\n”;
}
?>
</table>

This is an update to the Das Blinken Board from N&V June 2009. Der MagnetFelder uses a hall effect sensor to determine the relative strength and polar orientation of magnets.

Get the whole story in Nuts & Volts November 2009 and check out the website www.dasblinkenboard.com for the code.

I have been running into a problem when I am moving at really high IPM (inches per minute) using EMC2 Axis.

This image sums up the problem I was having:

Axis EMC2 was rounding my corners. I wanted it to go to that spot and then move on to the next line of G-Code. My friend Paul and I did a little research. He remembered that there was something on the emc2 list about CV problems. Where emc2 would try to keep a constant velocity.

As we researched we found out that emc2 implements “Trajectory Control” using the G61 and G64 commands.

So to solve the “problem” I was having. I told my Gcode file to use G61 Exact Path Mode. It got rid of the rounded corners I did not want.

Next Page »