## December 31, 2009

### 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

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

## December 22, 2009

### 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.

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
• 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

## December 17, 2009

### 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.

“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

## December 16, 2009

### 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

## December 07, 2009

### 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

## October 11, 2009

### 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.

## August 05, 2009

### 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

## August 03, 2009

### 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

## June 07, 2009

### 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.

Cheers,

Steve

## April 06, 2009

### YLDE comic: half as funny half as often.

because imitation is the best form of flattery.

title="and the product of their age will be my private key"/>

Cheers,

Steve

Cheers,

Steve

## February 16, 2009

### Futurlec Ultrasonic Sensor Note

Part number US1440, these sensors are not dual use, which means the transmitter and receiver is not exchangeable. They also look identical from the outside, so if you build my arduino ultrasound ranger with these (as I did) and find you can't see echoes, try swapping your transmitter and receiver around! It cost me no small amount of headach this morning.

Cheers,

Steve

### Arduino ultrasound ranger

Code to drive it is avaliable under GPL.

An updated version of the schematic as a .sch file is available also.

Cheers,

Steve

## February 13, 2009

### The libertarian argument against vaccination

Goes like this:

I have a right to decide what happens to my children!

To that I say, we have the right to not be a victim of your stupidity. Further, laws represent social contracts that all members of society enter into for everyone's benefit. Getting vaccinated is one such contract which serves to prevent epidemics of infectious diseases.

If you really don't want to vaccinate your child, then please ensure your child never comes into physical contact with the rest of society for our sake. I would not welcome them without vaccinations.

Cheers,

Steve

## February 06, 2009

### MATHS FAIL

What is the period if you want to generate a 40KHz signal? It certainly isn't 250E-6 seconds. The same calculator returns 2500E-3 for 1/4 which is 2.5, not 0.25.

The calculator is PEMDAS.

Cheers,

Steve

## January 25, 2009

### Auto leveller

A simple 2 DoF setup with an accelerometer (LIS302DL) attached to the effector. The seeeduino attempts to drive the servos so the Z and Y axis measure zero acceleration. The sketch is available at the usual place.

The algorithm employed is a simple PD controller with pseduo-gradient stepping to determine how to control each servo without any knowledge of how the servos are arranged. To deal with sensor noise from the accelerometer, a schmitt trigger mechanism is employed along with a moving average.

The code also allows the system to be calibrated to deal with accelerometer miscalibration.

It is cute, but that is about it :-) Coupled with a tripod and better construction ut might be useful for some DIY surveying or construction work.

Cheers,

Steve

## January 13, 2009

### Turn a servo into 1-wire-control bi-directional motor

It is often a pain building H-bridges or getting a motor shield just because you want to control a few motors. This is where servos come in: they are cheap(ish), have motor and gearbox, and they are controlled ysing only a single wire.

The only problem is of course, servos aren't designed for continuous motion. Servos are designed to respond to PWM pulses which encode the desired position for the servo to be in, not a desired speed or direction. So some modification is required.

Now there are many articles on the intertubes on how to do this, but they mostly concern themselves with making the servo into little more than a normal motor with a gearbox - you still need a H-bridge to control the direction. This modification is a little different: it leaves you with a servo that behaves like a bi-directional motor where the direction is controlled by a single wire.

Due to the variety of servos out there, I will present only the general idea, which applies to servos which use a potentiometer to determine position.

Firstly, a quick explanation of how these servos work. The principle behind these servos is that the potentiometer is connected to the output gear such that the voltage of the sweeper (connected to the middle pin usually) depends on the angular position of the output gear. The onboard controller converts the input PWM signal into a target voltage, then it powers the motor so it turns the output gear until the voltage of the sweeper matches the target voltage. This is kind of control action is relatively easy to achieve using an operational amplifier.

The basis of the modification is essentially this: if we fix the sweeper voltage, then any input asking the servo to move away from the sweeper voltage will result in the onboard controller continuously attempt to match sweeper voltage to target voltage. By making the target voltage higher or lower than the sweeper voltage, we get directional control.

To fix the sweeper voltage, the potentiometer will need to be disconnected and replaced with a voltage divider. I assume that when the output gear is in centre position, sweeper voltage is half the supplied power because the potentiometer will be in its centre position. Since I wanted 0 degree rotation to map to stop, I fixed the sweeper voltage at this value by using 2x1.5K resistors in series. This is all you need to do electronically. There should be enough room to fit in 2 extra resistors, even in small 8g servos (what I had).

The last thing to do is to remove any physical obstructions which prevent the output gear from completing a full revolution.

Once the electronic and physical modifications are complete, you should have a servo which can turn in either direction continuously and controlled via single wire. Two of these would be perfect for say powering a small rover...

Cheers,

Steve

## January 04, 2009

### Tips for interfacing a electret mic with an arduino

1. The arduino ADC is 10bit, which means the range is 0-1023 and this is mapped to 0-5V most of the time, unless you do funky things to AREF.

2. Most amplifier circuits on the net (using op-amps or LM386s) will have a DC bias of 2.5V, this is to allow the output to swing both ways. So on the arduino side even with complete silence you will read a value ~512 or so.

3. The resistor connecting the electret mic and power also adjust the sensitivity of the microphone in addition to providing power to the mic (which includes an internal pre-amp, by the way). This resistor is very important - if you find your microphone isn't responsive enough, then adjust this resistor first before debugging your amplifier circuit. For me this "fixed" my microphone's responsiveness. It is best of this was a variable resistor which makes adjustment trivial.

4. I was making a simple volume meter, and I did the following: clamp upper values to about 600, then using map map this to a range between 0-7 (since I had 8 LEDs). This was because I found the value never went above 600 very often, so the upper few LEDs were essentially going to waste sitting around. YMMV.

Cheers,

Steve