Skip to content

Commit

Permalink
just need to add wiring diagrams and replace buck converter content w…
Browse files Browse the repository at this point in the history
…ith motor driver content
  • Loading branch information
tguyenn committed Sep 21, 2024
1 parent d3b7091 commit 46d55c9
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 37 deletions.
4 changes: 2 additions & 2 deletions docs/_sections/_guide-general/welcome.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ nav_order: 1

This guide aims to provide you with helpful information and direction throughout your robot building process. While this guide is broad, it stays mostly within the realm of setup and basic tips since we encourage you to discover your own solutions.

Finally, if you have any technical questions or don’t understand a topic, ask the mentors or during office hours, which can be found [here (soon™️)](link)! We can help to resolve your problems, or point you to the right person who can. Mentors, office hours, and other teammates are valuable resources to turn to if you are stuck.
If you have any technical questions or don’t understand a topic, ask the mentors or during office hours, which can be found [here (soon™️)](link)! We can help to resolve your problems, or point you to the right person who can. Mentors, office hours, and other teammates are valuable resources to turn to if you are stuck.

## Overview

The first section, Getting Started, is about getting familiar with the ESP32 microcontroller, the software build process, and embedded systems development in general. We highly recommend that you at least take a look at Environment Setup, as this page will streamline your development process and prevent a lot of environment errors you may get in the future.

The second section, Sensors and Actuators, goes into detail about the various peripherals you will be using in the competition, which include motors, distance sensors, line sensors, and color sensors.
The second section, Sensors and Actuators, goes into detail about the various peripherals you will be using in the competition, which include motors, distance sensors, line sensors, and color sensors. Note that all this information is adapted from sources found off the Internet, so Google is a very good resource for more information or different documentation.

The third section, Designing a Robot, covers the physical construction of a robot, as well as the resources Texas Inventionworks (TIW) provides to students.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,23 @@ Please reference the setup guide found in the [Robotathon Repo's readme!](https:
## Programming goal
For this tutorial, we will control the onboard microcontroller by toggling it on and off periodically. This will serve as the goal for the Blink Checkpoint and demonstrates that you can flash your own program to the ESP32. If you are having trouble configuring your development environment, reference the setup guide on our [Github (scroll down)](https://github.com/ut-ras/RobotathonESP32) or ask a mentor for help!

Once your environment is set up, you should be able to flash the program to your ESP32 by
1. Copying it into the ```arduino_main.cpp``` file
1. Pressing the fire icon (build + flash) in VSCode's bottom ribbon
1. Holding the BOOT button on the ESP32 (button to the right of the USB port that puts it into flashing mode)
1. Waiting until the Serial Monitor shows up

The following program will blink the onboard LED (pin 2) on the ESP32 every second:

{: .highlight}
Note: While it is good coding practice to leave comments in your code to make it more understandable, they should be used sparingly to explain complex code — the below example has a ton of comments for the sake of explanation.
Note: While it is good coding practice to leave comments in your code to make it more understandable, they should be used sparingly to explain complex code — the below example has many comments for the sake of explanation.
{: .callout-toby}

```cpp
#include "sdkconfig.h"
#include <Arduino.h>

int LED_BUILTIN = 2; // defines the word "LED_BUILTIN" as the number 2 for ease of use when defining and using the pin later
#define LED_BUILTIN 2; // defines the word "LED_BUILTIN" as the number 2 for ease of use/readability when using the pin later

void setup() {
pinMode(LED_BUILTIN, OUTPUT); // configures pin 2 to be a GPIO output pin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ nav_order: 4
---

# Microcontroller Interfacing
Microcontrollers are cool and all, but they’re a lot more interesting when you can use them to do stuff in the real world! You can connect all sorts of devices to the ESP32 microcontroller to do whatever your heart desires. Below is a picture of that describes what kinds of connections can be made with each pin:
Microcontrollers are cool and all, but they’re a lot more interesting when you can use them to do stuff in the real world! You can connect all sorts of devices to the ESP32 microcontroller to do whatever your heart desires.

Below is a picture of that describes what kinds of connections can be made with each pin:

<img src="{{ '/_assets/images/wroom_pinout.jpg' | prepend: site.baseurl }}" alt="wroom_pinout.jpg">

Expand All @@ -19,28 +21,25 @@ We are only concerned with pins that are power, ground, GPIO, and ADC enabled, s
* ADC (Analog to Digital Converter) - only some pins. These pins can read analog values instead of just high or low.

{: .highlight}
Note: Do NOT short (connect) a power pin directly to a ground pin. This will likely fry your ESP32 by causing a huge surge of current.
Note: Do NOT short (connect) a power pin directly to a ground pin. This will likely fry your ESP32 and more by causing a huge surge of current.
{: .callout-toby}

For this competition, you will be able to control your robot with a wireless game controller.

It would be impractical to power your ESP32 through your laptop with a super long cable, so you will use a battery pack feeding through a buck converter to power the 5V pin of the ESP32.
You can power your ESP32 by 2 methods: USB connection to laptop or external battery pack.

<img src="{{ '/_assets/images/buck_converter.png' | prepend: site.baseurl }}" alt="buck_converter.png" width=400 height=400>
{: .highlight}
Note: Do NOT power your ESP32 through its 5V pin using the battery pack while simultaneously connecting it to your computer!! This may damage your devices (please only do one at a time).
{: .callout-toby}

You will use this buck converter to reduce the voltage of the battery pack down to a level the ESP32 can tolerate (5V). Here are the steps to interface the battery pack to the ESP32 (assumes ESP32 is seated in breadboard):
The USB connection is necessary for uploading and debugging your code through the serial monitor.

1.) Connect the red wire from the battery pack to the IN+ on the buck converter and the black wire from the battery pack to the IN- on the buck converter
For this competition, you will be able to control your robot with a wireless game controller to navigate around the field (sensor challenges should be completed autonomously). It would be impractical to power your ESP32 through your laptop with a super long cable all the time, so you will use an external battery pack feeding through a buck converter to power the 5V pin of the ESP32.

2.) Grab a multimeter, put it into voltage reading mode, and attach the leads to OUT+ and OUT-. Rotate the small yellow screw on the buck converter counterclockwise until the multimeter reads a voltage of 5V.
<img src="{{ '/_assets/images/buck_converter.png' | prepend: site.baseurl }}" alt="buck_converter.png" width=400 height=400>

3.) Remove the multimeter leads and attach a red wire from the buck converter's OUT+ terminal to the ESP32's 5V pin. Attach a black wire from the buck converter's OUT- terminal to the ESP32's GND pin.
You will use this buck converter to reduce the voltage of the battery pack down to a level the ESP32 can safely use (5V). Here are the steps to interface the battery pack to the ESP32 (assumes ESP32 is seated in breadboard):

(((insert picture of wire diagram here)))

{: .highlight}
Note: Do NOT power your ESP32 through its 5V pin using the battery pack while simultaneously connecting it to your computer!! This may seriously damage either of your devices (please only do one at a time).
{: .callout-toby}

If you want to know more about any features, feel free to ask a mentor or Google for more information :)

Expand Down
38 changes: 19 additions & 19 deletions docs/_sections/_guide-primaries/sensors-and-actuators/actuators.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ A motor controller, such as the L298N, acts as an intermediary between the micro
* PWM (Pulse Width Modulation) Control: This enables speed control by varying the duty cycle of the PWM signal.
* Power Supply Terminals: These provide the necessary power to the motor.

The following information is an adapted version of [this guide.](https://lastminuteengineers.com/l298n-dc-stepper-driver-arduino-tutorial/)

# How to Use Motor and Controller?
To control a DC motor using an ESP32 and a motor controller, you need to directly connect the power source and ESP32 to the motor controller as shown below:
<br>
<img src="{{ '/_assets/images/l298n_driver_pinout.png' | prepend: site.baseurl }}" alt="l298n_driver_pinout.png" width="300" height="400">

Power: Connect the motor controller's 12V terminal to a power source less than 12V
<br>
Motor Controller Power: Connect the motor controller's 12V terminal to a power source less than 12V
Motor Power: Connect the motor leads into the terminals with 2 slots. Polarity (order of red and black wires) do not matter because DC motors are designed to run either direction based on the current direction running through them.
Control Pins: Connect the control pins (e.g., IN1, IN2, ENA) on the motor controller to the GPIO pins on the ESP32.
<br>

| Motor Wire | Motor Controller Terminal |
|:-------------|:------------------|
Expand All @@ -42,10 +45,11 @@ Control Pins: Connect the control pins (e.g., IN1, IN2, ENA) on the motor contro
| +5V | 5V |
| IN1 | Any GPIO |
| IN2 | Any GPIO |
| ENA | Any GPIO |
| ENA | Any PWM enabled pin |

The following is an example of configuring and running the motor in software:
```cpp

#include "sdkconfig.h"
#include <Arduino.h>

Expand All @@ -61,24 +65,18 @@ void setup() {
}

void loop() {
// Move motor forward
// Spin motor
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
// analogWrite(ENA, 128); // Set speed (0-255)
analogWrite(ENA, 255);

delay(2000); // Run for 2 seconds
delay(1000); // Run for 1 second

// Stop motor
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
analogWrite(ENA, 0);

delay(2000);

// Move motor backward
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
// analogWrite(ENA, 128); // Set speed (0-255)
delay(1000); // Stop for 1 second
}
```
More detailed information about the L298N motor controllers can be [found here!](https://lastminuteengineers.com/l298n-dc-stepper-driver-arduino-tutorial/)
Expand All @@ -105,22 +103,24 @@ For the servos in our competition, you can use it to precisely control your mech
If you're not sure which ESP32 pins are hardware PWM capable, then check out the diagram in [this page!](https://ut-ras.github.io/RobotathonESP32/getting-started/microcontroller-interface)
{: .callout-toby}

In this competition, we will be using the Arduino servo library to control the servos. The following is an example of how to configure the servo:
In this competition, we will be using the Arduino servo library to control the servos. The following is an example of how to spin a servo using the ESP32's pin 2 as the PWM output.

```cpp
#include "sdkconfig.h"
#include <Arduino.h>

#include <ESP32Servo.h>

Servo myservo;
Servo myServo;

void setup() {
myservo.attach(9);
myservo.writeMicroseconds(1500); // set servo to mid-point
myServo.attach(2);
myServo.write(1750);
}

void loop() {}
void loop() {

}
```

Simply input a different value in the ```writeMicroseconds()``` function to change how the servo behaves!
Simply input a different value in the ```write()``` function to change how the servo behaves! See [this official Arduino guide for more info](https://www.arduino.cc/reference/en/libraries/servo/write/)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The TCS34725 from Adafruit will allow you to complete the Color Challenge.
<img src="{{ '/_assets/images/color_sensor.jpg' | prepend: site.baseurl }}" alt="color_sensor.jpg" width=300 height=300>

## How it Works
The RGB sensor uses the RGB color space to represent the color that it sees through photodiodes. It provides the data in integer values of 0-255, represented in 8 binary bits. We will grab that data using a communication protocol called I2C, which is used in many electrical devices. Implementing I2C is out of the scope of this competition, but you can find more information about it [here.](https://learn.sparkfun.com/tutorials/i2c/all)
The RGB sensor uses the RGB color space to represent the color that it receives through photodiodes. It provides the R G and B data in integer values of 0-255 (8 bit representation). We will grab that data using a communication protocol called I2C, which is used in many electrical devices. Implementing I2C is out of the scope of this competition, but you can find more information about it [here.](https://learn.sparkfun.com/tutorials/i2c/all)

If you want more details on how the color sensor works, check out [this link!](https://www.utmel.com/components/everything-you-know-about-tcs34725-color-sensors-faq?id=1986)

Expand All @@ -27,6 +27,8 @@ If you want more details on how the color sensor works, check out [this link!](h
Make sure to connect the color sensor's power pin to 3.3V! A 5V connection will fry the sensor.
{: .callout-toby}

insert wiring diagram here

## Programming
For this tutorial, we’re only going to be reading the RGB sensor values from the TCS34725. Make sure that your pins are correctly connected or otherwise you won’t receive the data!

Expand Down

0 comments on commit 46d55c9

Please sign in to comment.