Using a Raspberry PI Zero W to hold disk images for the BBC Micro

At Christmas I treated myself to a new machine, a BBC Master 128. It’s that new that it was manufactured somewhere between 1986 and 1993 – if you are into retro-computing you know what this is like.

Anyhow, this machine is in very good condition. It’s been refurbished with new capacitors in the power supply (something you must check on the BBC’s as they can go bang if you aren’t careful).

BBC Master 128 with GoTek drive to the left & another project sitting on top of it so ignore that 😉

It also came with a GoTek USB floppy emulator. This is a device that connects to the BBC (and others like the Amiga) as if they were a real floppy drive but instead of a disk it uses a standard USB stick which can contain images of the original disks. So many you could probably have a copy of every bit of software for the BBC micro ever produced on floppy on one stick!

Now this is perfectly fine if you have your software collection on it & rarely add anything but if you are doing any development and need to regularly add or update disks it’s a pain as you have to unplug the USB stick, put it in to your main development box, mount it, copy a 200K file (thats the capacity of a standard BBC DFS 40 track disk!), unmount it then plug it back into the drive.

You can tell it’s tedious and if regularly done could cause additional wear & tear to the contacts!

So to make this far easier I took a Raspberry PI Zero W and used it as the flash drive. In the above picture you can see a white USB cable in the GoTek, thats got the Zero on the other end of it.

If I needed to add or update a disk I can simply use SCP to copy the file to the pi and the GoTek then sees the new disk, I select it & the BBC can read it. From upload to opening it on the BBC can literally be a few seconds.

So, how to set it up? Well the MagPi has an article from about 2 years ago which tells you how https://magpi.raspberrypi.org/articles/pi-zero-w-smart-usb-flash-drive

This is a good article so I’m not going to repeat it here except you don’t need to do all of them & there’s a few errors in that article which I will repeat here:

  • Step 4 is not needed if you used a minimal Raspbian image – i.e. no need to use the full desktop one, use the lite image as the base.
  • For step 6 use the GoTek as the power source not the TV as used in the article & yes for now it is being powered solely by the drive it’s being used on.
  • You can ignore Step 9 as we won’t be using multimedia – you could use a bbc disk image here instead
  • Step 10 has the errors. Here it mentions gmassstorage this is wrong & I think it’s the formatting on the site that’s broken it. Replace all references to that with g_mass_storage not the _’s, some CMS’s use _ to say underline which you can see on that page.
  • Steps 11 & 12 are optional – I did them but don’t use them

That’s effectively it, except a comment about powering the PI (which is in step 6 of that article).

Now I am using the GoTek to power the Pi – so there’s just a single USB cable from the GoTek to the usb port on the PI (not the PWR IN). This is fine as my GoTek has it’s own power supply.

However if you were to use an external supply for the PI, then you must cut the red wire inside the micro USB cable else you’ll feed additional power from the PI to the GoTek as well as the PI suddenly having two 5V supplies feeding it – which will cause damage to both devices!

Getting up an ADS-B receiver on a Raspberry PI

This post describes how I setup a basic ADS-B receiver on a Raspberry PI Zero W using a USB RTL2832U based Software Defined Radio so that you can see any ADS-B equipped aircraft in your local area and present it on your own website.

Continue reading “Getting up an ADS-B receiver on a Raspberry PI”

Centralizing Certificate Management of LetsEncrypt with a Raspberry PI

Lets Encrypt is a new Certificate Authority (CA), run for the public’s benefit by the Internet Security Research Group (ISRG). At the time of writing it’s currently in Beta and is due to go public in December 2015.

Update: Lets Encrypt went into public -beta on December 3 2015. I have updated this article with the minor change needed to work with the live servers.

Now in the default mode, the standard Lets Encrypt client (it’s not the only one) can manage this automatically – however it’s not ideal if you have more than one server.

What I describe here is how to centralize managing certificate registration (& later renewal) on a central machine. When a certificate is then registered or renewed we can then copy the certs to the remote servers.

Continue reading “Centralizing Certificate Management of LetsEncrypt with a Raspberry PI”

Connecting an Arduino to a Raspberry PI using I2C

Some time ago I created a weather station using a Raspberry PI and an off the shelf weather station, connecting the two via USB.

However, for some time not I’ve been meaning to create a weather station from scratch – i.e. one or more Raspberry PI’s which connect to the network (via Ethernet or WiFi) and directly monitor the sensors directly.

Now the problem here is that some sensors are analog – for example the leaf, soil and UV sensors I have generate an analog signal so we need an ADC (Analogue to Digital Converter) which the Raspberry PI doesn’t have.

So we have two possible solutions:

  1. Add a Raspberry PI compatible ADC
  2. Use an Arduino

With the parts I have available, the Arduino won, not just on available ADC channels but also with the additional digital ports available.

Now how to connect it to the PI? Well the easiest way is to use USB, however the PI only has two USB ports (one for the Model A) and as I’m intending to use Model A’s for the final station I need that for WiFi (there won’t be room or power for hubs) so USB is out.

There’s RS232 which both support, however the PI runs on 3v3 whilst the Arduino (UNO) is 5v so I need to add a level converter between the two. It also limits me to just one arduino and I might need to use more than one so another solution is needed.

Continue reading “Connecting an Arduino to a Raspberry PI using I2C”

Setting up a Weather WebCam on Linux

Weather webcams are always popular and it is easy and free to set one up yourself.  This article will show how to setup a simple USB webcam to produce still images and serve them on a local apache webserver.

Continue reading “Setting up a Weather WebCam on Linux”

Formatting xml in emacs

I had this problem of debugging some xml but when reading the output of some log4j it was almost impossible to read so I needed some way of prettifying the xml quickly.

For this example I have the following xml:

<?xml version="1.0"?><xml><iq xmlns="jabber:component:accept" from="test1@temp.retep.org/client" id="iq_257" to="service.retep.org" type="get"><query xmlns="some:namespace"/></iq></xml>

So how do we pretify this in emacs?

Well the first thing to do is to write an extension function & place it into your ~/.emacs file. Placing it here means that when you open emacs the extension is available:

(defun xml-format ()
  (interactive)
  (save-excursion
    (shell-command-on-region (mark) (point) "xmllint --format -" (buffer-name) t)
  )
)

Now this works by passing the buffer to the xmllint utility and replaces it with the output – in this case nicely formatted xml.

Now we need to install xmllint:

pi@lindesfarne: ~$ sudo apt-get install libxml2-utils

Ok so now open emacs and open the xml. To format first select the xml you want to format then Press Escape then x followed by xml-format & press return. You should then get the xml nicely formatted:

<?xml version="1.0"?>
<xml>
  <iq xmlns="jabber:component:accept" from="test1@temp.retep.org/client" id="iq_257" to="service.retep.org" type="get">
    <query xmlns="some:namespace"/>
  </iq>
</xml>

Installing a USB Weather Station on a Raspberry PI part 2

In the first article I covered how to install a weather station on a Raspberry PI. In the second part I’ll cover how to get it to upload data on an hourly basis to a website using FTP.

Getting the station to run hourly

First we need to get the station to run hourly. To do this I created a script called weatherupload which I placed under /usr/local/bin

pi@kell: ~$ sudo vi /usr/local/bin/weatherupload

Enter the following:

#!/bin/bash
cd /usr/local/weather
python Hourly.py -vvv data

Once saved make it executable and then edit the main crontab:

pi@kell: ~$ sudo chmod +x /usr/local/bin/weatherupload
pi@kell: ~$ sudo vi /etc/crontab

At the end of the file you need to add the following:

0 * * * * root /usr/local/bin/weatherupload

Save it and now every hour it will now run.

Note: I’ve placed it there and not under /etc/cron.hourly because

  1. cron.hourly runs once an hour, but not necessarily at the top of the hour. I a later article when I add twitter you want the tweet to be close to 0m rather than at a random time.
  2. I’ve found in the past that using crontab -e doesn’t always work, even for root but in the core crontab it just works

Uploading to a website

First to generate the graphs pywws uses gnuplot so we need to install it:

pi@kell: ~/sudo apt-get install gnuplot

Next we need to add some details to the stations weather.ini file. At the top theres a section called paths. Make sure those point to the relevant templates and graph_templates directories in your pywws install.
Next under the hourly section you should see a pair of lines:

plot = []
text = []

You need to add the plots and pages that need to be generated:

plot = ['7days.png.xml', '24hrs.png.xml', 'rose_24hrs.png.xml', 'rose_7days_nights.png.xml']
text = ['current.html', '24hrs.html', '6hrs.html', '7days.html', 'feed_hourly.xml', 'allmonths.html']

Finally theres the ftp section which needs configuring with the remote ftp server (your web host will give you these):

[ftp]
secure = False
site = ftp.example.com
local site = False
user = myaccount@example.com
directory = /weather/
password = mypassword

That’s about it. Now when you run the hourly script it will generate some simple pages & images to your website.

You can see an example of this over at maidstoneweather.com – although the uploaded templates only form part of that site.