> For the complete documentation index, see [llms.txt](https://guide.petoi.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://guide.petoi.com/petoi-web-coding-blocks/upload-firmware-using-arduino.md).

# Upload Firmware Using Arduino

This firmware upload method is intended for users familiar with Arduino IDE. For general users, please refer to the previous page: [Upload Firmware Using Petoi Desktop APP](https://guide.petoi.com/desktop-app/firmware-uploader). If you have already uploaded the firmware successfully, please proceed to the next page: [Get Started: Create Your First Block Program](/petoi-web-coding-blocks/get-started-create-your-first-block-program.md).

## Set up BiBoard

### Prepare the ESP32 development environment

Open “**Preferences**” in Arduino IDE, add ESP32 development board URL:

`https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json`

<figure><img src="https://docs.petoi.com/~gitbook/image?url=https%3A%2F%2F1565080149-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-MQ6a951Q6Jn1Zzt5Ajr-887967055%252Fuploads%252FBeD6sfV1LKR8HOsRvvef%252Fimage.png%3Falt%3Dmedia%26token%3D469f106e-c18c-4e7e-9e36-cac3ea9cdda5&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=75d0ba4e&#x26;sv=2" alt=""><figcaption></figcaption></figure>

<figure><img src="https://docs.petoi.com/~gitbook/image?url=https%3A%2F%2F1565080149-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-MQ6a951Q6Jn1Zzt5Ajr-887967055%252Fuploads%252Fm4kA0SnO0HlaNRggKhTV%252Fimage.png%3Falt%3Dmedia%26token%3D7b4d2178-dc79-402e-886e-bccd277bd1e8&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=f8cdc92a&#x26;sv=2" alt=""><figcaption></figcaption></figure>

Click **OK** to save it and then exit.

Open “**Boards Manager...**” and wait for updates from external board support links. Search “esp32” and install the support package.

{% hint style="warning" %}
Please install the latest available version **2.0.12**. Installing version 2.0.13 and above may cause the motherboard to fail to startup.
{% endhint %}

<figure><img src="https://docs.petoi.com/~gitbook/image?url=https%3A%2F%2F1565080149-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-MQ6a951Q6Jn1Zzt5Ajr-887967055%252Fuploads%252FkaI7GwGmYWxJLTksqswt%252Fimage.png%3Falt%3Dmedia%26token%3Ddda85ff5-f77c-4636-ae1d-1c4c49ef6618&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=d474360&#x26;sv=2" alt=""><figcaption></figcaption></figure>

<figure><img src="https://docs.petoi.com/~gitbook/image?url=https%3A%2F%2F1565080149-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-MQ6a951Q6Jn1Zzt5Ajr-887967055%252Fuploads%252Fymh9lMUwgWJEB2eHT2kv%252Fimage.png%3Falt%3Dmedia%26token%3D509f781c-fbbe-47e4-91ec-48e57d7eba8b&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=e4d6c4ea&#x26;sv=2" alt=""><figcaption></figcaption></figure>

After showing “**INSTALLED**”, the BiBoard board support package is finished.

### Modify the code file in the package

* #### sdkconfig.h

{% hint style="info" %}

* For Windows:\
  C:\Users\\{username}\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.\*\tools\sdk\esp32\qio\_qspi\include\sdkconfig.h
* For Mac:\
  /Users/{username}/Library/Arduino15/packages/esp32/hardware/esp32/2.0.\*/tools/sdk/esp32/qio\_qspi/include/sdkconfig.h
* For Ubuntu:\
  Arduino root directory/.arduino15 (hidden file)/packages/esp32/hardware/esp32/2.0.12/tools/sdk/esp32/qio\_qspi/include/sdkconfig.h
  {% endhint %}

Append a line of code at the end of the file:

```cpp
#define CONFIG_DISABLE_HAL_LOCKS 1
```

### Set up the board options

Please set up the board's upload speed, CPU frequency, etc, as shown in the picture below.&#x20;

<figure><img src="https://4130507397-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXLpFdG7mubqEHWylLK3w%2Fuploads%2FgXFZxgxK83uvD5MM4jHO%2FWechatIMG251.jpg?alt=media&amp;token=1182bc82-6312-4b7c-8a54-016f8351da18" alt=""><figcaption></figcaption></figure>

### Choose hardware partition

The **BiBoard V0** uses an ESP32 with a **16M** flash. To simplify, you can use the **default** **4 MB** partition map without a problem. There's plenty of programming space for the standard OpenCatEsp32 firmware.&#x20;

The **BiBoard V1** uses an ESP32 with a **4M** flash.

#### 4 MB partition

You can use the **Minimal SPIFFS (1.9MB APP with OTA/190KB SPIFFS)**. You can also use other partition schemes under the 4 MB flash limit, such as "No OTA" or "Huge APP".&#x20;

<figure><img src="https://4130507397-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXLpFdG7mubqEHWylLK3w%2Fuploads%2FPzeNfeABQEkXSmWTG8gc%2Fimage.png?alt=media&amp;token=c363e73d-7a17-4696-af80-2579d3620b7e" alt=""><figcaption></figcaption></figure>

#### 16 MB partition

Suppose you want to fully utilize the 16 MB flash on **BiBoard V0** (it's unnecessary and takes longer to upload). You can read the user manual for the [Add hardware partition configuration option in Arduino IDE](https://guide.petoi.com/biboard/demo-applications/13.add-hardware-partition-configuration-option-in-arduino-ide).

### Download the source code and install the libraries

{% hint style="info" %}
We keep updating the code as an open-source project. You can star-mark and follow our GitHub repository to get the newest features and bug fixes. You can also share your codes with worldwide OpenCatEsp32 users.&#x20;

You can check the update history information in the [**ChangeLog.md**](https://github.com/PetoiCamp/OpenCatEsp32/blob/main/ChangeLog.md)**.**
{% endhint %}

1. Download the ​OpenCatEsp32 repository from GitHub repository: <https://github.com/PetoiCamp/OpenCatEsp32>\
   We suggest you utilize GitHub’s version control feature. Otherwise, make sure you download the **WHOLE OpenCatEsp32 FOLDER** every time. All the codes have to be the same version to work together.&#x20;

<figure><img src="https://content.gitbook.com/content/XLpFdG7mubqEHWylLK3w/blobs/NtFNfmJKxNF67PIZnGxu/downloadEsp32Repo.png" alt=""><figcaption></figcaption></figure>

2. If you download the Zip file of the codes, you will get an **OpenCatEsp32-main** folder after unzipping. Please rename it to **OpenCatEsp32** before opening the **OpenCatEsp32.ino** so that the two names match.&#x20;

{% hint style="warning" %}
No matter where you save the folder, the file structure should be:

![](https://content.gitbook.com/content/XLpFdG7mubqEHWylLK3w/blobs/lR2Eg03luXKcY9YVr9E5/OpenCatEsp32_tree.png)&#x20;
{% endhint %}

There are several **test\*\*\*.ino** codes in the **ModuleTests** folder. You can upload them separately to test specific modules (I recommend using **testBuzzer.ino** as your first test sketch).

3. Install the libraries
   * Download and install the [MU Vision Sensor library](https://github.com/mu-opensource/MuVisionSensor3) into the Arduino IDE.<br>

     <figure><img src="https://docs.petoi.com/~gitbook/image?url=https%3A%2F%2F1565080149-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-MQ6a951Q6Jn1Zzt5Ajr-887967055%252Fuploads%252FrwlwHLV03mwtrtqVazop%252FmuLib.png%3Falt%3Dmedia%26token%3Df7721966-efb2-4388-9563-002c9aa93c3a&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=852f24b1&#x26;sv=2" alt=""><figcaption></figcaption></figure>

     <figure><img src="https://docs.petoi.com/~gitbook/image?url=https%3A%2F%2F1565080149-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-MQ6a951Q6Jn1Zzt5Ajr-887967055%252Fuploads%252FRN0NyFXOV0ct9IOI0AqU%252FaddZipLib.png%3Falt%3Dmedia%26token%3D4803980c-41cf-406c-907c-3aaff81672ec&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=13cd3321&#x26;sv=2" alt=""><figcaption></figcaption></figure>

   * Install **ArduinoJson** in the Library Manager<br>

     <figure><img src="https://content.gitbook.com/content/XLpFdG7mubqEHWylLK3w/blobs/eO42w2l2e4U4rlsJiHl1/image.png" alt=""><figcaption></figcaption></figure>

     <figure><img src="https://content.gitbook.com/content/XLpFdG7mubqEHWylLK3w/blobs/QPwdyskelzcVgWOiaItp/image.png" alt=""><figcaption></figcaption></figure>

   * Install **WebSockets** in the Library Manager.<br>

     <figure><img src="https://4130507397-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXLpFdG7mubqEHWylLK3w%2Fuploads%2FATxxuuyWaFQB4cJ4vp5T%2Fimage.png?alt=media&amp;token=012e8788-3e7b-4e1e-860e-24937e4e6675" alt=""><figcaption></figcaption></figure>

### Download firmware & Petoi Web Coding Blocks source code

* Download the latest version from [Github](https://github.com/PetoiCamp/OpenCatEsp32-Quadruped-Robot/tree/redesignWeb) .

  <figure><img src="https://4130507397-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXLpFdG7mubqEHWylLK3w%2Fuploads%2FaVkN2SNxXOXUnu6QxMtC%2Fimage.png?alt=media&amp;token=dfdc9bb6-1c1d-416f-af16-c056b4563c88" alt=""><figcaption></figcaption></figure>
* After the download is complete, unzip the downloaded file and rename the extracted folder "OpenCatEsp32-Quadruped-Robot" to "OpenCatEsp32".

<figure><img src="https://4130507397-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXLpFdG7mubqEHWylLK3w%2Fuploads%2FtFjf37TXsb7r7mUe9M4x%2Fimage.png?alt=media&amp;token=de6ad482-93d7-4188-ab64-e312c0601650" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
This is because the firmware file **OpenCatEsp32.ino** inside must be placed in a folder with the same name.

If you skip this step and try to open **OpenCatEsp32.ino** directly, you will be prompted that it should be placed in a folder with the same name. This will complicate the process, and unless you are very familiar with Arduino's firmware upload procedure, we strongly do not recommend doing so.

<img src="https://4130507397-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXLpFdG7mubqEHWylLK3w%2Fuploads%2FEgaPGVMtjAWG0QJzXcUP%2FWeChat5c3c50baab41f30b8beb62e8357e6aa4.jpg?alt=media&amp;token=8e08f381-7a3e-438f-8411-3106d598fb01" alt="" data-size="original">
{% endhint %}

* Open the **OpenCatEsp32.ino** file in the folder.

  <figure><img src="https://4130507397-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXLpFdG7mubqEHWylLK3w%2Fuploads%2FO8QeA4XeFUKqYBEHrHIT%2Fimage.png?alt=media&amp;token=b55b024e-7873-43bc-a6e1-27d4e1a57ef6" alt=""><figcaption></figcaption></figure>

### [Connect to BiBoard](/quick-reference/upload-firmware.md#biboard) via USB type-C data cable

Set the serial port in the Arduino IDE.

&#x20;(Please note : For Mac user, only choose the **/dev/cu.wchusbserial** port here) :

<figure><img src="https://4130507397-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXLpFdG7mubqEHWylLK3w%2Fuploads%2FPkaVG9XRBogh9jQUyerX%2Fimage.png?alt=media&amp;token=d4c465ec-5fc4-44b0-9e6c-c3aee4a47feb" alt=""><figcaption></figcaption></figure>

### 1.7 Compile and upload the firmware

Modify the product type macro definition in **OpenCatEsp32.ino** according to the product type you used. e.g.: **Bittle**

```cpp
3  #define BITTLE    // Petoi 9 DOF robot dog: 1 on head + 8 on leg
4  //#define NYBBLE  // Petoi 11 DOF robot cat: 2 on head + 1 on tail + 8 on leg
5  //#define CUB
```

Modify the mainboard model macro definition in OpenCatEsp3&#x32;**.ino** according to the mainboard (BiBoard) version. e.g. : using **BiBoard\_V1\_0**

```cpp
7  // #define BiBoard_V0_1  //ESP32 Board with 12 channels of built-in PWM for joints
8  // #define BiBoard_V0_2
9  #define BiBoard_V1_0
10 // #define BiBoard2  //ESP32 Board with 16 channels of PCA9685 PWM for joints
```

If the robot(**Bittle X+Arm**) has the robotic arm, you should also activate the macro definition as follows:

```cpp
26 #define ROBOT_ARM                 // for attaching the head clip arm
```

Otherwise, please comment out this line of code.

After the modification is complete, click the Upload button (as shown below) to upload the sketch **OpenCatEsp32.ino**, and the changes in the code file will be automatically saved.

<figure><img src="https://4130507397-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXLpFdG7mubqEHWylLK3w%2Fuploads%2F2GTZ2btiW2BgEhDVdfkj%2FWeChatd6280a5ca0b7839d42340797ca49ebe6.jpg?alt=media&amp;token=c3b7667e-f7fb-436d-b801-ac35b9795a58" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://guide.petoi.com/petoi-web-coding-blocks/upload-firmware-using-arduino.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
