Motor Control Module

Motor Control

This module allows you to control actuators such as DC motors and servo motors.

To control a DC motor, select either Motor 1 or Motor 2. You can vary its speed using the slider and change the direction of rotation by selecting the respective button.

To control a servo, select either Servo 1 or Servo 2. You can vary the servo angle by sliding the yellow bar in the clockwise direction.

Introduction

The Motor Control module allows you to control actuators such as DC and Servo motors. 

You can control 2 DC Motors and 2 Servo Motors using this module.

DC Motor Control

Dabble Motor Control OFF

Using the DC Motor control you can control the direction in which the motor should rotate (clockwise or anti-clockwise) and the speed of rotation (adjustable from 0 to 100).

Dabble Motor Control ON

evive

For evive, you can control the motors connected to motor channel 1 and motor channel 2. 

evive motor channel

Arduino Uno/Mega

For controlling motors using Arduino Uno or Mega, you have to use a motor driver having controls through these pins: 

  1. Direction Pin 1 – Digital Pin
  2. Direction Pin 2 – Digital Pin
  3. PWM Pin – PWM Pin

You have to assign those pins in the Arduino Program to control the motor through this module. The example is given in the Arduino tab below.

Servo Motor Control

Dabble Motor Control Servo

Using the Servo Motor control you can control the direction of the servo from 0 degrees to 180 degrees by changing the yellow bar in the clockwise direction.

evive

For evive, you can control the servo motors attached to the servo motor channel 1 and 2. 

evive servo output channel

Arduino Uno/Mega

For controlling servo motors using Arduino Uno or Mega, you have connect signal pin to any digital pin on your board.

You have to assign those pins in the Arduino Program to control the servo motor through this module. The example is given in the Arduino tab below which will clear how to declare pins for motor and servos.

Arduino IDE Functions

Header

To include the Motor Control module in the Arduino program, you have to include the following header:

#define CUSTOM_SETTINGS

#define INCLUDE_MOTORCONTROL_MODULE

After defining the above mention headers, you have to include the dabble library:

#include <Dabble.h>

You can download zip of Dabble-Arduino (for evive, Uno, Mega and Nano) or Dabble-ESP32 depending board you are using.

Specify pins of DC motor in case of Mega, Uno and Nano

  • For controlling one DC motor from “Motor 1” block of Dabble app

motorControls Control = motorControls(pwm,direction1,direction2); 

In above command pwm, direction1 and  direction2 specifies the pin that will be used to control connected DC motor.

  • For controlling two DC motors from “Motor 1” and “Motor 2” block of Dabble app.

motorControls Control = motorControls(pwm_m1,direction1_m1,direction2_m1,pwm_m2,direction1_m2,direction2_m2);

In above command parameters like pwm_m1, direction1_m1 etc specifies the pin that will be used to control connected DC motor.

Enabling Bluetooth Communication

To enable Bluetooth communication, you have to initialize serial communication using the following code:

For evive and Arduino Mega, Uno and Nano

Dabble.begin(Baud_Rate);

Here Baud_Rate is the baud rate set for the Bluetooth module. With evive, you normally get 115200 baud rate modules. 

For ESP32

Dabble.begin("Bluetooth_Name");

In place of Bluetooth_Name  enter name that you want to keep for bluetooth of ESP32. Default name given in library is “MyEsp32”. 

Refreshing the data

To refresh the data that the device has got from the mobile app, you have to use the following line of code:

Dabble.processInput();

Functions

The following functions can be used to get the DC motor and servo motor control:

For evive, Mega , Uno and Nano

  1. Control.runMotor1(): This function runs the motor as per commands send  from “Motor 1” block in Dabble. In case of evive this function always controls motor connected to channel M1 on evive. For other Arduino boards  motor connected to the pins mentioned by user will be controlled.
  2. Control.runMotor2(): This function runs the motor as per commands send from “Motor 2” block in Dabble. In case of evive this function always controls motor connected to channel M2 on evive. For other Arduino boards  motor connected to the pins mentioned by user will be controlled.
  3. Control.getangle_Servo1(): Returns the value of angle as per the position of knob in “Servo 1” block of motor control module of app.
  4. Control.getangle_Servo2(): Returns the value of angle as per the position of knob in “Servo 2” block of motor control module of app.

For ESP32

  1. Control.runMotor1(pwmMotor1,dir1Motor1,dir2Motor1): This function runs motor as per the commands send from “Motor 1” block in Dabble. Here parameters pwmMotor1, dir1Motor1 and dir2Motor1 specifies the pins of esp32 on which motor will be connected with help of motor driver.
  2. Control.runMotor2(pwmMotor2,dir1Motor2,dir2Motor2): This function runs motor as per the commands send from “Motor 2” block in Dabble. Here parameters pwmMotor2, dir1Motor2 and dir2Motor2 specifies the pins of esp32 on which motor will be connected with help of motor driver.
  3. Control.runServo1(pinServo1): This function runs motor as per the commands send from “Servo 1” block in Dabble. Parameter pinServo1 specifies the pin of ESP32 on which signal pin of servo motor will be connected.
  4. Control.runServo2(pinServo2): This function runs motor as per the commands send from “Servo 2” block in Dabble. Parameter pinServo2 specifies the pin of ESP32 on which signal pin of servo motor will be connected.

PictoBlox (Scratch) blocks

evive

There are two blocks available in PictoBlox  for motor control module. One is for running DC motors as per command send from motor control module of Dabble and one  is for running Servo Motors.

  • enable motor channel ()”  is a stacked block with two options in its drop down for selecting motor channel and corresponding its corresponding control in Dabble. This means on selecting ‘1‘ from drop down you will be able to control motor channel M1 on evive with “Motor 1” module of motor control module. Similarly “Motor2” module runs motor channel M2  on evive.
  • enable Servo () for servo connected to channel ()” is a stacked block with two drop downs. First drop down is for selecting which servo module in motor control module will be used for controlling servo motor connected to pin selected from second drop down. As per the pin number listed in second drop down it is possible for user to connect servo to servo channel S1 and S2 as well as on digital pin 2 to 13.  

Mega,Uno and Nano

  • enable motor () connected to direction pin () , () and pwm pin ()” is a stacked block that has 4 drop downs. First drop down is for selecting which motor module of Dabble will control the motor driver connected to digital pins selected from the other three drop downs. In turn the motor driver will control DC motor connected to it. For example if you select ‘2‘ in first drop down then “Motor 2” module of Dabble will control motor connected to pins selected from other three drop downs. 
  • enable servo () connected to pin ()” is a stacked block with two drop downs. First drop down is for selecting which servo module in motor control module will be used for controlling servo motor connected to pin selected from second drop down. For example if ‘2‘ is selected from first drop down and ‘5‘ is selected from second drop down, a servo connected to pin 5 will be controlled by “Servo 2” module of Dabble.  

 

evive Notes Icon
Note: When you are using this module with Arduino Uno, Mega, and Nano,  you have to set the Bluetooth baud rate to the baud rate of the Bluetooth module to have proper communication between the board and the module. To set the baud rate you have to use set Bluetooth baud rate to () block.

set bluetooth baud rate to

Examples

Enable Motor Control Block

To enable the Motor Control feature, you have to make following script in Upload mode

 

 

You can either copy code stated below or navigate to “Files>>Examples>>Dabble>>” and select motor control code as per your board.

evive

The code given below controls DC motor connected on channel M1 and Servo connected to channel S2. Select “OneMotorOneServo”

example fromthe examples folder.

For other boards you have to connect motors to motor driver and mention the pins of your boards that you have used in with motor driver. Below mentioned code controls two motors and two servos.

Mega, Uno and Nano

ESP32

Leave a Reply

Leave a Reply

Close Menu
×
×

Cart

STEMpedia Starter Kit is now available on Indiegogo!
STEMpedia Starter Package is now on Indiegogo!
Get 41% OFF with Super Early Bird discounts!
x