hack news

Can Lego City Powered Up trains be computerized?

I have been exploring this not too long within the past, and I compulsory to part my experiences within the hopes that they’re precious to others. There are a pair of ideas this would also additionally be carried out. Some are conceivable out of the box, and others require extra hardware or Third-social gathering software.

Conventional Package Contents

Here’s the electronics we typically catch out of the box with a Powered Up insist set:

  1. Powered Up City hub (28738). This contains two I/O ports (outdated skool for a motor and possibly lights). The City hub doesn’t embody an accelerometer, compass, or GPS, so there might be restricted feedback equipped. It does embody a programmable RGB LED and a button.

City Hub

  1. Put collectively Motor (28740). This motor is one of handiest two Powered Up motors that conclude not embody rotation and distance monitoring, so there might be rarely the kind of thing as a easy formulation to clutch how a ways the insist has traveled, however we’re ready to alter its relative traipse.

Put collectively motor

  1. Lights (22168) would possibly even be integrated as headlights for the insist.

Lights

Programming using Powered Up App

The default abilities within the Powered Up app provides a controller for the insist, however we would possibly also additionally automate the insist using a Scratch-admire programming environment. This environment is extremely efficient, however the hardware at our disposal is terribly restricted as a robotics platform. In explicit, the integrated hardware has no precious sensors, which makes the environment unobservable.

If we originate the insist from a identified advise, we are able to plug it at a series approximate traipse for a explicit amount of time, leaving it at a brand fresh approximate advise. Sadly, these locations will exchange a exiguous bit over time, as we own no formulation of sensing precisely a ways now we own traveled. This would also be ravishing while you true need the insist to switch for a while then conclude for a while, however while you should conclude at stations, things catch trickier.

One resolution is to induce the insist to conclude at a identified advise on a fresh basis, a lot like a siding. We can intentionally stall against the buffer on the siding to reset to a identified scheme.

Adding Sensors

If we’re inviting to be able to add some additional hardware, things can catch basic extra superior. One option is to be able to add a color sensor to the bottom on the insist:

Step 1

We can connect the sensor to the port not being outdated skool by the motor.

Step 2

Step 3

With this in arena, we are able to modify our be conscious by adding plates or tiles of utterly different colors to repeat advise on the be conscious or explicit actions to preserve. On this vogue, we are able to own the insist reliably conclude at stations or preserve utterly different actions. Here’s an example program that lets within the insist to wait when it sees crimson under the color sensor:

Program screenshot

Here’s equal in belief to the DUPLO trains by formulation of input, however we are able to program the colors to exchange behaviors in any formulation we would possibly possibly admire.

We would possibly also identify to be able to add a clear sensor, a lot like a distance sensor or a tilt sensor. Alternatively, we would possibly also exchange the City hub with the next hub and add extra than one sensors, however this would seemingly require redesigning the insist and would add predominant charge.

Standalone Operation

In fact one of many weaknesses of the City Hub currently is that it requires a tethered Bluetooth tool, a lot like a mobile phone, tablet or computer, in uncover to characteristic. By flashing the custom Pybricks firmware to the hub, we are able to beat this limitation and write programs straight to the tool. Here’s extraordinarily precious for public shows or utterly different use cases where Bluetooth connections would possibly also become problematic.

Here is an example Pybricks program that will allow a insist to plug for 10 seconds and then conclude for 35 using the RGB LED on the hub to repeat its space:

"""Simple automated train that runs for 10 seconds then pauses for 35Light transitions from red to orange to yellow as timer counts down"""from pybricks.hubs import CityHubfrom pybricks.pupdevices import DCMotor, Lightfrom pybricks.parameters import Button, Color, Direction, Port, Stopfrom pybricks.robotics import DriveBasefrom pybricks.tools import wait, StopWatchhub=CityHub()motor=DCMotor(Port.A)while True:    hub.light.on(Color.GREEN)    motor.dc(60)    wait(10000)    motor.dc(0)    hub.light.on(Color.RED)    wait(15000)    hub.light.on(Color.ORANGE)    wait(15000)    hub.light.on(Color.YELLOW)    wait(5000)

I use a setup equal to the above to permit an computerized insist to plug around my son’s metropolis without the desire need to own a screen inner attain your total time.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button