Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Michael
Published © GPL3+

AI Autonomous Room Rover Robot (A2R3) - (Part 2)

AI Autonomous Room Rover Robot - wheel encoders & odometry. Part 2 Series.

AdvancedWork in progress6 hours472

Things used in this project

Hardware components

ESP32 WROOM-32 dev board
×1
AS5600 Magnetic Encoder 12bit 3.3V High Precision Magnetic Induction Angle Measurement Sensor Module
×2
TCA9548A I2C Multiplexer
×1
RS390 gear box with 14000 RPM 6V DC motor
×1
Plastic Foam tire
×2
TB6612FNG DC motor driver
×1
20Volt lithium-ion battery pack
×1
VL53L0X Time-of-Flight (ToF) Laser Ranging Sensor
×1
MPU6050 6 DOF Sensor
×1
Buzzer speaker
×1

Software apps and online services

Arduino IDE
Arduino IDE
You can use any IDE of your choice

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)
Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Custom parts and enclosures

3D Model design parts

You can download 3D parts of the bot here

Schematics

BOM

Code

Wheel Odometry

Arduino
Simple odometry using AS5600 magnetic encoder connected to TCA9548A I2C multiplexer.
#include <Wire.h>

#define AS5600_ADDR 0x36           // I2C address for AS5600
#define TCA9548A_ADDR 0x70         // I2C address for TCA9548A

// Function to select the channel on the TCA9548A
void tca9548aSelect(uint8_t channel) {
  if (channel > 7) return;
  Wire.beginTransmission(TCA9548A_ADDR);
  Wire.write(1 << channel);
  Wire.endTransmission();
}

// Function to read the angle from AS5600
uint16_t readAS5600Angle() {
  uint16_t angle = 0;
  
  // Start communication with AS5600
  Wire.beginTransmission(AS5600_ADDR);
  Wire.write(0x0C);  // High byte of angle register
  if (Wire.endTransmission() != 0) {
    Serial.println("Error: I2C communication failed!");
    return 0; // Return 0 if communication fails
  }
  
  // Request 2 bytes from AS5600 (high and low angle bytes)
  Wire.requestFrom(AS5600_ADDR, 2);
  if (Wire.available() == 2) {
    angle = Wire.read() << 8; // High byte
    angle |= Wire.read();     // Low byte
  } else {
    Serial.println("Error: Failed to read from AS5600!");
    return 0; // Return 0 if reading fails
  }
  
  return angle;
}

void setup() {
  Serial.begin(115200);
  Wire.begin(); // Initialize I2C communication
  
  // Optional: Check if AS5600 is connected properly
  Wire.beginTransmission(AS5600_ADDR);
  if (Wire.endTransmission() != 0) {
    Serial.println("AS5600 not detected. Check wiring!");
    while (1); // Stop the program if AS5600 is not found
  }

  // Select TCA9548A channel 0 where AS5600 is connected
  tca9548aSelect(0);
}

void loop() {
  // Ensure TCA9548A channel 0 is selected before reading
  tca9548aSelect(0);

  // Read the raw angle from AS5600
  uint16_t angleRaw = readAS5600Angle();
  
  // Convert the raw angle to degrees (12-bit resolution)
  float angle = angleRaw * (360.0 / 4096.0);
  
  // Print the angle in degrees to the Serial Monitor
  Serial.println(angle);

  // Optional: Add a small delay to avoid flooding the Serial Monitor
  delay(100);
}

PID controller

The easiest implementation of PID control. I will update and refine it time to time. So you can check it out in GitHub

Credits

Michael
7 projects • 6 followers
Knack for Tech and Science! Computer scientist!
Contact

Comments

Please log in or sign up to comment.