I added my Lego Rollercoaster on Home Assistant[0] a little while back. Nothing fancy, just cut a Power Functions extension wire to put a relay in-between and an ESP board to control it. On one side I had the power pack and the other the motor. Would have loved to switch out the power pack for a constant power source but never got to it.
If you're looking to do some Power Functions (PF) hackery, there are some interesting articles that cover the wiring and working of PF gadgets more in detail[1][2].
As someone who likes lego and programming, I love this answer. But I hate how hard lego has made it.
Yes, with some work you can make your train stop and go. But I don't think there's a good track switching solution that's lego only and automated. There's an aftermarket motor thing that connects with USB. The lego only attempts end up unwieldy and usually lacking in reliability (e.g. https://rebrickable.com/mocs/MOC-11841/1963maniac/train-trac...)
The Duplo trains ship with pretty neat functionality out of the box: lights, whistle, brick reader that activates an action when it sees a certain brick. You can't recreate this with lego with just a single power brick, as it's four things: sensor, light, motor, sound. Lego train can only do two.
It is a shame that Lego Duplo and Lego trains aren't compatible. One of my favourite demos of the sheer awesomeness of Lego is connecting a 2x4 Duplo with a 2x4 Lego block. Any way round. If you've never tried this, do it now :-)
So, while this is uhhh, off track, Legolands and such have some kind of automation, though, presumably, those are bespoke solutions and are not available to regular consumers.
I remember in middle school doing some programming on the Apple 2 in the logo language and using a lego motor to essentially schedule moving the car to the park and then making a motorized lego swing spin around.
I think this is the first time i saw the wonder of programming, sad that its harder to do this now.
Automating my Lego trains was my first introduction to programming, back in the late 1980s using GW-Basic. (When I was about 8 years old.)
I had several stations on a looped track, and controlled the train position by switching on the power to the motor for a certain time.
At first I used a photodiode taped to the CRT monitor (and controlling the motor by lighting up a square in the corner of the screen), later I upgraded to controlling a relay via the parallel port.
On a related note, Lego is cancelling Mindstorms. So if you were dreaming up an advanced train city with Mindstorms as the brain you'd better stock up now.
My child is starting Lego robotics courses and I was confused by the change. As close as I can tell WeDo, PoweredUp/Boost and Spike all operate similarly. The core is a hub consisting of a STM32 microprocessor with a BLE module, power management, options for internal lights and accelerometer, and varying count of IO to servos, motors and sensors. With certain kits some of motors are built in. They all use the same new proprietary connector but the usual folks are making converters for EV3 and PowerFunctions.
While Lego promotes use of their proprietary apps, other bluetooth shims can facilitate connections. I was able to connect to a Boost hub without issue using MIT's Scratch website to execute instructions. As far as I can tell, only Spike can operate untethered by BT with the default firmware.
I've been integrating some BBC Microbit with Geekservo Lego compatible microservos and the overall experience is similar. Lego throughout is easier to integrate but doesn't lend itself to as much customization/experimentation. Using the MIT Scratch IDE is similar to MS Makecode used for Microbit. Compose your blocks, flash your microprocessor. Some things I like about Makecode are GitHub integration and the ability to seamlessly move between blocks, JS and Python.
There isn't enough IO and connectivity for any Mindstorm or new Lego MCU to make an advanced train city. You'd be better off with ESP8266 on ESPNow mesh operating glue-your-own or Geekservo units.
> One of the weaknesses of the City Hub currently is that it requires a tethered Bluetooth device, such as a phone, tablet or computer, in order to function. By flashing the custom Pybricks firmware to the hub, we can overcome this limitation and write programs directly to the device.
Metal tracks had some advantages, but plastic have, too.
The "best" model railroads have electric track at a constant voltage and DCC or other controlled locomotives, so that you're not "driving" the train with the voltage on the track.
you can modify non-metal tracks to work with stained glass foil, and maybe a jumper or two depending on what you’re trying to modify. i used it successfully for cross-tracks (x’s) when they came out originally.
If you know the answer and it's a valid question (i.e. it's not trivial or easily googled already), it's fine to do. The point is less to reputation farm as it is to share knowledge.
There's nothing "fake" about self-answered questions, and Stack Exchange even includes UI specifically for posting an answer at the same time as your question.
In the past, the LEGO trains had a port on the motor to pull power from the tracks so you could run things like lights or small motors for effects.
There was no protection on the direction the power was going, so you could attach it to a motor port of an RCX brick. And therefore you had a programmable brick on the tracks. Side effect was that now the rails are also now powered so every train starts to move...
Pybricks lets you run MicroPython scripts on the hub. Once loaded onto the hub, you can just start the script again by pressing the button. No constant connection required.
You can even add sensors that count the track sleepers so you can get a constant speed no matter the load. Here's a demo with code.
I used to make all kinds of cool projects with lejos (https://lejos.sourceforge.io/) and am now a bit tempted to get the new toys and test out the Python interface. Would be nice if Lego actually invested more time into making a standard programming interface for advanced users.
It looks like LEGO is investing in bringing together the popular Raspberry Pi platform and its toys, and abandonning dedicated apps such as the Robot Inventor (Mindstorms) app.
You can see that in some railway engineering firms.
There have been train protection systems for decades, to stop trains when something is unusual (over-speed, incapacitated driver, running a red light,...), when railways aren't fully automated yet.
You can also encode information next to the tracks, and pick it up with the train !
This kind of system was a prerequisite for high speed trains. Drivers can't read signs at cruise speed, so they are replicated on their dashboard.
A fun but edgy automation would be to encode cards against humanity near the tracks, and to randomly route the train, to generate text.
The motivation of using a special device to untether from the app as being ‘to reduce screen time’ seems tenuous at best. Is using an app to program in a block language to control real trains in a customizable city really ‘screen time’? And even if it is, is it automatically bad?
The quote from the answer suggests a slightly different motivation than reducing screen time.
> I use a setup similar to the above to allow an automated train to run around my son's city without the need to have a screen nearby the whole time.
It’s a criticism that I hear regularly of the requirement to use an app for various of the motorized Lego kits: Having a phone in hand often leads to the result that the kids stop controlling (or even building) the kit and rather start playing on the phone. It’s also a bit an expensive thing to hand to your six year old so they can control their Lego train.
Noticed that the question and answer were authored by the same person. Skimmed their other answers for fun and they are quite the expert. Very impressive ability to identify specific LEGO bricks.
We have the first (?) generation in which each train uses IR (I think) and each controller can deal with 2 trains at once, but are selectable to 4 "channels" - so 8 trains in total. I wanted to buy another train or two a few years ago but they had switched to a bluetooth-only system.
We also have one of the Duplo bluetooth trains and it is pretty nice as well.
There's at least two generations before that "first (?)" generation: 12V powered trains from the 80s and 9V powered trains from the 90s. In both cases, the train tracks were conductive. No batteries needed. A controller was attached to the train tracks. Still my favorite system, as it has no parts that can ever become obsolete (dead batteries, unsupported phone apps, unsupported bluetooth protocols...)
Keep in mind that as noted in this article, the default Powered Up Hub behavior is as a "passthrough pipe" to the host device, so just using a Flipper might be a bit obnoxious.
Older Lego trains use IR for control so if you just want to control motors and lights, you can get one of those and control it with the IR blaster on the Flipper. If you also want the sensors/newer programmable hub, then you need the BLE protocol.
The question was about not using any of the built-in capabilities because they require the use of an app on a connected device which the poster thinks would be a distraction for their kid.
The answer offers some options that will work without a connected device.
Sometime it’s useful to at least visit the linked article before posting what amounts to an ad
keraf|3 years ago
If you're looking to do some Power Functions (PF) hackery, there are some interesting articles that cover the wiring and working of PF gadgets more in detail[1][2].
[0] https://twitter.com/iamkeraf/status/1274433444446113792 [1] https://www.hackster.io/Notthemarsian/take-control-over-lego... [2] https://www.philohome.com/pf/pf.htm
preinheimer|3 years ago
Yes, with some work you can make your train stop and go. But I don't think there's a good track switching solution that's lego only and automated. There's an aftermarket motor thing that connects with USB. The lego only attempts end up unwieldy and usually lacking in reliability (e.g. https://rebrickable.com/mocs/MOC-11841/1963maniac/train-trac...)
The Duplo trains ship with pretty neat functionality out of the box: lights, whistle, brick reader that activates an action when it sees a certain brick. You can't recreate this with lego with just a single power brick, as it's four things: sensor, light, motor, sound. Lego train can only do two.
matheweis|3 years ago
I wish this was the default interface that LEGO provided but I’m thankful for the PyBricks team creating a solution.
f4c39012|3 years ago
mc32|3 years ago
bignevi|3 years ago
esotericimpl|3 years ago
I think this is the first time i saw the wonder of programming, sad that its harder to do this now.
lode|3 years ago
I had several stations on a looped track, and controlled the train position by switching on the power to the motor for a certain time.
At first I used a photodiode taped to the CRT monitor (and controlling the motor by lighting up a square in the corner of the screen), later I upgraded to controlling a relay via the parallel port.
blobbers|3 years ago
rrobukef|3 years ago
We're all engineers now, the box is treasured and still works. Finding a PC with a parallel port has become challenging though.
iancmceachern|3 years ago
preinheimer|3 years ago
https://www.theverge.com/2022/10/28/23428766/lego-discontinu...
ceejayoz|3 years ago
adolph|3 years ago
While Lego promotes use of their proprietary apps, other bluetooth shims can facilitate connections. I was able to connect to a Boost hub without issue using MIT's Scratch website to execute instructions. As far as I can tell, only Spike can operate untethered by BT with the default firmware.
I've been integrating some BBC Microbit with Geekservo Lego compatible microservos and the overall experience is similar. Lego throughout is easier to integrate but doesn't lend itself to as much customization/experimentation. Using the MIT Scratch IDE is similar to MS Makecode used for Microbit. Compose your blocks, flash your microprocessor. Some things I like about Makecode are GitHub integration and the ability to seamlessly move between blocks, JS and Python.
There isn't enough IO and connectivity for any Mindstorm or new Lego MCU to make an advanced train city. You'd be better off with ESP8266 on ESPNow mesh operating glue-your-own or Geekservo units.
sschueller|3 years ago
als0|3 years ago
This is why I come to Hacker News
post_break|3 years ago
Or try to buy old stock on ebay etc.
bombcar|3 years ago
The "best" model railroads have electric track at a constant voltage and DCC or other controlled locomotives, so that you're not "driving" the train with the voltage on the track.
EamonnMR|3 years ago
Now what I really wish they'd bring back is the Space Monorail...
Teknoman117|3 years ago
It's been nearly 20 years since I last pulled out my LEGO trains... That and the Rokenbok.
jerrysievert|3 years ago
leetrout|3 years ago
I havent had much luck in the overflow communities so I am unsure how common this is. Is it what most people do?
OwlsParlay|3 years ago
josephcsible|3 years ago
unwind|3 years ago
At least on Stack Overflow it's a common way of sharing knowledge.
Source: been using SO quite intensely, have many reps.
megablast|3 years ago
Teknoman117|3 years ago
There was no protection on the direction the power was going, so you could attach it to a motor port of an RCX brick. And therefore you had a programmable brick on the tracks. Side effect was that now the rails are also now powered so every train starts to move...
Pybricks|3 years ago
Pybricks lets you run MicroPython scripts on the hub. Once loaded onto the hub, you can just start the script again by pressing the button. No constant connection required.
You can even add sensors that count the track sleepers so you can get a constant speed no matter the load. Here's a demo with code.
https://pybricks.com/projects/sets/city/60198-cargo-train/sp...
You can also automate the switches so you can get pretty creative with your layouts:
https://www.facebook.com/Pybricks/videos/989683888156075
With enough supporters, we may eventually even add a block-coding language as an alternative to MicroPython.
primitivesuave|3 years ago
dolmen|3 years ago
https://www.raspberrypi.com/news/raspberry-pi-build-hat-lego...
Teknoman117|3 years ago
hinata08|3 years ago
You can see that in some railway engineering firms.
There have been train protection systems for decades, to stop trains when something is unusual (over-speed, incapacitated driver, running a red light,...), when railways aren't fully automated yet.
You can also encode information next to the tracks, and pick it up with the train ! This kind of system was a prerequisite for high speed trains. Drivers can't read signs at cruise speed, so they are replicated on their dashboard. A fun but edgy automation would be to encode cards against humanity near the tracks, and to randomly route the train, to generate text.
jameshart|3 years ago
Xylakant|3 years ago
> I use a setup similar to the above to allow an automated train to run around my son's city without the need to have a screen nearby the whole time.
It’s a criticism that I hear regularly of the requirement to use an app for various of the motorized Lego kits: Having a phone in hand often leads to the result that the kids stop controlling (or even building) the kit and rather start playing on the phone. It’s also a bit an expensive thing to hand to your six year old so they can control their Lego train.
marpstar|3 years ago
Kon-Peki|3 years ago
We have the first (?) generation in which each train uses IR (I think) and each controller can deal with 2 trains at once, but are selectable to 4 "channels" - so 8 trains in total. I wanted to buy another train or two a few years ago but they had switched to a bluetooth-only system.
We also have one of the Duplo bluetooth trains and it is pretty nice as well.
TonyTrapp|3 years ago
greesil|3 years ago
jpace121|3 years ago
extasia|3 years ago
preinheimer|3 years ago
Really interesting ways to move balls around.
cactusplant7374|3 years ago
bri3d|3 years ago
https://lego.github.io/lego-ble-wireless-protocol-docs/
So it shouldn't be too hard to add one.
Keep in mind that as noted in this article, the default Powered Up Hub behavior is as a "passthrough pipe" to the host device, so just using a Flipper might be a bit obnoxious.
lini|3 years ago
blobbers|3 years ago
bcraven|3 years ago
alexheikel|3 years ago
fnordpiglet|3 years ago
[deleted]
BryanBeshore|3 years ago
[deleted]
pilif|3 years ago
The answer offers some options that will work without a connected device.
Sometime it’s useful to at least visit the linked article before posting what amounts to an ad