TwitBeeb 3

Posted by barnoid Thu, 22 Oct 2015 11:39:00 GMT

TwitBeeb on test at Bristol Hackspace, photo by John Honniball.

TwitBeeb is a BBC B microcomputer (vintage 1981) from which you can Tweet.

The Beeb itself was my main computer until 1994, I taught myself to program on it. A few years ago I pulled a rather scuffed up BBC out of a skip at Sussex University and took it home. Inside it had an add-on ROM board with several programs in ROM chips including a serial terminal emulator called Termulator. This allows it to connect to other computers via its serial port and for everything typed on the BBC's keyboard to be sent to the other computer which sends responses back to be displayed on the BBC's screen. It acts as what used to be called a "dumb terminal", just handling the input and output while a more powerful computer does the actual work. This was quite a common way of doing things back when computers were room-sized. Several terminals would connect to a large shared computer, possibly over phone lines using modems.

My first tests with the Beeb terminal involved connecting it to a Linux server using a cable I made from this recipe. It was a bit tricky to find 5 pin domino DIN plugs and note the warning about marking the top because you can plug them in either way up. I ran a text-based web browser called Lynx on the server via the BBC terminal and pointed it at Twitter. Termulator was not very good at handling the full Linux terminal and browser, it tended to crash and you can't use the arrow keys which makes using Lynx awkward. I did manage to send one tweet.

More recently, I got my hands on a Raspberry Pi. While considering what to do with it I remembered my BBC terminal experiments. Given that the Pi is cast from the same mould as the BBC, in terms of their educational intentions, they seem like an obvious pairing. They share a common heritage, in that the Raspberry Pi's ARM processor was designed by some of the same team who worked on the BBC Micro. I also enjoy the fact that in this case the terminal is physically far bigger than the vastly more powerful computer it connects to.

Some spec comparisons:

BBC Micro (Model B)Raspberry Pi (Model B)
Release Date1st December 198129th February 2012
CPU6502 2 MHz (8 bit)ARM1156 700 MHz (32 bit)
RAM32 KB256 MB (262144 KB)
StorageNone in this instance, except the 16KB ROMs containing the OS and terminal software.2 GB SD card

Twitter BBC early experiment.
The first experiment with the BBC B and Twitter via Lynx.

So due to Termulator's problems handling a full text-mode browser and because that would have been too complicated for use on the stand at an event like a Makerfaire I wrote my own specialised kind of Twitter client. The BBC's OS has a set of special bytes that you can send to control things like text colour and cursor position, I used these to make it pretty. It reminded me of the kind of programs that I used to write when I was 11, it was kind of odd to be doing that stuff in Ruby rather than BASIC.

Here is the code, on Github. It searches for a hashtag and displays some results on the screen below the title. At the bottom of the screen it shows a prompt very much like the BASIC one, you type your tweet there and press Return to send it. The hashtag is appended for you. The code stops you typing too many characters.

For TwitBeeb's first public outing at Derby Mini Makerfaire I had the Pi talking to the Internet using a USB Wifi dongle. I set up the network by connecting to the Pi's serial console from my laptop using a USB to serial converter and a Sparkfun level shifter. When the network was working I connected to the Pi with ssh and moved the USB to serial converter to the Pi and connected the serial end to the BBC (minus the level shifter). I then started Termulator on the Beeb, put it in BBC VDU mode and started the twitbeeb script on the Pi. I used the command line to redirect standard in and out for the script to the serial port device, having first set it to run at 4800 baud and several other parameters using stty.

It was quite popular at the Faire, mostly as a spectacle though. People were reluctant to come up with a witty tweet on the spot. It tweets from the @twitbeeb account, you can see people's tweets there. Most confusion came when there was a need to find the "delete" key, and also "@" hidden in plain view on a key of its own.



Since its public debut at the first Derby Mini Maker Faire in 2012, TwitBeeb has been on show several times. I'm about to show it again at the fourth Derby Mini Maker Faire.

Here are some of its outings:

TwitBeeb at Brighton Mini Maker Faire 2012
TwitBeeb at Brighton Mini Maker Faire 2012, photo by Hollie Lubbock.

Bristol Raspberry Jam - August 2012

I set it up in the demo room with a bunch of other people's projects, then went off to watch some talks. About 20 minutes later someone came over to tell me that my project was on fire. It turns out the capacitor in the BBC's power supply had failed, as they will do after 30 years. Those capacitors are partly made of paper so they make a lot of smoke when they fail. It didn't get used much that day.

Brighton Mini Maker Faire - September 2012

Having replaced all the power supply capacitors, I showed Twitbeeb on the Bristol Hackspace stand at Brighton Mini Maker Faire 2012.

Bristol Mini Maker Faire - March 2013

The next outing was the first Bristol Mini Maker Faire, with a few tweaks to the code to make it compatible with Ruby 1.9.

This happened:

TwitBeeb and Eben Upton at Bristol Mini Maker Faire 2013
TwitBeeb and Eben Upton at Bristol Mini Maker Faire 2013.

Eben and Liz Upton of Raspberry Pi fame were the special guests at the Faire. I had a brief chat with Eben and he seemed to like TwitBeeb.

Bristol Hackspace for BV Open Studios - June 2013

Between the last show and this one Twitter decided to close down their old API. So I had to scramble to basically rewrite my API code the day before this event.

Derby Mini Maker Faire - October 2014

I implemented some new features for this outing. When idle it now automatically reloads the tweets (previously someone had to press Escape to trigger this) and it cycles between tweets, a screen of self description and the Derby Mini Maker Faire logo.

Bristol Mini Maker Faire - August 2015

On the Bristol Hackspace stand again at the second Bristol Mini Maker Faire. Swindon Hackspace had a lovely Teletype typing out tweets nearby, so people were able able to use TwitBeeb to send it messages.

Oh really?!?

There's more!

David James Lennon has created a TwitBeeb twin using my code from Github! He will be showing it this Saturday (24th October 2015) at the RISC OS London show, which happens to be the same day the original TwitBeeb will be at Derby Mini Maker Faire.

His TwitBeeb tweets to @burrBeep. I've added a new tweet search page to the rotation that displays the result of a search for that Twitter handle. Hopefully we'll be able to get some inter-show chats going.

I've added a few other nice features, including word wrapping for the tweet list. When I implemented word wrapping for Ode, my terrible poetry generator that I wrote on my BBC (the same one) when I was about 13, it consisted of about 120 horrible lines of BASIC. This time it's basically just one regular expression. What a difference 20odd years experience and a computer science degree can make!

Taking TwitBeeb to shows has become easier over time as I've gradually improved its reliability. Nowadays it's pretty much at the ideal point where once it's connected to the network it can be left to its own devices. It's nice to chat to people about it still though. What happens often at a Maker Faire is that a parent of about my age with small children in tow will spot TwitBeeb and say "Look kids! This is the computer I used at school!". The children will look nonplussed and may attempt to poke and swipe things on the screen before mashing the keyboard. Meanwhile the parent realises that it's actually showing real live twitter and asks how it works.

I expect I'll continue to take TwitBeeb to events, as long as the Twitter API keeps working at least. I'd like to take it to the big Maker Faire in Newcastle next year, and maybe to EMF Camp 2016 as well, if I can keep it dry.


Posted by barnoid Tue, 26 Aug 2014 21:37:00 GMT

Meteonome is a musical weather station and a platform for making music based on weather readings.

Its sensors are:

  • Barometric pressure (SCP1000)
  • Humidity (SHT25)
  • Temperature
  • Light level (Adafruit GA1A12S202)
  • Wind speed (Cup anemometer)
  • Moisture detection (rain) (conductive thread)
  • Noise level (also rain mostly) (piezo sensor)

It produces OSC packets two or three times per second containing:

  • /meteonome/barometer/pressure

    Barometric pressure in mbar, the extremes are probably 850 to 1050 or so. Possibly most interesting to look at whether the value is changing as that indicates a change in the weather.

  • /meteonome/barometer/temperature

    Air temperature in Celsius, sensor built into barometer.

  • /meteonome/hygrometer/humidity

    Air relative humidity (percent), sensor seems to go up to 102%.

  • /meteonome/hygrometer/temperature

    Air temperature in Celsius, sensor built in to humidity sensor, seems to differ from the other one by a couple of degrees.

  • /meteonome/light/light

    Light level reading, from 0 to maximum of 1023, overcast is about 500 or so. Note: Meteonome's lighting is picked up by this too, up to about 100 - 200.

  • /meteonome/wind/rev_count

    Rough revs count of cup anemometer since last read.

  • /meteonome/wind/revcountavg

    Moving average of last 100 anemometer reads.

  • /meteonome/rain/wetness

    Conductivity between two lengths of conductive thread, 0 to 1023, about 330 is fairly wet, probably higher for actively raining. Dew is about 10 - 20. Occasionally goes to 1 or 2 when dry due to noise.

  • /meteonome/rain/noise

    Average of several thousand readings of a piezo sensor which should pick up rain noise. It's not very sensitive, might produce tiny numbers in heavy rain.

OSC is commonly used for exchanging data between music oriented software and hardware. For instance in Pure Data the OSC documentation is here:

Recent Developments in BBC B Hacking

Posted by barnoid Fri, 16 May 2014 21:39:00 GMT

BBC B running 2048

I've recently been experimenting at the Hackspace with UPURS and UPURSFS. These unfriendly strings of letters amount to a cable that links the BBC's User port to my laptop via a USB to serial converter, two ROMs that go in the Beeb and some Perl code that runs on my laptop. The upshot of which is that I can access parts of the filesystem of my laptop as if they were floppies on the BBC.

How it works

The cable and one of the ROMs are the UPURS part. The purpose of which is to allow the BBC's user port to be used as a fast serial port, much faster than the RS423 port on the back. It comes with a bunch of commands for shipping disk, tape and ROM images back and forth, but I was more interested in not having to use any of those.

UPURSFS works by using the Tube protocol over this serial link. The Tube protocol is usually used for communicating with second processor add-ons over the dedicated port on the bottom of the BBC. It basically diverts operating system calls and sends them to the second processor to handle. So nearly all operating system (* commands) and filesystem commands (not BASIC) are passed over to the computer on the other end of the serial link. The upshot of which is that you can implement a remote filesystem and access data stored on a modern computer directly from the BBC. No need for a floppy drive.

John at Bristol Hackspace was able to burn the two EPROMs for me and I made up the cable. We were able to verify that the ROMs work by the presence of their names in the output of *HELP. Having connected the cable, my next test was to upload the BASIC ROM by typing *UPXROM E (in this case) and observing the result in the serial terminal running on my laptop. The word "Roger" towards the end confirmed I was seeing the right stuff.

Next I downloaded the Perl TubeHost code. I set up a directory that will represent a disk and created a file in it called "test" containing the text "hello there". I modified the TubeHost code to look at that directory and then ran it with the option -U. Then by holding the U key and pressing Break on the BBC I put it in UPURSFS mode. I then typed *DCAT and my disk appeared. I typed *DIN 5 0 to select it and then *. to list its contents. There was my "test" file. I typed *TYPE TEST and "hello there" appeared on the screen. Success.

I wanted to try some real software, so I downloaded the SSD image of Eben Upton's version of 2048 that he recently implemented to observe 50 years of BASIC. I'd been wanting to try it on a real BBC since I saw it. I unpacked the SSD into my disks directory using MMB utils. Handily TubeHost respects .inf files that contain BBC file metadata. I was able to get the disk listing on the BBC so I typed CH. "2048" only to see the dreaded "Bad Program". It turns out that my serial link is not all that clean, occasional bytes are going missing or getting corrupted. It may be because I'm using the wrong type of USB to serial converter or it could be something else, it needs some debugging. As the corruption is random I figured I'd keep trying and hope for a try where nothing important gets broken. It took five or six goes.

So we played some 2048 (albeit with corrupted fonts). Ian got to 1024. The concept is proven, just need to iron out the kinks in the serial link.

Christmas Twitter Tree Lights 2

Posted by barnoid Sun, 22 Dec 2013 16:05:00 GMT

I recently bought a string of 50 individually addressable RGB LEDs from Embedded Adventures and so had to decide what to do with them. I decided it would be festive if they could reflect Twitter's current feeling about Christmas.

So I started Googling sentiment analysis and quickly discovered that Stanford University's Natural Language Processing Group has released the source and data for their sentiment analyser. When fed a sentence it outputs one of "Very negative", "Negative", "Neutral", "Positive" or "Very positive". It's pretty good but it's trained on movie reviews so it's not quite so accurate on tweets about Christmas. For example "Christmas time is defo the best time of the year !!" is classed as very negative.

The sentiment analysis is fairly slow. Much slower than the rate that the tweets come in, so I'm using beanstalkd for queueing. The tweets come in from the Twitter streaming API (filtering for "christmas" and "xmas"), get cleaned up, @usernames removed, hashes removed from hashtags, URLs deleted, then put in a queue. My desktop computer is the fastest in the house so it runs four instances of the sentiment analysis, pulling tweets out of the queue, processing them, pre-pending one of N, n, -, p or P and sticking the result in a second queue.

Raspberry Pi controlling the lights.
Raspberry Pi controlling the lights.

The lights themselves are controlled by a Raspberry Pi. They are connected to the SPI pins via a level shifter from Sparkfun. The pins on the Pi all work at 3.3V while the lights need 5V hence the shifter is needed. I'm using a fairly recent Raspian. To enable the SPI device /dev/spidev0.0 I removed the "blacklist spi_bcm2708" from /etc/modprobe.d/raspi-blacklist.conf. Then I just need to write a byte each for red, green and blue for each LED to the device file.

So the code on the Pi reads from the second queue, and shifts an LED on to the chain with a colour based on the initial sentiment letter: red for negative, green for positive, white for neutral, bright cyan for very positive and bright orange for very negative. The sentiment analysis processing can't keep up with the rate of incoming tweets so I've had it skip every other tweet.

The result is quite a pretty light display, though it's hard to say whether or not it's successful in reflecting the opinion on Twitter of Christmas.

The Code

This is the code that streams tweets from Twitter, cleans them up and puts them in a queue. It uses the tweetstream and beaneater gems.


require 'rubygems'
require 'tweetstream'
require 'beaneater'

TweetStream.configure do |config|
        config.consumer_key       = "SECRET"
        config.consumer_secret    = "SECRET"
        config.oauth_token        = "SECRET"
        config.oauth_token_secret = "SECRET"
        config.auth_method        = :oauth

beanstalk =['localhost:11300'])
tube = beanstalk.tubes["tweets-in"]

count = 0'xmas', 'christmas') do |status|
        tweet = status.text
        tweet.gsub!(/@.+?($|\s)/, "")
        tweet.gsub!(/^RT /, "")
        tweet.gsub!(/https?:.+?($|\s)/, "")
        tweet.gsub!(/[^\w\d \(\),\.\?\!\-\'\:\$\&\;\+]/, "")
        tweet.gsub!(/&/, "and")
        tweet.gsub!(/&.+?;/, "")
        if count % 2 == 0 then
        count += 1


This is the code that pulls tweets out of one queue, feeds them to the sentiment analyser and puts them in another queue with the result.


require 'rubygems'
require 'beaneater'

beanstalk =[''])
tube_in = beanstalk.tubes["tweets-in"]
tube_out = beanstalk.tubes["tweets-out"]

IO.popen("./run_sentiment", "r+") do |sent_io|
        # Wait until the sentiment analyser has printed its startup text
        while not sent_io.readline.match(/EOF/)

        while true do
                tweet_job = tube_in.reserve
                tweet = tweet_job.body
                sent_io.puts tweet
                sentiment = sent_io.readline.chomp
                case sentiment
                when "  Very positive"
                        sentiment = "P"
                when "  Positive"
                        sentiment = "p"
                when "  Neutral"
                        sentiment = "-"
                when "  Negative"
                        sentiment = "n"
                when "  Very negative"
                        sentiment = "N"
                puts "#{sentiment} #{tweet}"
                tube_out.put("#{sentiment} #{tweet}")


This starts the sentiment analyser telling it to accept input on STDIN. This is referenced as run_sentiment above.


cd stanford-corenlp-full-2013-11-12
java -cp "*" -mx5g edu.stanford.nlp.sentiment.SentimentPipeline -stdin 2>&1

This code runs on the Pi, controlling the lights.


require 'beaneater'

class Led

        attr_accessor :r, :g, :b

        def initialize(r = 0, g = 0, b = 0)
                @r = r
                @g = g
                @b = b

        def out
                return "#{@r.chr}#{@g.chr}#{@b.chr}"

        def to_s
                return "%02X%02X%02X" % [ @r, @g, @b ]


LED_V_POS =,128,255)
LED_POS =,64,0)
LED_NEG =,0,0)
LED_V_NEG =,128,0)

beanstalk =[''])
tube = beanstalk.tubes['tweets-out']

leds = []
50.times do
end"/dev/spidev0.0", "w") do |spi|

        while true do

                job = tube.reserve
                s = job.body[0]
                case s
                when 'P'
                        leds.unshift LED_V_POS
                when 'p'
                        leds.unshift LED_POS
                when '-'
                        leds.unshift LED_NEUTRAL
                when 'n'
                        leds.unshift LED_NEG
                when 'N'
                        leds.unshift LED_V_NEG
                #p leds

                50.times do |k|
                        spi.write leds[k].out



Halloween Wedding Photobooth

Posted by barnoid Sat, 26 Oct 2013 12:19:00 GMT

Testing the photobooth.

Almost exactly a year ago I got married, just before Halloween. It seems to be fairly typical these days to have a photobooth at the reception so that guests can take photos of themselves for you. We decided ours should have a Halloween theme.

What Happens

  • Guests enter a cubbyhole and sit on the chairs at one end. The space is lit by a lamp and there's a camera on a tripod pointing at them.
  • Scary props are provided, the background is decorated with spiders and bats.
  • They press the big illuminated red button in front of them.
  • The button flashes five times.
  • The lamp goes out, a strobe starts flashing, the middle spider on the background drops down and in front of them.
  • The camera takes a photo.
  • The spider goes back up, the strobe switches off and the lamp comes back on.
A re-enactment.

How It Works

Photobooth control box.
The control box.

A tupperware box with the illuminated button on top contains an Arduino, pressing the button sets the program in motion. It uses four outputs: the camera, the lamp, the strobe and a servo which moves the spider. The camera, lamp and strobe are connected via opto-isolators. The servo uses a PWM output in the usual way.

Photobooth mains switches.
Mains remote control switches with added external terminals.

The lamp and strobe are mains powered. To switch them safely I adapted two radio controlled sockets. The sockets have push buttons that toggle the relay without needing the remote control. I soldered wires either side of the button switch and ran them to screw terminals on top. The Arduino briefly pulses these to toggle the output.

The camera was a Canon EOS 1000D, triggered through its remote control socket.

For the spider movement I used a high torque servo which I clamped to the top of the whiteboard that formed the backdrop. The spider dangled by a thread from a stick made out of a straightened wire coat hanger, which was quite springy so allowed for quite a lot of boinging around. The servo rotated the stick through about 75 degrees, kind of like a fishing rod, casting into the booth, with a spider as bait.


I didn't have a lot of time on the day so I set it up in daylight. Then I had to go off to do some paperwork at the registry office for a bit. When the guests got to the reception it was nearly dark, so it turned out I'd set the exposure quite wrong. It was taking 30 second exposures which resulted it some interesting blurs.

Exposure too long.
The Angel of Death in patterned tights.

Having fixed that it worked fine and was rather popular. We printed out some of the results and sent them to guests as thank yous.

The Father of the Bride.
The father of the bride.
The lovely bride
The lovely bride.

That Wedding Playlist In Full

Posted by barnoid Sat, 03 Nov 2012 15:31:00 GMT

  • Dancing In The Street - Martha Reeves And The Vandellas
  • Papa's Got A Brand New Bag - James Brown
  • You Can't Hurry Love - Diana Ross And The Supremes
  • Going To A Go Go - Smokey Robinson
  • Think - Aretha Franklin
  • In The Midnight Hour - Wilson Picket
  • Knock On Wood - Eddie Floyd
  • Needle In A Haystack - The Velvelettes
  • Itchycoo Park - Small Faces
  • Brown Sugar - The Rolling Stones
  • Lola - The Kinks
  • Paperback Writer - The Beatles
  • Ride A White Swan - Marc Bolan & T Rex
  • Rebel Rebel - David Bowie
  • Heart Of Glass - Blondie
  • In Between Days - The Cure
  • This Charming Man - The Smiths
  • Dancing Queen - ABBA
  • Jumpin' Jack Flash - The Rolling Stones
  • (Edited Wayne Carr intro to Motherbanger from Chris Morris' Radio 1 Music Show)
  • Here Comes Your Man - Pixies
  • Something Changed - Pulp
  • Friday I'm In Love - The Cure
  • Blister In The Sun - Violent Femmes
  • Panic - The Smiths
  • Queen Bitch - David Bowie
  • Debaser - Pixies
  • Seether - Veruca Salt
  • Razzmatazz - Pulp
  • Hey Hey 16K - MJ Hibbett & The Validators
  • Lipgloss - Pulp
  • Shut Up And Let Me Go - The Ting Tings
  • Babies - Pulp
  • Disco 2000 (Nick Cave Pub Rock Version) - Pulp
  • Buy Nothing Day - The Go! Team
  • Where It's At - Beck
  • How Soon Is Now - The Smiths

All carefully edited together in Audacity to remove gaps. Our attempt to side-step the first dance thing with Dancing In The Street failed. The song says "every guy grab a girl" but everyone was too busy ogling us. I had thought people would be danced out by the final track, but no. It had to be skipped in favour of something more up beat.

Barometric Pressure Readings With A Bus Pirate 1

Posted by barnoid Sun, 13 Feb 2011 15:29:00 GMT

Bus Pirate and SCP1000

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:


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:


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.


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


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:


Now to check the DRDY pin:


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.


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


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

Posted by barnoid Tue, 05 Oct 2010 09:49:00 GMT

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

Posted by barnoid Mon, 06 Sep 2010 20:37:00 GMT

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

Posted by barnoid Sun, 20 Jun 2010 13:01:00 GMT

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.
  exit 0;

my @domains = ( "" ); # 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") {
    } 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";