Circuit Documentation
Summary
This circuit is designed to control a pair of DC gearmotors using a DRV8833 motor driver, with an ESP32-C3 microcontroller as the central processing unit. The circuit also includes an Adafruit VL6180 Time of Flight (ToF) sensor for distance measurement. The ESP32-C3 microcontroller is responsible for driving the motors through the DRV8833 and for interfacing with the ToF sensor to read distance values.
Component List
Xiao ESP32 C3
- Description: A microcontroller board based on the ESP32-C3 chip, featuring Wi-Fi and Bluetooth capabilities.
- Pins: D7, D8, D9, D10, 3.3v, GND, VUSB, D6, D5, D4, D3, D2, D1, D0
Adafruit VL6180 Time of Flight Sensor
- Description: A sensor that measures distance using laser light time-of-flight technology.
- Pins: VCC, GND, SCL, SDA, GPIO, XSHUT
DRV8833 Motor Driver
- Description: A dual H-bridge motor driver capable of driving two DC motors.
- Pins: EEP, OUT1, OUT2, OUT3, OUT4, ULT, IN4, IN3, GND, VCC, IN1, IN2
Gearmotor DC Wheels Right
- Description: A DC gearmotor used for the right wheel of a mobile platform.
- Pins: PIN1, PIN2
Gearmotor DC Wheels Left
- Description: A DC gearmotor used for the left wheel of a mobile platform.
- Pins: PIN1, PIN2
Wiring Details
Xiao ESP32 C3
- 3.3v: Connected to DRV8833 VCC and Adafruit VL6180 VCC
- GND: Connected to DRV8833 GND and Adafruit VL6180 GND
- D5: Connected to DRV8833 IN4
- D4: Connected to DRV8833 IN3
- D3: Connected to DRV8833 IN2
- D2: Connected to DRV8833 IN1
- D1: Connected to Adafruit VL6180 SCL
- D0: Connected to Adafruit VL6180 SDA
Adafruit VL6180 Time of Flight Sensor
- VCC: Connected to Xiao ESP32 C3 3.3v
- GND: Connected to Xiao ESP32 C3 GND
- SCL: Connected to Xiao ESP32 C3 D1
- SDA: Connected to Xiao ESP32 C3 D0
DRV8833 Motor Driver
- VCC: Connected to Xiao ESP32 C3 3.3v
- GND: Connected to Xiao ESP32 C3 GND
- IN1: Connected to Xiao ESP32 C3 D2
- IN2: Connected to Xiao ESP32 C3 D3
- IN3: Connected to Xiao ESP32 C3 D4
- IN4: Connected to Xiao ESP32 C3 D5
- OUT1: Connected to Gearmotor DC Wheels Left PIN1
- OUT2: Connected to Gearmotor DC Wheels Left PIN2
- OUT3: Connected to Gearmotor DC Wheels Right PIN2
- OUT4: Connected to Gearmotor DC Wheels Right PIN1
Gearmotor DC Wheels Right
- PIN1: Connected to DRV8833 OUT4
- PIN2: Connected to DRV8833 OUT3
Gearmotor DC Wheels Left
- PIN1: Connected to DRV8833 OUT1
- PIN2: Connected to DRV8833 OUT2
Documented Code
#include <Wire.h>
#include <Adafruit_VL6180X.h>
#include <Adafruit_MotorShield.h>
// Define motor driver pins
#define MOTOR_A1_PIN 4 // Forward pin for motor A (Left Motor)
#define MOTOR_A2_PIN 3 // Backward pin for motor A
#define MOTOR_B1_PIN 1 // Forward pin for motor B (Right Motor)
#define MOTOR_B2_PIN 0 // Backward pin for motor B
// Initialize the distance sensor
Adafruit_VL6180X vl = Adafruit_VL6180X();
void setup() {
// Initialize serial communication
Serial.begin(115200);
Serial.println("Starting Test");
// Set motor pins as outputs
pinMode(MOTOR_A1_PIN, OUTPUT);
pinMode(MOTOR_A2_PIN, OUTPUT);
pinMode(MOTOR_B1_PIN, OUTPUT);
pinMode(MOTOR_B2_PIN, OUTPUT);
// Initialize the VL6180 sensor
if (!vl.begin()) {
Serial.println("Failed to find sensor");
while (1);
}
Serial.println("VL6180X sensor initialized");
}
void loop() {
// Read distance
uint8_t range = vl.readRange();
Serial.print("Distance: ");
Serial.print(range);
Serial.println(" mm");
// Drive motors forward
digitalWrite(MOTOR_A1_PIN, HIGH);
digitalWrite(MOTOR_A2_PIN, LOW);
digitalWrite(MOTOR_B1_PIN, HIGH);
digitalWrite(MOTOR_B2_PIN, LOW);
delay(1000);
// Stop motors
digitalWrite(MOTOR_A1_PIN, LOW);
digitalWrite(MOTOR_A2_PIN, LOW);
digitalWrite(MOTOR_B1_PIN, LOW);
digitalWrite(MOTOR_B2_PIN, LOW);
delay(1000);
// Drive motors backward
digitalWrite(MOTOR_A1_PIN, LOW);
digitalWrite(MOTOR_A2_PIN, HIGH);
digitalWrite(MOTOR_B1_PIN, LOW);
digitalWrite(MOTOR_B2_PIN, HIGH);
delay(1000);
// Stop motors
digitalWrite(MOTOR_A1_PIN, LOW);
digitalWrite(MOTOR_A2_PIN, LOW);
digitalWrite(MOTOR_B1_PIN, LOW);
digitalWrite(MOTOR_B2_PIN, LOW);
delay(1000);
}
This code is designed to run on the Xiao ESP32 C3 microcontroller. It initializes the Adafruit VL6180X ToF sensor and controls the DRV8833 motor driver to move the gearmotors attached to the wheels of a mobile platform. The code includes functionality to drive the motors forward and backward, as well as to read the distance from the ToF sensor and output it to the serial monitor.
