Web
Analytics
 
 

Getting Started with the ESP32 Voyager and Explorer!

In our last post, we introduced and gave a brief overview of two of our newest and most exciting robots, the ESP32 Voyager, and the ESP32 Explorer. In this tutorial, we'll be going over everything you'll need to get started having a blast using your ESP32 Voyager or Explorer! If you've picked up one of our ESP32 based robotics kits, we hope you have a blast programming and exploring with your bot! If you haven't yet picked one up, you can join the exciting community of robot explorers by picking one up in our shop here:


https://www.anyonecanbuildrobots.com/product-page/esp32-voyager-robotics-kit


Let's get started! If you've never written programs for, or uploaded programs to the ESP32, then this is just the place for you! If you've developed programs for Arduino, then a lot of this info will seem familiar. Regardless, the first step is to download the Arduino IDE! If you already have the Arduino IDE installed, be sure to update. At the time of writing this tutorial, I'm using version 1.8.11, and a newer version may be available. Now you have the ability to use most Arduino compatible boards without any additional setup, but to get the ESP32 working, we need a few extra steps, listed here. If you'd like to see this process live, feel free to check out our video here.





Part One: Setting up the ESP32 with the Arduino IDE

The first step is heading over to the "preferences" menu, under the "file" tab.

Next, with the preferences menu open, you'll want to click on the small button that looks like two boxes, next to the area labeled "Additional Boards Manager URLs:" highlighted here.

Once you click on that button, you'll be greeted with a screen that will let you paste in URLs that will allow you to install different development boards. You more than likely won't have as many as we do here, don't worry about that. On a new line, you'll want to past the following URL.


https://dl.espressif.com/dl/package_esp32_index.json


Then hit ok, and you're all set for step two!

Next, you'll want to head to the "tools" tab, then select "board", then click on the "board manager", just like we have here.

This will open up the board manager! In the search bar, you'll want to type "esp32", then hit install on the Espressif Systems board pack, and you're all set! You'll want to exit out of Arduino, and start it back up. Once you have, you're ready to upload code onto your ESP32 Voyager!

Part Two: Getting your Voyager and Explorer Rolling!

Alright, now that we have the Arduino all setup, it's time to write our first ESP32 program. Now at this point, I want to mention that the ESP32 is much more powerful than a standard Arduino, and there are a few ways to create the PWM signals we need to control our motor drivers! There is an easy way, and then there is the correct way. Not that the way presented in this tutorial is wrong, it's just simplified! For more advanced programs, and integrating servos, and other features, I highly recommend checking out some of our other ESP32 tutorials that cover those concepts in greater detail. The goal of this tutorial is to show you just how easy it is to get a basic program working for your ESP32 Voyager or Explorer! We'll start with a simple example that drives our robot forward! In order to compile this code, you'll need to download and install the "ESP32 AnalogWrite" library. It can be found here:


https://github.com/ERROPiX/ESP32_AnalogWrite


Once the GitHub page is open, select "clone or download", and download the file as a .zip. Then head back over to Arduino and click on the "Sketch" tab, then "Include Library", and "Add .Zip library". Then find that zip file you just downloaded. Exit out of the Arduino IDE one last time, and open it back up!


Now that may have seemed like quite a few steps, but the good news is, we only need to do all of that once. Now that we have the board files added, and the library installed we're ready to write our first program. This first program will simply drive our robot forward!


/* Hey guys! 
 * This code is designed to act as a simple exmaple 
 * to control the ESP32 Voyager, and Explorer Robot.  
 * This example will simply drive the robot forward
 * Feel free to alter, or customize this code as 
 * you'd like.  Have fun!
 * 
 * - Matt ACBR 2020
 */
#include <Arduino.h>
#include <analogWrite.h>
 
int inOne = 12;          //The pins of the DRV8871 are hardwired to  
int inTwo = 13;          //pins 12 and 13 for motor 1, pins 16 and 17  
int inThree = 16;        //for motor 2, pins 23 and 22 for motor 3, and 
int inFour = 17;         // pins 2 and 15 for motor 4.
int inFive = 23;
int inSix = 22;
int inSeven = 2;
int inEight = 15;

 
void setup(){
pinMode(inOne, OUTPUT);     //All of our drv8871 pins are outputs
pinMode(inTwo, OUTPUT); 
pinMode(inThree, OUTPUT);
pinMode(inFour, OUTPUT); 
pinMode(inFive, OUTPUT);
pinMode(inSix, OUTPUT); 
pinMode(inSeven, OUTPUT);
pinMode(inEight, OUTPUT); 
}

void loop(){
analogWrite(inOne, 0);          //motor one backward   
analogWrite(inTwo, 255);        //motor one forward   
analogWrite(inThree, 0);        //motor two backward   
analogWrite(inFour, 255);       //motor two forward   
analogWrite(inFive, 0);         //motor three backward   
analogWrite(inSix, 255);        //motor three forward   
analogWrite(inSeven, 0);        //motor four backward   
analogWrite(inEight, 255);      //motor four forward
}

That's it! Pretty simple right?? Now admittedly, to add in wireless control, servos, and sensors, this code can get pretty complicated pretty quickly, but the barebones code you need to get rolling is pretty simple! Let's go ahead and break this down a little bit!

Here's the code we have about our void setup.

int inOne = 12;          //The pins of the DRV8871 are hardwired to 
int inTwo = 13;          //pins 12 and 13 for motor 1, pins 16 and 17 
int inThree = 16;        //for motor 2, pins 23 and 22 for motor 3, and
int inFour = 17;         // pins 2 and 15 for motor 4.
int inFive = 23;
int inSix = 22;
int inSeven = 2;
int inEight = 15;

If you've written code for other motor drivers in the past, then this code might seem a little strange. In many common motor driver chips, you typically have one variable for speed, and two for direction, but the motor driver we use in these robots is the DRV8871, and it is an awesome little chip for a few good reasons. The first is that is really small, really affordable, and really powerful. The second is that we can control both the speed and the direction of a DC motor with only two variables. In this case, inOne and inTwo control our first motor, inThree and inFour control our second motor, inFive and inSix control our third motor, and inSeven and inEight control our fourth motor.


Each variable corresponds to the speed of your motor in one direction, therefore sending a PWM signal to inOne and motor one may spin clockwise, but spend a PWM signal to inTwo, and that same motor would spin counterclockwise! This example will be made more clear in the code we have in our void loop. Let's keep going!

void setup(){
    pinMode(inOne, OUTPUT);      //All of our drv8871 pins are outputs
    pinMode(inTwo, OUTPUT); 
    pinMode(inThree, OUTPUT);
    pinMode(inFour, OUTPUT); 
    pinMode(inFive, OUTPUT);
    pinMode(inSix, OUTPUT); 
    pinMode(inSeven, OUTPUT);
    pinMode(inEight, OUTPUT); 
    }
<