Answers.Body: <p>TL;DR: It's not trivial.</p>
  <hr />
  <p>First, let me quote the pin-out of a PoweredUP (PU) connector from <a href="https://bricks.stackexchange.com/a/10365/13403">https://bricks.stackexchange.com/a/10365/13403</a> :</p>
  <p><a href="https://i.sstatic.net/QskUYdhn.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/QskUYdhn.png" alt="PF connector with numbered pins" /></a></p>
  <pre><code>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)
  </code></pre>
  <p>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 &quot;How to supply 3.3v&quot;, &quot;How to drive a PWM signal&quot; and &quot;How to read data from a UART&quot; from a computer via USB.</p>
  <p>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:</p>
  <p><a href="https://i.sstatic.net/Fyvu95xV.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Fyvu95xV.png" alt="PL2303" /></a></p>
  <p>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 <a href="https://www.philohome.com/wedo2reverse/protocol.htm" rel="nofollow noreferrer">https://www.philohome.com/wedo2reverse/protocol.htm</a> .</p>
  <p>(Note that these kind of USB-UART boards usually provide you with the needed 3.3v line)</p>
  <p>On the other hand, there are no off-the-shelf USB-to-PWM boards. The closest I'd get is using an <a href="https://docs.arduino.cc/learn/" rel="nofollow noreferrer">Arduino</a> (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</p>
  <hr />
  <p>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 <a href="https://www.raspberrypi.com/" rel="nofollow noreferrer">Raspberry Pi</a> (or similar single-board computers with a compatible GPIO block suck as Pine64's <a href="https://pine64.org/devices/rock64/" rel="nofollow noreferrer">Rock64</a>), plus a <a href="https://www.raspberrypi.com/products/build-hat/" rel="nofollow noreferrer">so-called &quot;Build Hat&quot;</a> shield:</p>
  <p><a href="https://i.sstatic.net/JfH1To42.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/JfH1To42.png" alt="RPi build hat" /></a></p>
  <p>See also the <a href="https://www.raspberrypi.com/documentation/accessories/build-hat.html" rel="nofollow noreferrer">documentation for the &quot;build hat&quot;</a>.</p>
  <p>Note that the shield is pretty &quot;dumb&quot;, 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 <a href="https://www.radishlogic.com/raspberry-pi/raspberry-pi-pwm-gpio/" rel="nofollow noreferrer">some documentation on driving a PWM GPIO through micropython</a>.</p>
  <p>EDIT: this question is related to &quot;PF stuff&quot; and not &quot;PU&quot; because the plugs are diffrent but you can buy a PU to PF adapters like <a href="https://pv-productions.com/product/powered-up-to-power-functions-adapter/" rel="nofollow noreferrer">this one</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-06-17T10:47:08.717Z
Answers.Text: "Non trivial" indeed.
Answers.UserDisplayName: zovits
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-06-17T20:33:21.057Z
Answers.Text: 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 https://www.adafruit.com/product/5287 show the electronics.
Answers.UserDisplayName: Peter Green
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-06-17T21:41:45.993Z
Answers.Text: Interesting - the board seems too clean from the top. I'll edit the answer later to reflect this.
Answers.UserDisplayName: IvanSanchez
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-06-17T10:38:06.910Z
Answers.LastActivityDate: 2024-06-19T07:06:00.250Z
Answers.LastEditDate: 2024-06-19T07:06:00.250Z
Answers.UserDisplayName: IvanSanchez
Answers.Body: <p>Since both the connector and <a href="https://www.philohome.com/pf/LEGO_Power_Functions_RC.pdf" rel="nofollow noreferrer">the protocol</a> 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 <a href="https://atlbrick.com/products/legor-power-functions-to-usb-adapter" rel="nofollow noreferrer">one adapter</a> on the market, but it is &quot;dumb&quot;, 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.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-06-17T09:55:36.717Z
Answers.LastActivityDate: 2024-06-17T09:55:36.717Z
Answers.UserDisplayName: zovits
Body: <p>Can you connect the Lego Power Functions M motor to a computer with USB?</p>
  
Tags: <programming><motor><power-functions><3rd-party>
Title: Connecting a Lego PF M motor to computer
UserDisplayName: Anonymous
ThreadText: # Connecting a Lego PF M motor to computer
  
  (Asked by: username_0 on 2024-06-17)
  
  Can you connect the Lego Power Functions M motor to a computer with USB?
  
  **Tags:** programming, motor, power-functions, 3rd-party
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2024-06-17. Score: 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](https://i.sstatic.net/QskUYdhn.png)](https://i.sstatic.net/QskUYdhn.png)
  
  ```
  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](https://i.sstatic.net/Fyvu95xV.png)](https://i.sstatic.net/Fyvu95xV.png)
  
  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](https://docs.arduino.cc/learn/) (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](https://www.raspberrypi.com/) (or similar single-board computers with a compatible GPIO block suck as Pine64's [Rock64](https://pine64.org/devices/rock64/)), plus a [so-called "Build Hat"](https://www.raspberrypi.com/products/build-hat/) shield:
  
  [![RPi build hat](https://i.sstatic.net/JfH1To42.png)](https://i.sstatic.net/JfH1To42.png)
  
  See also the [documentation for the "build hat"](https://www.raspberrypi.com/documentation/accessories/build-hat.html).
  
  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](https://www.radishlogic.com/raspberry-pi/raspberry-pi-pwm-gpio/).
  
  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](https://pv-productions.com/product/powered-up-to-power-functions-adapter/)
  
  > **Comments:**
  > **username_2**: "Non trivial" indeed.  
  > **username_3**: 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 https://www.adafruit.com/product/5287 show the electronics.  
  > **username_1**: Interesting - the board seems too clean from the top. I'll edit the answer later to reflect this.  
  
  ---
  
  ### Answer by username_2 on 2024-06-17. Score: 2
  
  Since both the connector and [the protocol](https://www.philohome.com/pf/LEGO_Power_Functions_RC.pdf) 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](https://atlbrick.com/products/legor-power-functions-to-usb-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.
  
  
  ---
  
  