Lego Power Function (PF) Motor Speed Controller With a 16 LED Neopixel Ring and a Rotary Encoder

by rvdalen in Circuits > Arduino

100 Views, 1 Favorites, 0 Comments

Lego Power Function (PF) Motor Speed Controller With a 16 LED Neopixel Ring and a Rotary Encoder

Lego PF Motor speed controller-neopixel-lasercut Box-result1.JPG
Lego PF Motor speed controller-neopixel.JPG
2868 Train Speedregulator.jpg
Lego PF Motor speed controller neopixel lasercut Box result1

Inspired by the good old conventional Lego train speed regulator (2868), I made this design for controlling Lego PF Motors. It is based on an Arduino ProMini (or clone) and has a DRV8833 Motor driver module, a Rotary encoder and a 16 LED Neopixel Ring as forward/reverse speedindicator and placed in a lasercut wooden console

The conventional train regulator gives a analog 0-9V output signal. In this design, the PF motor is controlled with a Pulse Width Modulation (PWM) output signal. This means that the motor speed is controlled by varying the duty cycle of a square wave signal.

Earlier I made another version of a Lego speed controller based on the well known NE555 timer-IC.

Supplies

Arduino ProMini's.jpg
Lego PF Motor speed controller-neopixel-BOM.JPG

For the Arduino boards both the Arduino ProMini and the cheap LGT8F328P LQFP32 MiniEVB (Pro Mini Style) can be used or even the very cheap LGT8F328P SSOP20 MiniEVB (pseudo Pro Mini Style).

Some time ago I bought a whole bunch of LGT8F328P MiniEVB modules on AliExpress for less than €0,70 each - I used the 5V version, because not all types of Neopixels are compatible with 3V3.

Furthermore, I use, among other things;

  1. A DRV8833 Motor driver module
  2. A Neopixel ring with 16 LEDs
  3. An EC11 Rotary encoder with push button

The Schematic Design

Lego PF Motor speed controller-neopixel-Schematic.JPG
Breadboard setup.jpg

The design is made in KiCad 9.0 and is straight forward. It can be powered by, for example, a 9V Lego battery box (8881) or by an external 9Vdc power adapter. I first tested it in a breadboard setup.

You can find the latest KiCad files on my github.

The PCB Design

PCB - JLCPCB.jpg
PCB -3D view.jpg
Lego PF Motor speed controller-neopixel-PCB_Back.JPG
Lego PF Motor speed controller-neopixel-PCB_Front.JPG

Finally I designed a 76x100mm PCB, which I ordered from JLCPCB. So I have now 5 boards of which I can give away (or sell) 4 pieces to relatives :-).

The pcb design takes into account the footprint of the different Arduino boards, however only 1 of the Arduino boards needs to be placed.

You can find the the gerber files on my github.

DIY PF Cable

PF Connector.jpg
Lego PF Motor Speed Controller - PF_Connector.jpg

On AliExpress I bought a couple of PF connectors and 4 core wire and made my own DIY Lego PF connection cables.

Before assembling the Input PF cable (connected to J11 in the schematic), I removed the C1 and C2 contacts from the Bottom part of the connector so that this connector can be used to connect both the battery box (via the 0V and 9V contacts in the BOTTOM part) as the Lego PF-motor as well (via the C1 and C2 contacts in the TOP part).

The output PF cable (connected to J13 in the schematic) is not modified (so has all its contacts).

So the PF-motor can be connected or to the input connector (connected to the Battery box) or to the output connector.

See this article about the working of de LEGO Power Function cable.

Programming

FTDI USB to TTL Adapter.JPG
Boardsettings LGT8F328P.jpg

To upload the sketch from your computer into the Arduino board you will need a FTDI USB to TTL Adapter.

Then;

  1. Install the following libraries:
  2. lgt8fx library (When you use a LGT8F328P MiniEVB Board)
  3. Neopixel library
  4. Rotary library
  5. Download the sketch (You can also download the the sketch from my github)
  6. Set the proper board settings (see picture for the LGT8F328P board settings)
  7. Upload the sketch


For clarification;

  1. The Neopixel ring indicates the output signal (similar to the big yellow button on the conventional Lego train speed regulator).
  2. Turning the Rotary encoder knob to the right wll increase the speed in forward direction (Green color), turning to the left will decrease the speed to 0 (LED8 is the center of the indication scale) and then increases the speed in reverse direction (Red color).
  3. Neopixel LED0 is set to blue as power-on indication.
  4. When your Rotary encoder is equipped with a push button; a short button press will increase the brightness of the LEDs (in 9 steps) and a long button press (>2sec) will reset the brightness to the default 10% and set the speed to 0 (Stop).

The Assembled Board

PCB - Assembled.jpg
Lego PF Motor speed controller-neopixel - Video PCB Assembled
Lego PF Motor Speed Controller - ButtonPress

And this is what it looks like when the board is assembled and tested.

Yellow Knob & Enclosure

Lego PF Motor speed controller-neopixel-Button.jpg
Lego PF Motor speed controller-neopixel-lasercuts.JPG
Lego PF Motor speed controller-neopixel-lasercut panel.JPG
Lego PF Motor speed controller-neopixel-lasercut Box.JPG
Lego PF Motor speed controller-neopixel-lasercut Box-assembling1.JPG
Lego PF Motor speed controller-neopixel-lasercut Box-assembling2.JPG
Lego PF Motor speed controller-neopixel-lasercut Box-assembling3.JPG

I designed a big 45mm knob in FreeCad (v1.0) for the Rotary encoder and 3d printed it in yellow

The design is parametric - so the knob dimensions can be modified (spreadsheet tab)

-------------------

The enclosure is a clever lasercut design from this site with lots of boxes. It is based on this console and has a small box on the back for the Battery box.

Then I imported the svg output files into the lasercutter software (XTool) and made cutouts for the neopixel ring LEDs and the other things. The labels on the parts come on the inside of the box.

-------------------

You can find all the latest native files on my github.

-------------------

The holes in the front panel for the neopixel ring LEDs were reworked with a dremel tool to mill out the screws and smd resistors.

The Final Result

Lego PF Motor speed controller-neopixel-lasercut Box-result1.JPG
Lego PF Motor speed controller-neopixel-lasercut Box-result2.JPG
Lego PF Motor speed controller neopixel lasercut Box result1

And this is how it looks like after assembling all the parts