Lesson 13.5: miniAuto Car Assembly

Building Your Complete Arduino Robot Car

๐Ÿ“– Official Assembly Guide:

Hiwonder miniAuto Section 1.3 - Hardware Assembly โ†’

๐ŸŽฏ Learning Objectives

Assembly Goals:

  • โ€ข Assemble complete miniAuto robot car
  • โ€ข Connect all sensors and actuators
  • โ€ข Test individual components
  • โ€ข Troubleshoot common issues

Skills Developed:

  • โ€ข Mechanical assembly
  • โ€ข Electrical wiring
  • โ€ข System integration
  • โ€ข Problem-solving

๐Ÿ“ฆ Section 1: Parts Inventory

Mechanical Components:

  • โ€ข Chassis frame
  • โ€ข 4x DC motors with wheels
  • โ€ข Motor brackets
  • โ€ข Screws and spacers
  • โ€ข Battery holder

Electronic Components:

  • โ€ข Arduino Uno
  • โ€ข Motor driver (L298N)
  • โ€ข Ultrasonic sensor
  • โ€ข IMU sensor
  • โ€ข Jumper wires

๐Ÿ“š Official Documentation

๐Ÿ”—

Hiwonder miniAuto Official Wiki

Complete assembly guide, programming examples, and troubleshooting

๐Ÿ“– View Official Documentation โ†’

๐Ÿ“‹ What You'll Find:

  • โ€ข Detailed Assembly Instructions: Step-by-step photos and diagrams
  • โ€ข Wiring Diagrams: Complete connection guides for all components
  • โ€ข Programming Examples: Ready-to-use Arduino code samples
  • โ€ข Troubleshooting Guide: Solutions for common assembly issues
  • โ€ข Advanced Projects: Line following, obstacle avoidance, and more

๐Ÿ—๏ธ Section 2: Assembly Steps

Step-by-Step Assembly:

  1. Mount motors to chassis with brackets
  2. Attach wheels to motor shafts
  3. Install Arduino mounting plate
  4. Secure battery compartment
  5. Mount ultrasonic sensor at front
  6. Connect all wiring per diagram

โšก Section 3: Wiring Connections

Motor Driver Pins:

  • โ€ข ENA โ†’ Pin 3
  • โ€ข IN1 โ†’ Pin 4
  • โ€ข IN2 โ†’ Pin 5
  • โ€ข IN3 โ†’ Pin 6
  • โ€ข IN4 โ†’ Pin 7
  • โ€ข ENB โ†’ Pin 8

Sensor Pins:

  • โ€ข Ultrasonic Trig โ†’ Pin 9
  • โ€ข Ultrasonic Echo โ†’ Pin 10
  • โ€ข IMU SDA โ†’ A4
  • โ€ข IMU SCL โ†’ A5
  • โ€ข Power: 5V and GND

๐Ÿงช Section 4: Component Testing

Comprehensive Motor Test (Manufacturer Code):

/**
 * @file miniAuto_comprehensive_test.ino
 * @brief Comprehensive Motor and System Test Program
 * @author miniAuto Team / Hiwonder
 * @version V1.0
 * @date 2024-04-22
 * 
 * Motor Layout (numbers correspond to motorpwmPin[4] and motordirectionPin[4] indices):
 * [0] --|||--[1]       
 *  |          |        ^ counterclockwise
 *  |          |        |
 *  |          |        |
 *  |          |        |
 * [3] -------[2]
 */

#include <Arduino.h>

const static uint8_t pwm_min = 2;
const static uint8_t motorpwmPin[4] = {10, 9, 6, 11};        // Motor speed control pins
const static uint8_t motordirectionPin[4] = {12, 8, 7, 13};  // Motor direction control pins

void Motor_Init(void);
void Velocity_Controller(uint16_t angle, uint8_t velocity, int8_t rot, bool drift);
void Motors_Set(int8_t Motor_0, int8_t Motor_1, int8_t Motor_2, int8_t Motor_3);
void testSensors();

void setup() {
    Serial.begin(9600);
    Serial.setTimeout(500);
    Serial.println("๐Ÿค– miniAuto Comprehensive Assembly Test");
    
    Motor_Init();  // Initialize motors
    
    // Comprehensive motor movement test
    Serial.println("Testing omnidirectional movement...");
    
    Serial.println("โ†’ Forward");
    Velocity_Controller(0, 50, 0, 0);    // Move forward
    delay(1000);
    
    Serial.println("โ†— Left-Forward diagonal");
    Velocity_Controller(45, 50, 0, 0);   // Move left forward
    delay(1000);
    
    Serial.println("โ† Left");
    Velocity_Controller(90, 50, 0, 0);   // Move left
    delay(1000);
    
    Serial.println("โ†™ Left-Backward diagonal");
    Velocity_Controller(135, 50, 0, 0);  // Move left backward
    delay(1000);
    
    Serial.println("โ†“ Backward");
    Velocity_Controller(180, 50, 0, 0);  // Move backward
    delay(1000);
    
    Serial.println("โ†˜ Right-Backward diagonal");
    Velocity_Controller(225, 50, 0, 0);  // Move right backward
    delay(1000);
    
    Serial.println("โ†’ Right");
    Velocity_Controller(270, 50, 0, 0);  // Move right
    delay(1000);
    
    Serial.println("โ†— Right-Forward diagonal");
    Velocity_Controller(315, 50, 0, 0);  // Move right forward
    delay(1000);
    
    Serial.println("โ†บ Rotate left in place");
    Velocity_Controller(0, 0, 50, 0);    // Turn left in place
    delay(1000);
    
    Serial.println("โ†ป Rotate right in place");
    Velocity_Controller(0, 0, -50, 0);   // Turn right in place
    delay(1000);
    
    Serial.println("๐ŸŒช๏ธ Drift mode");
    Velocity_Controller(0, 100, 50, 1);  // Drift movement
    delay(1000);
    
    Serial.println("โน๏ธ Stop");
    Velocity_Controller(0, 0, 0, 0);     // Stop all motors
    
    // Test other systems
    testSensors();
    
    Serial.println("โœ… Assembly test complete - All systems operational!");
}

void loop() {
    // System monitoring
    Serial.print("Battery Status: ");
    // Add battery monitoring code here
    Serial.println("OK");
    delay(5000);
}

// Motor initialization function
void Motor_Init(void) {
    for(uint8_t i = 0; i < 4; i++) {
        pinMode(motordirectionPin[i], OUTPUT);
    }
    Velocity_Controller(0, 0, 0, 0);
}

/**
 * @brief Speed control function for omnidirectional movement
 * @param angle     Controls robot motion direction (0-359ยฐ, front=0ยฐ, counterclockwise positive)
 * @param velocity  Controls robot speed (0-100)
 * @param rot       Controls rotation speed (-100 to 100, positive=counterclockwise)
 * @param drift     Enables drift mode (0=normal, 1=drift)
 */
void Velocity_Controller(uint16_t angle, uint8_t velocity, int8_t rot, bool drift) {
    int8_t velocity_0, velocity_1, velocity_2, velocity_3;
    float speed = 1;
    angle += 90;
    float rad = angle * PI / 180;
    
    if (rot == 0) speed = 1;  // Speed factor
    else speed = 0.5; 
    
    velocity /= sqrt(2);
    
    if (drift) {
        velocity_0 = (velocity * sin(rad) - velocity * cos(rad)) * speed;
        velocity_1 = (velocity * sin(rad) + velocity * cos(rad)) * speed;
        velocity_2 = (velocity * sin(rad) - velocity * cos(rad)) * speed - rot * speed * 2;
        velocity_3 = (velocity * sin(rad) + velocity * cos(rad)) * speed + rot * speed * 2;
    } else {
        velocity_0 = (velocity * sin(rad) - velocity * cos(rad)) * speed + rot * speed;
        velocity_1 = (velocity * sin(rad) + velocity * cos(rad)) * speed - rot * speed;
        velocity_2 = (velocity * sin(rad) - velocity * cos(rad)) * speed - rot * speed;
        velocity_3 = (velocity * sin(rad) + velocity * cos(rad)) * speed + rot * speed;
    }
    Motors_Set(velocity_0, velocity_1, velocity_2, velocity_3);
}

/**
 * @brief PWM and motor direction setting function
 * @param Motor_x   PWM and motor direction control values (calculated from mecanum wheel kinematics)
 */
void Motors_Set(int8_t Motor_0, int8_t Motor_1, int8_t Motor_2, int8_t Motor_3) {
    int8_t pwm_set[4];
    int8_t motors[4] = {Motor_0, Motor_1, Motor_2, Motor_3};
    bool direction[4] = {1, 0, 0, 1};  // Forward direction: left=1, right=0
    
    for(uint8_t i = 0; i < 4; ++i) {
        if(motors[i] < 0) direction[i] = !direction[i];
        else direction[i] = direction[i];

        if(motors[i] == 0) pwm_set[i] = 0;
        else pwm_set[i] = map(abs(motors[i]), 0, 100, pwm_min, 255);

        digitalWrite(motordirectionPin[i], direction[i]); 
        analogWrite(motorpwmPin[i], pwm_set[i]); 
    }
}

void testSensors() {
    Serial.println("Testing sensors...");
    // Add sensor testing code here
    Serial.println("โœ“ Sensors OK");
}

โœ… Assembly Verification

Pre-Programming Checklist:

  • โ€ข โœ“ Chassis is sturdy and wheels spin freely
  • โ€ข โœ“ All components securely mounted
  • โ€ข โœ“ Wiring matches reference diagram
  • โ€ข โœ“ Power system test passes
  • โ€ข โœ“ Motors respond to commands
  • โ€ข โœ“ Sensors provide readings
  • โ€ข โœ“ Ready for Lesson 14 programming!
โ† Lesson 13: Communication Protocols
Assembly Complete!
Lesson 14: Programming miniAuto โ†’