In this project, we will show you how to control the LEGO® Technic 4x4 Mercedes-Benz Zetros Trial Truck (42129) with the Powered Up (Train) Remote.

This is a fun way to drive the truck around without having to look at your phone screen all time time. You can also use this setup to create your own remote-controlled cars with Pybricks.

You’ll also use the remote to lock and unlock the differentials.

Driving the LEGO® Technic 4x4 Mercedes-Benz Zetros Trial Truck (42129) with the Powered Up Train Remote.
Driving the LEGO® Technic 4x4 Mercedes-Benz Zetros Trial Truck (42129) with the Powered Up Train Remote.

Requirements

To follow this project, you will need the following:

Understanding the code

This Technic truck drive motors on Ports A and B and has one steering motor on Port D. It also has a DC Motor on Port C that controls the locking mechanism for the differentials. The program starts by setting up these motors accordingly.

This program lets you drive the LEGO® Technic 4x4 Mercedes-Benz Zetros Trial Truck (42129)
  with the Powered Up Remote. First, you set up the car, and then you can
  control the steering and power level using the buttons on the remote.
This program lets you drive the LEGO® Technic 4x4 Mercedes-Benz Zetros Trial Truck (42129) with the Powered Up Remote. First, you set up the car, and then you can control the steering and power level using the buttons on the remote.

Driving and steering

The car setup block takes care of centering the steering motor and makes it easy to drive later on. Finally, we add the setup block for the Powered Up remote.

The main program is quite simple. There is an infinite loop that sets the steering and drive power based on the buttons you press. It uses the ternary block to set the steering to:

  • 100% when you press the left + button,
  • otherwise to -100% when you press the left - button,
  • otherwise to 0%

Similarly, it sets the drive power to:

  • 100% when you press the right + button,
  • otherwise to -100% when you press the right - button,
  • otherwise to 0%

You could achieve the same effect using conventional if-else blocks. The ternary block makes the code more compact and easier to read.

Close up of the steering mechanism.
Close up of the steering mechanism.

Locking and unlocking the differentials

The center button of the remote is used to lock and unlock the differentials. When the differentials are locked, the truck will have better traction on rough terrain. When they are unlocked, the truck can make tighter turns.

The locking mechanism is controlled by a DC Motor on Port C. Running it clockwise unlocks the differentials, and running it counterclockwise locks them.

Since this motor does not have position sensors, we use a variable to store the current state of the differentials. The comments throughout the program explain how this works.

Central differential lock mechanism.
Central differential lock mechanism.
Rear differential lock mechanism.
Rear differential lock mechanism.

Running the Pybricks program

This project uses Pybricks on your LEGO hub. Pybricks makes your creations come alive and helps you unlock the full potential of your LEGO Technic, City, MINDSTORMS, BOOST, or Spike sets.

If you haven’t already, install Pybricks on your hub as shown below, or check out our getting started guide for more details. You can go back to the LEGO firmware and apps at any time.

Install the Pybricks firmware.
Tools
Install

Now import the program you downloaded earlier, as shown below. Click to connect your hub and ▶ to start!

Import a Pybricks Code project.
files
import
open
connect
run

You can run imported block programs even if you’re not signed up. This is a great way to try out Pybricks and see how it works.

The truck in action

When you’re ready, you can drive the truck as shown below. Make sure to turn on the remote when you start the truck program, so that the hub can find it.

Running it as a Python program

You can also run this project as a Python (MicroPython) program. The following code was generated from the block program above. To run it, create a new empty Python program in Pybricks and copy the code into it.

from pybricks.parameters import Button, Color, Direction, Port
from pybricks.pupdevices import DCMotor, Motor, Remote
from pybricks.robotics import Car
from pybricks.tools import wait

# Set up all devices.
steering = Motor(Port.D, Direction.CLOCKWISE)
drive1 = Motor(Port.B, Direction.CLOCKWISE)
drive2 = Motor(Port.A, Direction.CLOCKWISE)
car = Car(steering, [drive1, drive2])
lock = DCMotor(Port.C, Direction.CLOCKWISE)
remote = Remote(timeout=None)

# Initialize variables.
locked = 0


# The main program starts here.
# Initialize the lock in the locked state.
lock.dc(-60)
wait(600)
lock.stop()
locked = True
remote.light.on(Color.BLUE)
# Now we can run the main loop.
while True:
    # Control steering using the left - and + buttons.
    car.steer(100 if Button.LEFT_PLUS in remote.buttons.pressed() else (-100 if Button.LEFT_MINUS in remote.buttons.pressed() else 0))
    # Control drive power using the right - and + buttons.
    car.drive_power(100 if Button.RIGHT_PLUS in remote.buttons.pressed() else (-100 if Button.RIGHT_MINUS in remote.buttons.pressed() else 0))
    # Handle the lock using the center button.
    if Button.CENTER in remote.buttons.pressed():
        # If pressed, first stop driving for safety.
        # Set light to red to indicate that the lock is being moved.
        remote.light.on(Color.RED)
        car.drive_power(0)
        wait(500)
        # If currently locked, rotate at +60% power to unlock it.
        # Otherwise, rotate it at -60% to lock it.
        lock.dc(60 if locked else -60)
        wait(600)
        lock.stop()
        # Now we have to update the lock state.
        # If locked was True we will make it False, because it is no longer locked.
        # If locked was False we will make it True, because it is now locked.
        # So we always have to set it to the opposite value. The not block does that.
        locked = not locked
        # Set the light color depending on the new state, so we can easily
        # see if it is locked (blue) or not (green).
        remote.light.on(Color.BLUE if locked else Color.GREEN)
        # Make sure the button is released before we proceed to drive.
        while Button.CENTER in remote.buttons.pressed():
            wait(1)
    wait(50)
Python representation of the block program.

More about the Zetros Trial Truck

The photographs in this article were contributed by Jim van Gulik. Used with permission. For more great pictures of this set and details of its intricate mechanics, check out Jim’s review over at Eurobricks.