Wednesday, 13 September 2017

BitIO blog 7: Minecraft CPU temperature monitor

BitIO blog 7: Minecraft CPU temperature monitor 

David Whale has been busy crafting more add on's to his BitIO library for the MIcro:bit. A few days ago he added the Micropython function to check the CPU temperature. His library can be accessed from here:

Here is the link to the code:

I have built / recycled Minecraft graphing code to create a CPU temperature monitor. Every time you press the a button it takes a temperature reading and then out puts this to Minecraft as a random coloured wool bar. Here is what you end up with:

1. Open python 3 on the Raspberry Pi.
2. Plug your Micro:bit into the Pi/PC.
3.   Ensure that you have read blog 1:
and downloaded the BitIO master files from David Whales github

4. Go into the 'Bitio master' folder, find the 'src' folder 
5. Create a new Python 3 script.6. Call it "Minecraft CPU temperature"
7. Type in the following code:

import microbit
from mcpi import minecraft as minecraft
from mcpi import block as block
import time
import random

WoolList = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]

mc = minecraft.Minecraft.create()
orx,ory,orz = mc.player.getPos()

mc.postToChat("Start Graph")

TempBlock = 35,14

HumidityBlock = 35,3
Temperature_List = []#stores temp data

DataStreamCount= 0

def BuildDataBlockTemp(ImportedBlock):# take data for temp
    temp = int(microbit.temperature())
    orx,ory,orz = mc.player.getPos()

    for i in range (0,temp):
        x,y,z = mc.player.getPos()  
    msg = "Temp = {0}".format(temp)
while True:
    if microbit.button_a.was_pressed():
        TempBlock = random.choice(WoolList)

8. Open Minecraft, create a new world.
9. Run the code by pressing f5, checking for any errors that arise.
10. Press the a button on the Micro:bit.

Try automating the graph so that it carries on every 10 seconds

You can now download a pdf version of these tutorials as part of the updated #hackpack resource booklet here:

No comments:

Post a comment