USB Fart Detector (unfortunately)

It is a truth universally acknowledged, that an engineer in possession of a solid-state flammable gas detector, will shortly make a fart detector with it. I’m sorry, but call it childishness, simple-minded curiosity, or the results of a diet high in polysaccharides, but this is something I have to get out of my system. (It’s okay; I’ll waft the door.)

This all started when our carbon monoxide detector decided it was past its best, and started to emit an ear-splitting shriek. Thinking there might be some cool parts inside, I took it apart. Inside, in amongst the other stuff, I found this:

gas sensor boardThankfully, David Cook of Robot Room had once had the same idea as me (well, minus the puerile bits), and he documented the sensor board very well: Explosive Gas Detector Board. Here are the four pins that you really need to get the thing going:

 Pin # (from left)    Function
===================  ==========
       1              Vcc
       2              /Enable
       3              /Gas
       5              Gnd

Pins 2 and 3 are active low signals. To be typographically correct, I’d write them as Enable and Gas, but that’s hard to do in fixed-pitch ASCII. I can understand why the Gas signal should be active low (think about it; if the Figaro TGS 2611 sensor fails or shorts, it will likely fail to an alarm state, so you’ll still be alive to curse the bloody noise that woke you at 03h00), but the Enable being active low? Dunno.

I was hoping to have presented a little sketch for the Digispark that would have typed something unhelpful every time that gas was detected, but it was not to be. It seems that Macs and Digispark keyboard emulation is a thing of great wobbliness, so I had to resort to an Arduino and a serial connection.

Here’s the code:

/*
 gas_detector - uses board scavenged from CO detector
 
 scruss - 2013-02-18 (unfortunately)
 */

int gas     = 2;               // /Gas line on pin 2
int val     = 0;
int lastval = 0;

void setup() {                
  pinMode(gas, INPUT);
  Serial.begin(115200);
}

void loop() {
  val = digitalRead(gas);
  if (val != lastval) {
    if (val == LOW) {          // LOW means gas detected
      Serial.println("gas");
      Serial.println();
      delay(1000);             // wait 1s for air to clear
    }
  }
  lastval = val;
}

Before you ask, I tested the circuit by briefly hitting the button on a gas lighter. Honest.

I’ll keep working on the Digispark; it’s such a nifty little device, and this is such a worthy project …

Raspberry Pi as a USB audio capture device

The Raspberry Pi’s hardware and software support has come a long way in the few months it has been in the wild. I first tried this application in the summer, and the results were dismal. Now, thanks much improved USB driver support under Raspbian, I’m pleased to say it works flawlessly.

Earlier this year, I bought a turntable (ack!) for transferring vinyl to mp3. I have a TC-772 USB phono preamp, which spits out a 48 kHz stereo audio stream. If you plug the USB output of the preamp into a Rapberry Pi (running Raspbian Wheezy with all the updates), it’s instantly recognized as an audio device:

$ lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp. 
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. 
Bus 001 Device 004: ID 08bb:2902 Texas Instruments Japan PCM2902 Audio Codec

If you install the ALSA recording utilities (sudo apt-get install alsa-utils pulseaudio – this should pull in a whole bunch of necessary packages), you can record directly from this device with the following command:

arecord -D 'pulse' -V stereo -c 2 -f dat -d 900 out.wav

which records from the ‘pulse’ audio device, displaying a stereo text VU meter (handy for setting levels), writing to a two channel 16-bit 48 kHz file called ‘out.wav’ for a maximum of 900 seconds (15 minutes). arecord has a baffling number of recording source options; arecord -L will show them. ‘pulse’ was the first one I tried.

So how does it sound? Here’s a 30 second excerpt from the only single I owned for years, The Music Tapes‘ “The Television Tells Us/Freeing Song by Reindeer”: Freeing Song by Reindeer – excerpt [mp3]. I’ve saved an even smaller snippet as lossless FLAC so you can see that the waveform’s pretty clean: FreeingSongbyReindeer-tiny_excerpt [flac].

Sounds pretty good. Not quite as good as having Julian play it in your house, I’ll allow, but not bad for a first try with a $35 computer.

Wireless, Cordless Raspberry Pi

Yay! I found a wireless adapter that the Raspberry Pi is able to power without an external hub. It’s a Belkin N150 Micro Wireless USB Adapter. Not sure of the range, but it works well enough, and is cheap.

Just to show you how hard-core I am, that’s a screenshot of a browser (showing a picture of the Raspberry Pi + LSTech Solar charger) running on that Raspberry Pi with an X session tunnelled to the laptop you can see in the background. My head hurts now.

#swagfail

Put me out to pasture, my conference swag skills are failing.

I picked this up at Solar Power International:

I thought I was picking up a USB memory stick, as I’d nabbed one in the same form factor before. Break off the backing card at the hinge, and you’ve got a nice tiny data store like the Kingmax ones I used to use.

On plugging it into my Mac, a couple of icons bipped on my dock, then Skype opened. Wat? More importantly, there was no storage to be seen, so once my virus fears had subsided a bit, I was determined to find out what this pointless piece of plastic was doing.

The stick identified itself to the system as an Apple keyboard (USB ID 05ac:020b), and spits out the following characters (captured by cat and xxd on my Raspberry Pi):

0000000: 1b72 1b5b 317e 1b5b 3477 7777 2e62 757a  .r.[1~.[4www.buz
0000010: 7a63 6172 642e 7573 2f73 6365 2d32 3230  zcard.us/sce-220
0000020: 0a                                       .

After reading about evil USB dongles, it seems that the Ctrl-R keypress it's sending is the Windows "Open Browser" command, and then opens the url www.buzzcard.us/sce-220. This link redirects to www.plugyourbrand.com/gosolar_sce/index.html?u=220, which appears to do some Flash/JS stuff which I don't want to understand.

The funny thing is, the card has the perfectly respectable www.GoSolarCalifornia.ca.gov (well, respectable if you consider a US .gov website as such) link printed on it. Even printing a card with a QR code linking to that address would be less opaque.

(This is not a link to goatse, honest.)

As is, a bunch of plastic was wasted in vain just to save people typing an URL. We're all going to die, and it really is your fault ...

Pibow; it’s official – normal USB cables don’t fit

I’d noted previously that a standard USB micro-b power plug doesn’t fit into a Pibow. I’ve measured the opening in the case at 10.4 mm. This is what the USB.org spec says for the Micro-B plug:

A conforming cable can be up to 0.2mm larger than would fit into the Pibow. The rather weak excuse given by the designer is:

My Micro-USB cable doesn’t fit!

The Pibow supports a wide range of svelte, stylish micro USB cables, we recommend on [sic] of these. We may be able to slightly widen the aperture to include more cable. We don’t intend to support cables with large sleeves though, they just look naff :(

While I had the vernier calipers out, I measured all the USB connectors I could find. Not one was under 11 mm, way out of spec, and completely unlikely to fit in the Pibow.

a very quick guide to using a remote release with CHDK

CHDK allows your Canon P&S to do nifty things. One of them is to rig up a USB Remote Cable. Someone on Metafilter asked how to set this up, so here’s what worked with me and my PowerShot SD790is (Ixus 90).

!!! Warning: this requires you to apply unauthorized voltages to your camera. If in doubt, don’t. Check the CHDK camera-specific page for notes on voltages. Don’t hold me responsible if you let the magic smoke out of your camera !!!

You’ll need to install CHDK first. What you download and how you install it depends on your camera model and the memory card your using. This might help.

The good news is that CHDK comes with the remote script built in, so you don’t need to download anything else. You will need a suitable remote trigger, or a cannibalized USB Mini-B cable.

First, call up the CHDK menu. On my camera, that’s the Direct Print button (looks like this: ), which puts CHDK in Alt mode. Hit Menu in Alt mode, and you should see this menu:

Scroll down to Miscellaneous Stuff and select it:

Scroll all the way down to Remote Parameters (or, more quickly, scroll up, and the menu wraps round):

Now Enable Remote:

Go back to the main menu, and scroll down to Scripting Parameters:

Select Load Script from File …:

Enter the EXAM folder:

Select REMOTE.BAS:

Now you’ll be taken back to the Script menu, and the bottom of the menu shows that you’ve enabled the Remote button script:

Exit the menu, and hit the shutter button to extend the lens. You’ll get a normal display, a bit like this:

To allow the remote script to run, hit Direct Print/Alt, and the bottom of the display will show that the remote script is running:

Now you’ll need to rig up a trigger. I cannibalized an old USB Mini-B cable, and connected the black wire to ground, and the red wire – momentarily – to +5V. You will likely come up with something much more elegant.

And here’s me triggering a shot (you can see the amber focus/flash LED lit) by touching the red wire to +5V:

That’s all there is to very basic remote work in CHDK. Note that USB Remote V2 is in development, which allows finer control and many more options.

Chirp, the universal HT programmer

CHIRP is rather good. It replaces all the horrid proprietary HT programming software with one cross-platform, cross-radio solution. It allowed me to program my new Kenwood from data from my Wouxun. It uses transparent file formats, and can import from everything. It’s great!

Update: Whoa! It can now program my FT-857D! I just uploaded all the repeaters within 50km, and there’s a bunch going on on a few of them.

#nookfail

Got a couple of spare NOOKcolor Charging Cables, since (grar! gnash!) it uses its own special twist on the USB Micro-B connector that just doesn’t work with anything else. They came in a middling size box, and then each cable was packaged thus:
That’s a 120×75mm box with 70×70mm blocked out, leaving only 50mm for the cable. Stay wasteful, Barnes & Noble …

Arduino Uno USB invisible to OS X

as posted on the forum:

Just got my Uno after finding semi-permanent projects for two previous Duemilanoves. Upgraded to Arduino 0020. After rebooting, and power cycling the Uno, there’s still no serial port for the Uno.

The board is noted under Linux, which reports an unknown device with ID 2341:0001. On my MacBook (10.6.4), System Profiler lists:
Code:

Communication Device:

  Product ID:	0x0001
  Vendor ID:	0x2341
  Version:	 0.00
  Speed:	Up to 12 Mb/sec
  Location ID:	0x24110000
  Current Available (mA):	500
  Current Required (mA):	Unknown (Device has not been configured) 

There are no /dev/tty* or /dev/cu* devices that correspond to the device.

perhaps a slightly easier way to make SD cards bootable for CHDK under OS X

Now that CHDK has a working beta in the source tree for my Canon PowerShot SD790is, I actually have to prepare SD cards for it. The Bootable SD card – OS X instructions seem a bit contrived, so I took a look at the linux instructions, and modified them accordingly. These instructions should work for FAT16-formatted SD cards of 2GB capacity and under. It will not work for SDHC cards, which are generally formatted to FAT32.

This is all command-line only for here on in. It seems to work. Please note that you will be modifying raw file systems with root permissions here; there is no safety net. If you b0rk your main hard drive, don’t say I didn’t warn you.

Firstly, you’re going to have to find out where the SD card in mounted. Do this with:
df
I got:

Filesystem    512-blocks      Used Available Capacity  Mounted on
/dev/disk0s2   487463200 318749896 168201304    66%    /
devfs                222       222         0   100%    /dev
map -hosts             0         0         0   100%    /net
map auto_home          0         0         0   100%    /home
/dev/disk2s1     3969280      3328   3965952     1%    /Volumes/CANON_DC

There are three important concepts to note when looking at the mounted card:

  1. The mount point (or volume) – in this case /Volumes/CANON_DC. This is the location that you see in Finder when moving files around.
  2. The filesystem – here /dev/disk2s1. This is the partition on the disk, arranged according to a certain formatting scheme like MS-DOS FAT16.
  3. The disk device – which for me is /dev/disk2. This is the disk device itself, and it may contain several filesystems.

Your locations for these three could well be different, so please substitute your values.

You’ll need to unmount the device, as writing to a raw filesystem while the OS thinks it has control often results in hilariously unexpected results. I used the OS X-specific command

diskutil unmount /Volumes/CANON_DC

You should get a message like Volume CANON_DC on disk2s1 unmounted. Now you need to write the boot instruction:

echo -n BOOTDISK | sudo dd bs=1 count=8 seek=64 of=/dev/disk2s1

This will prompt you for your password.

If you need to, you can remount the filesystems on the card with

diskutil mountDisk /dev/disk2

(Note that we used the disk name here, not the filesystem. If there were several partitions on the disk, this command would mount all of them that it could. It’s also kinda handy for remounting USB devices that you’ve accidentally ejected from Finder.)

Update: Knowing a difficulty getting the firmware update method of getting CHDK to work on a Mac? Running a Leopard or newer machine? Then you need to learn all about Apple’s quarantine attribute and how to remove it with xattr: FAQ/Mac – Still having trouble?.

good, not quite great

I accidentally dropped and broke my car mp3 player, so had to come up with another music solution. I caved and bought an iTrip for my iPod Nano. It sounds pretty good.

What’s good about it is that it allows you to charge your iPod from a standard USB Mini-B. What’s not so good is that it doesn’t have full USB pass-through, so you can’t sync your iPod, and have to stick with that stupid dock cable.

(and don’t get me started on the really annoying connector on my work cell phone …)

the great thing about standards is that there are so many to choose from

I have a suspicion that, while I Want My Green Plug and their associated blog One Plug. One Planet want to replace all power adaptors with theirs, all that will really happen is that:

number_of_power_adaptor_variants = number_of_power_adaptor_variants + 1

I’m not wild about their idea for DC power strips. The I2R losses would be huge.
Also, dealing with the world of input voltages and frequencies, not to mention the many plug variants, would make the thing huge, heavy and expensive.
But the fact is, there’s already a standard low voltage power adaptor: the USB mini-B.

the analogue hole

I have a bunch of Catherine’s old family recordings to digitise (do people still do that – sit around a tape recorder and make recordings?) and I had recorded one of Ken’s shows on minidisc, so I needed a relatively clean way to get analogue audio onto the computer.

I ended up getting a Griffin iMic, a small USB audio input device. The sound quality is remarkably clean; here’s a sine wave recorded from CD to minidisc, then recorded on the iMic:

tracks000.png

 

The  iMic seems to work with all Mac audio software as an input device. The free Final Vinyl recording sofware is pretty, but a bit buggy and annoyingly, only works when the iMic is connected. I just use Audacity, and have done with it.

so-called wizard

Windows has just spent the last 15 minutes searching for a driver for my Garmin GPS. Y’know, the one I use with the computer a lot. It’s claiming it’s new hardware, but in the words of Syd, “I’ve had it for months”. Oh Windows, you really are very stupid. In fact, you are a silly wizard.

a small form of happiness is

… a USB key with the irritating U3 software uninstalled.

Seriously, U3 is a major annoyance if you:

  • use Mac
  • use Linux
  • work on a PC with locked-down permissions
  • work on a PC with a one-letter drive gap (like having D: and F:, but no E:); U3‘s read-only system will appear in the gap, but your data won’t be accessible.
    (It’s not really U3‘s fault. The fact that Windows still has drive letters amazes me; why don’t they go for the whole 70s thing and have punch cards and gargantuan 5MB hard disk packs?)

All four of the above apply to me, so u3 uninstall.exe is my friend.