Thursday, 23 April 2020

REMOTE Controlling a Lego train motor with a micro:bit




REMOTE Controlling a Lego train motor with a micro:bit


What you will need:



  • TWO micro:bit's, TWO USB cable's to load the program onto the micro:bit
  • A Lego train motor
  • A motor controller this is the best one I have found link
  • A battery box that holds 4 x AA batteries
  • 4 x AA batteries
  • A small phillips head screw driver 


What you will learn:

  • How to create the code to get your train motor moving at the push of a button on a remote controller micro:bit
  • How to to operate your remote controlled Lego Train

Lets get started:


Step 1. This blog assumes you have followed blog one controlling a lego train link if not start there first.


Step 2: Now we need to add some code for the train to listen for messages from the remote control. This uses the radio set of blocks(I'm saying its purple coloured blocks). You will need to create add new messages to be able to send them. Like below:


Other than that the code should be pretty clear for the train's micro:bit.


Here is the code for the train micro:bit, this needs all the code from tutorial 1 as well:



Step 3: Next up we need to create the code for the second micro:bit which will act as the remote controller. It is very simple:

Press a for "fwd" to be sent

Press b for "rev" to be sent

press a and b to send stp

Below is the code for the remote:




Now you should be able to control your Lego train like the demo below. 

Demo






Enjoy :) 






If you like this blog check out all the others here

Wednesday, 22 April 2020

micro:bit express: simple motor control




Controlling a Lego train motor with a micro:bit


What you will need:



  • One micro:bit, USB cable to load the program onto the micro:bit
  • A Lego train motor
  • A motor controller this is the best one I have found link
  • A battery box that holds 4 x AA batteries
  • 4 x AA batteries
  • A small phillips head screw driver 


What you will learn:

  • How to assemble the micro:bit to the motor controller and put cables in the correct way using a screw driver 
  • How to create the code to get your train motor moving at the push of a button 
  • How to operate your code controlled train

Lets get started:

Please read this first ....
Parents and young people word of warning. To get this to work you will need to cut off the connector on the train motor so that you can attach it to the motor controller. You can buy new ones from Lego for (at the time of writing 22/04/20) £11.99 + £3.95pp or get them cheaper on ebay. If you are human and under 16 just check with parents I don't want to get you into trouble. 




Lets get cracking...


Step 1. Cut off the plastic connector as seen on the picture above.


Step 2.  As you can see there are four metal wires that run along the cabling. You will need to CAREFULLY strip off some of the plastic coating so that you can see each of the four wires. This is easy enough but ask for adult help if you are not confident doing this. It needs to be enough so that you can either a) wrap the two left wires around each other and the two right wires around each other or solder them(See picture below, I have only ever done this once wrapping is just as good). 







Step 3: Get your battery box something like this link


Step 4: Screw the black wire from the battery into the bottom left screw and the red wire into the right screw(Orange circle on the diagram).  


Step 5: Screw the two wires from the train motor into the screws highlighted with the red circle on the diagram above.


Step 6: Add 4 x AA batteries to your battery box.

Step 7: Using a computer go to the makecode editor link

Step 8: Click New Project


Step 9: You will need to scroll down on the menu and click advanced as we need to add two additional libraries. (This gives you access to key blocks that you will need later)


Step 10: After you have clicked on "Extensions" you will need to select the radio broadcast extension. This may appear like below, but if it doesn't you can search for it and then it will appear. Double click on it to import the blocks to your menu.

Step 11: You need to repeat step 9 this time you need to search for "drivebit" then double click on the icon.
Step 12: Time to code... all the blocks can be found at the relevant coloured part of the menu for example the blue on start is selected from the blue "Basic" part of the menu. The only part that may not make sense is the speed variable. You will need to go to the red "Variables" part of the menu and click "create new variable" and call it Speed. The final code is below. 


Code:

Now you should be able to control your Lego train like the demo below. We can easily extend this later to become remote control but for now this is a great start. :) try that here 

Demo






Enjoy :) 




If you like this blog check out all the others here




Tuesday, 21 April 2020

Using micro:bits to control Lego

Using micro:bits to control Lego

These resources show you how to control the Lego that you may have tucked away in a toy box in your house using the micro:bit.

These resources will have you controlling your Lego Train set by push button and remotely  and much more! comeback for updated tasks over the coming days and weeks...

Project 1: Lights on!


What will you 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 to create the code
  • Tape
  • Scissors

What will you learn:

  • How to attach the crocodile cables to the neo pixel and then attach them to the micro:bit
  • How to create the code to turn the neo-pixel on and set the colour   
  • How to download and put the code onto the micro:bit

Lets get started:

Link to project



Project 2: Controlling a Lego train motor with a micro:bit


What you will need:

  • One micro:bit, USB cable to load the program onto the micro:bit
  • A Lego train motor
  • A motor controller this is the best one I have found link
  • A battery box that holds 4 x AA batteries
  • 4 x AA batteries
  • A small phillips head screw driver 



What you will learn:

  • How to assemble the micro:bit to the motor controller and put cables in the correct way using a screw driver 
  • How to create the code to get your train motor moving at the push of a button 
  • How to operate your code controlled train

Lets get started:

Project 3 REMOTE Controlling a Lego train motor with a micro:bit


What you will need:


  • TWO micro:bit's, TWO USB cable's to load the program onto the micro:bit
  • A Lego train motor
  • A motor controller this is the best one I have found link
  • A battery box that holds 4 x AA batteries
  • 4 x AA batteries
  • A small phillips head screw driver 

What you will learn:

  • How to create the code to get your train motor moving at the push of a button on a remote controller micro:bit
  • How to to operate your remote controlled Lego Train

Lets get started:


If you like this blog check out all the others here

micro:bit with Minecraft projects



Using micro:bits to control Minecraft 

These resources show you how to control the popular block-based building game Minecraft using your micro:bit. This is achieved using bitIO, an I/O library for Python. This allows you to interact directly with your micro:bit in Python 2 or 3 on your computer.
These resources will have you making pixel art, building cities, flying through space, and much more! comeback for updated tasks over the coming days and weeks...

Project 1: Getting Started with BitIO


What will you need:


  • 1 micro:bit and usb cable to connect to the Raspberry Pi
  • 1 x Raspberry Pi plugged in to a power source with a screen and keyboard mouse, ideally connected to the internet so you can download the files needed in the below task.

What will you learn:

  • How to download the files needed to get your micro:bit to talk to Minecraft on the Pi.
  • The steps needed to get the Pi to find the micro:bit so they can communicate through the usb / serial connection.  
  • How to use the micro:bit to control the Minecraft character in a game world by tilting in up, down, left and right.

Lets get started:

Link to project


Project 2: Walking Rainbow blocks


What will you need:


  • 1 micro:bit and usb cable to connect to the Raspberry Pi
  • 1 x Raspberry Pi plugged in to a power source with a screen and keyboard mouse

What will you learn:


  • How to create a list in python to store items e.g. Minecraft block id numbers 
  • How to randomly select one of these block ids from the list
  • Use the micro:bit as a controller for the Minecraft character and after each movement drop the random block selected. 

Lets get started:

Link to project


Project 3: Tilting Rainbow Road


What will you need:


  • 1 micro:bit and usb cable to connect to the Raspberry Pi
  • 1 x Raspberry Pi plugged in to a power source with a screen and keyboard mouse

What will you learn:


  • How to create a list in python to store items e.g. Minecraft block id numbers 
  • How to randomly select one of these block ids from the list
  • Use the micro:bit as a controller for the Minecraft character and after each movement drop the random block selected. 

Lets get started:

Link to project

Project 4: Tilt me around the world


What will you need:


  • 1 micro:bit and usb cable to connect to the Raspberry Pi
  • 1 x Raspberry Pi plugged in to a power source with a screen and keyboard mouse

What will you learn:


  • How to create a list in python to store items e.g. Minecraft block id numbers 
  • How to randomly select one of these block ids from the list
  • Use the micro:bit as a controller for the Minecraft character and after each movement drop the random block selected. 

Lets get started:

Link to project

Project 5: Touching pins simple


What will you need:


  • 1 micro:bit and usb cable to connect to the Raspberry Pi
  • 1 x Raspberry Pi plugged in to a power source with a screen and keyboard mouse

What will you learn:


  • How to create a list in python to store items e.g. Minecraft block id numbers 
  • How to randomly select one of these block ids from the list
  • Use the micro:bit as a controller for the Minecraft character and after each movement drop the random block selected. 

Lets get started:

Link to project


Project 6: Touching pins takes you places


What will you need:


  • 1 micro:bit and usb cable to connect to the Raspberry Pi
  • 1 x Raspberry Pi plugged in to a power source with a screen and keyboard mouse

What will you learn:


  • How to create a list in python to store items e.g. Minecraft block id numbers 
  • How to randomly select one of these block ids from the list
  • Use the micro:bit as a controller for the Minecraft character and after each movement drop the random block selected. 

Lets get started:

Link to project


Project 7: Minecraft CPU temperature graphing 


What will you need:


  • 1 micro:bit and usb cable to connect to the Raspberry Pi
  • 1 x Raspberry Pi plugged in to a power source with a screen and keyboard mouse

What will you learn:


  • How to create a list in python to store items e.g. Minecraft block id numbers 
  • How to randomly select one of these block ids from the list
  • Use the micro:bit as a controller for the Minecraft character and after each movement drop the random block selected. 

Lets get started:

Link to project



Project 8: Pixel Craft

 


What will you need:


  • 1 micro:bit and usb cable to connect to the Raspberry Pi
  • 1 x Raspberry Pi plugged in to a power source with a screen and keyboard mouse

What will you learn:


  • How to create a list in python to store items e.g. Minecraft block id numbers 
  • How to randomly select one of these block ids from the list
  • Use the micro:bit as a controller for the Minecraft character and after each movement drop the random block selected. 

Lets get started:

Link to project


Project 9: micro:bit transport

 


What will you need:


  • 1 micro:bit and usb cable to connect to the Raspberry Pi
  • 1 x Raspberry Pi plugged in to a power source with a screen and keyboard mouse

What will you learn:


  • How to create a list in python to store items e.g. Minecraft block id numbers 
  • How to randomly select one of these block ids from the list
  • Use the micro:bit as a controller for the Minecraft character and after each movement drop the random block selected. 

Lets get started:

Link to project


Project 10: Pixel Craft 2.0

 


What will you need:


  • 1 micro:bit and usb cable to connect to the Raspberry Pi
  • 1 x Raspberry Pi plugged in to a power source with a screen and keyboard mouse

What will you learn:


  • How to create a list in python to store items e.g. Minecraft block id numbers 
  • How to randomly select one of these block ids from the list
  • Use the micro:bit as a controller for the Minecraft character and after each movement drop the random block selected. 

Lets get started:

Link to project



Project 11: Pixel Craft 2.0

 


What will you need:


  • 1 micro:bit and usb cable to connect to the Raspberry Pi
  • 1 x Raspberry Pi plugged in to a power source with a screen and keyboard mouse

What will you learn:


  • How to create a list in python to store items e.g. Minecraft block id numbers 
  • How to randomly select one of these block ids from the list
  • Use the micro:bit as a controller for the Minecraft character and after each movement drop the random block selected. 

Lets get started:

Link to project

Project 12: Scalable housing

 


What will you need:


  • 1 micro:bit and usb cable to connect to the Raspberry Pi
  • 1 x Raspberry Pi plugged in to a power source with a screen and keyboard mouse

What will you learn:


  • How to create a list in python to store items e.g. Minecraft block id numbers 
  • How to randomly select one of these block ids from the list
  • Use the micro:bit as a controller for the Minecraft character and after each movement drop the random block selected. 

Lets get started:

Link to project


Sunday, 17 November 2019

25 Hacks of Christmas 2019


During 2018 I compiled the blog '25 Minecraft hacks of Christmas'. As we approach Christmas 2019 here is my follow up '25 Hacks' of Christmas 2019'.   

1st:   Lego link
2nd: Minecraft link
3rd: Lego link
4th: Minecraft link 
5th: Lego link
6th: Minecraft link
7th: Lego link
8th: Minecraft link

9th:  Lego link
10th: Minecraft link

11th: Lego link 
12th: Minecraft link
13th: Lego link 
14th: Minecraft link

15th: Lego link 
16th: Minecraft link
17th: Lego link 
18th: Minecraft link
19th: Lego link 
20th: Minecraft link

21st: Lego link 
22nd: Minecraft link
23rd: Lego link 
24th: Minecraft link



If you like this blog check out all the others here

Friday, 15 November 2019

Microbit Express 3.5(Controlling multiple trains)



A few weeks ago The Micro:bit Express got an upgrade with a new motor controller from 4tronix Read more here(link). Two weeks down the line I bought another one as I was so impressed with it. Now I have updated the code for the remote control to use the pins to allow independently remote control two separate Lego Trains. You can see a brief but shaky demo of this working below:


Again I have used MakeCode editor link

Below are the hex files for the two trains and the remote control.

Train 2 code link
Train 1 code link 
Remote controller link

You will need:

  •  Three Micro:bits
  • Two Lego Trains 
  • Two 4tronix motor controllers 
  • 2 6 volt battery packs to power the motor controller and the Micro:bits.

Basic info added(more detail to come)

Cya 

Chris

If you like this blog check out all the others here

Thursday, 24 October 2019

Microbit Express 3.0


Over the last year I have been gradually tweaking away at iterations of controlling Lego Trains with code. Here is the most recent attempt from the summer link.

Recently the Kitronic motor controller that I had broke / wore out. I needed a replacement, I initially tried a cheap motor controller from China, which worked but I struggled with dealing with the connections of wires / not being able to get a consistent response from the motors. This is more an indication of my lack of finesse with this sort of thing than the motor controller being inappropriate Les wrote a blog especially as ever the man is a saint(link).

Then two weeks ago I saw Les Pounder was testing a new smaller, cheaper motor controller from 4tronix. So I read up on it here (4tronix blog for about Drivebit link ) and then bought one  (You can buy the Drivebit here). Delivery charge was cheap and it came the next day, which was a bonus.

Here is what Micro:bit Express 3.0 currently looks like:


Here it is in action:
I used Microsoft Makecode, and eventually settled on the code below, which uses the 4tronix extension which can be added on the extensions section. It isn't apparently there but if you type in the following URL in the extensions search bar it will appear: https://github.com/4tronix/DriveBit

Also I found 4tronix super responsive to customer questions through email.

You can download the code here

Here is what the code looks like(please note the motors should be directed fwd and back but I will edit at some point):



If you like this blog check out all the others here