I use Lego Extension cables when connecting Lego motors and motor driver board. This way, Lego motors can be reuse in pure Lego based projects.
Cable for Lego Power Functions Battery
Lego cable has four wires. Wires on each side doesn't change polarity when battery box switch turns to either side. Right outer cable is +ve and left outer is -ve. Use this to attach to desired power source.
See this picture to get an idea
Caution: Use multi meter to confirm polarity
Cable for Lego Power Functions Motor
Middle two wires are used to power Lego PF motors.
I prefer to use light grey head side, (which doesn't fit the battery), for motor connection as it can be attached to Lego Buggy Motor. Picture for information
Cable for Lego Power Functions Servo
Lego PF servo uses all four wires. Side wires are to power and middle two wires are used to set duty cycle and direction. I use breadboard to share battery power with PF Servos.
Note engine speed on shifting to 4th gear, it's slow. Reading motor battery was on 3V. Not sure if batteries were not able to handle such load or was there any other issue.
Next Step
Hook up sensors, lights, Camera and Automated Action
Use a Remote not laptop, which looks something like this
Control Lego Power Functions Servo motor to it's full functionality. The Servo motor moves to 90 degree on both sides assuming, center is at 0 and it can also do 7 steps to each side.
Implementation
Lego Power Functions uses PWM frequency of 1150 Hz. Using this frequency, Power Functions servo can do 7 steps using duty cycles, 26.6, 38.9, 51.2, 63.0, 75.0, 87.2 and 100. I confirmed my tinkering with oscilloscope, that it is giving correct frequency and duty cycles.
Below are my findings so far
Microbit
Kitronik All in one Robotic board
This is the first board, I have tinkered with. It can be powered with Lego 8881 battery box. By setting PCA frequency to 1150, it can step through with correct duty cycles.
The microbit Makecode is here. To set desired PWM frequency for this board, see line 132 in robotics.ts. I also added a functionality to brake motor, see Line 303 robotics.ts
Dfrobot Driver expansion board
My tinkering failed with this board. After updating the code, stepping always tunring motor to all the way 90 degree. Oscilloscope reading was not showing correct frequency and duty cycle which I was using.
I don't have electrical, electronics knowledge but my guess is it is due to the design of the board. This board has led which light up when motors are running. These leds are lighting up when move motors by hand.
Elecfreaks Motor:bit
This board just have a TB6612 based motor driver chip. PWM has to be set by Microbit using analogSetPeriod. See forward function here at Line 24
The board is available here, Adafruit has detailed steps on how to use this board with Raspberry Pi, so just used those steps
By default, PWM frequency is set to 1600. After installing the library, I changed the code to accept pca_frequency when creating the class object. To do so
Edit /usr/local/lib/python3.7/dist-packages/adafruit_motorkit.py or locate adafruit_motorkit.py based on installation
Add default parameter, pca_frequence=1600 like this
Wiring
Lego PF servo uses all four wires. Side wires are to power and middle two wires are used to set duty cycle and direction.
I use Lego PF Extension wires to connect Servo with custom Motor Driver boards. This way the motor can be reuse in Pure Lego based projects
This picture should give an idea about wiring and connections