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 :) 








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 :) 









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:

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