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:
Code for remote 3.0
Code for Motor controller 3.0
Over :)
I love the simplicity of the Edublocks code, but I've always thought that the Kitronics Class stuff is a bit to heavy (especially in Primary, where I do all my work). You could use Edublocks for the Rx side too. I can't figure out how to post a pic on here, so I'll DM you on Twitter with it.
ReplyDeleteAlso, it's worth using radio.config(), on both sides, to set the channel away from the default (7?) to avoid clashes in the future.