2 thoughts on “Lego Hacking

  1. Please find here some test code to control the Legomotor. It works fine.

    I’ve used the following library: https://github.com/TheArduinist/DRV8833

    DRV8833 – Library for the DRV8833 dual motor driver carrier.
    * The DRV8833 can be found here: https://www.pololu.com/product/2130
    * The DRV8833 data sheet can be found here: https://www.pololu.com/file/download/drv8833.pdf?file_id=0J534

    * DRV8833_Test_PWM
    * PWM (Pulse Width Modulation) test for the DRV8833 library.
    * The DRV8833 is a dual motor driver carrier made by Pololu.
    * You can find it here: https://www.pololu.com/product/2130
    * Attach the positive wire of a motor to the Aout1 and the negative
    * wire to the Aout2 pins on the DRV8833.
    * Attach the positive wire of a motor to the Bout1 and the negative
    * wire to the Bout2 pins on the DRV8833.
    * Attach the Arduino’s ground to the one of the GND pins on the DRV8833.
    * Attach a 9V battery’s positive connection to the Vin pin
    * on the DRV8833, and the negative connection to one of the GND pins.
    * Created March 31, 2015, by Aleksandr J. Spackman.

    * Modified for testing a single Legomotor at A with differend speeds and direction.
    * No mapping from digital value to actual RPM has been done so far.
    * Observations:
    * – 64 (25% of max value 255) seem to be the minimum reasonable speed
    * – Motors seems to be slower in reverse direction
    * Modified September 28, 2015, by Stephan Dankers

    // Create an instance of the DRV8833:
    DRV8833 driver = DRV8833();

    // Pin numbers. Replace with your own!
    // For this example sketch, these pin numbers MUST be PWM.
    // Attach the Arduino’s pin numbers below to the
    // Ain1, Ain2, Bin1, and Bin2 DRV8833 pins.
    const int inputA1 = 9, inputA2 = 6;

    // The speed of the motors:
    const int motorSpeedHigh = 255;
    const int motorSpeedLow = 64;
    int myDelay = 4000;

    void setup() {
    // put your setup code here, to run once:

    // Start the serial port:

    // Wait for the serial port to connect. Needed for Leonardo.
    while (!Serial);

    // Attach the motors to the input pins:
    driver.attachMotorA(inputA1, inputA2);

    void loop() {




Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s