Instagram filter used: Hudson
Blog
-
A Murder of Crows on your Raspberry Pi with Boodler
Boodler is rather fun. It generates ambient music based on user-defined or downloaded ‘soundscapes’. If you’ve got a modern (HTML5/Opus-capable) browser, you can hear a streaming demo here: http://repeater.xiph.org:8000/clock.opus. It’s using the FM3 Buddha Machine samples in this demo, but it can run lots more: a tree full of crows, a thunderstorm, dripping water, …
It’s pretty easy to run on a Raspberry Pi running a recent version of Raspbian. The only technical glitch I had was that there’s something deeply confused about ALSA sound handling on the Raspberry Pi. I’m sure it’ll get fixed soon, but for now, you have to use PulseAudio. (If you want to read about my ALSA woes, go here.)
The installation prerequisites are simple:
sudo apt-get install pulseaudio pulseaudio-utils libpulse-dev python-dev
Now download and configure Boodler:
wget http://boodler.org/dl/Boodler-2.0.4.tar.gz tar xvzf Boodler-2.0.4.tar.gz cd Boodler-2.0.4 python setup.py build
It takes a while to do this, but make sure it does something useful when it’s building the various sound drivers. You don’t want it to say:
skipping 'boodle.cboodle_pulse' extension
If it says that, you haven’t installed Pulseaudio. Go back and check your apt-get line.
Once it’s built, now install it:
sudo python setup.py install
Now test it:
boodler --hardware --output pulse --testsound
Not merely should you get some pleasant tones from your Raspberry Pi’s audio, but you sound get some informative and non-threatening terminal output. Mine looks like:
Boodler: PulseAudio sound driver. PulseAudio library: 2.0.0. Sample rate is 44100 fps. Samples are 16-bit little-endian. Buffer size is 32768. 21:37:46 (root) Running "Boodler test sound"
If that works, let’s get those crows a-cawin’. Download the soundscapes you need:
boodle-mgr install http://boodler.org/lib/org.boodler.old.crow.1.0.boop boodle-mgr install http://boodler.org/lib/com.eblong.zarf.crows.1.0.boop
and run it:
boodler --output pulse com.eblong.zarf.crows/ParliamentOfCrows
Crows everywhere!
I really like the Buddha Machine samples. It’s quite big (> 80 MB), so this next set will take a while to download:
boodle-mgr install http://boodler.org/lib/com.azulebanana.buddhamachine.1.5.1.boop boodle-mgr install http://boodler.org/lib/com.azulebanana.buddhaagent.1.5.1.boop
It’s worth the wait:
boodler --output pulse com.azulebanana.buddhaagent/ChangingLoops
Boodler has tons of options, prebuilt packages, and instructions to build your own: Boodler Documentation.
One thing I’ve tried to get working, but failed, is streaming from Boodler via icecast. Sure, I can install and run it, it’s just that the results are, um, undesirable. If you want to have a play, here’s how to install icecast:
sudo apt-get install icecast2 ices2 libshout3-dev
Icecast will configure itself, and ask for a couple of passwords. You’ll have to rebuild and reinstall Boodler for it to catch the new configuration. You can then try streaming:
boodler --output shout --define shout-password=mypassword --define shout-mount='/boodler-buddha.ogg' com.azulebanana.buddhaagent/ChangingLoops
If you open a web browser at this address http://raspberrypi:8000/ you should see a config page listing your boodler-buddha.ogg stream. Click on the M3U link next to it, and your streaming music player should start making a joyful noise …
… except in my case, something went very wrong, and it started to produce industrial ultra-glitch nightmare noise: boodler-streaming_test-fail. I’m sure it’s fixable with some tweaking, but I’m not there yet.
-
X10 for Raspberry Pi on the Cheap [North American Edition]
Now I’ve got my X10 system running and know its limitations, I could have saved a wheen of money not buying stuff I don’t need. Our house appears to have been wired by an, um, spirited amateur, so powerline signalling is of limited use. Thankfully, the tiny and cheap X10 FireCracker CM17A (warning: too many flashing GIFs at this link!) can be driven from heyu [previously]. You can score these on eBay for under $10, and all you need is a serial adapter to drive them.
The really cheap bit in my system was discovered in Active Surplus. I found a case of Leviton “Plug-in Frequency Transceiver Modules” for $4/each. One was out of its case, and wouldn’t you know it, it’s the same as a RR501 module, which typically retails for about $30. Sure, these are old stock and are a nasty beige colour, but they provide a way of switching a two-pin appliance. They can also relay remote commands from RF to wired controls.The only X10 controller I can’t get to work with the Raspberry Pi is the CM19a USB PC Transceiver. I suspect it draws a bit too much power to run from a Raspberry Pi, as it makes the machine unresponsive if it’s plugged it. Running from my bench setup it works fine with the mochad driver, but no dice with the other machine. The CM19a reads wireless RF X10 commands, and it would be useful if I’d added a motion sensor. As is, I’ll stick to the lights going on and off.
(Update: there’s a good chance that my CM19a problems are down to the ancient dwc_otg* fixes I still run on my Raspberry Pi’s kernel. You probably don’t need them, and this device could work fine. One day I will find time to fix ’em …)
(Incidentally, this is the “North American Edition” because X10 RF controls are completely different in Europe, and none of the above is useful to you. Yeah, I know this article is the equivalent of PC Load Letter to you; sorry.)
-
hey, it’s the sun … heyu and sunwait and cron on the Raspberry Pi
Yep, springtime’s coming, and today’s the first day I know it, despite the -5.8°C outside. I know spring is coming because my sunrise-adjusted lights came on before my alarm today. I’m controlling them with a Raspberry Pi, cron, and X10.
I’d described how to build and use heyu previously, so I won’t go into it further. I use sunwait to control the timing relative to local sunrise and sunset. Sunwait is a simple C program which builds quickly, and you can put the executable somewhere in your path.
(NB: newer versions of sunwait use a completely incompatible command line format. Everything here refers to the 2004 version I linked to above, which does exactly what I need in the way it’s described here.)
You need to know your latitude and longitude to use sunwait. To check its setting for the day, you can call it with the
-poption:$ sunwait -p 43.729N 79.292W Using location:            43.729000N, 79.292000W Date:                       6 Feb 2013 Local time:                 7:44 Day length:                10:13 hours With civil twilight        11:10 hours With nautical twilight     12:18 hours With astronomical twilight 13:25 hours Length of twilight: civil  0:28 hours                  nautical  1:02 hours              astronomical  1:35 hours Current specified time zone: EST (-5 from UTC) Sun transits meridian 1231 EST                   Sun rises 0726 EST, sets 1736 EST       Civil twilight starts 0656 EST, ends 1806 EST    Nautical twilight starts 0622 EST, ends 1840 EST Astronomical twilight starts 0548 EST, ends 1913 EST
So for me, today’s sunrise is at 0726, and sunset is at 1736. All sunwait does is wait until a specific solar time is reached, and then exit. Whatever command you call after sunwait, therefore, is what gets run at the right time. So if I wanted X10 device H1 to come on an hour before sunrise, I’d run:
sunwait sun up -1:00:00 43.729N 79.292W; heyu on h1
Remembering to run this every day before sunrise would be a pain, so this is where cron helps. cron uses a slightly odd config file that is edited using the
crontab -ecommand. Here’s the relevant bit of my crontab, showing the light control times:# m h dom mon dow  command  01 00  *  *  *  /usr/local/bin/sunwait sun up -1:00:00 43.729N 79.292W; /usr/local/bin/heyu on h1  02 00  *  *  *  /usr/local/bin/sunwait sun up +1:00:00 43.729N 79.292W; /usr/local/bin/heyu off h1  03 00  *  *  *  /usr/local/bin/sunwait sun down -1:00:00 43.729N 79.292W; /usr/local/bin/heyu on h1  45 22  *  *  *  /usr/local/bin/heyu off h1
(you can view your crontab with
crontab -l)The columns in crontab are:
- minute
- hour
- day of month
- month
- day of week
- command
So the four crontab lines mean:
- Every day at 00:01, wait until an hour before sunrise and turn light H1 on
- Every day at 00:02, wait until an hour after sunrise and turn light H1 off
- Every day at 00:03, wait until an hour before sunset and turn light H1 on
- At 22:45, turn light H1 off.
So for quite a bit of the day, there are a couple of sunwait tasks just quietly waiting until sunrise or sunset to do their thing. cron, incidentally, is picky about executable paths; that’s why I specified full paths to both sunwait and heyu.
What I’d really like to do is have time on this machine update without a network connection, because it’s running from a particularly messy router set up in a spare bedroom. I should investigate a real-time clock, with GPS time updates from an I²C GPS, talking through a bluetooth console. In my copious free time, of course.
-
Simple ADC with the Raspberry Pi
Hey! This is a really old article. You should really be using gpiozero these days.
I hadn’t realised it, but the The Quite Rubbish Clock did something that a lot of people seem to have trouble with on the Raspberry Pi: communicating using hardware SPI. Perhaps it’s because everything is moving so fast with Raspberry Pi development, tutorials go out of date really quickly. Thankfully, hardware SPI is much easier to understand than the older way of emulation through bit-banging.
SPI is a synchronous serial protocol, so it needs a clock line as well as a data in and data out line. In addition, it has a Chip Enable (CE, or Chip Select, CS) line that is used to choose which SPI device to talk to. The Raspberry Pi has two CE lines (pins 24 and 26) so can talk to two SPI devices at once. It supports a maximum clock rate of 32 MHz, though in practice you’ll be limited to the rate your device supports.
The device I’m testing here is an MCP3008 10-bit Analogue-to-Digital Converter (ADC). These are simple to use, cheap and quite fast converters with 8 input channels. If you hook them up to a 3.3 V supply they will convert a DC voltage varying from 0-3.3 V to a digital reading of 0-1023 (= 210 – 1). Not quite up there in quality for hi-fi audio or precision sensing, but good enough to read from most simple analogue sensors.
The sensor I’m reading is the astonishingly dull LM35DZ temperature sensor. All the cool kids seem to be using TMP36s (as they can read temperatures below freezing without a negative supply voltage). One day I’ll show them all and use a LM135 direct Kelvin sensor, but not yet.
To run this code, install the SPI libraries as before. Now wire up the MCP3008 to the Raspberry Pi like so:
MCP 3008 Pin Pi GPIO Pin # Pi Pin Name ============== =============== ============= 16 VDD 1 3.3 V 15 VREF 1 3.3 V 14 AGND 6 GND 13 CLK 23 GPIO11 SPI0_SCLK 12 DOUT 21 GPIO09 SPI0_MISO 11 DIN 19 GPIO10 SPI0_MOSI 10 CS 24 GPIO08 CE0 9 DGND 6 GND
The wiring for the LM35 is very simple:
LM35 Pin MCP3008 Pin ========== ============= Vs 16 VDD Vout 1 CH0 GND 9 DGND
The code I’m using is a straight lift of Jeremy Blythe’s Raspberry Pi hardware SPI analog inputs using the MCP3008. The clever bit in Jeremy’s code is the
readadc()function which reads the relevant length of bits (by writing the same number of bits; SPI’s weird that way) from the SPI bus and converting it to a single 10-bit value.#!/usr/bin/python # -*- coding: utf-8 -*- # mcp3008_lm35.py - read an LM35 on CH0 of an MCP3008 on a Raspberry Pi # mostly nicked from # http://jeremyblythe.blogspot.ca/2012/09/raspberry-pi-hardware-spi-analog-inputs.html import spidev import time spi = spidev.SpiDev() spi.open(0, 0) def readadc(adcnum): # read SPI data from MCP3008 chip, 8 possible adc's (0 thru 7) if adcnum > 7 or adcnum < 0: return -1 r = spi.xfer2([1, 8 + adcnum << 4, 0]) adcout = ((r[1] & 3) << 8) + r[2] return adcout while True: value = readadc(0) volts = (value * 3.3) / 1024 temperature = volts / (10.0 / 1000) print ("%4d/1023 => %5.3f V => %4.1f °C" % (value, volts, temperature)) time.sleep(0.5)The slightly awkward code
temperature = volts / (10.0 / 1000)is just a simpler way of acknowledging that the LM35DZ puts out 10 mV (= 10/1000, or 0.01) per °C. Well-behaved sensors generally have a linear relationship between what they indicate and what they measure.If you run the code:
sudo ./mcp3008_lm35.py
you should get something like:
91/1023 => 0.293 V => 29.3 °C 93/1023 => 0.300 V => 30.0 °C 94/1023 => 0.303 V => 30.3 °C 95/1023 => 0.306 V => 30.6 °C 96/1023 => 0.309 V => 30.9 °C 97/1023 => 0.313 V => 31.3 °C 97/1023 => 0.313 V => 31.3 °C 98/1023 => 0.316 V => 31.6 °C 99/1023 => 0.319 V => 31.9 °C 99/1023 => 0.319 V => 31.9 °C 100/1023 => 0.322 V => 32.2 °C 100/1023 => 0.322 V => 32.2 °C 100/1023 => 0.322 V => 32.2 °C 101/1023 => 0.325 V => 32.5 °C 101/1023 => 0.325 V => 32.5 °C 102/1023 => 0.329 V => 32.9 °C 102/1023 => 0.329 V => 32.9 °C 103/1023 => 0.332 V => 33.2 °C
Note that the sensor had been sitting over the Raspberry Pi’s CPU for a while; I don’t keep my house at 29 °C. I made the temperature go up by holding the LM35.
So, you’ve just (fairly cheaply) given your Raspberry Pi 8 analogue input channels, so it can behave much more like a real microcontroller now. I remember from my datalogging days that analogue inputs can be pretty finicky and almost always return a value even if it’s an incorrect one. Check the chip’s datasheet to see if you’re doing it right, and if in doubt, meter it!
-
clawhammer banjo for people who have never played anything before
I’d never played any other instrument when I learned the banjo a decade ago. I’m still not entirely sure why I picked up the banjo, beyond the fact that it wasn’t a guitar. So weak were my musical recognition skills that instead of learning the style I really liked (Peter Stampfel’s two finger style) I picked up clawhammer.
So, you’ll need a banjo. Beyond being what you can afford, having five strings, a straight neck with frets that won’t shred your hands, and tuning pegs that don’t slip, it can be anything you want. Almost everyone learns on a Deering Goodtime, just as they did on a Harmony Reso-Tone in the 1960s. There are others: the Gold Tone CC-OT, the Epiphone MB-100; they’ll do. Don’t get anything too heavy at first.
Other kit you’ll need: a strap, a tuner, spare strings, and a metronome (maybe). Nails on your right hand kinda help. It helps to swap out the fifth string for a heavier gauge. Most beginner banjos come with a 0.010″ string, while a 0.012″ is much stiffer and won’t squirm about under your thumb.



Three banjos, same thumb
The key to clawhammer is that your thumb lives on the fifth string. No matter what you do, your thumb always returns to the fifth string. Is the action on your banjo high enough to make the fifth home for your thumb? If not, a taller bridge is a cheap way of fixing this.
Find a teacher, and get a couple of lessons, just so you know how to hold the thing and do some very basic frailing strums. As Peter Stampfel said: “Find a teacher whose playing you like — who is not a jerk”. I found Chris Coole:
Players I like? Apart from Coole, there’s:
Kyle Creed
http://www.youtube.com/watch?v=_nzi6qXb5pU
Reed Martin
(and before you complain about your banjo not being good enough, Reed’s playing that on a very basic Gold Tone.)
Cathy Fink
(and, perhaps slightly unfairly because she had the world’s worst cold at the time, here are Cathy and the Banjo Puppets … the cold didn’t seem to slow her down any.)
Need lessons and can’t get to a teacher? There’s Chris Coole’s DVD. Donald Zepp‘s videos. Many teachers offer Skype lessons.
You don’t need chords for clawhammer banjo. I’m barely aware of what they are (and with only 4½ strings and no sustain, they don’t sound great on a banjo). You’ll end up knowing more tunings than chords. That’s okay.
Banjo Hangout is both a resource and a trap. If in doubt, play banjo instead of reading BHO.
You may never get great at this. That’s okay; it’s not a destination. As Peter Stampfel said, I like “… the idea of something you’ll never finish”.
(and if you really do want to learn two finger style, Sean’s Thumb-Lead Banjer is great. It’s a totally different style from clawhammer, but it’s part of the old time canon.) -
qrclock, the demo reel
The video of the Quite Rubbish Clock isn’t running the same code that’s in the listing. Here it is, showing off some of the handy code that’s in bgreat’s nokiaSPI Python class:
#!/usr/bin/python # -*- coding: utf-8 -*- # qrmovie import time # need to use git://github.com/mozillazg/python-qrcode.git import qrcode from PIL import Image, ImageFont import ImageOps # uses bgreat's SPI code; see # raspberrypi.org/phpBB3/viewtopic.php?f=32&t=9814&p=262274&hilit=nokia#p261925 import nokiaSPI noki = nokiaSPI.NokiaSPI()             # create display device qr = qrcode.QRCode(version=1,          # V.1 QR Code: 21x21 px error_correction=qrcode.constants.ERROR_CORRECT_M, box_size=2, border=1) bg = Image.new('1', (84, 48))          # blank (black) image background # intro noki.cls() noki.led(0) time.sleep(3) for i in range(0,769,32): noki.led(i) time.sleep(0.04) # display is 14 columns by 8 rows noki.centre_word(1, 'scruss.com') noki.centre_word(3, 'presents') time.sleep(3) noki.cls() noki.centre_word(1, 'qrclock') noki.centre_word(2, 'the') noki.gotorc(3,3) noki.text("[Q]uite") noki.gotorc(4,3) noki.text("[R]ubbish") noki.gotorc(5,3) noki.text(" Clock") time.sleep(3) elapsed=0 start_time = time.time() while (elapsed<12): qr.clear() newbg = bg.copy()                  # copy blank background s = time.strftime('%Y-%m-%d %H:%M:%S') qr.add_data(s)                     # make QR Code of YYYY-MM-DD HH:MM:SS qr.make() qrim = qr.make_image()             # convert qrcode object to PIL image qrim = qrim.convert('L')           # make greyscale qrim = ImageOps.invert(qrim)       # invert colours: B->W and W->B qrim = qrim.convert('1')           # convert back to 1-bit newbg.paste(qrim, (18, 0))         # paste QR Code into blank background noki.show_image(newbg)             # display code on LCD time.sleep(0.4)                    # pause before next display elapsed = time.time() - start_time noki.cls() noki.centre_word(1, 'for') noki.centre_word(2, 'more') noki.centre_word(3, 'details') time.sleep(3) noki.cls() noki.load_bitmap("blogpost-nokia.bmp", True) time.sleep(7) noki.cls() noki.centre_word(3, 'fin') noki.centre_word(5, 'scruss, 2013') time.sleep(1) for i in range(768,-1,-32): noki.led(i) time.sleep(0.05) time.sleep(1) noki.cls()(This source, plus nokiaSPI class: qrclock-movie.zip)
Lines 43-58 show off the QR clock for a maximum of 12 seconds. Any more, and you’d get really bored.
The screen handling functions I used are:
- cls() — Clears the screen.
- led(brightness) — sets the backlight to brightness. For me, full brightness is at 768. A value of zero turns the backlight off. If you don’t have the screen LED connected to one of the Raspberry Pi’s PWM pin, this will either be full on (for any brightness >= 1), or off, for brightness=0. This is used to fade up the screen in lines 24-26, and fade it down far too theatrically in lines 72-74.
- show_image(PILImage) — display a single bit depth black and white Python Imaging Library object PILImage. This can be no larger than 84×48 pixels.
- load_bitmap(file, Invert) — load a single bit depth black and white BMP file of maximum size 48×84. If Invert is true, keep the colours as they are, otherwise swap black and white to make a negative image. nokiSPI flips images by 90°, so the image I loaded to show the URL of the blog post looks like this:

(I know, I could have generated this in code, but I’d already made the image using qrencode. I couldn’t be bothered working out the image size and offsets.)
The text handling functions I used are:
- gotorc(row, column) — move the text cursor to row, column. The screen only has 14 columns by 8 rows if you use the standard 6×6 pixel font, so keep your text short to avoid disappointment.
- text(text) — write text at the current cursor position.
- centre_word(row, text) — write text centred in row row. Since the text rows are a maximum of 14 columns, text with an odd number of characters will appear slightly off-centre.
There are many more functions in the nokiaSPI class; watch the demo, have a dig through the source and see what you can use.


























