# ESP32

# Overview



# Flashing the ESP32

### What you need

- A computer with the [Arduino IDE](https://www.arduino.cc/en/software) installed
- Your ESP32
- A [USB-A to USB Micro-B](https://upload.wikimedia.org/wikipedia/commons/d/db/MicroB_USB_Plug.jpg) cable, to connect to your computer

### Preliminary steps

##### Make sure your USB cable can transmit data

A fully-featured USB 2 cable contains 4 wires: two are used for power transmission, and two for data. Some cables, especially on the cheaper end, only wire up the two power wires, meaning those can't pass any information.

To test your cable, you can try to plug in something that can trasmit data to your computer with that cable. An older phone, another microcontroller, a printer, whatever you might have to make sure it's known good.

<p class="callout warning">The LED on the ESP32 lighting up does not mean the cable can tramsit data. All cables will be wired for power, thus the LED will always turn on, even with a bad cable</p>


##### Install the required Arduino libraries

<p class="callout info">The library versions are susceptible to change if you read this page late after it was last updated</p>

<table border="1" id="bkmrk-via-the-taskbar-on-t" style="border-collapse: collapse; width: 100%; height: 930.067px;"><colgroup><col style="width: 50.0494%;"></col><col style="width: 50.0494%;"></col></colgroup><tbody><tr><td colspan="2"><span style="text-decoration: underline;">**SSR1 - OSR2 - SR6**</span>

</td></tr><tr style="height: 435.167px;"><td style="height: 435.167px;">This library offers support for the ESP32 to the Arduino IDE, and is mandatory if you use an ESP32.

Via the taskbar on the left, click on the Boards Manager. Search for "ESP32", and install the `esp32` library by *Espressif Systems*

</td><td style="height: 435.167px;">[![image.png](https://osr.wiki/uploads/images/gallery/2023-12/scaled-1680-/image.png)](https://osr.wiki/uploads/images/gallery/2023-12/image.png)</td></tr><tr style="height: 35.2px;"><td colspan="2" style="height: 35.2px;"><span style="text-decoration: underline;">**SSR1 only**</span>

</td></tr><tr style="height: 459.7px;"><td style="height: 459.7px;">OSR2 and SR6 both use servomotors, but the SSR1 uses a BLDC (***B**rush**L**ess **D**irect **C**urrent*) motor, driven by an FOC controller, and we need two libraries to control it using the ESP32.

In the Library Manager tab, under the Boards Manager, search for "SimpleFOC". Install **both** the `Simple FOC` and `SimpleFOCDrivers` libraries, by *Simplefoc.*

<p class="callout warning">As of January 1st 2024, you **must** use specific versions of said libraries:  
Simple FOC <span style="text-decoration: underline;">**2.3.0**</span>  
SimpleFOCDrivers <span style="text-decoration: underline;">**1.0.4**</span>  
</p>

<p class="callout danger">Once installed, **do not update** them</p>

[![image.png](https://osr.wiki/uploads/images/gallery/2023-12/scaled-1680-/K4Jimage.png)](https://osr.wiki/uploads/images/gallery/2023-12/K4Jimage.png)

</td><td style="height: 459.7px;">[![image.png](https://osr.wiki/uploads/images/gallery/2023-12/scaled-1680-/EPoimage.png)](https://osr.wiki/uploads/images/gallery/2023-12/EPoimage.png)![image.png](https://osr.wiki/uploads/images/gallery/2023-12/scaled-1680-/9xLimage.png)  
</td></tr></tbody></table>

##### Install the USB drivers for the ESP32

ESP32 boards are designed and maintained by Espressif, who have [a handy guide on how to connect to them](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/establish-serial-connection.html#connect-esp32-to-pc).  
For our purpose, we only need the USB drivers, [to be downloaded from Silicon Labs' website](https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers?tab=downloads).

<p class="callout warning">ESP32 boards should possess a `cp2102` UART to USB chip, which handles talking to the computer over the USB cable. However, Espressif also lists FTDI as a possible manufacturer.  
</p>

<p class="callout warning">Check the chip circled in red on your own board, and make sure it has "SILABS" written on it before downloading and installing the Silicon Labs drivers.</p>

[![image.png](https://osr.wiki/uploads/images/gallery/2023-12/scaled-1680-/GnVimage.png)](https://osr.wiki/uploads/images/gallery/2023-12/GnVimage.png)

<p class="callout info">To install the Silicon Labs drivers, right click the `silabser.inf` file and select *Install*</p>

### Flashing the firmware  


1. Plug in your ESP32 to your computer.  
    With the Arduino IDE opened, select your board and COM port via the *Select Board* dropdown menu  
      
    [![image.png](https://osr.wiki/uploads/images/gallery/2023-12/scaled-1680-/Foiimage.png)](https://osr.wiki/uploads/images/gallery/2023-12/Foiimage.png)If you have installed the `esp32`library correctly, the board should show up under the name `DOIT ESP32 DEVKIT V1`. Select it.  
    The COM port number will vary, it might not be COM5, but COM3 or COM9 for example.  
      
    [![image.png](https://osr.wiki/uploads/images/gallery/2023-12/scaled-1680-/dQqimage.png)](https://osr.wiki/uploads/images/gallery/2023-12/dQqimage.png)
2. Click on the `Upload` button (the right-pointing arrow) once everything is in order  
      
    [![image.png](https://osr.wiki/uploads/images/gallery/2023-12/scaled-1680-/OD7image.png)](https://osr.wiki/uploads/images/gallery/2023-12/OD7image.png)
3. When the console shows a line saying "*Connecting...*" you *may* need to **press and hold** the `boot` button on your ESP32, until other lines show up, at which point you can release the button (not all boards require this).  
    Otherwise, it won't be able to be flashed, and you'll get an error  
      
    [![image.png](https://osr.wiki/uploads/images/gallery/2023-12/scaled-1680-/kNgimage.png)](https://osr.wiki/uploads/images/gallery/2023-12/kNgimage.png)
4. The end of the console output should look like this after the fact  
      
    **[![image.png](https://osr.wiki/uploads/images/gallery/2023-12/scaled-1680-/RiAimage.png)](https://osr.wiki/uploads/images/gallery/2023-12/RiAimage.png)**

<p class="callout success">**Congratulations!**  
You have successfully flashed your ESP32 microcontroller with your stroker's firmware.  
Next step: testing that all the axes move the right way.  
</p>