Friday 28 December 2018

Raspberry Pi RC Lego car


In the next iteration of the Raspberry Pi based controlling of Lego motors I purchased another basic motor previously used with the Ferris Wheel, the aim was to create a simple RC Lego car. The remote control is the same idea as in the RaspiExpress using GuiZero and accessing that over wifi on my Iphone using Real VNC.

Here is a photo of the latest hacked together vehicle:

Here is the code:......Link

Here is a video of it working.... Link

Updated 08/01/19.

New updated GUI using GuiZero.

Here is the updated code: link

Here is what it now looks like:




Cya.

Saturday 15 December 2018

3d printed light up Lego Christmas Tree



Kari Lawler has helped out at several jams over the last 18 months and has kindly made some 3d printed christmas trees that slot together and sit nicely on a Lego brick. Here is the relevant info if this something that interests you:

Here is the 3D stl file : link
Here is a video of it working: link
Here is the code : link

To control the light you will need:

  • 1 x neo pixel 
  • 1 x Micro:bit
  • 3 x crocodile clips
  • Power for the Micro:bit


Here are basic images of how it was put together:




Over

Wednesday 12 December 2018

Blocks controlling blocks




This recycles the code from the RaspiExpress and replaces the GUI buttons with whacking different blocks in Minecraft. This still uses a Raspberry Pi and a Lego motor. The same Edu Kit 3 motor controller/ hat is used. Please see a video below of how the initial test worked.

Here is a link to the code: link



Cya

Friday 30 November 2018

25 Minecraft hacks of Christmas '18


Over the next 25 days I shall be recycling existing blogs and maybe a few new ones to look at 25 different coding experiments with Minecraft and Python.

Day 1: Modding interface with GUIZero. This experiment pulls together several previous coding experiments and cements them all into one GUI which can trigger a range of different array of block based events.

Read more here ...... Link

Day 2: This blog has a link to dozens and dozens of my Minecraft experiments from over the years. They are all linked into a pdf document called the 'hackpack' here is the link to the related blog .........Link

Day 3: Getting started with BitIO and MInecraft....... Link

Day 4: BitIO and Minecraft 'Tilting Rainbow Road'......... Link


Day 5: EduBlocks  and MInecraft getting started............ Link


Day 6: EduBlocks  and MInecraft ...........Amen to walking blocks............Link


Day 7: BitIO  and MInecraft 'Touching pins takes you places'...........Link


Day 8: Edublocks / BitIO and MInecraft..........The Liverpool Makefest Minecraft Pixel art Twitter bot........... Link


Day 9: BitIO and MInecraft  ''Minecraft CPU temperature graphing"


Day 10: Edublocks and Minecraft 'Bridging the gap between visual coding and text based coding with EduBlocks'.......Link

Day 11: MInecraft Education Edition My First Command Block.......Link

Day 12: BitIO and MInecraft : PixelCraft.......Link


Day 13: Minecraft Education Edition: Give inventory and changing weather.......Link


Day 14: BitIO and MInecraft 'Micro:bit Transport' ........LInk


Day 15: M:EE MakeCode 'Get coding'........Link

Day 16: BitIO and MInecraft 'Scalable Housing'..........Link

Day 17: MInecraft Education Edition: MakeCode Getting started........Link

Day 18: MInecraft Education Edition:MakeCode 'Wool Wall'........Link

Day 19: Raspberry Pi Minecraft controlling Lego motors .... Link

Day 20: Raspberry Pi and Minecraft: Pixel Cakes(RPI big birthday weekend resource)
...................link

Day 21:  Raspberry Pi and Minecraft: Pixel Craft 2.0......Link

Day 22: Raspberry Pi and Minecraft: Experiments with GPIO triggers and Minecraft
.......Link

Day 23: Minecraft Education Edition: Vertical farming ......Link

Day 24: Raspberry Pi and Minecraft: GPIO zero Minecraft "Whack on board Led's"
........Link

TUI Calculator/ binary to denary conversion



This is code covers:


  • Casting 
  • Functions 
  • Tui's
  • Basic input
  • Procedures
  • String element checking
  • Basic mathematical operators
  • Simple validation on binary section
It allows the user to chose from a text based menu and either:

  • add, subtract, divide or multiply two numbers that the user inputs
  • enter an 8 bit binary number and convert it denary
Here is the code:

Over

Monday 26 November 2018

Lists and TUI's


Here is a program I used with year 9 to introduce list basic list functions and TUI's.
It contains:

  • selection
  • procedures
  • procedure calls
  • casting 
  • pop
  • remove 
  • lists 
  • append
It is a very simple simulation of a "game server" allows the user to add gamer tags, remove and pop off the end of the list. 

Here is the code : link

Tuesday 6 November 2018

Micro:bit Express 2.0 'adjustable speed'



This is an incremental improvement to the original Micro:bit Express which went via remote control fwd and back and stop. The next project the Micro:bit controlled Ferris Wheel allowed you to adjust the speed within a small range. This project applies the same logic to the train with a greater range of speed.

You will need all the same kit as in the original blog here is the key info:


  • A video of the updated train in action link
  • Code for the updated remote link
  •  Code for the updated motor controller link 
Enjoy :)

Monday 29 October 2018

Micro:bit Controlled Lego Ferris Wheel


Micro:bit Controlled Lego Ferris Wheel 

Here is the basics of what you need to create your own remote controlled Micro:bit Ferris Wheel. You will need:

  • 2 x Micro:bits
  • 1 x Lego Ferris Wheel
  • 1 x 4.5 battery box
  • 1 Kitronic motor controller link 
  • 1 Lego motor

Here are photos of the set up.






Video of action

link

remote code link

motor controller code link

Over :)

Harry Potter sorting




This code consolidates:

  • Lists
  • Count controlled loops
  • Conditions 
  • IF Then Else 
  • Random and time libraries.
I've used this with year 9 who have just done basics with input, loops, basic conditions etc. This takes their learning a little deeper without killing it.

Here is the link to the code: link

Here is the code:


import random
import time

Students_List = ["Harry","Ron","Dave","Hermione"]

Slytherin_Students = [] # stores s students
Hufflepuff_Students = [] # stores hp students
Ravenclaw_Students = [] # stores rc students
Gryffindor_Students = [] # stores g students

House_Names = ["Gryffindor", "Ravenclaw", "Hufflepuff", "Slytherin"] # list of house names to randomly select.

#create a variable to store current position in student list
Current_Student = 0

while Current_Student < len(Students_List) :
#randomly choose a house for the 1st student
House = random.choice(House_Names)
time.sleep(5)
print("Your house is",House)
#add student to correct house list
if House == "Gryffindor":
Gryffindor_Students.append(Students_List[Current_Student])
print(Gryffindor_Students)#show house population

elif House == "Ravenclaw":
Ravenclaw_Students.append(Students_List[Current_Student])
print(Ravenclaw_Students)#show house population

elif House == "Hufflepuff":
Hufflepuff_Students.append(Students_List[Current_Student])
print(Hufflepuff_Students)#show house population
elif House == "Slytherin":
Slytherin_Students.append(Students_List[Current_Student])
print(Slytherin_Students)

else:
print("You have chosen a house that doesn't currently exist")


#add one to current position in student list
Current_Student = Current_Student + 1

Python programming resources



Here are a links to any Python resources that do not involve any hardware such as Raspberry Pi or Micro:bit.


Blog 1 Harry Potter sorting
link

Sunday 21 October 2018

Lego hacking: RaspPi Ferris Wheel


I bought my daughter a basic Lego Friends Ferris Wheel.

Insert image

I reused the code from Raspberry Express:

link

I have modified the GUI to include new speed range which is more in keeping with the speed a Ferris Wheel should go. Essentially the main speed scale is from 0.1-0.2. Due to the weight issues you have to run the Ferris Wheel at 0.3 speed to pick up enough momentum to get it to turn at all.

I have also cut down the bulky code from the Raspberry Express so that it is less hefty.

here is the code:

link

I will update this blog over the next few days with more detail.

Enjoy!

Chris

Sunday 29 July 2018

Lego + Code blog 3: The Raspberry Express


Lego + Code blog 3: The Raspberry Express

Here is a demo of 'turtle mode': Link
I have tried to recreate the Micro:bit express but simply swap in Raspberry Pi 3b+ currently. This is not a comprehensive blog just a few notes on how to get yourself started.

Raspberry Pi connected to the Lego Power functions motor:

Closer look at the train:

A few notes:
  • I used a cheap £1 rechargable battery to run the Pi.
  • I used a 4.5 volt battery and motor controller found in the Raspberry Robot kit which you can get here called EduKit 3. Link   
  • Again I have used Python 3 to code the train.
  • To create the remote I have used a GUI library for called GuiZero written by Laura Sachs and contributed by Martin O'Hanlon. Link
  • To connect to the Pi attached to the train and use the remote I have used a free app called RealVNC. Link
  • I think thats the nuts and bolts of it.
  • Here is a screen grab of the really simple remote controller.  
  •  I have managed to code it to use scalable speed both forward and back using GPIO zero. Link which is managed by Ben Nuttall.
  • The turtle option allows you to code a 'coded path' if you look my code below it should be fairly clear.
  • Finally here is the code in its current version: Link
Enjoy :)


Lego Hacking: Lego + Code



Lego Hacking : Lego + Code

Blog 1: Lights on: Link


Blog 2: The Micro:bit Express V1 : Link

Blog 2a: Edublocks Micro:bit Express V1 version(simple motor control)  link

Blog 2b: Edublocks Micro:bit Express V1.5 Remote controlled link

Blog 3: Micro:bit Express 2.0 'adjustable speed' : Link 

Blog 4: The Raspberry Express : Link  

Blog 5 : Micro:bit controlled Lego Ferris Wheel : Link


Blog 6: Raspberry Pi powered Lego Ferris wheel : Link 

Blog 7: 3D printed Lego Christmas Tree / coded light : Link

Blog 8:Lego RC "car" with Raspberry Pi : Link

Blog 9: Blocks controlling blocks: 'Using Minecraft to control Lego motors' : Link


Blog 10: Raspberry Zero Express Link

Blog 11: Stop frame animation with Lego : Link

Blog 12:  Micro:bit controlled Rollercoaster Link

Blog 13: Micro:bit Express EduBlocks simple Link

Blog 14: Micro:bit Express EduBlocks remote controlled Link

Sunday 24 June 2018

Micro:bit Express


Lego + Code blog 2: The Micro:bit Express 


I set myself the challenge of getting an old Lego train set and controlling it with code. Here are a few notes to get you started. 

I bought my son a 1980's train set.


Version 1: getting it to work

Then bought a Micro:bit compatible motor controller from Pimoroni: (Motor controller ) link
buy link
I already had two Micro:bits.
Then I downloaded and modified this code link 
This ended up being my final version of the code:
(code you will need)link 

Load this code onto one of the two Micro:bits using this site: link 
This well then create a hex file which will need to be loaded onto the Micro:bit by dragging and dropping.

I recycled the battery pack from the Cam Jam Edukit 3 buy here link any generic 4.5 battery pack will suffice. 

To connect the motor to the motor driver board you will need to unscrew the Lego metal pins to expose the two wires then connect them to the motor one sockets on the motor controller.

Insert picture


Now to create to create the remote control use this site:


Then create the code below and load it on to your Micro:bit. It should now work. 




Update 1 02/07/2018 Version 2: Remote controlled







Remote code

Edublocks screenshot to come...

Motor controller code


Edublocks screenshot to come...

Remote V1....

Remote V2... plugged into a Pi..



This now reliably works and doesn't require a laptop to power the remote. I have tried the battery pack provided with the Micro:bit and I havent found that it works. I have a suspicion I just may have a dodgey one.


Version 3: Code controlled movement and using power functions motors.

In t

Video of the power functions motor running

Power functions motor with Lego adapter removed and cables soldered

Picture of train with motor controller attached



Video of train running with power functions motor:
link 
Code for remote 3.0

Code for Motor controller 3.0



Over :)












Wednesday 16 May 2018

Lego + Micro:bit + edublocks 1: ''Lights on"



Lego + Code blog 1 : 'Lights on'



You will need:

  • A Micro:bit
  • USB power cable for Micro:bit
  • 3 x crocodile clips
  • 1 neo-pixel 
  • A Lego building of your choice(I borrowed my sons Police building)
  • https://microbit.edublocks.org/
Step 1 Connect the crocodile clips to the Micro:bit.





Step 2 Connect your crocodile clips to the input on the neo pixel.



Step 3 Attach neopixel on your building.


Step 4 Head over to https://microbit.edublocks.org/



Step 5 Create the following code:

Step 6: Download hex and copy and paste it to your Micro:bit

Step 7: After it flashes press the 'a' button to turn on the lights and 'b' to turn off.

Enjoy.

Thursday 10 May 2018

Scratchy:bit IO getting started





Full credit is given in the read me of the zip file. Suffice to say I have used BitIO built by David Whale and a Python to Scratch script created by Laurence Molloy.

It essentially allows you to use the Micro:bit to interact and control Scratch. I have created a simple demo to get you started.


Step 1. You will need to download the tar / zip file from here link

Step 2: Unzip the folder by extracting it.

Step 3: Follow the following file path Scratchy:bit IO-master/src

Step 4: Open Scratch 1.4  from the programming menu and open the 'Scratchy:bit IO led example1.sb' project 

Step 5:  Click on the green flag to run the project.

Step 6: Open Python 3 from the programming menu.

Step 7: From the Scratchy:bit IO-master/src file path open the test_example_MB1.py script.

Step 8:  Press f5 to run the script. 


Step 9: On first run you will have to run through the following steps to set up your Micro:bit


First of all it will display this message:

No micro:bit has previously been detected
Scanning for serial ports
remove device, then press ENTER

Step 1. So unplug the Micro:bit and press enter.

Step 2  Next the following text will display:

scanning...
found xx device(s)
plug in device, then press ENTER 

 Step 3  Now press enter and the following text will display:

scanning...
found 68 device(s)
found 1 new device
selected:/dev/ttyACM0
Do you want this device to be remembered? (Y/N)

Step 4 Press 'y' and enter to confirm and the following text will display:

Your micro:bit has been detected.
Now running your program


Step 10 Finally if you click on the 'a' button you see some events take place. You can also press 'b' and use pins 0,1,2.

See below for button 'a' being pressed



Cya


EduBlocks: BitIO blog 1 "Hello Micro:bit, Hello Minecraft"




This is a very simple introduction to using BitIO with Edublocks on the Raspberry Pi. Firsly lets set out how you need to get set up:






1. Open Minecraft and create a new world, then minimise this for later. Tip, use the tab key to allow your mouse to minimise the Minecraft window.

2. Open Edublocks from the programming menu, this should open in the chromium browser.

3. Plug in your Micro:bit to one of the available USB ports.

4. You will need to download this file and drag a copy of it onto the Micro:bit. This file allows the Micro:bit communicate with your program. Link https://github.com/whaleygeek/bitio/blob/master/bitio.hex

5. Now snap into place the code that you see below. It will trigger a message on the Micro:bit when the 'a' button is pressed and a message in Minecraft when the 'b' is pressed.

Code








6. When you run the program Edu Blocks will show a black screen which will show you the shell output. This tells you what is going on with your program. First of all it will display this message:

No micro:bit has previously been detected
Scanning for serial ports
remove device, then press ENTER

7. So unplug the Micro:bit and press enter.

8. Next the following text will display:

scanning...
found xx device(s)
plug in device, then press ENTER 

9. Now press enter and the following text will display:

scanning...
found 68 device(s)
found 1 new device
selected:/dev/ttyACM0
Do you want this device to be remembered? (Y/N)

10. Press 'y' and enter to confirm and the following text will display:

Your micro:bit has been detected.
Now running your program
11. Now try and pressing the 'a' button and 'b' button. When you press 'b' you should see this...


 Cya