Externally powering the Technic hub

Posted by ,

Last year I wrote about running Pybricks on Powered Up hubs, in particular the 4-port grey Technic hub which is a powerful device but essentially useless without it.

In this article I show the method I use to modify them so that they can be powered from an external 5v USB power supply. It is not suitable for all applications, especially if your model moves, but for Great Ball Contraptions (GBCs) and other static models it negates the need to use batteries, which is particularly useful if you're planning to run them for a whole weekend at a public show.

I will also explain how to install Pybricks on the hub and use a simple program that runs motors at a constant speed, which is often all that's needed for the majority of GBC modules.

Please be warned, this article contains explicit photographs of LEGO pieces being mutilated.


What you will need

Tools

  • Soldering iron and solder
  • Small flat head screwdriver
  • Electric drill, 4mm and 10mm bits, small block of wood
  • Sharpie and ruler
  • Round file
  • Glue, if you're using the clip-on battery cover version of the hub

Parts

Technic Powered Up hub, either the older version with clip-on battery cover, or the newer one with screw-on cover. As they are of limited use without installing Pybricks they are dirt cheap on BrickLink, around $15/£12.

5.5mm jack socket. I use these from Amazon.co.uk which are already wired up. There's 6 in the pack, along with 6 plugs, which we won't be using.

5v USB to 9v adapter, such as this one from Amazon.co.uk. This enables the hub to be powered using a USB phone charger, of which you probably have plenty.

Finally, if you're using the clip-on battery cover version you'll also need four 1x1 bricks, two 1x1 plates and two 1x1 tiles in any colour.


Modifying the hub

I have used the older style clip-on lid variety of hub to create this guide. I don't have any of the newer types to hand to modify, but the process should be much the same. I'll point out where it's likely to differ.

Please note that you perform the procedure detailed below at your own risk, and you should only proceed if you are competent at drilling and soldering.

1. Remove battery holder

Remove the battery cover, take out the battery holder and discard. It won't be needed any more.

2. Mark a hole

Mark a hole with the Sharpie, 10mm from the top and 18mm from the right, as viewed here.

3. Drill

Drill where you've marked, first with the 4mm drill bit, then the 10mm. You will find you'll get a cleaner hole if the 10mm bit is rotating before introduced to the 4mm pilot hole, and it will help if you hold a piece of wood inside the hub to drill into.

4. Splay the connectors

Use the screwdriver to bend the power connectors upwards so that they are roughly horizontal. This will make them easier to solder onto.

5. Insert the socket

Push the socket into the hole. You may find that you need to file the hole out a bit to get the socket to fit because its external diameter is fractionally larger than 10mm. Replace the washer and nut and screw finger-tight.

6. Solder the wires

A soldering tutorial is beyond the scope of this guide but suffice to say that the best way to do it is to melt a blob of solder onto each terminal, then introduce the wire to it while heating it with the iron. The ends of the wires I used are already soldered which makes things much easier.

The black negative wire should be connected to the left-hand terminal and the red positive one to the right.

Be sure to keep the hot iron away from the plastic case!

7. Glue supports

This step can be skipped if you're using the screw-on lid variety of the hub.

If you reattach the clip-on lid you'll find that the end above the connector is unsupported so to remedy that glue two stacks of two 1x1 bricks, a 1x1 plate and a 1x1 tile to the end, making sure the one in the corner is not on top of the light grey clip.

8. Replace lid

Job done!

The approximate cost of doing this is £12 for the hub, £1.50 for the socket and £8 for the USB to 9v adapter, a total of £21.50 (c.$25), which compares favourably with the cost of second-hand 9v train controllers nowadays that are usually used for powering GBCs and other models. The hub is also much smaller and lighter to transport!

Non-destructive method

If mutilating your hub is too much for you, an alternative is to 3D print a new battery insert and modify it to allow a tethered cable to enter through one of the holes in the side of the hub.


Installing Pybricks

Installing the Pybricks firmware on the hub is a very straightforward and quick process and, should the need arise, is reversible.

Navigate to the Pybricks development environment (IDE) at code.pybricks.com, click on the gear wheel on the left, then on Install Pybricks Firmware.

Select the Technic hub, click Next, accept the licence, click Next.

Give your hub a name and click Next.

Power up the hub using a USB adapter then follow the instructions given.

That's it: over in a couple of minutes.


Sample code

Once that's done you can use the PyBricks IDE to write Python code, connect to the hub via Bluetooth, then download and run your script.

Once downloaded it will be saved in the hub's memory and remain there ready to be executed by pressing the green button on the hub the next time you power it up. There's no need for phones or other devices to be tethered to it, which gives PyBricks a major advantage over LEGO's Powered Up solution.

If all you want to do is use a Powered Up (PU) motor in your model and run it at a constant speed the sample program below shows you how.

For added flexibility, it will look for motors in all four ports and if found run them at different speeds, which makes it a general purpose program suitable for the majority of GBC applications: simply plug your motor into each port in turn (remembering to stop and restart the program while doing so) and see which one provides the required speed.

If you have two modules with PU motors next to each other that run at different speeds you can use one hub running this code to power them both, although the length of the motor cables can be a restriction.

#import libraries 
from pybricks.pupdevices import Motor
from pybricks.parameters import Color, Port
from pybricks.hubs import TechnicHub
from pybricks.tools import wait

# Declare the hub and flash the light red
hub = TechnicHub()
hub.light.blink(Color.RED,(250,250))

try:
    # Declare a motor in port A
    motor = Motor(Port.A)
    # The next statements will only be executed if a motor is present
    hub.light.on(Color.GREEN)
    # Set the speed, in degrees per second, and run the motor
    speed = 90
    motor.run(speed)
    # Print a message on the console
    # (visible if the hub is connected to a device by Bluetooth)
    print("Motor detected in port A, running at", speed, "degrees per second")  
except:
    # No motor found, do nothing
    pass        

# Repeat for the other three ports, doubling the speed each time.

try:
    motor = Motor(Port.B)
    hub.light.on(Color.GREEN)
    speed = 180
    motor.run(speed)
    print("Motor detected in port B, running at", speed, "degrees per second") 
except:
    pass

try:
    motor = Motor(Port.C)
    hub.light.on(Color.GREEN)
    speed = 360
    motor.run(speed)
    print("Motor detected in port C, running at", speed, "degrees per second") 
except:
    pass      

try:
    motor = Motor(Port.D)
    hub.light.on(Color.GREEN)
    speed = 720
    motor.run(speed)
    print("Motor detected in port D, running at", speed, "degrees per second") 
except:
    pass          

# Loop indefinitely
while True:
    wait(10)

To get the program onto your hub, cut and paste it into the PyBricks editor, click on the Bluetooth icon at the top to connect to your hub, then on the > button next to it.

If you need different speeds, or motors running at the same speed, or in reverse, you can of course modify the code to suit. The maximum speed of the two motors commonly found in Technic sets, as reported by Pybricks, is as follows:

  • Small motor: 1470 degrees per second = 245rpm
  • Large motor: 1525 degrees per second = 254rpm

I have a slightly more complex version of this code on all my hubs, so it doesn't matter which one I use for which module: every module will work with the code on every hub, which makes it easy when it comes to setting things up at a show.

I have merely scratched the surface of what's possible with the hub when coded with Pybricks. The PU motors have rotation sensors inside, and the hub can be controlled with the bluetooth remote control unit, so the sky's the limit even before adding external light, touch and other sensors. I therefore encourage you to read the extensive Pybricks documentation to find out more.


With external power and a relatively straightforward piece of Python code the Technic hub and Powered Up peripherals finally become useful. I hope this article has shown that for GBCs and other static models it's now practical to transition away from Power Functions motors powered by bulky and scarce 9v train controllers to more readily available modern components.

33 comments on this article

Gravatar
By in United States,

Aaahhhh! I wasn't ready. I wasn't ready. The horror, the horror! Po' lil' bricks.

Nice article. Grateful for the know-how.

Gravatar
By in Netherlands,

Thank you for the disclaimer. I will avoid the article's graphic imagery :)

Gravatar
By in Germany,

Fascinating article, thank you very much for the detailed description.
I found it funny that you made it sound as if soldering was more complicated than programming (which to some it might well be).
Since my other hobby is model making, particularly model railroading, soldering is something I have done since I was a kid.
Programming otoh is something that I do at work using VBA, and I have learned the basics of Perl, Java and other older programming languages when I studied (not to mention my first steps in programming on the C64/C128 using Commodore Basic as a kid), but Python and other more modern programming languages still kind of elude me. Especially since I haven't really had a practical use for them yet.
Nevertheless I find these articles highly interesting and perhaps some day I might try out something along those lines.

Gravatar
By in Australia,

Interesting article. As part of my Year 10 IST curriculum last year we did a robotics unit with Mindstorms where, in pairs, we had to build a functional robot that could traverse an obstacle course with mainly the colour sensors, and which also had a working claw that could pick up a rubber duck in the centre of the course to bring it all the way to the end. (Naturally me and my partner won the challenge; I was the only person familiar with LEGO in my entire class)

Gravatar
By in United Kingdom,

Nice tutorial. I'll save this for later reference, as I was planning on doing something like this myself.
The newer screw-on hubs & battery box can have the lid secured without the supports inside. Take out the battery compartment and there is a handy slot in the side of the box through which wires can be passed, negating the need for drilling a hole.

There are a couple of things to note with the power. Lego motors are 9V, so using a USB-A 5V power supply will slow them down. With more than 2 motors it may be possible (at high load) to exceed the 2.1A load limit on such a power supply.

Gravatar
By in United Kingdom,

Very useful article. Of course soldering should already be a prerequisite for any Lego fan who wants to light a model without paying the laughable light kit prices!

I think my 1st ever attempt at soldering was on a 101-3 Battery Box which contained a couple of thin wires that were very prone to snapping. I know there was more melted plastic that solder!

Gravatar
By in Netherlands,

It's nice that this is available, but not something I'm going to try out myself.

@Huw: The code block doesn't work well in dark mode, it has a white background with light gray letters on it making them almost invisible

Gravatar
By in United Kingdom,

@janl said:
"It's nice that this is available, but not something I'm going to try out myself.

@Huw : The code block doesn't work well in dark mode, it has a white background with light gray letters on it making them almost invisible"


Ok it's the first time I've used html [pre] I'll sort it later.

Gravatar
By in Italy,

I did that (a lot less destructively) on my RCXes. But they still tend to lose the programming from time to time.

Gravatar
By in United Kingdom,

LEGO alchemy.

Gravatar
By in United States,

@DoonsterBuildsLego said:
"Nice tutorial. I'll save this for later reference, as I was planning on doing something like this myself.
The newer screw-on hubs & battery box can have the lid secured without the supports inside. Take out the battery compartment and there is a handy slot in the side of the box through which wires can be passed, negating the need for drilling a hole.

There are a couple of things to note with the power. Lego motors are 9V, so using a USB-A 5V power supply will slow them down. With more than 2 motors it may be possible (at high load) to exceed the 2.1A load limit on such a power supply."


I was wondering abut the same concerns related to power consumption. If possible I'd recommend a dedicated 9V adapter or power supply directly from mains voltage with a high current rating. It might be a bit expensive, but reduces the chance of the Control+ unit browning out.

Gravatar
By in United Kingdom,

@Agent00Z said:
" @DoonsterBuildsLego said:
"Nice tutorial. I'll save this for later reference, as I was planning on doing something like this myself.
The newer screw-on hubs & battery box can have the lid secured without the supports inside. Take out the battery compartment and there is a handy slot in the side of the box through which wires can be passed, negating the need for drilling a hole.

There are a couple of things to note with the power. Lego motors are 9V, so using a USB-A 5V power supply will slow them down. With more than 2 motors it may be possible (at high load) to exceed the 2.1A load limit on such a power supply."


I was wondering abut the same concerns related to power consumption. If possible I'd recommend a dedicated 9V adapter or power supply directly from mains voltage with a high current rating. It might be a bit expensive, but reduces the chance of the Control+ unit browning out. "


Reading the article or checking the linked cable indicates it's a step up 5V -> 9V cable.

I use a dedicated 9V mains adapter for doing a similar thing to Huw for my Mindsorms NXTs. The NXTs have a cut-out for the rechargeable battery cable so just need to snap off the tab on the normal battery cover and put the female cable socket in the hole.

Gravatar
By in United States,

I've been saying for years that Lego should have a USB c solution.

Gravatar
By in Australia,

I definitely think a 3D printed insert is preferable, but this is still a super neat mod and seems like a great option for GBCs.

Gravatar
By in United States,

Wow, you have got to be really dedicated!

Gravatar
By in United States,

Regarding possible plastic melting - also don’t hold a soldering iron on the battery terminals too long!

Gravatar
By in United States,

Perhaps there's hope for my collection of decorative but useless early Lego hubs, like the Spybot controllers!

Gravatar
By in United Kingdom,

@Agent00Z said:
" @DoonsterBuildsLego said:
"Nice tutorial. I'll save this for later reference, as I was planning on doing something like this myself.
The newer screw-on hubs & battery box can have the lid secured without the supports inside. Take out the battery compartment and there is a handy slot in the side of the box through which wires can be passed, negating the need for drilling a hole.

There are a couple of things to note with the power. Lego motors are 9V, so using a USB-A 5V power supply will slow them down. With more than 2 motors it may be possible (at high load) to exceed the 2.1A load limit on such a power supply."


I was wondering abut the same concerns related to power consumption. If possible I'd recommend a dedicated 9V adapter or power supply directly from mains voltage with a high current rating. It might be a bit expensive, but reduces the chance of the Control+ unit browning out. "


Yes a dedicated 9v supply would of course be better but I've been using these adapters for 6 months or so and they will quite happily power a hub with two motors connected all weekend. I have not tried it with more: as I said in the article, the length of the motor's cable usually restricts how many can practiically be connected.

The Spike hubs can be trickle charged via USB, so using these cables means everything I use on my GBCs can be plugged into multi-port USB chargers which simplifies things and reduces the number of mains sockets needed.

Gravatar
By in Netherlands,

I like your idea, have been thinkering about doing something simular but never got to it. I have bought this USB power box from pv productions which works great and I don't need to damage my precious lego haha. I think pv is a cleaner solution. Anyhow great article. Keep up the work! Here is the usb power box I got for the lego pu hub and power funcations battery box, https://pv-productions.com/product/usb-power-box/?attribute_power-connector=PU+Technic+Hub

Gravatar
By in United Kingdom,

@JoachimSW said:
"I like your idea, have been thinkering about doing something simular but never got to it. I have bought this USB power box from pv productions which works great and I don't need to damage my precious lego haha. I think pv is a cleaner solution. Anyhow great article. Keep up the work! Here is the usb power box I got for the lego pu hub and power funcations battery box, https://pv-productions.com/product/usb-power-box/?attribute_power-connector=PU+Technic+Hub "

Nice, but 5x the price and double that of the hub itself so not really viable if you need loads.

Gravatar
By in United Kingdom,

I really enjoyed the article, and responses. Always good to hear about about different sides to this hobby. Most of it however was beyond me... I'm a bit like Chewie being told by Han "No no this one goes here, that one goes there".

Gravatar
By in United Kingdom,

You can do something similar with an old laptop power supply and a cheap buck converter (about £2-3) to drop the voltage down from 19V to 9V.

Gravatar
By in New Zealand,

Great article.

I use an external power supply connected to one of my EV3 bricks. I use alligator clips connected to the battery terminals and keep the battery cover off rather than this more permanent option.

Gravatar
By in United Kingdom,

@FlagsNZ said:
"Great article.

I use an external power supply connected to one of my EV3 bricks. I use alligator clips connected to the battery terminals and keep the battery cover off rather than this more permanent option. "


Right -- it wouldn't be sensible to mutilate a much more expensive hub, after all.

Gravatar
By in United States,

The funny thing to me is how much this article plugs into my childhood. My father was an electrical engineer who decided to teach electronics/science/industrial arts in junior high school.

So, I grew up playing with soldering guns and irons. He also took me to the Pascal programming classes he was taking to complete his Masters. I spent a lot of time in those days making simple computer games with Basic. Sad part is that I mostly stopped all of that when I entered my teen Dark Ages. I'm going to tackle this Huw mutilation project in tribute to my Dad who always loved this kind of stuff.

Here's to all the AFFOLs (Adult Father Fans of Lego) out there! Happy Father's Day!!

Gravatar
By in United States,

I don’t think I have a real need to do this. But I’m definitely doing it now. Challenge accepted!

Gravatar
By in United Kingdom,

Great tutorial! Thanks Huw :-)

I wonder if there's a pure USB solution, rather than converting to a jack, then converting again to USB?

Gravatar
By in United Kingdom,

@omnium said:
"Great tutorial! Thanks Huw :-)

I wonder if there's a pure USB solution, rather than converting to a jack, then converting again to USB?"


Probably not given the need for 9v rather than 5.

Gravatar
By in United States,

I don't understand/follow why you need to do all the power alterations to install pybricks? Is it just to not have to use batteries anymore?

Gravatar
By in United Kingdom,

@asherkobin said:
"I don't understand/follow why you need to do all the power alterations to install pybricks? Is it just to not have to use batteries anymore?"

Yes

Gravatar
By in United States,

Nice... I was going to do something similar to my lighthouse to eliminate the batteries, but just with a knot in the wire for strain relief and without the power sockets. Now that I know these exist, I have altered my plans.

Gravatar
By in Australia,

Rather than taking out the battery holder and discarding it, and 'mutilating' the hub itself, couldn't you just 'mutilate' the batter holder, having the wire/socket come out where the battery holder thumb holds are?

That way you can insert a fresh battery holder (with AA batteries) to get the hub back to stock standard, or insert the 'mutilated' battery holder to plug into USB power.

This would also negate the need to glue in extra brick supports to hold the lid in place.

Gravatar
By in United Kingdom,

@slfroden said:
"Rather than taking out the battery holder and discarding it, and 'mutilating' the hub itself, couldn't you just 'mutilate' the batter holder, having the wire/socket come out where the battery holder thumb holds are?

That way you can insert a fresh battery holder (with AA batteries) to get the hub back to stock standard, or insert the 'mutilated' battery holder to plug into USB power.

This would also negate the need to glue in extra brick supports to hold the lid in place. "


Yes, if you don't mind a tethered wire.

Return to home page »