Pi Zero Express aka Raspi Express 2.5(now with added bluedot control)
Over the last 6 months I've iterated between Pi and Micro:bit versions of the microboard controlled Lego train. Micro:bit version will always be visible given the size of the motor controller. Whereas with the Edu Kit 3 motor board with a Raspberry Pi Zero W you have the potential for hiding the brains in the actual train somewhere. In every single version up until last week the micro controller was visible. That changed last week end. Up until recently I have tried to bolt a full sized Pi onto the train motor, in the summer ModMyPi kindly gave me a Pi zero W with GPIO actually attached (you can buy
here ).
I received it in August, it took until February to actually dig in and get into miniaturisation. So here is my account of how to get a Lego Train to move without it looking like a horrific mess.
Over the last year we have accumulated three cheap find's on eBay. My main aim was to make it remote control so if my son / daughter felt like it they could do it with out loads of fussing about. To this point that hasn't been achievable given everything hanging out / everything being very brittle.
The other major problem that I have had to contend with is that I've tried to attach the motor and everything else to the train, which in hindsight was daft. Because if the kids wanted to swap out the train that would mean pulling out the cables and faff. So I decided to bury everything into the train carriage. If the kids want to use the HP express or either of the other two available then they can simply attach the train they want and the carriage hides all the gubbins, there are no exposed cables to worry about.
Below you can see them all....
The set up
The height of the train carriage had to be raised to fit everything in.
Also I have added a few of the flat plates to minimise how secure the roof is so it is easier to remove and less likely to fall apart each time. (at the bottom is the Pi Zero W which has wireless built in, there is also a battery holder for 4 x AA batteries, which powers the motor.)
On top of that is a cheap phone power bank which powers the Pi Zero W. Then the roof fits on top.
I even managed to nick one character at the back.
I use white plastic strip to keep the battery from making contact with the battery box when the train is not being used, it stops the batteries from draining, plus I don't have to physically pull out the batteries.
The first two or three iterations required bolting down the pi(3b+), battery to power the pi and the 4 x AA batteries to power the motor. As you can see from the previous blog it was some what clunky(
link). The key to getting this to work as a remote controlled train has been
GUIZero and
RealVNC. GuiZero for the interface and RealVNC for the ability to connect to the Pi remotely from my Iphone(insert your own phone / tablet). You can read the respective links for how to set up RealVNC, GUIzero comes pre-installed with Raspian OS.
The code
The code for this hasn't really changed a great deal since version 1.0, I have added a slider to adjust the speed. Currenly this version isn't on github, but I will be refining it soon and I will come back and update the link then.
Link
Real VNC
Is free and makes it really easy to enable remotely logging into your pi. You can find out more here
link.
The future iterations...
- Using light sensor to stop at the station
- Lights????
- Improved GUI
Bluedot Control update.....
I have recently dug out the Pi Touch screen and wanted to use this to be able to control the Pi Express. The best idea I could think of was using Bluedot by Martin O'Hanlon link .
1. I followed these instructions to install the app for my Pi touch screen and the necessary libraries for the Pi Express Pi Zero W.
2. Then I wrote the following code on the Pi Zero W which controls the train link.
3. Run the python code on the Pi controlling the train
4. On the second Pi which will be used as the remote controller run the bluedot app.
5. Then you should be able to swipe on the blue dot t control the train.
swipe up to increase forward speed
swipe down to increase forward speed
swipe left or right to stop the engine
n.b. when the speed hits 1 it stops the motor and resets speed to 0.
Over