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); 
    }

This is the code from our void setup, and it's pretty straight forward. We're not taking in any data here, we're simply planning on sending signals out from our ESP32, and into our motor drivers. Let's take a look at our void loop!

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
  } 

We stated earlier that every set of two variables corresponds to one motor, so in this first example, we've got all four motors going full speed (255) forward, and off in the backward direction (0), and so our robot will drive forward! When you're wiring up your motors, be sure to follow the same wiring pattern we follow in our video if you'd like your code to match ours in terms of your robot's direction.


Part Three: Let's upload our code!

Alright, now that we have our first simple example written, it's time to upload it to our ESP32! The first step will be making sure we have the ESP32 connected to the IDE properly. To do that you'll want to head back over to the tools tab, and check on a few things.

First things first, under the "board:" make sure you select the "DOIT ESP32 DEVKIT V1". The upload speed, flash frequency and debug level are standard, and shouldn't need to be changed. The last important thing to check is that under the port menu, you take the time to click on the com port that your ESP32 is using. The number of your COM port will more than likely be different than the one listed here, which is no big deal. The most important thing is that you see the small check mark next to the COM port.


Once you have that all figured out, it's time to hit the "upload" button to send over your code! This is the button with the arrow on it in the upper left hand corner of the screen. Before you do, you'll need to know about one last step, and it's really important. In order to get the ESP32 into upload mode, you have to press the "boot" button located on the board as you upload. Once you hit the upload button, you'll see a message that says "connecting..." then press the boot button, and hold it until you see the message change to "uploading..." Once you see the message change to "Leaving..." then you know your code is all uploaded and ready to go! All that's left now is testing it!


Make sure your robot is not sitting on the table, pick it up, and try turning it on! If all four motors start to spin forward, then you're done! You have officially written your first program for your ESP32 Voyager!


Part Four: Take things further!

Now that you can upload programs to your ESP32 Voyager there are all kinds of awesome things you can do! If you head to our other tutorial for the ESP32 Voyager here:


https://www.anyonecanbuildrobots.com/post/the-esp32-voyager-the-ultimate-open-source-esp32-adventure-robot


you'll find the source code for adding in PS3 control as well as servo code for the robotic arm!


If you'd like to mess around with more autonomous control, feel free to try out this example with more commands! This last example will allow you to chain together multiple directions to build all kinds of fun software. We hope you guys have a blast using the ESP32 Voyager. We had a blast developing it!

/* Hey guys! 
 * This code is designed to act as a simple exmaple 
 * to control the ESP32 Voyager, and Explorer Robot.  
 * This example wil drive the robot forward, backward,
 * left, and right. 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(){
   forward();
   delay(3000);
   backward();
   delay(3000);
   left();
   delay(3000);
   right();
   delay(3000);
   }

void forward(){
  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
  }

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

void left(){
  analogWrite(inOne, 255);      //motor one backward
  analogWrite(inTwo, 0);        //motor one backward
  analogWrite(inThree, 255);    //motor two backward
  analogWrite(inFour, 0);       //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
  }

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

370 views0 comments

Anyone Can Build Robots!

1+ (858) 434 5830

©2020 by Anyone Can Build Robots!