Answers.Body: <p>You will need extra hardware to drive the motor since is uses high current. You won't be able to directly connect it to your ESP32 and make it move.</p>
  <p>The LEGO hubs use a LB1836 motor driver chip (see <a href="https://bricks.stackexchange.com/a/10258/3498">this answer</a> for a photo and link to data sheet). So you will need to find a breakout board with a motor driver with similar specs (<a href="https://www.sparkfun.com/products/14450" rel="nofollow noreferrer">example</a>) or make your own PCB and use the same chip as LEGO.</p>
  <p>The PWM output of the ESP32 will connect to the motor driver chip. You will need two PWM outputs to make the motor go both forwards and backwards. The motor driver chip will need to be connected to a 6-9V battery (7.2V LiPO, 6 AA, etc.). And the output of the motor driver will need to be connected to pins 1 and 2 of the motor.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-20T00:06:10.587Z
Answers.Text: Thank you both for your answers, David and @jncraton, I was trying to build a H-bridge with 4 npn2222 transistors, but I couldn't get the motor to run, then I found a LM298N lying around and did the wiring exactly like [this](https://randomnerdtutorials.com/esp32-dc-motor-l298n-motor-driver-control-speed-direction/) (used some other pins), and with the code in there, the motor is running. I am only using the first two cables (M1 and M2). I am using an old power source which is giving me almost 13 V, and feeding the 5V to the L298N.
Answers.UserDisplayName: Eduardo
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-17T15:53:54.470Z
Answers.LastActivityDate: 2023-04-17T16:49:52.943Z
Answers.LastEditDate: 2023-04-17T16:49:52.943Z
Answers.UserDisplayName: David Lechner
Answers.Body: <p>There is still a simple analog connection for these motors in the Powered Up system. The wiring is similar to the older PF system in that way, except that there are now 2 dedicated signaling lines. Here's the <a href="https://philohome.com/wedo2reverse/connect.htm" rel="nofollow noreferrer">pinout from Philo</a>:</p>
  <p><a href="https://i.sstatic.net/L37JT.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/L37JT.png" alt="Powered Up connector pinout" /></a></p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Pin</th>
  <th>Label</th>
  <th>Function</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>M1</td>
  <td>Motor power lead 1 (PWM controlled)</td>
  </tr>
  <tr>
  <td>2</td>
  <td>M2</td>
  <td>Motor power lead 2 (PWM controlled)</td>
  </tr>
  <tr>
  <td>3</td>
  <td>GND</td>
  <td>Ground (0V)</td>
  </tr>
  <tr>
  <td>4</td>
  <td>VCC</td>
  <td>Power for device electronics (3.3V)</td>
  </tr>
  <tr>
  <td>5</td>
  <td>ID1</td>
  <td>Identification line 1 / Serial data (hub -&gt; device)</td>
  </tr>
  <tr>
  <td>6</td>
  <td>ID2</td>
  <td>Identification line 2 / Serial data (device -&gt; hub)</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>You should be able to drive the motor by applying pure DC voltage to the M1 and M2 pins. You can control speed using any of the common approaches to controlling DC motor speed.</p>
  <p>In terms of voltage, anything up to 9V should be safe.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-17T15:38:04.230Z
Answers.Text: Technically speaking, the GPIOs connected to pins 5 and 6 cannot be configured as analog inputs on the MCU. There are two gpios connected to each pin. The detection algorithm uses these in a serial of tests to detect one of 4 states for each pin. The detected states are A) directly connected to VCC, B) directly connected to GND, C) connected to GND through a resistor and D) not connected to anything. This is all done using digital inputs, not analog. Source code: https://github.com/pybricks/pybricks-micropython/blob/2f39fbad475687f8223963dfca01a9b0cd6561de/lib/pbio/drv/ioport/ioport_lpf2.c#L35
Answers.UserDisplayName: David Lechner
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-17T16:43:06.307Z
Answers.Text: @DavidLechner That makes sense. I appreciate you sharing the source code for that. I took the analog language there to mean that the device can identify itself using only passive analog components without the need for any sort of digital logic. This makes basic analog devices like the train motor more cost effective, as they don't need to include a microcontroller. You are right that these are digital pins on the device.
Answers.UserDisplayName: jncraton
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-17T16:57:00.593Z
Answers.Text: I think the analog language is a carryover from EV3 which did use analog inputs to identify connected devices. The first person to see that some of the Powered Up devices had a 2.2K resistor assumed (incorrectly) that since there was a resistor, that analog must still be involved and this info has been repeated ever since. But I suppose using the terminology somewhat inaccurately is more polite than calling I/O devices "smart" (meaning the device contains a microcontroller and uses UART) or "dumb" (meaning the device does not contain a microcontroller and pins 5/6 are for identification only).
Answers.UserDisplayName: David Lechner
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-17T18:24:12.367Z
Answers.Text: @DavidLechner That makes sense. I've removed the analog language to avoid any possible confusion about these actually being analog pins on the device.
Answers.UserDisplayName: jncraton
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-17T14:44:30.220Z
Answers.LastActivityDate: 2023-04-17T18:22:53.550Z
Answers.LastEditDate: 2023-04-17T18:22:53.550Z
Answers.UserDisplayName: jncraton
Body: <p>I'm doing a project for my kiddos.</p>
  <p>I'm trying to find the schematics of a lego train motor 88011, I want to control them using an ESP32 through a telegram bot.</p>
  <p>I have the ESP32 and the telegram bot working to power up or power down a led (like in this page but with some modified parts for the telegram bot <a href="https://randomnerdtutorials.com/esp32-pwm-arduino-ide/" rel="nofollow noreferrer">https://randomnerdtutorials.com/esp32-pwm-arduino-ide/</a>)</p>
  <p>I was trying to understand the wiring on the lego motor, but only found some videos on 4 wired connections, these have six.</p>
  <p>I also have no idea of what voltage these motors are, attached my hardware.<a href="https://i.sstatic.net/RrnW9.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/RrnW9.jpg" alt="enter image description here" /></a></p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-04-17T09:11:44.420Z
Comments.Text: well i found the page here: https://philohome.com/wedo2reverse/wedo2.htm
Comments.UserDisplayName: LKBricks
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-04-17T09:18:09.720Z
Comments.Text: Use pins M1 and M2 to control the motors
Comments.UserDisplayName: LKBricks
Tags: <motor><trains><powered-up>
Title: How to power on and adjust speed for a PU Train 88011
UserDisplayName: Eduardo
ThreadText: # How to power on and adjust speed for a PU Train 88011
  
  (Asked by: username_0 on 2023-04-16)
  
  I'm doing a project for my kiddos.
  
  I'm trying to find the schematics of a lego train motor 88011, I want to control them using an ESP32 through a telegram bot.
  
  I have the ESP32 and the telegram bot working to power up or power down a led (like in this page but with some modified parts for the telegram bot <https://randomnerdtutorials.com/esp32-pwm-arduino-ide/>)
  
  I was trying to understand the wiring on the lego motor, but only found some videos on 4 wired connections, these have six.
  
  I also have no idea of what voltage these motors are, attached my hardware.[![enter image description here](https://i.sstatic.net/RrnW9.jpg)](https://i.sstatic.net/RrnW9.jpg)
  
  **Tags:** motor, trains, powered-up
  > **Comments:**
  > **username_1**: well i found the page here: https://philohome.com/wedo2reverse/wedo2.htm  
  > **username_1**: Use pins M1 and M2 to control the motors  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2023-04-17. Score: 5
  
  You will need extra hardware to drive the motor since is uses high current. You won't be able to directly connect it to your ESP32 and make it move.
  
  The LEGO hubs use a LB1836 motor driver chip (see [this answer](https://bricks.stackexchange.com/a/10258/3498) for a photo and link to data sheet). So you will need to find a breakout board with a motor driver with similar specs ([example](https://www.sparkfun.com/products/14450)) or make your own PCB and use the same chip as LEGO.
  
  The PWM output of the ESP32 will connect to the motor driver chip. You will need two PWM outputs to make the motor go both forwards and backwards. The motor driver chip will need to be connected to a 6-9V battery (7.2V LiPO, 6 AA, etc.). And the output of the motor driver will need to be connected to pins 1 and 2 of the motor.
  
  > **Comments:**
  > **username_0**: Thank you both for your answers, David and @jncraton, I was trying to build a H-bridge with 4 npn2222 transistors, but I couldn't get the motor to run, then I found a LM298N lying around and did the wiring exactly like [this](https://randomnerdtutorials.com/esp32-dc-motor-l298n-motor-driver-control-speed-direction/) (used some other pins), and with the code in there, the motor is running. I am only using the first two cables (M1 and M2). I am using an old power source which is giving me almost 13 V, and feeding the 5V to the L298N.  
  
  ---
  
  ### Answer by username_3 on 2023-04-17. Score: 2
  
  There is still a simple analog connection for these motors in the Powered Up system. The wiring is similar to the older PF system in that way, except that there are now 2 dedicated signaling lines. Here's the [pinout from Philo](https://philohome.com/wedo2reverse/connect.htm):
  
  [![Powered Up connector pinout](https://i.sstatic.net/L37JT.png)](https://i.sstatic.net/L37JT.png)
  
  | Pin | Label | Function |
  | --- | --- | --- |
  | 1 | M1 | Motor power lead 1 (PWM controlled) |
  | 2 | M2 | Motor power lead 2 (PWM controlled) |
  | 3 | GND | Ground (0V) |
  | 4 | VCC | Power for device electronics (3.3V) |
  | 5 | ID1 | Identification line 1 / Serial data (hub -> device) |
  | 6 | ID2 | Identification line 2 / Serial data (device -> hub) |
  
  You should be able to drive the motor by applying pure DC voltage to the M1 and M2 pins. You can control speed using any of the common approaches to controlling DC motor speed.
  
  In terms of voltage, anything up to 9V should be safe.
  
  > **Comments:**
  > **username_2**: Technically speaking, the GPIOs connected to pins 5 and 6 cannot be configured as analog inputs on the MCU. There are two gpios connected to each pin. The detection algorithm uses these in a serial of tests to detect one of 4 states for each pin. The detected states are A) directly connected to VCC, B) directly connected to GND, C) connected to GND through a resistor and D) not connected to anything. This is all done using digital inputs, not analog. Source code: https://github.com/pybricks/pybricks-micropython/blob/2f39fbad475687f8223963dfca01a9b0cd6561de/lib/pbio/drv/ioport/ioport_lpf2.c#L35  
  > **username_3**: @DavidLechner That makes sense. I appreciate you sharing the source code for that. I took the analog language there to mean that the device can identify itself using only passive analog components without the need for any sort of digital logic. This makes basic analog devices like the train motor more cost effective, as they don't need to include a microcontroller. You are right that these are digital pins on the device.  
  > **username_2**: I think the analog language is a carryover from EV3 which did use analog inputs to identify connected devices. The first person to see that some of the Powered Up devices had a 2.2K resistor assumed (incorrectly) that since there was a resistor, that analog must still be involved and this info has been repeated ever since. But I suppose using the terminology somewhat inaccurately is more polite than calling I/O devices "smart" (meaning the device contains a microcontroller and uses UART) or "dumb" (meaning the device does not contain a microcontroller and pins 5/6 are for identification only).  
  > **username_3**: @DavidLechner That makes sense. I've removed the analog language to avoid any possible confusion about these actually being analog pins on the device.  
  
  ---
  
  