Monday, 26 September 2016

Flotilla and Minecraft Pi Light-Up Real-World Furnace with Python

Our first Flotilla Python project adds a lit furnace effect to our real-world Minecraft storage solution. We can now make the furnace glow with a programmable fire effect using the array of RGB LEDs on the Flotilla Rainbow module.

Flotilla is a plug-and-play electronics dock and modules for the Raspberry Pi from Pimoroni. We backed the Flotilla Kickstarter and have a big treasure chest of components to play with. You can read our first impressions review (keep in mind that it was early days) and our more recent experience with the Flotilla Cookbook recipes.

We decorated IKEA storages boxes to create a Minecraft chest, furnace and crafting table, check our our real-world Minecraft storage article to find out how to do this. Originally we just created a removeable cardboard cut-out to allow the furnace to change between lit and unlit, but the long term plan is to add electronics to our Minecraft storage.

The Flotilla Rainbow Module

The Flotilla Rainbow Module has 5 bright RGB LEDs in a row. Perfect for creating a fire effect in front our our furnace. The Minecraft furnace had red colours towards the outer edges through to orange and then yellow in the middle so we wanted to program a similar effect.

Choosing Python

We considered the Rockpool UI for controlling the Rainbow module but it didn't seem to be quite the right tool and also we knew we would want to link up with Minecraft Pi using Python.

We looked at node-red (a graphical way of connecting up inputs and outputs with functions in between) but couldn't work out how to set the LEDs individually. We'll have a look at Flotilla node-red again in future, we did get some other stuff working.

Installing Flotilla Python

The instructions for installing Flotilla Python can be found right at the end of

Note that if you don't have git installed then you can just go to and choose Clone or download -> Download ZIP and then unzip the downloaded zip. 

A set of examples is included so we took a copy of the example to get us started (there's not much in the way of documentation!)

We also looked at in the Flotilla Python library to see what functions we could use and found that it's pretty straightforward. 

There are methods for setting the colour of each pixel individually or all of them at once and a method for setting the brightness. You also need to call an update method for your changes to take effect. 

First we just tried setting the LEDs to different colours. The set_pixel function takes a pixel number from 0 to 4 and red, green and blue values, each from 0 to 255.

Here's the code:

#!/usr/bin/env python

import time
from random import *

import flotilla

from mcpi.minecraft import Minecraft
import mcpi.block as block

mc = Minecraft.create()

client = flotilla.Client(
            'eight': flotilla.Rainbow

on = False

    while True:

        for module in client.available.values():
            if module.is_a(flotilla.Rainbow):

                if on:
                    red = randint(155,255)
                    module.set_pixel(0, red, 0, 0)             
                    module.set_pixel(1, red, 55, 0)
                    module.set_pixel(2, 255, 135, 0)
                    module.set_pixel(3, red, 55, 0)
                    module.set_pixel(4, red, 0, 0)
                    module.set_all(0, 0, 0)
        for hitBlock in
            if mc.getBlock(hitBlock.pos.x, hitBlock.pos.y, hitBlock.pos.z) ==               
                mc.setBlock(hitBlock.pos.x, hitBlock.pos.y, hitBlock.pos.z,, hitBlock.face)
                on = True
            elif mc.getBlock(hitBlock.pos.x, hitBlock.pos.y, hitBlock.pos.z) ==
                mc.setBlock(hitBlock.pos.x, hitBlock.pos.y, hitBlock.pos.z,, hitBlock.face)
                on = False
except KeyboardInterrupt:

This all worked very smoothly. There's lots of scope for trying out different ways to create more realistic fire effects.

Diffusing the Light 

During prototyping we used a box lid to diffuse the light to see what kind of effect we could create.

We added code to change the amount of red in the four outer LEDs within a range. The amount of red changes every tenth of a second to create a flickering effect. 

We also experimented with the brightness of the LEDs to create a realistic flame effect. 

3D Printed Diffusion Panel

Next we created designed a 3D printed diffusion panel in Open SCAD to go in front of the Rainbow module.

The pixels in our real-world Minecraft are 2cm square. We only created a panel for the inner part of the bottom of the furnace so that we didn't need to 3D print a huge panel. 

Here's the OpenSCAD code for creating the shape that we used:

sw = 20;

rows = [6, 6, 4, 2];
for (i = [0:len(rows)-1]) {
  translate([sw*(3-rows[i]/2), 0, 0]) {
    for (j = [0 : rows[i]-1]) {
      difference() {
        translate([sw*j, sw*i, 1.25]) cube([sw, sw, 2.5], center = true);
        translate([sw*j, sw*i, 1.25+2]) cube([sw-4, sw-4, 2.5], center = true);

If you don't have access to a 3D printer then you could just cut a shape from some semi-translucent plastic packaging or cover a cardboard frame with tissue paper.

Turning the Furnace on from Minecraft Pi

Of course the next obvious step was to be able to turn the Furnace on from Minecraft Pi using Python. You don't have crafting in Minecraft Pi but you do have active and inactive Furnace blocks.

When programming Minecraft with Python on the Raspberry Pi you're pretty limited in what events you can access. You do get an event when a block gets hit so that's what we used. 

When you hit an inactive Furnace it turns to active and so does the Furnace in real world Minecraft. When you hit an active Furnace it switches to inactive and so does the Furnace in real world Minecraft. 

Here's the end result:

We're pretty please with what we managed to do and we'll be doing more projects with Flotilla and Minecraft on the Raspberry Pi.

You might also like:

More from Tech Age Kids:


Post a Comment