0

Example for ML-R BLDC Motor Driver 4x2.5A reverse protection (mrm-bldc4x2.5), using UART interface

Prerequisites

Required hardware:

Task

We will drive 4 BLDC motors using Arduino program and UART interface.

Hookup

×
  1. Do not connect battery yet.
  2. Use ML-R Cable KK254-KK254 20 cm (mrm-kk2.54-2.54-20), or similar, and connect 3.3 V voltage output to controller's logic voltage input (any orange connector). If You have some other power supply, use 2 Dupont 0.1" wires to deliver 3.3 V DC to any of the 2 orange connectors. Mind + and -! The controller has reverse input voltage protection, but it is better not to test it. At least, the board will not work, if voltage is reversed.
  3. Take 2 Dupont cables and connect Mega's pin 14 (TX1) to controller's pin RX. Connect Mega's pin 15 (RX1) to controller's TX.
  4. Connect cable for input voltage between power supply and the controller.
  5. Check all the polarities!
  6. Turn power switch off.
  7. Connect battery.
  8. Turn power switch on.
  9. Controller's green LED must blink 0.1 sec. every second. If so, You are good to go.
Even if You have some other type of hookup, make sure that the sensor and Mega 2560 have common ground (GNDs connected).

Program

Here is a sample code.

uint8_t buffer[5] = {0x20, 0, 0, 0, 0};
const uint8_t SPEEDS[] =  {128, 255, 0};
int current = 0;
int motor = 3;

void setup() {
  Serial.begin(115200);
  Serial1.begin(38400);
}

void loop() {
  uint8_t startSpeed = SPEEDS[current];
  if (++current > 2)
    current = 0;
  uint8_t endSpeed = SPEEDS[current];
  for (int speed = startSpeed; 
    startSpeed < endSpeed ? speed < endSpeed : speed > endSpeed; 
    startSpeed < endSpeed ? speed++ : speed--)
  {
      buffer[motor + 1] = speed;
      Serial1.write(buffer, 5);
      Serial.print("Motor ");
      Serial.print(motor);
      Serial.print(", speed ");
      Serial.println(speed);
      delay(20);
      if (speed == 128 && startSpeed < endSpeed && ++motor > 3)
        motor = 0;
  }
}
Upload the program, open Arduino monitor, and change baud rate to 115200.