Barometric Pressure Readings With A Bus Pirate 1
I decided to learn how to use my Bus Pirate (v3) by getting it to talk to an SCP1000 chip that I've had for a while but not got round to using. The SCP1000 is a very accurate barometric pressure sensor with an SPI interface, mine is on a handy breakout board and came from Sparkfun. The datasheet has the details.
For the first step I found it pretty much vital to label each of the connectors on the end of the Bus Pirate cable as tracking down which is which was taking too long.
Having done that I hooked them up as follows:
GND - GND 3.3V - 3.3V CLK - SCK MOSI - MOSI MISO - MISO CS - CSB AUX - DRDY
I'm talking to the Bus Pirate using a computer running Ubuntu Linux. Plugging it in results in a new serial device, probably /dev/ttyUSB0 if you have no other USB-serial devices plugged in (an Arduino counts). I use Screen to connect to the serial device like so: screen /dev/ttyUSB0 115200. To disconnect and close screen type ctrl-a followed by k.
Once connected there was nothing to see, so I hit return to make a prompt appear:
HiZ>
The bit before the > is the current mode. HiZ means high impedance, none of the lines will allow current to flow so it's safe to connect up.
Type ? to see what's possible:
HiZ>? MENUS ? Help I Status info M Bus mode B Terminal speed O Data display format V Check supply voltages F Frequency count on AUX G Frequency generator/PWM on AUX C AUX pin assignment L Bit order P Pullup resistors = HEX/DEC/BIN converter ~ Self test # Reset $ Bootloader SYNTAX A/a/@ AUX output toggle H/L/read W/w Power supply toggle on/off d (D) Measure voltage on ADC probe (continuous) [ ({) Start (with read) ] or } Stop R or r Read byte 0b Write BIN byte 0h or 0x Write HEX byte 0-255 Write DEC byte , Delimiter (also space) & 1uS delay : Repeat (r:2, 0x0a:4, &:20, ^:2, etc.) (#) Run macro, (0) for macro list RAW BUS OPERATIONS /\ Clock H/L -/_ Data H/L . Read data input pin state ^ Clock tick ! Read bit HiZ>
Type M to see the mode menu:
HiZ>M 1. HiZ 2. 1-WIRE 3. UART 4. I2C 5. SPI 6. JTAG 7. RAW2WIRE 8. RAW3WIRE 9. PC KEYBOARD 10. LCD (1) >5 Mode selected
I want SPI so typed 5. I'm then asked for various settings for SPI:
Set speed: 1. 30KHz 2. 125KHz 3. 250KHz 4. 1MHz (1) >1
The SCP1000 datasheet says it can go up to 500kHz. Speed is not of the essence so I just went with the slowest.
Clock polarity: 1. Idle low *default 2. Idle high (1) >2
I picked Idle high based on the SPI examples in the datasheet. It probably works either way round.
Output clock edge: 1. Idle to active 2. Active to idle *default (2) >1 Input sample phase: 1. Middle *default 2. End (1) >2
I picked the above two settings based on the following from the datasheet:
"Bits from MOSI line are sampled in on the rising edge of SCK and bits to MISO line are latched out on falling edge of SCK."
Select output type: 1. Open drain (H=Hi-Z, L=GND) 2. Normal (H=3.3V, L=GND) (1) >2
Open drain isn't mentioned anywhere in the datasheet, I went with normal.
READY SPI>
Good to go. The mode light should now be on and probably also the VREG one.
I hooked up the Bus Pirate's Aux line to the DRDY pin. This one goes high when there's data ready to read. I can check for this by typing an @.
SPI>@ AUX INPUT/HI-Z, READ: 0
Nothing to read yet. Not surprising because I haven't told it which sampling mode to use.
The SCP1000 has four modes: high resolution, high speed, ultra low power and low power with an external trigger. All fairly self explanatory, I want high resolution. Communication is done by reading and writing to numbered registers which are either 8 or 16 bits wide. They're all detailed in the datasheet. All SPI communication starts with a byte that has the register number in the top six bits, bit seven is 0 for reading or 1 for writing and bit eight is always 0. The following bytes are then either the data to write or 0xFF when reading.
So to engage high resolution mode I need to write 0x0A to register 0x03. The register byte is arranged like so:
0x03 = 000011 Write & 1 0 Pad & 0 = 00001110 = 0x0E
On the Bus Pirate a { means start the protocol by enabling the CS pin and I want to read after every write. } means stop. Commands can be strung together on one line by separating them with a space. So I proceed like so:
SPI>{ 0x0E 0x0A } CS ENABLED WRITE: 0x0E READ: 0x00 WRITE: 0x0A READ: 0x00 CS DISABLED
Now to check the DRDY pin:
SPI>@ AUX INPUT/HI-Z, READ: 1
It's high! So there's readings to read. I'll start by reading the temperature in register 0x21 which is 16 bits wide.
0x21 = 100001 Read & 0 0 Pad & 0 = 10000100 = 0x84
I write two 0xFF bytes just to cause it to read the result bytes, they don't actually do anything.
SPI>{ 0x84 0xFF 0xFF } CS ENABLED WRITE: 0x84 READ: 0x00 WRITE: 0xFF READ: 0x01 WRITE: 0xFF READ: 0xB3 CS DISABLED
Ta da! It's a balmy 0x01 0xB3. Converting the temperature is explained in the datasheet with examples, but basically it's MSB first, 14 bit, twos-complement then divide by 20. So the above comes to 21.75 degrees centigrade.
Getting the pressure involves reading two registers, 0x1F for the top part (8 bits wide) and 0x20 for the bottom part (16 bits wide).
SPI>{ 0x7C 0xFF } CS ENABLED WRITE: 0x7C READ: 0xFF WRITE: 0xFF READ: 0x06 CS DISABLED SPI>{ 0x80 0xFF 0xFF } CS ENABLED WRITE: 0x80 READ: 0x00 WRITE: 0xFF READ: 0x25 WRITE: 0xFF READ: 0x5E CS DISABLED
The result is 0x06 0x25 0x5E. Again MSB first and it's an unsigned integer so I just stick the bytes together then divide by 4 to get the reading in Pascals, which is 100695.5.
Barney is...
So you're wondering where that quote on every page of my site comes from?
Every night a script runs that uses a Google API to search the web for the string "Barney x ", where x is one of: "is", "was", "can", "should", "shall", "will", "thinks", "says", "does", "keeps", "won", "isn't", "wasn't", "can't", "shouldn't", "won't". The results are cleaned up and then stored in a file along with the URL of the source and the date of the search. Up to 200 quotes are kept in the file with the older ones being replaced when new ones are found, this ensures the quotes remain topical. A random quote is picked from the file on page load, it might not always change every time though due to caching.
The original idea for this came from googlism.com several years ago. My old site used to achieve the same thing by doing a Google query for every page load, which is not ideal.
A certain Purple Dinosaur has always featured as the subject of many quotes along regular appearances from a Flintstone, a Simpsons character and from the artist Matthew Barney. More recently there seem to be a lot of quotes about a character from How I Met Your Mother and about the politician Barney Frank. The number of quotes about George W Bush's dog have reduced in recent years.
119 Reasons The iPad Is Not For Me 1
Note: I said not for me, it might be the Bee's Pyjamas for you.
The Register is running a series called 119 iPad apps for admins, coders, and geeks. I would seem to fit this bill quite securely, the "apps" themselves however appear to be poor approximations of useful.
I obviously haven't actually tried any of them due to lack of iPad so I'm going on The Register's descriptions and information on the Apple website. I'm assuming The Register really has picked the best of the bunch, it's hard for me to tell because iTunes is in the way, but that's a whole other rant.
It starts with two glorified notepad things specially for taking inventory of computers, one of them costs $2. At work we use OCS Inventory so the computers inventory themselves, it's free. Another alternative is a pen and paper.
Oh hey, $2 for an unzipper!
Next up is an encrypted password storing app for the bargain price of $15. Great. Then a few password generators that they want money for.
The "network" section of the article includes what appears to be a copy of the DHCP RFC which they expect you to pay for. There I was thinking the iPad had a web browser.
Something for crafting UDP packets ($8).
Ah ha! Something useful: an app that does nslookup, ping and traceroute. The absolute basics of network troubleshooting, a mere $4.
They mention an SSH client which looks as if it's rather lacking in features. For me the bare minimum a useful computer/device requires is a functional SSH client, and maybe a web browser. It would at least allow me to get out to a more usable computer. I thought Apple devices had SSH better covered, but I can't tell, again due to iTunes.
$2 for a subnet calculator! Woo Hoo!
The next section of the article covers training and reference and includes a bunch of stuff accessible on the Web in one way or another. It seems to me that this is the case for many of the "apps" available for the iPad and iPhone. Apple likes to tout the huge number of apps you can stick on your shiny joy-slab, but I'd like to see numbers on how they divide up into such categories as: "truly frivolous and useless (and possibly harmful to human culture)", "reimplementations of websites that the browser could cope with just as well", "marketing drivel", "games" and "useful". I suspect the last category is by far the smallest.
As for complaining about being asked to pay for software: I'm not wholly against it, I just object to it (even if it's for tiny tiny amounts) when it's for basic functionality, worthless rubbish, or stuff that's freely available elsewhere but has been poorly repackaged and chucked out into the artificial scarcity of a walled-garden marketplace. Oh, back to iTunes then.
I know the iPad is really designed to be a web and media consuming device. For the high asking price I'd want it to do a bit more than that though. There are also a few other deficiencies in its software design that I won't go into here. Did I mention I really hate iTunes?
So, yeah, it's not for me.
Certificate Expiry Checking Script
Here's a script I wrote a while ago for checking a bunch of domains to see if their certificates have expired using openssl. Just add your domains to the @domains list. At work we have a cronjob that does this every day:
checkcerts -d 31 | mail -e -s"SSL Certificates Expiring Within a Month" systems@...
#!/usr/bin/perl -w # checkcerts # Barney Livingston 2008-11-18 use strict; use Date::Parse; use Date::Format; use POSIX qw(floor); use Getopt::Long; my $days = 9999999999; #about 27 million years should be enough my $help; GetOptions( "days=i" => \$days, "help" => \$help ); if ($help) { print <<"END"; Usage: checkcerts [options] --days -d <days> Only show certificates due to expire within <days> days. END exit 0; } my @domains = ( "example.com" ); # Your list of domains goes here. my $time = time; foreach my $domain (@domains) { my $tries = 3; my $date = ""; my $cn = ""; my $expdays = 0; my $x509 = ""; while ($tries > 0) { $x509 = `echo Q | openssl s_client -connect $domain:443 2>&1 | openssl x509 -noout -text`; $date = "ERROR"; if ($x509 =~ /Not After : (... .. ..:..:.. .... ...)\n/) { $date = str2time($1); } $x509=~ /Subject:.+CN=(.*?)[\/\n]/; $cn = $1; if ($date eq "ERROR") { $tries--; } else { $tries = 0; } } if ($date eq "ERROR") { print "Failed to get a useful response from $domain\n"; } else { $expdays = floor(($date - $time) / (3600 * 24)); my $expired = ""; $expired = " EXPIRED" if ($expdays < 0); if ($expdays < $days) { print time2str("%Y-%m-%d %T", $date) . " -$expired $expdays days - $cn\n"; } } }
New Colours
The current political climate in the UK has prompted me to alter the default colour scheme of this site.
I took the opportunity to make it much easier to re-colour the site using CSS and PNGs with alpha channel transparency. Styles can even be switched using the box at the bottom of the sidebar.
Lucid Muddle
Today I did the Kubuntu Karmic to Lucid upgrade on my Thinkpad T60 with 2GHz Core Duo CPU, 3GB RAM and ATI Radeon Mobility X1400 GPU.
The upgrade itself went ahead flawlessly but I started to see problems after the desktop started. Things seemed generally sluggish, especially moving windows around and scrolling, and it seemed to get worse over time. Flash video was very teary and unwatchable fullscreen. When I tried to play a 3D game it caused a strange horizontal black line interference that didn't go away until I rebooted. Also, seemingly unrelated, the wireless network would lose connection after a while and refuse to reconnect until I switched the wireless kill switch off and on again.
The solution to all these problems seems to have been to switch off Kernel Mode-Setting. I did this by editing the file /etc/default/grub and changing the line:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
to
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash radeon.modeset=0"
Then running update-grub and rebooting. This has resulted in a much more stable desktop, but at the cost of making the boot splash screen look very ugly indeed. The wireless connection now works perfectly.
Now it's working properly the KDE desktop with compositing seems much more responsive than on Karmic. I might even leave effects turned on this time. Video is fine and 3D games work reasonably well, I've had trouble with 3D stuff before. I'm still seeing a fair bit of corruption on icons and window decorations, something I've seen ever since switching to the open source ATI driver.
So generally Lucid is looking good and I'm liking the new stuff in KDE 4.4. Perhaps it's still a bit early to be enabling the kernel stuff for the radeon driver though.
Welcome to barnoid.org.uk 2.0

New site iteration 3, typo theme 2.

New site iteration 2, typo theme 1.

New site iteration 1, from scratch in ruby on rails.

barnoid.org.uk from 2003 to 2010.

My first website from 1997.
In 2005 I said I was thinking of redoing the site and it is finally done. I made quite a few attempts, each less ambitious than the previous, until I finally hit on one that was actually realistic.
This site went live at about 00:40 on 07/04/2010. It is a slightly modified Typo with my own theme. Once everything is working properly I intend to make some more drastic modifications.
In the meantime here's some pictures of the various iterations that lead to the site you see now.
