3

Can you connect the Lego Power Functions M motor to a computer with USB?

2 Answers 2

6

TL;DR: It's not trivial.


First, let me quote the pin-out of a PoweredUP (PU) connector from https://bricks.stackexchange.com/a/10365/13403 :

PF connector with numbered pins

Pin 1 - Motor
Pin 2 - Motor
Pin 3 - GND (0v)
Pin 4 - VCC (3.3v)
Pin 5 - ID 1 (UART TX for active devices)
Pin 6 - ID 2 (UART RX for active devices)

Assuming that you have solved the physical part of the problem (i.e. you can reliably connect cables to those connector pins), now the question becomes "How to supply 3.3v", "How to drive a PWM signal" and "How to read data from a UART" from a computer via USB.

In order to read data from the UART (which is used just to know which kind of motor is attached), you'll need a USB-UART converter, such an inexpensive CP210x or a PL2303, which looks like this:

PL2303

You'll then need to connect the TX and RX pins from the UART to pins 5 and 6 of the PU connector, and you should be able to send and receive data using serial console software. You can find details of what commands you can send (and what responses you can expect) at https://www.philohome.com/wedo2reverse/protocol.htm .

(Note that these kind of USB-UART boards usually provide you with the needed 3.3v line)

On the other hand, there are no off-the-shelf USB-to-PWM boards. The closest I'd get is using an Arduino (or a similar electronics prototyping board, e.g. RPi zero, ESP32) to drive the PWM signal to the motor. It'd be possible to program the Arduino board in such a way that it can receive commands via USB and change the PWM output accordingly


Another possibility (since we're getting into electronics anyway) is to eschew USB altogether and rely on a computer platform capable of driving PWM signals, e.g. the Raspberry Pi (or similar single-board computers with a compatible GPIO block suck as Pine64's Rock64), plus a so-called "Build Hat" shield:

RPi build hat

See also the documentation for the "build hat".

Note that the shield is pretty "dumb", and doesn't contain any electronics. You might as well connect the PoweredUP (PU) pins 1 and 2 directly to the GPIO block (one pin to GND, the other pin to a PWM-capable GPIO). Then read some documentation on driving a PWM GPIO through micropython.

EDIT: this question is related to "PF stuff" and not "PU" because the plugs are diffrent but you can buy a PU to PF adapters like this one

3
  • "Non trivial" indeed.
    – zovits
    Commented Jun 17 at 10:47
  • 2
    Contary to this post, the build hat does have electronics on it (on the bottom of the PCB so they don't show up in most product shorts) including a rp2040 microcontroller. The fifth and sixth pictures on adafruit.com/product/5287 show the electronics. Commented Jun 17 at 20:33
  • Interesting - the board seems too clean from the top. I'll edit the answer later to reflect this. Commented Jun 17 at 21:41
2

Since both the connector and the protocol are different, it's definitely impossible to just plug the motor into a PC. If you allow for using a converter which would use a custom electronic board to convert between the USB and LEGO PF interfaces, then it is definitely possible - but I don't think this custom electronic part exists. There is one adapter on the market, but it is "dumb", as in merely connects the power pins, resulting in the motor turning continuously with full throttle. If you want to control the motor from the PC, you need to get busy with electronics and software.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.