Little Box of Haiku

Following on from my Little Box of Poems – which printed a random poem on till-roll (and which also inspired Carrie Anne Philbin’s Little Box of Geek) – I present: The Little Box of Haiku.

It’s made from a RaspberryPi and one of Pimoroni’s lovely Displayotron 3000 LCD display / button gizmos.

You push a button and this Python script generates a random haiku from a set of 5, 7 and 5 syllable sentences.

Enjoy!


#!/usr/bin/env python
import time
import dot3k.lcd as lcd
import random
import dot3k.backlight as backlight
import dot3k.joystick as j
import signal

backlight.rgb(0,0,255)
lcd.set_cursor_position(0,0)
lcd.write("@blogmywiki's   amazing random  haiku machine")

five_syllable = ['Cat crouches     wisely', 'Dog wags tail in hope', 'Leaves fall on   the ground', 'Apples are       falling', 'A child stops to look']
seven_syllable = ['No-one knows why they come here', 'The moon rises   unnoticed', 'Stars are       falling to Earth now', 'The grass is moist underfoot', 'Buttercups hide in the shade']

time.sleep(3)

lcd.clear()
lcd.write("Press button to create your     personal haiku")

while True:

        @j.on(j.BUTTON)
        def handle_button(pin):
          backlight.rgb(255,255,255)
          lcd.clear()
          line1 = random.choice(five_syllable)
          line2 = random.choice(seven_syllable)
          line3 = random.choice(five_syllable)
          lcd.set_cursor_position(0,0)
          lcd.write(line1)
          time.sleep(5.5)
          lcd.clear()
          lcd.set_cursor_position(0,0)
          lcd.write(line2)
          time.sleep(5.5)
          lcd.clear()
          lcd.set_cursor_position(0,0)
          lcd.write(line3)
          time.sleep(5.5)
          backlight.rgb(0,255,0)
          lcd.clear()
          lcd.set_cursor_position(0,0)
          lcd.write("Press button to create your personal haiku")
        # Prevent the script exiting!
        signal.pause()
Posted in poetry, Raspberry Pi | Tagged , , , | Leave a comment

Thoughts about Serial

It seems as if everyone in my Twitter timeline is raving about Serial. Serial is an American podcast about a possible miscarriage of justice. Episode 1 describes itself thus:

It’s Baltimore, 1999. Hae Min Lee, a popular high-school senior, disappears after school one day. Six weeks later detectives arrest her classmate and ex-boyfriend, Adnan Syed, for her murder. He says he’s innocent – though he can’t exactly remember what he was doing on that January afternoon. But someone can. A classmate at Woodlawn High School says she knows where Adnan was. The trouble is, she’s nowhere to be found.

I’ve listened to 6 of the 50-minute episodes now – so clearly it must be doing something right. And yet, I don’t have the same passion about it, the same addiction about it that most people do.

There are plenty of things to like. Oddly, we don’t tend to use the term ‘sound design’ in radio, but it sounds fantastic. It’s very well mixed and edited, the original music is haunting, presenter Sarah Koenig has an easy-on-the-ear voice and a personable style.

And yet something is missing. Perhaps I’ve not been paying close enough attention, listening whilst doing other things, last night listening at 4am because I couldn’t sleep, and Koenig’s voice is almost as soothing a narcotic as a radio programme in Burmese. Or it could be because of the things that are not there; you’d expect heart-wrenching, tear-jerking testimony from the murder victim’s family, and that’s missing. It’s oddly dispassionate, almost matter-of-fact in the way material is covered. Sarah Koenig is no John Sweeney – the tempo and tone of her voice rarely changes much, you can’t imagine her losing her temper and railing against the injustice of it all.

Possibly (and I’m not quite up-to-date yet) this is because she just doesn’t know herself. And neither do I. As a slightly casual listener, who hasn’t read through the paperwork, I’m thinking at this point that this probably wasn’t a miscarriage of justice. Clearly something doesn’t add up in this case, but I’m far from convinced of Adnan’s innocence.

I am, however, convinced by the Serial web site. It is beautiful to look at, clear, it responds to mobile devices, the audio player is really well-designed, and I have fallen in love with the headline font, Sackers Gothic, beautifully serious, very, very North American. Perfect.

Posted in radio | Tagged , , | Leave a comment

Displayotron3000 Pi Radio

IMPORTANT UPDATE JULY 2015: The BBC has changed the way it streams network radio – see here for details. And Fip has moved to http://audio.scdn.arkena.com/11016/fip-midfi128.mp3

In the summertime I built a Raspberry Pi radio that I could control via a web interface from my phone, and got to musing about some kind of Arduino-type shield that could snap on to a Pi to turn it into a little internet radio with a display, a few buttons and a speaker.

Well, blimey charlie, imagine my surprise when I discovered something pretty darn similar already exists! The good people at Pimoroni make and sell the splendidly-named Displayotron 3000 (not sure if it is related to Andre). This sits snugly on a Pi’s pins and gives you a 3-line LCD display with 3 strips of variable RGB backlights, a 4 way mini joystick with centre-press and a strip of eye-wateringly bright (but dimmable) white LEDs for use as a bar graph. It even has its own radio module, and I’ve been testing it out.

In short, I love it. It does everything my imaginary radio gizmo did, apart from having a built-in speaker (how about it, guys?). It goes perfectly with Pimoroni’s Pibow Coupe case (pictured) – this is a half-height case that leaves GPIO pins and other gubbins accessible.

It took a bit of tweaking to get it working. I started with a fresh install of Raspbian, updated my Pi with
sudo apt-get update
sudo apt-get upgrade
sudo rpi-update

I then installed the files from https://github.com/pimoroni/dot3k:
sudo apt-get install python-dev python-pip python-smbus
sudo pip install dot3k
git clone https://github.com/pimoroni/dot3k

I couldn’t get it to work, and then discovered that I had a bit more work to do: namely enabling spi and i2c. Details on how to do that are here and here.

I then installed psutil, another requirement:
sudo apt-get install python-psutil

My previous Raspberry Pi radios have all used mpd/mpc to play radio streams, but this one uses VLC, and I’m impressed. I installed VLC and added some stations to the config file*, and bingo! a cool little internet radio with a colourful screen and a well-designed menu allowing you to browse stations, view CPU load and temperature, change the volume and a very cool clock with an optional binary display and time-sensitive dimmer.

It’s a great piece of work – Pimoroni and @gadgetoid should be very, very proud.

My wishlist for tweaks:
- an alarm clock
- display time and station name at the same time
- ‘now-playing’ track info, as per my web-based radio
- weather info
- a record function
- a built-in speaker!

Time to retire my PiRadio made with an Arduino-driven LCD display and buttons.

* the radio bit of my config file now looks like this (starting with the world’s greatest radio station, fip. Mais oui.)

[Radio Stations]
fip32 = fip bas debit,http://mp3.live.tv-radio.com/fip/all/fip-32k.mp3
fip128 = fip haut debit,http://mp3.live.tv-radio.com/fip/all/fiphautdebit.mp3
radio1 = BBC Radio 1,http://bbcmedia.ic.llnwd.net/stream/bbcmedia_intl_lc_radio1_p?s=1365376033&e=1365390433&h=a0fef58c2149248d6bff1f7b7b438931
radio2 = BBC Radio 2,http://bbcmedia.ic.llnwd.net/stream/bbcmedia_intl_lc_radio2_p?s=1365376067&e=1365390467&h=d43dc8ae0f888809462a6cb7c389b46b
radio3 = BBC Radio 3,http://bbcmedia.ic.llnwd.net/stream/bbcmedia_intl_lc_radio3_p?s=1365376123&e=1365390523&h=d53cf2a92272f3289b314a2251d23bc8
radio4 = BBC Radio 4,http://bbcmedia.ic.llnwd.net/stream/bbcmedia_intl_lc_radio4_p?s=1365376126&e=1365390526&h=ed9a0642b30c422b07fbcd8683c52335
radio4x = BBC Radio 4Extra,http://bbcmedia.ic.llnwd.net/stream/bbcmedia_intl_he_radio4extra_p
radio5 = BBC 5Live,http://bbcmedia.ic.llnwd.net/stream/bbcmedia_intl_lc_5live_p?s=1365376271&e=1365390671&h=e0d82133f35ae74d41d5eab6b9c150a6
6music = BBC 6Music,http://bbcmedia.ic.llnwd.net/stream/bbcmedia_intl_lc_6music_p?s=1365376386&e=1365390786&h=de40a9915206c4402c73e3766dc3fec0
einws = BBC WS News, http://bbcwssc.ic.llnwd.net/stream/bbcwssc_mp1_ws-einws
nwpr = NWPR,http://69.166.45.47:8000
meat = MEATransMISSION,http://46.28.49.164:7184/
monocle = Monocle M24,http://radio.monocle.com/live
resonance = ResonanceFM,http://radio.canstream.co.uk:8004/live.mp3
purple = Purple Radio,http://uk1-pn.webcast-server.net:8184/
rte1 = RTE Radio 1,http://icecast2.rte.ie/radio1
share = Share Radio,http://tx.sharp-stream.com/icecast.php?i=shareradiorpmobilehigh.mp3

Posted in Raspberry Pi, Raspbian, Uncategorized | Tagged , , , , , | 17 Comments

Raspberry Pi internet radio with web interface

Having made a bare-bones Raspberry Pi internet radio and one with an LCD display with push buttons to change channel, I decided that it would be nice to be able to control it from my smartphone, as well as displaying ‘now playing’ track information.

This was a fun challenge that kept me busy in the summer… I got distracted dreaming of different RaspberryPi shields (see below) with little speakers, buttons and LCD displays that would make nice Kickstarter projects, and I’ve been so busy since that I never wrote it up. So here, from memory and a few scribbled notes, is how you might do it…

In brief, you install mpd and mpc music players, add some internet radio stations, install a simple web server and add a bit of PHP code to dish up a web page that controls the radio and displays tracklistings. It was the latter that was an especially tough nut to crack. The BBC, despite being funded from public subscriptions, does not seem to freely syndicate its ‘now playing’ data, and I have had to get it via a commercial third party’s RSS feed (last.fm). Madness. (Or possibly The Specials. Without the now playing data, I’m not sure.) For my favourite radio station, fip, I used its Twitter feed to display the last 3 tracks played.

How to build one (very) roughly

1) Start with a vanilla RaspberryPi running Raspbian OS ‘headless’ so it doesn’t boot into a GUI. Adding wifi and giving it a static IP address is a good idea (in my experience, most wifi routers allow you to give devices the same IP address each time they start up). Enable SSH so you can log into your PiRadio remotely.

2) Install MPD and MPC music players as per http://www.suppertime.co.uk/blogmywiki/piradio/

3) Add internet radio stations of your choice as per http://www.suppertime.co.uk/blogmywiki/piradio/

4) Plug in some headphones, powered speakers or an amp into the analogue audio output of the RaspberryPi to test it works when you type
mpc play 1

5) Optional: add a line to /etc/rc.local to play the radio station of your choice at boot-up.

6) Install nginx web server and PHP.

6.5) Install SimplePie to handle the RSS feeds that give ‘now playing’ data for BBC Radio.

7) Add my index.php and shutdown.php file (code here) to /usr/share/nginx/www – there was probably a whole mess of permissions horror here that my notes glide over. It looks like I had fun making the shutdown work, I probably had to give the nginx user sudo rights or something horribly ill-advised.

8) You should now have a radio you (or your children! such hilarity!) can remotely control from a web-browser on any smartphone, computer, tablet – or indeed eBook reader. The stylesheet is optimised for an iPhone, but this easily be tweaked.

To do:
- enable recording (I did make some headway with this using streamripper but ran out of time).
- have a nice HTML5 volume control slider (this was beyond me).
- find a better way of setting it up so you can configure the wifi from a simple command line in a KanoOS-style.
- make it so you can easily edit the station list from web interface or command line.
- mesh in better with my Arduino-driven LCD display (at the moment if you change the channel using the web interface, the LCD shows the wrong station name).
- find someone to help me build my Kickstarter radio shield/widget. Adafruit do an LCD screen with buttons like my Arduino one, but it’s a kit. I’d like a cute little box with a screen, buttons and a speaker or two, powered by USB.


Controlling an early version of PiLittleRadio from an old Kindle 3G.

Posted in Raspberry Pi | Tagged , , | 4 Comments

10 fun things to do with a Raspberry Pi

Got a Raspberry Pi? Not sure what to do with it? Here are some cool things I’ve done with mine to get you thinking:

Some of these posts are old and the precise details of what you need to do may be out-of-date, but I hope this list gives you some ideas.

Posted in Raspberry Pi | Tagged , , | Leave a comment