Skip navigation
2014

minecraft-banner-3_3510581_3522898.jpg

We can use the programming language Python to interact with the Minecraft world in a few short lines of code.


First, we have to do a bit of setting up. To keep our code separate to the original code in the MCPI folder, we will make a new directory to keep all of our code in. In LXTerminal, type mkdir python This will make a directory called python. To use the MCPI API we will have to copy that folder over to our new directory. Make sure that you are in your new directory (cd python) and then type the following command: cp -r ~mcpi/api/python/* . Include the full-stop one space after the *!


Finally, we are ready to start coding. By default, the API only uses Python 2. x but you can change this to allow Python3 use as well by following this link, however, I will not be going in to that today, for now, we will stick with Python 2. I will also be using the command line text editor nano but you can use other text editors if you wish.


Our first task is to make the file that we will run. Make sure that you are in your new directory, then type cd mcpi followed by sudo nano block_placer.py This should open up an empty file in nano. The first two lines of code are import minecraft and then import block underneath it. Next, we have to connect to our Minecraft world which we do by typing mc = minecraft.Minecraft.create() This first example will simply place a block at a set of co-ordinates, so first, we will define three variables, one under the other, called x, y and z. The code could look a bit like this:

x = 5
y = 0
z = 5


Now that we have our co-ordinates, we just need to place the block. Our last line of text will be mc.setBlock(x, y, z, block.STONE) Note, this is case sensitive so make sure that everything is capitalised correctly if you get an error message. The final file should look like this:

mport minecraft

import block


mc = minecraft.Minecraft.create()


x = 5

y = 0

z = 5


mc.setBlock(x, y, z, block.STONE)


Now we can just save the file (press ctrl x, then press y to save changes and then enter) and get Minecraft running. These programs will not work unless Minecraft is running and a world is loaded. Open up another LXTerminal window, type cd mcpi and then ./minecraft-pi to get Minecraft going and then load into a world. Now, press the tab key to release the mouse from Minecraft, go back to our other LXTerminal window and type python block_placer . This should run the file and at the co-ordinate 5, 0, 5 there should now be a block of stone.


That’s it for the basic python stuff. In the next tutorial, we will move on to some more complicated code and look at how to build structures and some of the other useful commands we can use.


Written By Mathew Monk MinecraftMastery | @minecraftmasterybook

minecraft-banner-3_3510581_3522898.jpgNow that you have installed Minecraft, it is probably important to learn how to play it. If you are looking for how to install Minecraft: Pi Edition, please follow the previous guide. For those of you who have played Minecraft on a Mac or PC before then you can skip this section as the controls and principles of this version are similar enough for you to pick it up. If this is your first time playing Minecraft on a computer, keep reading!

 

When you start up Minecraft, you will be greeted with an option to either “Start Game” or “Join Game”. For now, we will select “Start Game”. Just a word of warning, the cursor can be a bit off sometimes so be patient! If this is the first time that you are running Minecraft on the Pi, then you will only have one option- “Create New”. Click this, and it will tell you that it is building the world and there should be a progress bar. If Minecraft has been run on that Pi before, then you can either double-click a world to load it or you can also select “Create New”.


Once you loaded up your world, you will need to now how to move. Minecraft uses the “WASD” controls, which means that you use the “WASD” keys to move. W is forward, A is left, S is back and D is right. As well as this, you can also crouch by holding down the shift key, jump by pressing space bar, and fly by quickly double tapping the space bar. When in flying mode, hold space bar to ascend and hold shift to descend: the other direction keys stay the same.


Being able to run/fly around the world is fun, but it’s even better if you can place/destroy things. When looking at a block, hold down left-click to destroy the block. You will also notice that you have a bar at the bottom of your screen. The highlighted box is what your character is currently holding and each box represents a block or item. If you right-click while looking at another block and while holding a block, you will place it. In this version, you are always in creative mode, which means you have unlimited resources. You can swap between the nine items in your “hot bar” (the name of the bar a the bottom of the screen) by either scrolling or pressing the number key corresponding to that item/block’s position. For example, if I had stone in my sixth slot, I could select it by pressing 6.


minecraft-pi-edition-svet.png


Having nine items soon gets boring, so why not have more. To do this, select the slot you want to put your new item/block in using the scroll wheel or the number keys, then press the “e” key. This brings your inventory screen up, where every block/item in the game that is available to you is displayed. Simply click the item that you want and it will now be in the highlighted slot in your inventory.


That concludes the section on regular (so called vanilla) Minecraft for the Pi. Next time, we will get stuck into using python to change things in the Minecraft world.


Written By Mathew Monk MinecraftMastery | @minecraftmasterybook


minecraft-banner-3_3510581_3522898.jpg


If you haven’t heard of Minecraft before, it is a game developed by Mojang and originally created by Markus “Notch” Persson. Quite simply, it is a game about placing different types of blocks. Although it may sound a bit dull, Minecraft is one of the most popular games on PC (and has since come to consoles) because of the creativity involved of making anything from complex contraptions (using something called “Redstone“) to massive buildings and even whole countries. Sadly, the Raspberry Pi version has to be limited as the Raspberry Pi itself is limited and therefore uses a C rendition of the originally Java based, mobile version of the game. All of the Minecraft: Pi Edition information from this guide is sourced from pi.minecraft.net


First things first, this is for the Raspbian (wheezy) Operating System on the Raspberry Pi. Also note that XWindows must be running (type startx into the LXTerminal to do this). XWindows may be already start by default with your Pi and if not you can change this by typing sudo raspi-config . The first task is to actually download Minecraft for the Raspberry Pi. So, to start off,  type wget http://tinyurl.com/rasp-pi-minecraft into LXTerminal and your download should begin.


Now that you have the file on your Raspberry Pi, and you have made sure that XWindows is running (see above) you need to type the following command into LXTerminal to unpack the tar.gz file- tar -zxvf  rasp-pi-minecraft Lots of file/file paths should show up in your window (see picture below). If it does not, make sure you have spelt everything correctly.


E14-1.png


That’s everything that has to be downloaded! All that’s left now is to run Minecraft. To do this, first we need to change our current working directory in LXTerminal to mcpi- simply type cd mcpi The final step is to start the Minecraft program by typing ./minecraft-pi Make sure you put the ./ at the start! If everything went well, you should now have an instance of Minecraft running on your Raspberry Pi.


Written By Mathew Monk MinecraftMastery | @minecraftmasterybook



Hi all,

 

In this blog post, I go through the basic steps required to blink an LED on a Raspberry Pi - the basic microprocessor way of saying "Hello World!"

 

In case you missed it and need help getting started on the basics of writing and running a Python program on the Raspberry Pi, my previous blog post goes into a lot more detail of those first steps: Raspberry Pi - HelloWorld

 

For this tutorial, I am using:

1x Raspberry Pi Model B+ running Raspbian (other models should work fine too)

1x breadboard to make the connections

1x LED

1x 470Ω resistor (the precise value is not important)

2x M-F jumper wires

 

One of the great features of the Raspberry Pi is that it includes IO pins which, like an Arduino, allow you to connect it to other bits of hardware.

But, unfortunately, the default installation does not allow access to the IO pins, so the first step here is to change things so that we do have access.

 

Thankfully this can be done very easily by just changing the settings of the "IDLE 3" desktop icon.

To do this, simply right-click on the IDLE 3 icon, then choose "Open With...", toggle to see Accessories, and then select Leafpad and click OK.

This pops up an editor showing several lines of text.

For the line that starts with "Exec", after the = sign add "sudo " (just the part within the quotation marks, including the space)

This will run the Python IDE as "root", giving it full access to the machine.

Now save and exit, and you are ready to blink the LED!

pi_idleroot.png

 

To connect the LED:

- put the LED into the breadboard

- connect one side of the 470Ω resistor to the short lead of the LED

- connect a wire from the long lead of the LED to pin 11 (GPIO17) on the Raspberry Pi

- connect a wire from the other side of the 470Ω resistor to pin 9 (GND) on the Raspberry Pi.

 

Now the fun begins!

You can open up a new window and try this yourself, or just download the attached blink.py example and open it.

 

To use the GPIO pins, you will need to import the correct library:

import RPi.GPIO as GPIO

 

Then you need to get the GPIO system set up:

GPIO.setmode(GPIO.BOARD)

 

And the output pin has to be set up as output:

GPIO.setup(11, GPIO.OUT)

 

After that basic setup you can then send a high or low value to the pin:

GPIO.output(11, GPIO.HIGH)

and

GPIO.output(11, GPIO.LOW)

 

When the script finishes, remember to clean up:

GPIO.cleanup()

 

In my example I use a little loop and a timer to turn the LED on and off 10 times.

RPi_blink.jpg

 

It's actually quite easy to use once you know the basics

 

ps, I've given a bit less detail in the steps than in my last post, as that would make this a very long post, but please feel free to ask questions if any of it is unclear.

 

edit: Here is a picture of how the IO pins are arranged for the B+

 

Next: Raspberry Pi - DS18B20 Temperature Sensor

 

Edit: This has been tested and works on both the RPi model B+ and the RPi 2 model B.

 

Cheers,

-Nico

Hi All,

 

In this blog post I go through the very first basic steps of programming a Raspberry Pi using Python, to run the familiar starting program "Hello World"

 

Note that this is geared for people who are complete beginners with Raspberry Pi.

 

My first thought was that this must have been done a zillion times before, but when I started looking I couldn't find anything that summed it up in easy steps, and I found myself having to dig a little just to get the first steps figured out. Not too difficult, but a bit annoying. So I thought I may as well track what I'm doing and make this blog post, in the hopes that it might make someone else's life a bit easier.

 

First of all, I'm assuming that your Raspberry Pi is already set up, and that you are using the Graphical User Interface. I'm using Raspbian here, and all my steps will be based on that. I'm also using the version of Raspbian that came on a NOOBS SD card, circa October 2014. So if your version is older it may not have all the tools installed in the same way. In that case, please refer to the many other resources out there that can do a much better job than I of explaining how to update and/or install the software.

If all else fails, it might be easiest just to get a new SD card and install the latest version of Raspbian on it.

 

I am doing this on a Raspberry Pi Model B+, but everything should work the same way on other models.

 

The tool we will use is "IDLE 3", which is a handy little Python editor. It comes pre-installed with Raspbian.

 

The first step is to just double-click the IDLE 3 icon to open the "shell" - basically a line by line Python interpreter.

Now you can try your very first line of Python: at the >>> prompt, type this line:

print("Hello World!")

then press the enter key. The shell should respond by printing "Hello World!" on the next line and then giving you a new >>> prompt.

 

The shell provides a nice and easy way to try single line Python commands, but most programs require more than one line. To accomplish this, you need to either open a file, or create a new file.

Let's create a new file: from the file menu of the Python Shell window, choose "New Window".

A new window titled "Untitled" will pop up on your desktop, and it'll be a blank slate. We'll just ignore the obvious self-contradiction of the title of the window. But this is where you can now start typing in your program.

 

Keeping with the super-easy theme, let's also make it say "Hello World!", by typing the same line as before, but this time type it into the Untitled window.

You'll notice that it won't automatically try to run it. That's the point - it gives you time to type out a more complex program before it tries to run it.

 

To run it, we'll need to save the file first. The usual ctrl-S or File-Save will do the trick. Put it somewhere where you'll be able to find it back later, of course. I prefer to put it under "Documents", as I'm not using this Raspberry Pi computer for anything else.

 

Now from the file menu, select Run and Run Module to run your new Hello World program.

 

You'll notice that it switches the window selection to the Python Shell, and then prints a long line that says "RESTART", shows a prompt, then shows your "Hello World!" line, and then another prompt.

 

pi_helloworld.png

 

That's it! That's all there's too it.

 

Now the next time you open IDLE 3, you can simply use "File-Open..." to open the existing helloworld.py file and run it again.

 

I hope that helps out. My next blog post will go on to show how to blink an LED - the basic microprocessor version of "Hello World"

 

Edit: This has been tested and works on both the RPi model B+ and the RPi 2 model B.

 

Cheers,

-Nico

Through our Community, element14 has long strived to support the work of the modern engineer. In doing so, we’ve also recognized that engineering is no longer the sole remit of professionals in workshops; beginners, hobbyists and enthusiasts alike are all now actively involved in the Community.

 

Together, these various groups are working to develop their understanding of the electronic world, collaborating and sharing knowledge along the way.

 

It made sense that the next logical step was to begin introducing these resources to the world of education. After all, if the current generation of engineers can assist and teach one another, the next generation could benefit immeasurably if they had access to the same knowledge base from an early age.

 

Since September this year, computing has become a core part of the UK national curriculum. Some of you may right now be getting flashbacks to your own ICT classes: dusty computer labs, yellowing old desktops, and spreadsheet formulae.

 

But the new curriculum is intended to be more like a fully fledged computer science class, helping to equip the next generation for more computer focused employment. And with our role in helping the engineers of today learn and share information, we are also committed to helping the engineers of the future.

 

We’re already involved in some ways as distributor of the Raspberry Pi.  We’re also working closely with Leeds Beckett University in the UK, providing opportunities for students to learn from working in a real-life industry setting.

 

Now that we are almost a term in to the new curriculum in the UK, we’re keen to stop and take stock of how it is working. This is where you can help us.

 

We’re conducting a survey of anyone involved in the education sector and would love to hear your feedback on the new curriculum. Whether you’re actively teaching the new Computer Science curriculum in a UK school and wish to help develop a better understanding of what is and isn’t working, or can just pass it on to someone who is involved in the wider education sector, we’d like to hear from you.

 

As an added incentive, everyone who responds will be entered in a prize draw to win a Raspberry Pi Starter Kit, perfect for use in the classroom!

 

You can complete the computing curriculum survey here.

Through our Community, element14 has long strived to support the work of the modern engineer. In doing so, we’ve also recognized that engineering is no longer the sole remit of professionals in workshops; beginners, hobbyists and enthusiasts alike are all now actively involved in the Community.

Together, these various groups are working to develop their understanding of the electronic world, collaborating and sharing knowledge along the way.

It made sense that the next logical step was to begin introducing these resources to the world of education. After all, if the current generation of engineers can assist and teach one another, the next generation could benefit immeasurably if they had access to the same knowledge base from an early age.


Since September this year, computing has become a core part of the UK national curriculum. Some of you may be getting flashbacks to your own ICT classes: dusty computer labs, yellowing old desktops, and spreadsheet formulae.

But the new curriculum is intended to be a fully fledged computer science class, helping to equip the next generation for more computer focused employment. And with our role in helping the engineers of today learn and share information, we are also committed to helping the engineers of the future.


We’re already involved in some ways as distributor of the Raspberry Pi. We’re also working closely with Leeds Beckett University in the UK, providing opportunities for students to learn from working in a real-life industry setting.

Now that we are almost a term in to the new curriculum in the UK, we’re keen to stop and take stock of how it is working. This is where you can help us.


We’re conducting a survey of anyone involved in the education sector and would love to hear your feedback on the new curriculum. Whether you’re actively teaching the new Computer Science curriculum in a UK school and wish to help develop a better understanding of what is and isn’t working, or can just pass it on to someone who is involved in the wider education sector, we’d like to hear from you.


As an added incentive, everyone who responds will be entered in a prize draw to win a Raspberry Pi Starter Kit (see Terms & Conditions), perfect for use in the classroom - or at home, if you’d prefer! You can complete the computing curriculum survey here.

Introduction

It is one thing to check the temperature of something with a thermometer. However logging data and observing the change over time is a great way to see trends and gain more insight.

This blog post covers just a simple experiment but the aim is to have a more general solution for good quality temperature measurement, monitoring and logging at low cost.

 

What is needed?

A temperature sensor and logger is needed. Thanks to support from Element14 and element14Dave check out the blog post for a Raspberry Pi based temperature measurement solution. Of course, any temperature logging system could be used (e.g. off-the-shelf system, or an Arduino based solution mentioned in the comments section below).

 

Is it interesting?

In general, I believe so – perhaps if students are curious then they can measure anything within limits of hundreds of degrees C technically. Practically that would depend on their age and supervision.

 

As a suggestion for further discussion, maybe it could be turned into a game:  A challenge could be, "how long can one keep a drink hot", using nothing other than insulation or materials around the home/school and an hour of time? (by the way It turns out that the answer is: quite a long time. There is some more information on that later).

 

The challenge would involve researching parameters like thermal conductivity, area, and material thickness.

 

Variations of the challenge could involve guessing the temperature of an object at different times on a spreadsheet, and seeing who gets closest to the actual temperature curve – i.e. like a temperature based variation of battleships :  ) This could be automated of course.

therm-battleships.png

As a first step, I tried an easier experiment to check out the performance of disposable cups – I wanted to know, is it really worth doubling-up on cups to keep a drink warm?

 

How to do it

First, get some water heated up (or use hot water from a tap).

 

Set up the temperature logging device and get it recording data. At this point the data is just recording room temperature.

 

Measure out an amount of the water into a cup placed in a tray or bowl (in case it leaks or is knocked over), and insert the temperature sensor.

 

I tried a paper cup (make sure it is intended for hot drinks) from the supermarket (Tesco in my case) with no lid, and measured for an hour. It didn’t keep the drink hot for very long. I used 200ml of water from a kettle. Room temperature was about 21 degrees C. I then repeated with a lid, and then a third experiment was with a doubled-up cup but still with one lid.

 

The conclusion (which I knew from experience since we have very similar cups at work!) is to drink quickly or always use a lid :-)

 

This is a very basic experiment of course, but it did help test out the Raspberry Pi temperature logger. The graph below shows the measured temperatures for an hour.

coffee-cup-results.png

 

For the “how long can you keep a drink hot” challenge, here is my entry; I decided to use expanded polystyrene (Styrofoam) about 15mm thick sheets. I chopped it up using a piece of resistance wire connected up to a power supply. I used Nichrome wire of about 40 ohms/metre, and used 50cm of it connected to a 15V supply (outdoors in case the fumes were toxic) – this gently cuts, or turn up the voltage for a more aggressive cut : )

 

The pieces were glued using epoxy resin adhesive (Araldite) – other glues may damage the polystyrene. It was very tricky to get it absolutely watertight but eventually it was (a ready-made polystyrene cup would be an easier option, but my local supermarket didn’t have any : (

 

I also made a tight-fitting lid using expanded polystyrene. I again used 200ml of water, and started at around 51 degrees C, ambient temperature was 21 degrees C. Over the space of an hour, the temperature dropped by just under 8 degrees C. So that’s my record – looking forward to hearing if others can beat it (it shouldn't be hard : ).

therm-challenge.jpg

 

To do the measurements, I used a temperature sensor known as a thermocouple, type ‘K’. It was an ‘exposed junction’ type, which isn’t really intended for liquids but is low cost – dry it thoroughly afterwards to prevent corrosion. Some thermocouple models have an exposed junction (such as the one in the photo below), others are enclosed in a probe where the end is either grounded to the probe or insulated, which affects response time.

 

Some of the enclosed models can handle over 1000 degrees C; others have insulation which functions up to about 250 degrees C, so it is worth checking before using it.

thermocouple-tip.jpg

 

If you’re interested in building a thermocouple sensor solution for the RPI, check out the blog post here.

So I have been tinkering with Raspberry Pis for a little while now, and I am thoroughly convinced of their utility, and I am hoping to spread that out in my classroom.

 

On example of a project I would like to do is taking temperatures using the waterproof temperature probe.  There are many others, but that is a good place to start.  My students make it a habit to bring their devices (phones, computers, tablets) to class, and it seems like I should be able to get their devices to control a probe on the RPi.  The most obvious way to do that is through a web client. 

 

So, I have some code I have been using for getting temperatures to report out to a Google spreadsheet by using gspread.  You can find it here:  https://github.com/MDScience/temperature

 

I would like to use it improve upon it with a web client so that my students could use their device to go to the RPi and tell the probe to start collecting temperature information once they are ready.  I imagine there would be buttons and fields for required information (like the name of the file they would like to output to, and so on).

 

This, of course, is just the beginning.  We would want to do more than temperature measurements, and we would need other sensors and other web clients. 

 

If there is a good tutorial, or a model to follow I would greatly appreciate knowing about it.  Similarly, if there are any engineers who have experience in this area, and would like to lend a hand, I would appreciate that as well.

 

Thanks!