2009-12-31

Reality Blows: Strange LCD Problem and Strange Solution.

I spent the better part of two hours struggling with your average HD44780 driven 16x2 character LCD, even though I was using the LiquidCrystal library that comes with the arduino environment. My problem was the text I was printing out looks like this:


I tried a lot of things, like adding in delays here and there, even going so far as to use a subclass of LiquidCrystal which inserts a 2ms delay after each write to no avail. Then by a process of elimination, I found that if I reverse the order in which the lines were printed, i.e. print line 1 then line 0, the problem goes away:


Whiskey Tango Foxtrot.

Cheers,
Steve

Order Matters With XCode's Build Phrases

I use a custom script to insert the current git commit into GeoNote, so when I get bug reports I have a better idea of which version the user is running. The script is as below:

import os
from Foundation import NSMutableDictionary

version = os.popen4("/sw/bin/git rev-parse --short HEAD")[1].read()
info = os.environ['INFOPLIST_FILE']
print info
plist = NSMutableDictionary.dictionaryWithContentsOfFile_(info)
print plist
plist['revision'] = version[:-1]
plist.writeToFile_atomically_(info, 1)

This was added as a Run Script Build Phrase. The problem I noticed was that the commit short hash inserted into Info.plist was always one commit behind. After some head scratching, I realised this was because by default the new build phrase is inserted last, and the order matters! It isn't actually possible to reorder build phrases by drag and dropping the children nodes around. You have to do a head-insert by dragging a child to the parent, which inserts it at the top.


Voila, problem solved.

Cheers,
Steve

2009-12-22

Don't Worry About the Pirates.

So you are an indie musician, and you are worried about pirates – those naughty people who are allegedly stealing food off your table and from the mouth of your children.

Well I am here to tell you there is no need to worry – pirates may just be the best thing to ever happen to you.

First, let me tell you something that you probably don't want to hear – you are nobody. You are nobody in the sense that 99.9999% of the people on this planet has never heard of you. The only way to change this is to get your music into the ears of as many people as possible

Big artists do this – they have TV spots, radio spots, newspaper reviews. These are all ways to reach listeners without them paying anything.

This is also what you need to do, and pirates do this very well. If a single pirate distributed your music to two other pirates, and they in turn distribute to two more pirates and so forth, in a very short time you would have reached all of western civilisation.

Now I can see you getting puffed up, about to yell at me how this doesn't make you a dime. Just give me a second, will you?

The second thing I am going to tell you is that to a first approximation, you make money only from your fans. Remember that the word "fan" comes from fanatic – they are people who bought the Fellowship of the Ring when it first came out on DVD, then bought the Director's Cut, then bought the Special Limited Collector's Tin Box Edition , and then the Super Mega Ultra Edition that came with a Gandalf bust, then they did it again for the Two Towers, Return of the King, then for the whole damn series. These are people who have 12 versions of each Lord of The Rings trilogy, and will purchase the anniversary edition when it comes out in 2012 anyway.

The point is: your fans love you, they will buy your music, your merchandise, and go to your concerts even if they can get it for free – that is just how fans are.

Now the only way to get fans is to have people listen to your music, and as long as you have a non-zero conversion rate of joe-listener-to-fan, you come out on top. The more people you reach, the more fans you get, and the more money you make.

Just in case you don't get it yet, here it is in point form:

  • no one has heard of you
  • if no one has heard of you, you have no fans
  • you make money from fans
  • people become fans from listening to your music
  • pirates distribute your music to millions, even billions of people
  • this increases your fanbase
  • a larger fanbase means more money
  • a large enough fanbase means you have Made It Big

Got it?

Cheers,
Steve

Latching Power Supply With Electronic Turn Off



This circuit has (as far as I can tell), 0 off current, and 17mA on current. It is latched by the momentary push button, and can be turned off by applying >0.7V at the input as shown. It is intended for use with embedded interactive installation (e.g. an arduino) where the user pushes the button to turn the device on, and the device will turn itself off after some time to conserve battery.



It is a modified version of this circuit.


Cheers,

Steve

2009-12-17

Nice Work Australia Computer Society


You came to me during my first year in university, and sold yourself as the paragon of virtue and integrity - the kind organisation I would be foolish not to be associated with if I want to get anywhere in Australia doing software, or "Information Technology" as they call it now days.




I didn't join then, because I didn't have the money. I didn't join later because my career focus shifted away from software. I won't join now ever, because you have sold out.




I am referring to the honorary membership you awarded to none other than one Stephen Conroy, Internet Villain of the Year, 2009.




You had such nice things to say about him too:




“We are very pleased to honour Senator Conroy’s contribution and support of the significance of ICT to the economy and the key role of ICT professionals in Australia’s future,” said Mr Wells.



If I am so inclined as to read between the lines, I can't help but get the feeling you are thanking Mr. Conroy for pushing the Internet filter scheme, and in the process provided jobs for the programmers and technicians involved in the various trials and consultations.




“Senator Conroy has always encouraged the ACS in its role as the independent voice of the ICT profession, welcoming our input to various enquiries and working groups, and regularly attending key ACS events. We are grateful for his on-going support,” Mr Wells said.



I don't think Mr. Conroy is listening to your input, or learning from your events - he continues to believe filtering the Internet is doable, and not a waste of time and resources.




I reject you, Australia Computer Society, as "voice of the ICT profession". Your actions are deplorable and shows a lack of integrity. If I was a member, I would be ashamed.




Cheers,

Steve

2009-12-16

Yet Another Arduino Float Print Function

Note: in arduino-0017, floating point printing is supported by default. The function below is not necessary.

void floatPrint(float f, int places=6)
{
        int _d;
        if (f < 0)
        {
                Serial.print("-");
                f*=-1;
        }

        _d = (int)f;
        
        if (!places)
        {
                return;
        }

        Serial.print(_d, DEC);
        Serial.print('.');

        while(places--)
        {
                f-=_d;
                f*=10;
                _d = (int)f;
                Serial.print(_d, DEC);
        }
}

void floatPrintln(double f, int places=6)
{
        floatPrint(f, places);
        Serial.println();
}
Why another float print function? The ones I found wasn't too nice, one of which required long integers. Yuck. It was also fun, and now I know where to look for one in the future :P
Cheers,
Steve

2009-12-07

A subtle source of linker errors under XCode



If one source file is sourcecode.c.objc and another is sourcecode.cpp.objcpp, you will have problems if you try to call function defined in one file from the other. The resolve this either make them the same source type, or follow this guide.



This drove me nutty because the template I was working off has code set to sourcecode.cpp.objcpp, but XCode adds new classes as sourcecode.c.objc! To check the file type, use "Get Info" in the source file's context menu.



Cheers,

Steve

2009-10-11

qrbackup

I generated a gpg keypair for myself today, and I was looking for a fairly safe way to back it up. I don't particularly trust DVD/CDs, and keeping it on flash is even more worrying. I wanted a means of backup I can see and touch.



Paperbak would be great if it was ported to something not windows. Since it wasn't, I settled on QR Code.



Thus qrbackup was born. It will base32 encode a file, then encode it into QR codes using google chart service.



I have tested it from backup to restoration, and it works. YMMV, more instructions available after the jump.




Cheers,

Steve



P.S. Pardon my python.

2009-08-05

git-daemon on debian vserver

Annoyingly git-daemon-run requires runit on debian, but runit will fail to install properly in a debian vserver because it doesn't have init.



One solution is to reconfigure vserver to use plain init style.



However I didn't want to this because I don't want to take down my vserver just yet. So here is the required line for /etc/inetd.conf:




git stream tcp nowait nobody /usr/bin/git git daemon --inetd /var/git-repos



Cheers,

Steve

2009-08-03

Homeopathic logic

On Dr Karl on Triple J Podcast recently, and a lady called in (lets call her B) to say homeopathy works for her. She said her children were never vaccinated, and only receives homeopathy treatments, just like all her friend’s children, and that they are all healthy. B thus concluded that homeopathy works, and to show she isn’t the only one who thinks so, she presents the Royal family, who practices homeopathy, as a supporting fact.



It would appear at first she is right: homeopathy works and the facts are compelling - but a little critical thinking goes a long way.



Firstly, the only logical conclusion one can draw from the facts presented isn’t homeopathy works, but homeopathy isn’t fatal.



To arrive at B’s conclusion one would need to:



  • give one of her children placebo

  • give one of her children prescribed medicine

  • give one of her children nothing

  • give one of her children homeopathy



Further, one would need to observe the child given homeopathy doing better than the other children to show homeopathy:



  • isn’t a (costly) placebo

  • works better than prescribed medicine

  • isn’t harmful



These kind of things are done in clinical trials, and no clinical trial to date has shown that homeopath has anything more than a placebo effect.



So what about the Royal Family? Surely, you think to yourself, this lends homeopathy the weight of authority. However this is a logical fallacy known as “argument from authority” or “appeal to authority”. Simply put, just because some one in authority says it is true, doesn’t mean it is. After all, we were told there were weapons of mass destruction in Iraq...



It would appear most adults do not engage critical thinking: to look at what facts are presented, evaluate how reliable they are, and judge claims based on those facts. Even a cursory examination of the principles of homeopathy shows it runs contrary to, and has no basis in, reality. Yet this makes no difference to some people, who latch on to any fanciful tale as the truth as long as it makes them feel better, or it aligns with their world view.



In a world populated by scientologists, perhaps it is unsurprising we find fervent supporters of homeopathy. I can only hope that natural selection does its job.



Cheers,

Steve

2009-06-07

Dealing with rkhunter warnings

rkhunter often warns on file property changes after upgrade and such, and sometimes you just aren't sure whether it is due to recent upgrades, or because you really were compromised. The following script was written to compare the checksum of all files rkhunter warns about against the originals in a debian repository.



The latest version of this is available in my script.git respos.




#!/bin/bash
desc="
This script will verify whether files for which rkhunter has logged a
warning for is still valid. It does this by finding which debian package
it came out of, and downloads them, unpacks them, then checks
the checksums.

Run it by supplying a rkhunter log file as first argument
"

HASHER="sha256sum"

IFS="
"
function find_suspect_files
{
echo "parsing $1 for suspect files" 1>&2
grep -1 Warning "$1"| grep File | sed 's|.*File: ||'
}

function find_packages
{
echo "finding packages" 1>&2
for suspect_file in $1
do
package=$(dpkg -S $suspect_file|awk '{print $1}'|sed 's/.$//')
echo "suspect file $suspect_file found in $package" 1>&2
echo $package
done

}

function make_aptitude_args
{
echo "generating aptitude arguments" 1>&2
for package in $1
do
version=$(dpkg -p $package | grep Version | awk '{print $2}')
echo $package=$version
done
}

function cleanup
{
echo "cleaning up"
popd
rm -rf tmp
exit $1
}

function setup
{
echo "setting up"
rm -rf tmp
mkdir tmp
pushd tmp
}

if [ $# -ne 1 ];
then
echo "$desc"
exit 1
fi

suspect_files=$(find_suspect_files "$1")

packages=$(find_packages "$suspect_files" | sort | uniq)

if [ -z "$packages" ];
then
echo "***WARNING****"
echo "No packages contain any of the suspect files!"
cleanup 1
fi

aptitude_args=$(make_aptitude_args "$packages")

setup

echo "downloading packages"
aptitude download $aptitude_args 1>/dev/null
if [ $? -ne 0 ];
then
echo "aptitude download failed!"
echo "args=$aptitude_args"
cleanup 1
fi

echo "unpacking"
for deb_file in *.deb
do
ar -x $deb_file
tar zxf data.tar.gz
rm -rf data.tar.gz control.tar.gz
done

for suspect_file in $suspect_files
do
if [ ! -f ".$suspect_file" ]
then
echo "***WARNING****"
echo "For some reason .$suspect_file does not exis!"
continue
fi
echo -n "verifying $suspect_file... "
suspect_sum=$($HASHER $suspect_file | awk '{print $1}')
clean_sum=$($HASHER ".$suspect_file" | awk '{print $1}')
if [ $suspect_sum == $clean_sum ];
then
echo "OK"
else
echo
echo "***WARNING****"
echo "Checksum mistmatch for $suspect_file!!!"
echo "Should be: $clean_sum"
echo "Is: $suspect_sum"
fi
done
cleanup


Cheers,

Steve

2009-06-04

microbric viper review

The microbric viper is neat. Good quality parts and unique idea. Makes a decent robotics platform if you get the wheel add-on. However, you gotta have small fingers to get some of the parts in place. Despite this, the hardware is solid, I like it. The one thing I would ask for however is more short-nuts and a printed manual, not a CDROM with a PDF. Take a leaf from LEGO and their construction manuals.



While the hardware is decent, the microbric viper is sadly let down by the software.



The microbric viper uses the basicAtom (by basicmicro), a PIC 16F87{6,7} with a custom bootloader. Now there is nothing wrong with this - arduino uses a custom bootloader too. However the custom bootloader uses a proprietary programming protocol. This is pretty fail, but what really fails is the programming software only runs under windows (or wine under ubuntu, but only for now).



IMHO the basic-esque language used by basicAtom is no better than what picaxe offers. I am completely at a lost as to why companies would use the basicmicro's products and lock themselves to a single supplier. Think about it: if basicmicro goes bust, your products using the basicAtom will not longer have a supported development environment.



Robotics companies need to seriously consider how their selection of controller will affect their customers - specifically those customers who aren't going to be running windows and staying with in the limits of whatever custom language designed by the controller vendors.



Arduino would be the best choice IMHO. Open hardware, open software. You don't have to pay premiums for the bootloader, and the number of people who will consider your product increases to include people like me.



I bought the microbric viper because it was on sale: reduced to $29 from $199. If I had known I could only program it under windows or that it used such a closed platform, I won't have bought it, even for that price.




Cheers,

Steve