Friday, 29 September 2017

Adventures with EduBlocks and Minecraft the collection

EduBlocks  

This summary of all the stuff that I have produced in the last year with edublocks:

EduBlocks on Raspberry Pi


Blog 1: EduBlocks getting started 

Blog 2: Amen to walking blocks

Blog 3: The Minecraft update, pixel art block demo
http://warksjammy.blogspot.co.uk/2017/05/edublocks-minecraft-update-pixelart.html

Blog 4: The Liverpool Makefest Minecraft Pixel art Twitter bot
http://warksjammy.blogspot.co.uk/2017/06/liverpool-makefest-minecraft-pixel-art.html

Blog 5: Graphing live data in Minecraft
http://warksjammy.blogspot.co.uk/2017/06/exabytes-17-workshops-v1.html

Blog 6: Bridging the gap between visual coding and text based coding with EduBlocks.
http://warksjammy.blogspot.co.uk/2017/10/edublocks-blog-6-123-coding-cards.html


NEW NEW
Edublocks : BitIO
'Hello Micro:bit, hello Minecraft'
link






EduBlocks for Micro:bit

Blog 1: Variables, Buttons and lists
link

Blog 2: For loops
link

Blog 3: Random Names
link

I will add more over time enjoy :)



Wednesday, 13 September 2017

Micro:bit and the neo pixel strip / Codebug colour star

I have 5 codebug colour stars and one code bug. But I have access to many Micro:bits through work. Here is how to connect the codebug colour star to a MIcro:bit.

You will need:


  • A code bug colour star
  • 3 x jumper cables see below, fig 1
  • 3 x Crocodile clips see below, fig 2

fig 1

fig 2
 Instructions
1. Turn the colour star so you can see the pins on the back. Attach one jumper cable to the data in pin and then attach a crocodile cable see fig 2 to the jumper cable and attach to the Micro:bit pin 0.

2. Attach the second jumper cable to the GND pin on the colour star and then attach a crocodile cable see fig 2 to the jumper cable and attach to the Micro:bit GND pin.

2. Attach the third jumper cable to the 5V pin on the colour star and then attach a crocodile cable see fig 2 to the jumper cable and attach to the Micro:bit 3V pin.

3. Attach the Microbit to your PC/Pi Open MU micro python IDE.

4. Type in the following code:


from microbit import *
import neopixel
from random import randint


np = neopixel.NeoPixel(pin0,9)

while True:
    for pixel_id in range(0,len(np)):
        red = 255
        green = 0
        blue = 0
        
        np[pixel_id] = (red,green,blue)
        
        np.show()
        sleep(200)
        np.clear() 

5. Flash the code to the Micro:bit.
 
 This version is adapted from the MIcro:bit micropython website:
http://microbit-micropython.readthedocs.io/en/latest/neopixel.html

I have changed it to loop a red light around the neopixels. (See fig 3)
                                               

                                                      Fig 3


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:



Instructions:
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:
http://warksjammy.blogspot.co.uk/2017/07/blog-1-getting-started-with-bitio.html
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 monitor.py"
7. Type in the following code:

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())
    Temperature_List.append(temp)
    orx,ory,orz = mc.player.getPos()

    for i in range (0,temp):
        x,y,z = mc.player.getPos()  
        mc.setBlock(x+30,i,z,35,ImportedBlock)
    mc.player.setPos(orx,ory,orz+1)
    msg = "Temp = {0}".format(temp)
    
    print(msg)
while True:
    
    time.sleep(0.25)
    if microbit.button_a.was_pressed():
        TempBlock = random.choice(WoolList)
        BuildDataBlockTemp(TempBlock) 

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.

Extension:
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:
https://github.com/ncscomputing/HpAnthologyV2/raw/master/Hackpack%20Anthology%20V2%200.3.pdf


Monday, 11 September 2017

24 hours tracking the ISS in Minecraft and Twitter


During the last week or so I have been gradually tweaking my spin on Damien Mooney's ISS tracker. link https://damianmooney.wordpress.com/2016/02/16/raspberry-pi-minecraft-iss-tracker/

My bolt on is to take a screenshot record of each ISS movement and then tweet that picture from a twitter bot that I set up (@warksmessabout1).

This has worked for a while in trials, but has always fallen flat after a few hours. By trial and error I have hit upon a version which has run for 27 hours continuously updating 4 times an hour.

Here is an example screenshot of one of the recent updates from earlier today:




Here is the main twitter bot code:

"""
Tweeting ISS current position at set intervals with Minecraft Pi.
Get current ISS position from http://wheretheiss.at/ and map it on
a raspberry pi with minecraft
Damian Mooney wrote this minecraft Tracker in 2016. I have added a few
features on top, namely:
walking random wool blocks to mark current and positions
ability to screenshot the position using Martin O'Hanlons raspi2png tutorial:
(http://www.stuffaboutcode.com/2016/03/raspberry-pi-take-screenshot-of.html)
ability to tweet that using twython python library
"""
__author__ = '@damianmooney' #additions by @ncscomputing
from mcpi import minecraft as minecraft
from mcpi import block as block
from datetime import datetime
import time
import urllib2
import json
import random
import subprocess # to run shell script to autocall raspi2png
import sys
from twython import Twython
import BuildWorldDM as BuildWorld


consumer_key = ''
consumer_secret = ''
access_token = ''
access_token_secret = ''
       
api = Twython(consumer_key,consumer_secret,access_token,access_token_secret)

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

""" call where the iss at api thanks to Bill Shupp"""
def getiss():
    response = urllib2.urlopen('https://api.wheretheiss.at/v1/satellites/25544')
    mydata = response.read()
    return mydata

""" longitude: convert our longitude to a minecraft co-ordinate"""
def do_coord(longitude):
    mine_long = longitude * -.55
    return mine_long


#if __name__ == "__main__":


mc = minecraft.Minecraft.create()
mc.postToChat(" Minecraft ISS Tracker for @naascoderdojo")
mc.player.setting("autojump", False)
mc.player.setPos(6, 20, 50)
time.sleep(10)
while True:

    try:
        BuildWorld.Build()
        time.sleep(5)
        iss = getiss()
        pos = json.loads(iss)
        lat = pos['latitude']
        lon = pos['longitude']
        mc.postToChat("MC ISS tracker Version 1.4.1 of @naascoderdojo's Minecraft ISS Tracker")
        mc.camera.setFollow()
        mc.postToChat("Credits to @damianmooney")
        mc.postToChat(' ISS Location Lat: %.2f Long: %.2f' % (lat,lon))
        new_long = do_coord(lon)
        mc.player.setPos(int(new_long), 20, int(lat))
        mc.setBlock(int(new_long), 20-1, int(lat),35,random.choice(WoolList))
        msg = 'ISS pos '+'@SpacePiJam'+' lon %d lat %d' % (new_long, lat)
                    #print msg
        mc.postToChat(msg)
                    #ory to location that you havesaved raspi2png in
                    
        a=subprocess.check_output('./raspi2png -d 3 -p "myscreenshot.png"',shell=True)
        photo = open('myscreenshot.png', 'rb')
        time.sleep(8)
        api.update_status_with_media(status=msg, media=photo)
    except:
        mc.postToChat("update issue")
        a=subprocess.check_output('./raspi2png -d 3 -p "myscreenshot.png"',shell=True)
        photo = open('myscreenshot.png', 'rb')
        api.update_status_with_media(status="update issue", media=photo)

    time.sleep(450) # --only update once every 15 minutes


It reads in and renders the world text file from here:
https://raw.githubusercontent.com/ncscomputing/HpAnthologyV2/master/BuildWorldDM.py

The data file is here:
https://raw.githubusercontent.com/ncscomputing/HpAnthologyV2/master/world3.txt

Enjoy :)