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
  • Step 1: Hardware & Software Overview
  • Step 2: Assemble
  • Step 3: Run & Test
  • Codes
  1. SMD Applications
  2. Interactive

Chrome Dino Game Player

PreviousRadarNextPlay Chrome Dino Game With Joystick

Last updated 2 months ago

The Chrome Dino Game Player project is an innovative application that combines hardware and software to spark the joy in robotic projects. There is a 100 RPM BDC Motor with an Encoder is used as an actuator, and an is used as the input sensor, to differentiate the dark colored obstacles from the free road

About Tools and Materials:

()

()

()

()

()

Step 1: Hardware & Software Overview

Project Key Components

  1. The SMD acts as a bridge between the script and the modules. It is responsible for interpreting the commands sent by the script and translating them into actions that read input from the and actuate the DC motor precisely.

  2. The 100 RPM BDC Motor with Encoder allows the user to press the spacebar when an obstacle is detected. The built-in encoder is the key to control the position of the motor, thus, the user can use the motor to rapidly and repeteadly press the key and get high scores.

  3. The is used to detect the emitted light differences of the dark obstacles and white free road. The module can differentiate thousands of levels of ambient light in terms of lux.

  4. The SMD library is at the heart of the application. It communicates with the SMD using a specific communication protocol, sending commands to read the and actuate the BDC motor.

Project Key Features

  • Dynamic Obstacle Detection

    The Ambient Light Sensor Module that is controlled by the SMD can detect surroundings ambient light intensity several times in a second. It allows to the system to be dynamic and responsive.

  • Responsive and Real-time Gameplay

    The script continuously monitors the ambient light level, it can be printed on the terminal for more precise control editings and monitoring.

Step 2: Assemble

Getting Started

  1. Hardware Setup

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

  2. Software Integration

    • Implement the cursor of the BDC motor to the spacebar of the keyboard, test the code if the motor can precisely press and release the spacebar. Change the position values in set_position function if key is not pressed and released correctly.

Project Wiring Diagram

Step 3: Run & Test

  1. Run the Application

    • Execute the script and launch the Chrome Dino Game.

    • Observe how the DC motor actuates according to the ambient light intensity and make high scores.

Codes

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

baudrate = 115200           # Baud rate of communication
ID = 0                      # ID of the SMD board
ambient_module_id = 5       # ID of the ambient light sensor module


def USB_Port():
    """
    Scans and identifies a compatible USB port for the current operating system.

    Returns:
        str: The detected USB port or None if no suitable port is found.
    """
    # Get a list of available ports
    ports = list(comports())
    
    # Known USB port names for different operating systems
    usb_names = {
        "Windows": ["USB Serial Port"],  # Names specific to Windows
        "Linux": ["/dev/ttyUSB"],        # Names specific to Linux
        "Darwin": [                      # Names specific to macOS
            "/dev/tty.usbserial",
            "/dev/tty.usbmodem",
            "/dev/tty.SLAB_USBtoUART",
            "/dev/tty.wchusbserial",
            "/dev/cu.usbserial",
        ]
    }

    # Detect the operating system
    os_name = system()
    print(f"Operating System: {os_name}")

    if ports:
        for port in ports:
            # Check if the port matches any known USB names
            if any(name in port.device or name in port.description for name in usb_names.get(os_name, [])):
                print(f"USB device detected on port: {port.device}")
                return port.device  # Return the first matching port
        # If no suitable port is found, print the list of available ports
        print("No suitable USB device found. Available ports:")
        for port in ports:
            print(f"Port: {port.device}, Description: {port.description}, HWID: {port.hwid}")
    else:
        print("No ports detected!")
    return None


try:
    # Find a valid serial port
    SerialPort = USB_Port()
    if not SerialPort:
        raise Exception("No compatible USB port found. Please check your connection.")

    print(f"Using serial port: {SerialPort}")

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

    # Motor and control configuration
    master.set_shaft_rpm(ID, 100)                               # Sets the RPM value of the motor
    master.set_shaft_cpr(ID, 6533)                              # Sets the CPR value of the motor
    master.set_operation_mode(ID, 1)                            # Sets the operation mode to 'Position Control'
    master.set_control_parameters_position(ID, 10, 0, 50)       # Sets the PID parameters, can be auto-tuned instead
    master.enable_torque(ID, 1)                                 # Enables the motor to spin if any command says so

    # Main loop
    while True:
        # Get ambient light data from the sensor
        light = master.get_light(ID, ambient_module_id)         # Variable to store the ambient light data
        print(f"Ambient light level: {light}")                  # Printing the value to observe

        if light < 30:                                          # If it detects obstacles (black reflects less light)
            master.set_position(ID, 1000)                       # Motor moves to the spacebar key location
            time.sleep(0.2)
            master.set_position(ID, 0)                          # Motor returns to the start position
        else:
            master.set_position(ID, 0)                          # Stays at the start position if there are no obstacles

except Exception as e:
    print(f"Error: {e}")
#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

int ambient_module_id = 1;          // ID of the ambient light sensor module

int light = 0;                      // Variable to store the ambient light data

void setup() {
    master.begin();                 // Starts the communication
    master.scanModules();           // Scans for the connected modules

    master.setMotorRPM(100);        // Sets the RPM value of the motor
    master.setMotorCPR(6533);       // Sets the CPR value of the motor

    master.setOperationMode(PositionControl);                           // Sets the operation mode to 'Position Control'
    master.setControlParameters(PositionControl, 10, 0, 50, 0, 0);       // Sets the PID parameters, can be auto-tuned instead
    master.torqueEnable(1);                                             // Enables the motor to spin if any command say so
}

void loop() {
    light = master.getLight(ambient_module_id);     // Getting the ambient light value and storing it
    
    if (light < 30) {                               // If it sees obstacles, which are black, so will emit less light than other colors
        master.setpoint(PositionControl, 1000);     // Motor goes to the spacebar key location, change position value if it doesn't reach
        delay(200);
        master.setpoint(PositionControl, 0);        // Motor goes back to the start position
    }

    else {
        master.setpoint(PositionControl, 0);        // Stays at the start position if there are no obstacles
    }
}

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

Connect the 100 RPM BDC Motor with Encoder to the motor ports of the SMD and the to the SMD using an RJ-45 cable.

Ambient Light Sensor Module
SMD Red
Purchase Here
SMD USB Gateway
Purchase Here
Arduino Gateway Module
Purchase Here
BDC Motor
Purchase Here
Ambient Light Sensor Module
Purchase Here
SMD
Ambient Light Sensor Module
BDC Motor
Ambient Light Sensor Module
Ambient Light Sensor Module
SMD Libraries
Ambient Light Sensor Module
USB Gateway Module
Arduino Gateway Module
Ambient Light Sensor Module