Lego Hacking – Guides Table of Contents
Hacking Power Functions
Part 1 – Introduction
Part 2 – Equipment
Part 3 – Wiring Hacking
Part 4 – Wiring Arduino
Part 5 – Program the Arduino (coming soon)
Lego Hacking – Guides Table of Contents
Hacking Power Functions
Part 1 – Introduction
Part 2 – Equipment
Part 3 – Wiring Hacking
Part 4 – Wiring Arduino
Part 5 – Program the Arduino (coming soon)
Hi, thanks very much for your posts ! When the Part 5 will be available ?
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
*/
#include
// 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:
Serial.begin(9600);
// Wait for the serial port to connect. Needed for Leonardo.
while (!Serial);
// Attach the motors to the input pins:
driver.attachMotorA(inputA1, inputA2);
Serial.println(“Ready!”);
}
void loop() {
Serial.println(“Forward:”);
driver.motorAForward(motorSpeedHigh);
delay(myDelay);
driver.motorAStop();
driver.motorAForward(motorSpeedLow);
delay(myDelay);
driver.motorAStop();
Serial.println(“Reverse:”);
driver.motorAReverse(motorSpeedHigh);
delay(myDelay);
driver.motorAStop();
driver.motorAReverse(motorSpeedLow);
delay(myDelay);
driver.motorAStop();
}