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
      • What You Can Build
    • Education Kit
      • What You Can Build
    • Motion Kit
      • What You Can Build
  • 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
      • Differential Robot Projects
      • Mouse Cursor Tracker Motion Robot
      • Waypoint tracker robot
      • Braitenberg Robot
      • Line-Follower Robot
      • Teleoperation Robot
      • Obstacle Avoidance Robot
      • ESP32 Wireless Controlled Mobile Robot
  • AI
    • Object Tracking Robot
    • Groq Chatbot-Controlled Robot
  • ROS
    • Teleoperation Robot with ROS
  • 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
  • Step 1: Hardware & Software Overview
  • Step 2: Assemble
  • Step 3: Run & Test
  • Codes
  1. SMD Applications
  2. Basics

Blink

PreviousBasicsNextAction - Reaction

Last updated 2 months ago

The LED Blink application is a project that allows the user to control the blinking of an LED using an and an . This project is designed for simplicity, making it an ideal starting point for those wishing to experience the SMD hardware control using .

About Tools and Materials:

()

Step 1: Hardware & Software Overview

Project Key Components

  • The SMD library is at the heart of the application. It communicates with the SMD using a specific communication protocol, sending commands to turn the RGB LED on or off, adjust the color, or set a specific blinking pattern.

Project Key Features

  • Detailed Control over the LED

Step 2: Assemble

  1. Hardware Setup

    • Make sure that the SMD is powered and all connections are correct.

Project Wiring Diagram

Step 3: Run & Test

  1. Run the Script

  2. Experience and Customize:

    • Explore different blinking patterns, change the color of the RGB LED to suit your preferences.

Codes

import time
from smd.red import *
from serial.tools.list_ports import comports
from platform import system

def USB_Port():
    """
    Detects the USB serial port based on the operating system.
    Returns the detected port or None if no suitable port is found.
    """
    ports = list(comports())
    usb_names = {
        "Windows": ["USB Serial Port"],  # Serial port names specific to Windows
        "Linux": ["/dev/ttyUSB"],        # Serial port names specific to Linux
        "Darwin": [                      # Serial port names specific to macOS
            "/dev/tty.usbserial",
            "/dev/tty.usbmodem",
            "/dev/tty.SLAB_USBtoUART",
            "/dev/tty.wchusbserial",
            "/dev/cu.usbserial",
        ]
    }
    
    # Get the operating system name
    os_name = system()
    if ports:
        for port, desc, hwid in sorted(ports):
            # Check if any known USB name matches the port or its description
            if any(name in port or name in desc for name in usb_names.get(os_name, [])):
                print("Connected to:", port)
                return port
        # If no suitable port is found, display all available ports
        print("Available ports:")
        for port, desc, hwid in ports:
            print(f"Port: {port}, Description: {desc}, HWID: {hwid}")
    else:
        print("No ports detected!")
    return None

# Detect the serial port dynamically
SerialPort = USB_Port()
if not SerialPort:
    print("No suitable USB port found! Exiting...")
    exit(1)

# Define constants
baudrate = 115200       # Baud rate for communication
ID = 0                  # ID of the SMD
rgb_module_id = 5       # ID of the RGB LED module

try:
    # Initialize the Master module for communication with the SMD
    master = Master(SerialPort, baudrate)       # Sets up the USB gateway module
    master.attach(Red(ID))                      # Connects to the SMD with the specified ID
    master.scan_modules(ID)                     # Scans and identifies connected modules to the SMD

    # RGB LED control loop
    while True:
        # Set the RGB LED to red
        master.set_rgb(ID, rgb_module_id, 255, 0, 0)        # RGB values: 255 (Red), 0 (Green), 0 (Blue)
        time.sleep(0.5)                                     # Delay to control blinking frequency
        # Turn off the RGB LED
        master.set_rgb(ID, rgb_module_id, 0, 0, 0)          # RGB values: 0 (All colors off)
        time.sleep(0.5)                                     # Delay to control blinking frequency

except FileNotFoundError as e:
    # Handle the case when the serial port is not found
    print(f"Error: {e}")
    print("Make sure the specified serial port exists and is connected.")
except Exception as e:
    # Handle any unexpected errors
    print(f"Unexpected error: {e}")                                    # Value can be changed to see how the blinking frequency changes
#include <Acrome-SMD.h>

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

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

int rgb_module_id = 1;              // ID of the RGB LED module
void setup() {
    master.begin();                 // Starts the communication
    master.scanModules();           // Scans for the connected modules
}

void loop() {
    master.setRGB(rgb_module_id, 255, 0, 0);    // Numbers are correspond to the R - G - B color values
    delay(500);                                 // Value can be changed to see how the blinking frequency changes
    master.setRGB(rgb_module_id, 0, 0, 0);      // Sets all colors to zero, meaning turning the RGB LED off
    delay(500);                                 // Value can be changed to see how the blinking frequency changes
}

()

()

()

The SMD acts as a bridge between the script and the . It is responsible for interpreting the commands sent by the script and translating them into actions that toggle the RGB module.

The is designed to emit different colors, allowing users to experiment with different lighting effects.

The user can easily control the LED of the colors by simply using the necessary function of SMD libraries. The LED on the module can emit all RGB color values.

Connect the SMD to the PC or Arduino board using or .

Connect the to the SMD using an RJ-45 cable.

Run the script on your computer. This will establish communication with the SMD and initiate control of the .

SMD USB Gateway
Purchase Here
Arduino Gateway Module
Purchase Here
RGB LED Module
Purchase Here
SMD
RGB LED Module
RGB LED Module
RGB LED Module
SMD Libraries
RGB LED Module
USB Gateway Module
Arduino Gateway Module
RGB LED Module
RGB LED Module
SMD
RGB LED Module
the SMD libraries
SMD Red
Purchase Here
"Blink" Project