Friday, March 15, 2013

Pi Projects (generally no soldering iron required)

The Register has done its homework and come up with some of the easy Raspberry Pi construction projects.
  • Coffee table arcade game
  • LAMP server (that is Linux, Apache, MySQL, and PHP, and server as in a computer server)
  • Pi/Kindle Chimera
  • Pi Netbook
  • Info kiosk info projector
  • Weather station
  • Cloud server
  • Pi scales
  • Pi-BX
The projects are summarised on www.theregister.co.uk.

Saturday, March 2, 2013

Python and Minecraft on the pi.

Right, first for a copy of Minecraft: Pi Edition visit pi.minecraft.net/. And background information on Minecraft on the raspberry pi; see www.raspberrypi.org).

Copy the file (e.g. minecraft-pi-0.1.1.tar.gz) into your home directory.
Expand it; I used the tar -xvf command to unpack the gzipped and tarred up distribution.
tar -xvf minecraft-pi-0.1.1.tar.gz
cd mcpi
./minecraft-pi
And this starts Minecraft from the xterm.
At this point you can play Minecraft as you would expect on any conventional computer.

Now for the spice; using Python to send commands to directly to Minecraft, taking command of or interacting with the environment.

Well Python comes with the Raspbian “wheezy” Linux distribution for pi. It's already there waiting for me.
Following instructions from numerous other early explorers (best and most interesting for beginners I judge to be that by prmrytchr).

From a new xterm and staring in the mcpi directory...
cd api/python/mcpi/
Then start Python, and tell Python to import the minecraft.py functions and connect to my local running Minecraft session. My xterm looked like this.

Python
Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import minecraft as minecraft
>>> mc = minecraft.Minecraft.create()

The >>> indicates that the Python session is running so now I can type in some of the suggested Python instructions.
>>> mc.postToChat(“Hello, Minecraft!”)
And I see the message display in my running Minecraft game.
I can get the game to report my player position...
>>> mc.player.getPos()
Even if my player is at the spawn point I should probably can use this position (x,y,z) to do stuff. Like this to place a mushroom at the coordinates...
>>> mc.setBlock(x,y,z,40)
Now from Ger a quick command to test set all the numbered block types in sequence.
>>> for i in range(50):
>>> mc.setBlock(i, 53+i, 25, i)

Useful links for further progress
www.minecraftwiki.net beginners guide
www.minecraftwiki.net tutorial
www.stuffaboutcode.com
A maze generator: www.jonasavrin.com

And when you've finished shutdown X to the console then type sudo shutdown