2017-04-23

A publishing experiment about source code in cinema and TV

I was persuaded by buddy Mr H to make a YouTube channel out of my Source Code in TV and Film Tumblr. The Tumblr shows the source code that flashes by on computer screens in films and TV programmes and look at its heritage.

This is sometimes surprising, funny, or relevant, and often ridiculous. For the first experimental episode I looked at what I believe is an Easter Egg in the original Iron Man film:



I would be interested to hear people's thoughts on this format.

The second episode is a forensic examination of the opening sequence of the Doctor Who episode The Bells of Saint John:

2017-04-16

A Totoro to forecast the weather

Regular readers may know that I like ambient devices: devices that fit into the environment unobtrusively and provide information at a glance. One such device is my bus monitor that shows times of buses at the stop near my house.


Recently I decided to solve the problem of answering the question "Do I need an umbrella?" when I leave the house. For this I chose to use an ESP8266 in the form of a NodeMCU running Lua and display the coming weather by illuminating the eyes on a small Totoro figure.


This was my first NodeMCU/ESP8266 project and there's definitely a bit of a learning curve. I ended up using luatool to upload my Lua code to the device, and esptool to flash the firmware using a custom firmware build from this wonderful website with the following modules present: cjson, file, gpio, http, net, node, tmr, uart, wifi, and ws2812.

./esptool.py --port /dev/cu.SLAB_USBtoUART write_flash -fm qio 0x00000 nodemcu-master-10-modules-2017-04-08-20-28-08-integer.bin

The first step was to prise open the Totoro figure and then drill out the eyes so that two LEDs cut from a NeoPixel strip could be hot glued in place.



I made a mess of opening the bottom of the Totoro as I didn't realize there was a large chunk of resin in the bottom (for stability). However, I ended up with a nice hole through which it's possible to connect a USB cable for reprogramming the NodeMCU.


The rear part of the Totoro contains the NodeMCU with just five wire connections: power, ground and data to the NeoPixel strip, and a pig tail to supply power through a hole drilled in the back (5V from an old wall wart I had lying around is fed straight to Vin and GND on the NodeMCU).


I used heat shrink tubing to insulate the connections so that there aren't any inadvertent short circuits when the Totoro is closed.

The code that runs Totoro is here. It uses the Met Office's DataPoint API to get the weather forecast for a location in the UK. You'll need to register there for an API key and figure out the location you want to get weather for from the Met Office data. As coded it gets the weather forecast for a maximum 6 hour period (two 3 hour forecasts) and figures out the worst weather to happen during that time.

The configuration for the Totoro is all in totoro-config.lua where you'll fill in the weather location, API key and the credentials for the WiFi network you want your Totoro to connect to.

The Totoro conveys the following with its eyes:

  • Red: heavy rain
  • Blue: rain
  • White: snow
  • Flashing white/black: hail
  • Yellow: sunny
  • Flashing red/blue: Internet or API connection problem
  • Flashing green: updating weather forecast
  • Black: no special weather
Here's Totoro having trouble reaching the API (flashing red/blue).


And here's Totoro checking the weather (flashing green) and finding that it's nothing special (goes black).



2017-04-03

Computer languages I learnt before university

I was thinking about the various languages I have learned over the years and why. Here they are in rough order. I don't think there's a great insight here, just a personal reflection.

Pre-teen

TURING/REGISTER MACHINE

Around age 6, I was sent to the Cavendish Laboratory at Cambridge University to a sort of camp for bright kids. I asked a man (undoubtedly a professor or lecturer from Cambridge) to tell me how a computer worked. This was the early 1970s and I'd only seen computers on television.

The man sat down with a piece of paper and drew a long strip of boxes and described a machine that looks at the boxes and decides what to do next. He also showed me a language for programming this strip-of-boxes-machine.

He had described both a Turing machine and also a register machine and I was absolutely fascinated: computers were so simple!

Teen

FORTRAN

My first hands-on time with a computer came via a teletype that no one seemed to touch. It was kept in the corner of a room at school and connected to some far away machine. But it was possible to program it in FORTRAN. I don't recall ever being told what machine I was typing to, only that it was possible to prepare simple programs in FORTRAN. I mostly wrote some simple mathematical programs (such as calculating the value of pi or factorials). Magic! (when it worked).

Pretty sure is was an ASR 33 Teletype like this:

By Bubba73 (Jud McCranie) - Own work, CC BY-SA 3.0

BASIC

The school entered the 'home computer' era with a Sharp MZ80K which I spent hours in front of first learning its BASIC so that I could write simple programs (including something called STATPAC which was a package for doing statistics: think, really, really simple R).

That machine still works and runs my old programs. The school was kind enough to let me take this computer home during the holidays. This was the first machine I knew inside out.



Z80 ASSEMBLY/MACHINE CODE

But to get any power from the machine it was necessary to learn Z80 assembly language (and the machine code since I didn't have an assembler to everything was typed in as opcodes hidden inside REM statements in BASIC programs). This didn't seem hard at all, more like a crazy game where the moves are limited and you have to work with them. I obtained a copy of Rodnay Zacks' Programming the Z80 at great cost and devoured it.



PASCAL

At some point the school got a network of Research Machines 480Z machines and on these we were able to program in BASIC and machine code. We later got an assembler and I wrote some quite large assembly language programs, such as one for scooping up network packets and analyzing them, another for spying on disk access and a complete 'network management' system.



But PASCAL was a bit of a revelation because suddenly programs that had been structured with subroutines (GOSUB or CALL) and rough and ready data structures were no structured with actual functions that operated on well-defined data. And there was a compiler.

FORTH and 6502 ASSEMBLY

I had a BBC Micro Model B (in fact I still do) and it, of course, I programmed in BASIC and 6502 assembly language, but FORTH suddenly became popular and I figured I had to try it out since this whole 'stack-based programming' thing seemed interesting. And FORTH on the BBC Micro was fast. It came on a ROM that was plugged into an expansion port.



I wrote a lot of fun programs in FORTH but it ended up feeling like an academic exercise. Fun but never going to really catch on. Of course, that's before I got to university and wrote things using Common LISP, ML and Occam :-)