Maker Nano RP2040 Interfacing With Maker Drive Using Arduino IDE

Maker Nano RP2040 Interfacing With Maker Drive Using Arduino IDE

 

Introduction

In this tutorial we shall see how to interface Maker Nano RP2040 with Maker Drive to control dc micro metal gear motor. The ultimate goal is to build a line following robot. And this is the first part of it, whereby we try to control the DC motor using the Maker Nano RP2040 and Maker Drive.

 

Video

Hardware Preparation

This are the list of items used in this tutorial.

makernanorp2040 makerdrive time 0 00 1815

 

Building The Circuit

  1. Constructing the circuit is pretty much easy since we are using the grove connector. The connection between the devices are done as per the below figure.

 

makernanorp2040 makerdrive time 0 00 3810

Once the connection are made as per the figure above, we can now start to code.

 

Code

For the code, since we have used different type of devices, please ensure that all the library has been downloaded prior to running this code.

 

/*******************************************************************************
 * THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTY AND SUPPORT
 * IS APPLICABLE TO THIS SOFTWARE IN ANY FORM. CYTRON TECHNOLOGIES SHALL NOT,
 * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR CONSEQUENTIAL
 * DAMAGES, FOR ANY REASON WHATSOEVER.
 ********************************************************************************
 * DESCRIPTION:
 *
 * This example shows how to drive 2 motors using the PWM and DIR pins with
 * 2-channel motor driver.
 * 
 * 
 * CONNECTIONS:
 * 
 * Arduino D3  - Motor Driver PWM 1 Input
 * Arduino D4  - Motor Driver DIR 1 Input
 * Arduino D9  - Motor Driver PWM 2 Input
 * Arduino D17 - Motor Driver DIR 2 Input
 * Arduino GND - Motor Driver GND
 *
 *
 * AUTHOR   : Kong Wai Weng
 * COMPANY  : Cytron Technologies Sdn Bhd
 * WEBSITE  : www.cytron.io
 * EMAIL    : support@cytron.io
 *
 *******************************************************************************/

 #include "CytronMotorDriver.h"


// Configure the motor driver.
CytronMD motor1(PWM_DIR, 3, 4);  // PWM 1 = Pin 3, DIR 1 = Pin 4.
CytronMD motor2(PWM_DIR, 9, 17); // PWM 2 = Pin 9, DIR 2 = Pin 17.


// The setup routine runs once when you press reset.
void setup() {
  
}


// The loop routine runs over and over again forever.
void loop() {
  motor1.setSpeed(128);   // Motor 1 runs forward at 50% speed.
  motor2.setSpeed(-128);  // Motor 2 runs backward at 50% speed.
  delay(1000);
  
  motor1.setSpeed(255);   // Motor 1 runs forward at full speed.
  motor2.setSpeed(-255);  // Motor 2 runs backward at full speed.
  delay(1000);

  motor1.setSpeed(0);     // Motor 1 stops.
  motor2.setSpeed(0);     // Motor 2 stops.
  delay(1000);

  motor1.setSpeed(-128);  // Motor 1 runs backward at 50% speed.
  motor2.setSpeed(128);   // Motor 2 runs forward at 50% speed.
  delay(1000);
  
  motor1.setSpeed(-255);  // Motor 1 runs backward at full speed.
  motor2.setSpeed(255);   // Motor 2 runs forward at full speed.
  delay(1000);

  motor1.setSpeed(0);     // Motor 1 stops.
  motor2.setSpeed(0);     // Motor 2 stops.
  delay(1000);
}

 

Outcome

 

makernanorp2040 makerdrive time 0 01 1605
DCIM\101MEDIA\DJI_0203.JPG

 

Thank You

Thanks for reading this tutorial. If you have any technical inquiries, please post at Cytron Technical Forum.

"Please be reminded, this tutorial is prepared for you to try and learn.
You are encouraged to improve the code for a better application."