Arduino Library

SMD Arduino library is designed to improve the mobility of your system by enabling the operation of SMD with Arduino. The library simplifies the process of programming various projects and gives lots of ways to control motors in your system. It also works seamlessly with all SMD modules, which gives more imagination for countless projects.

The Arduino library can be used directly with Arduino IDE. It is user friendly as well as Arduino, familiarity and ease of programming an Arduino project with your Arduino and precise motor control availability is indispensable for makers.

Installation

To use Acrome Smart Motor Drivers with Arduino library, follow the installation steps below.

Prerequisities

Before you begin, make sure you have the following prerequisities:

  • Latest Arduino IDE (click to download)

  • Any programmable Arduino board

Once you have met the prerequisites, you can follow the steps.

  1. Open Arduino IDE

  2. In the Arduino IDE, go to Sketch -> Include Library -> Manage Libraries... or simply click the book stack icon on the left, and search for Acrome-SMD in the search bar.

  3. Click "Install".

Verification of Installation

To verify that Arduino library successfully installed, open Arduino IDE and open a new sketch. Type this code line into your first line of sketch as shown in the image below, then click "Verify" button on the top left.

#include <Acrome-SMD.h>

Basic Use of Arduino Library

First of all, the Arduino and SMD connections should be made. Connect your Arduino to the PC and place the Arduino gateway module on your Arduino board as the front two pins of the module should meet with the RX-TX pins and analog pins of module should sit on the analog pin slots. Then, connect SMD to the Arduino gateway module with an RJ-11 cable. Finally, connect a 12V adapter to supply power to the SMD.

Since SMD cards can be connected to each other, each of them can have a different ID by user's choice. However, an SMD Red has an ID of 0 by default. This value can be intentionally changed between 0 - 255 .

SMD can communicate with different baud rates, user may want to change baud rate depending on the needs of the project. SMD Red has a default baud rate of 115200.

With all this information, the crucial part of coding can begin.

Here is the first part of the code:

#include <Acrome-SMD.h>

#define ID        0        // ID of the SMD board
#define BAUDRATE  115200   // Baud rate of the communication


Red master(ID, Serial, BAUDRATE);    // Defines the Arduino gateway module

void setup() {

}

void loop() {

}

This code snippet acts as a communication setup for SMD.

We defined baud rate as 115200 and ID as 0 (default SMD ID, if it wasn't changed), and used Red class to create an object named master, object name depends on user. Then, we used necessary parameters of Red class, which are ID, Serial (communication with Arduino), and baud rate.

Then we can do our first application , PID auto-tune and velocity control, to practice with our library. In addition to the Arduino board, you will need an SMD, Arduino gateway module, and a brushed DC motor, which are included in the Starter Kit.

We start with the communication setup, and then add the necessary motor control functions, which will be explained below.

#include <Acrome-SMD.h>

#define ID        0        // ID of the SMD board
#define BAUDRATE  115200   // Baud rate of the communication

Red master(ID, Serial, BAUDRATE);    // Defines the Arduino gateway module

void setup() {
    master.begin();    // Starts the communication
    
    master.setMotorRPM(100);      // Defines the motor RPM value as 100
    master.setMotorCPR(6533);     // Defines the motor CPR value as 6533
    master.setOperationMode(VelocityControl);    // Sets the motor's operation mode as "Velocity"
    master.torqueEnable(1);       // Enables motor to operate
    
    master.tune();    // Starts the PID auto-tune process
    delay(30000);     // Waits 30 seconds for the process to complete
}

void loop() {
    
}

There are various operation modes for motor control, for example, we have selected "Velocity" control mode, which allows the motor to be controlled in terms of RPM value.

Then, we specified the RPM and CPR value of motor, in order to be tuned properly. Brushed DC motor in Starter Kit has 100 RPM and 6533 CPR value.

To run the PID auto-tune process, we use the tune() function with the object name of the target SMD. After running the function, the motor will start spinning and the process will take about 30 seconds. That's why we put the delay(30000) in order to wait for any other processes before the end of the process.

For all detailed function and feature explanations of Arduino library, visit the Arduino library GitHub page.

For more use cases, visit the projects and see the Arduino codes:

Projects

Last updated