Wireless motor control from Lego using Steam Controller



When I was young, I always wanted to have Lego Technics kits to collect all sorts of cool stuff from them. Autonomous tanks with rotating turrets firing Lego bricks. But then I didn’t have such a set.

And even the usual bricks from Lego were not. I had only a friend whose brother had all these expensive toys.

And now I have a son of his own age. And he builds tanks that ... stupidly stick forward until they hit the wall :)

And now, the time has come for ESP32 and the magic of the soldering iron - we will assemble the right remote control for them!

No, of course, I know about the existence of such remotes. But not one of them suits me completely. They are either infrared, with technology of the 80s, or too large. Or expensive. And most importantly - I can’t say to my son about any of them: “I did it especially for you!”

So let's make a new, improved remote to rule everyone!



Ingredients:

  • ESP32-WROOM-32D | WiFi, BLE and a processor with I / O - enough to control two motors and an LED .
  • DRV8833 | double H-bridge with enough power for motors.
  • TPS62162 | lowering voltage to 17 V, as well as for entertainment when soldering the case WSON-8 2 × 2 mm
  • CP2104 | for programming ESP32
  • . , Lego .

All this will be placed on a rather small board - here is its appearance in the EasyEDA editor: The



wire that is visible in the header photo is not needed to fix any errors, but to supply power from USB. It may not be enough for the motor, but, unfortunately, contacts from China still have not come to me. Therefore, I first check the operation of the LEDs. For the beauty in the photo, I just put the connector from the motor on the board.

On version 1.1 of my board (unlike version 1.2, which is already on EasyEDA), there were no LEDs, so I soldered two anti-parallel diodes to the output so that what was happening was visible. If you look closely, the video shows the alternate inclusion of a pair of 0603 diodes, indicating forward / backward movement.



As for the control panel, at first I just wanted to collect an additional board with buttons and another ESP32 - a classic remote control.

However, then I remembered that Steam Controllers have a Bluetooth Low Energy Mode (BLE). I decided to tackle this issue, and after a few hours I learned how to receive packets from the controller.

To do this, simply search for the HID device that calls itself SteamController and connect to it. And then use Valve's undocumented service and a few undocumented commands that allow packet transfers.



And I also came across an undocumented report format, which I parsed manually.



After about an hour, the meaning of the flags and values ​​became clear to me, and I managed to blink the LED using the Steam controller and ESP32. ¯ \ _ (ツ) _ / ¯

Files



v1.0: “trial approach”
- the first option for which I chose the wrong voltage regulator. TPS62291 raises the voltage only to 6 V. I developed several projects in parallel, and I forgot that the device needs to work with 9 V.

v1.1: “good enough”
- this option is visible in the commercials, and everything works

v1.2: “final”
- added indicator LEDs to the output and optimized the size and layout of the board.

The next short video shows the connection phase (1-3 seconds after turning on the power) and control of the motor outputs. The Lego connector is not yet connected. It will go to an empty space next to the other connectors, marked with a white rectangle.



My son now regularly uses this controller to control the devices he has assembled.

During the stress test, I encountered only one problem: I thought that the “fast decay” mode of the motor driver would work best, but because of it, after a few seconds of operation, the motor speed would drop very much. So I changed the code so that it used “slow decay”.



So far I’m not sure how the DRV works and why the motor first rotates quickly, and then after 10 seconds it starts to slow down gradually. Perhaps the MOSFETs are warming up and their resistance rises too much.



I hope this example of using Arduino effortlessly inspires other people and allows them to introduce their children to electronics.

All Articles