Acrome-SMD Docs
All Acrome ProductsReferencesBlogCase StudiesContact Us
  • ACROME SMD
  • Electronics
    • 🔴SMD Red
      • Troubleshooting Guide
    • 🔵SMD Blue
    • 🟢SMD Green
    • Gateway Modules
      • Arduino Gateway Module
      • USB Gateway Module
    • Electrical Motors
      • Brushed DC Motors (BDC)
      • Stepper DC Motors (SDC)
      • Brushless DC Motor (BLDC)
      • Linear Actuator with Feedback – 75 lbs
    • Add-on Modules
      • Ambient Light Sensor Module
      • Button Module
      • Buzzer Module
      • IMU Module
      • Joystick Module
      • Potentiometer Module
      • Reflectance Sensor Module
      • RGB LED Module
      • Servo Module
      • Ultrasonic Distance Sensor Module
  • SMD Kits
    • Starter Kit
      • Basic Brushed DC motor Applications
    • Education Kit
    • Motion Kit
      • Differential Robot Projects
  • Software
    • Libraries
      • Python Library
      • Arduino Library
      • Java Library
      • Matlab Library
    • SMD UI
    • SMD Blockly
      • Introducing Customized Blockly Blocks
  • SMD Applications
    • Basics
      • Blink
      • Action - Reaction
      • Autonomous Lighting
      • Smart Doorbell
      • Security System
      • Distance Buzzer Warning
      • Distance Auto Stop
      • Smart Light Control
    • Interactive
      • Automatic Trash Bin
      • Radar
      • Chrome Dino Game Player
      • Play Chrome Dino Game With Joystick
      • Snake Game With Joystick
      • Pan-Tilt with Joystick Module
      • Joystick Mouse Control
      • Rev Up the Engine
      • Motor Rotation Based on Turn Input Value
      • Basic Motor Speed Control Application
      • Basic Motor Control Application Using PWM Input
      • Basic Motor Position Control Application
      • Basic Motor Torque Control Application
      • Motor Rotation Based on Joystick Counting
    • Robotics
      • Mouse Cursor Tracker Motion Robot
      • Waypoint tracker robot
      • Braitenberg Robot
      • Line-Follower Robot
      • Object Tracking Robot
      • Teleoperation Robot
      • Obstacle Avoidance Robot
      • ESP32 Wireless Controlled Mobile Robot
  • AI
    • Groq Chatbot-Controlled Robot
  • Mechanics
    • Building Set
      • Plates
        • 2x2 Plate Package
        • 2x3 120° Plate Package
        • 3x3 Plate Package
        • 3x5 Plate Package
        • 3x9 Plate Package
        • 11x19 Plate
        • 9x19 Plate
        • 5x19 Plate
        • 3x19 Plate
        • 9x11 Plate
        • 5x13 Plate
      • Joints
        • 60° Joint Package
        • 90° Joint Package
        • 120° Joint Package
        • Slot Joint M2 Package
        • Slot Joint M3 Package
        • U Joint Package
      • Mounts
        • Add-on Mount Package
        • Motor L Mount Package
        • Pan-Tilt Package
      • Wheels
        • Ball Wheel Package
        • Caster Wheel Package
        • Wheel Package
      • Cables
        • Power Cable 10 cm Package
        • Power Cable 20 cm Package
        • Power Cable 35 cm Package
        • RJ-11 Cable 7.5 cm Package
        • RJ-11 Cable 20 cm Package
        • RJ-11 Cable 35 cm Package
        • RJ-45 Cable 7.5 cm Package
        • RJ-45 Cable 20 cm Package
        • RJ-45 Cable 35 cm Package
      • Fasteners
        • M2x5 Allen Hex Screw Package
        • M3x6 Allen Hex Screw Package
        • M3x8 Allen Hex Screw Package
        • M3 Hex Nut Package
  • Help
    • Manual
    • Shops
    • Reach Us
Powered by GitBook
On this page
  • Installation
  • Verification of Installation
  • Basic Use of the Python Library
  1. Software
  2. Libraries

Python Library

PreviousLibrariesNextArduino Library

Last updated 8 months ago

SMD Python library provides easy-to-use Python modules and methods to extensively use Acrome Smart Motion Device products. It's user friendly for programmers at any level who have desire to learn and countless projects in mind.

Whether you need simple tasks like changing the speed of each motor or more complex processes like precise positioning, PID auto-tuning etc., this library lets you do it with the versatility of Python. You can easily implement various motor control methods.

The library also enhances your projects by allowing easy integration with SMD sensor modules. This means that it allows you to perform numerous applications by using the necessary modules for your needs. It eliminates the hassle of integrating third-party sensors and their software modules into your system, thus improving the functionality and efficiency of your project.

All you need to develop your projects with the SMD is a computer capable of running your Python scripts.

Installation

To use with Python library, follow the installation steps below. The library is compatible with Python 3.x and can be installed on both Windows and Linux systems.

Prerequisites

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

  • Python 3.x:

  • Pip (comes default with Python)

Beware that you should check the pip feature while installing Python 3.x. If you didn't, you always can install pip from the source for any OS.

pip installation with Python setup is demonstrated below for Windows.

"Add python.exe to PATH" is necessary for using Python from any terminal.

You can check if pip is installed properly by typing this command in terminal of any OS:

pip --version

This command will return you the version and directory of pip, which means it is installed and ready to use.

Once you have met the prerequisites, you can follow the steps for whichever OS you use.

  1. Open a Command Prompt with administrative privileges.

  2. Install the SMD library using pip (Python package manager) by running the following command:

pip install acrome-smd
  1. Wait until the installation is complete. Pip will automatically download and install the library and any required dependencies.

  1. Open a terminal.

  2. Install the SMD library using pip (Python package manager) by running the following command:

pip install acrome-smd
  1. Wait until the installation is complete. Pip will automatically download and install the library and any required dependencies.

Verification of Installation

To verify that the SMD library has been successfully installed, open a Python interpreter and run the following command:

import smd
import smd.red

If no errors are raised, the installation was successful.

Basic Use of the Python Library

There are basics to start programming with SMD Python library. First, the user needs to know the serial port (COM... or /dev/tty...) of the connected USB gateway module, COM3 as an example.

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 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:

from smd.red import *

SerialPort = "COM3"    # Serial port of the USB gateway module
baudrate = 115200      # Baud rate of the communication
ID = 0                 # ID of the SMD board

master = Master(SerialPort, baudrate)    # Defines the USB gateway module
master.attach(Red(ID))                   # Gives acces to the SMD of specified ID

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 Masterclass to create an object named master, object name depends on user. Then, we used necessary parameters of Masterclass, which are serial port and baud rate.

Serial port value can be different device to device, so the user can change the code of the serial port as COM... or /dev/tty... according to the OS.

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

from smd.red import *

SerialPort = "COM3"    # Serial port of the USB gateway module
baudrate = 115200      # Baud rate of the communication
ID = 0                 # ID of the SMD board

master = Master(SerialPort, baudrate)    # Defines the USB gateway module
master.attach(Red(ID))                   # Gives acces to the SMD of specified ID

master.set_operation_mode(ID, OperationMode.Velocity)    # Sets the motor's operation mode as "Velocity"
master.set_shaft_rpm(ID, 100)        # Defines the motor RPM value as 100
master.set_shaft_cpr(ID, 6533)       # Defines the motor CPR value as 6533
master.pid_tuner(ID)                 # Starts the PID auto-tune process
time.sleep(30)    # Waits 30 seconds for the process to complete
print(master.get_control_parameters_velocity(ID))    # Prints the calculated PID values

master.enable_torque(ID, True)       # Enables motor to operate
master.set_velocity(ID, 50)          # Sets motor to operate at 50 RPM

You should specify the ID of the target SMD when using functions, in this application there is only one SMD and it has an ID of 0, which is also defined as ID variable.

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.

To run the PID auto-tune process, we use the pid_tuner() function with the ID 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 time.sleep(30) in order to wait for any other processes before the end of the process. The calculated PID values are printed with the get_control_parameters_...() function, the last part of function name changes with the operation mode of the motor, which in our application is "Velocity".

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

For usage and more info, see our page.

First of all, PC and SMD connections should be made. Connect your to your PC's USB port and connect your SMD to the gateway module with an RJ-11 cable. Lastly, connect a 12V adapter to supply power to the SMD.

Then we can do our first application , PID auto-tune and velocity control, to practice with our library. You will need an SMD and a brushed DC motor, which are included in the .

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

For all detailed function and feature explanations of Python library, visit the .

Github
USB gateway module
Starter Kit
Starter Kit
Python library GitHub page
Acrome Smart Motion Devices
Python Official Website
https://pip.pypa.io/en/stable/installation/
Step 1: Customize installation
Step 2: Check the "pip"