# Firmware Uploader

## \*\* Download the latest version of the [Petoi Desktop APP](https://github.com/PetoiCamp/DesktopAppRelease/releases). \*\*

{% hint style="info" %}

* After downloading the compressed file(.zip), please unzip it first.
* Do **NOT** move the UI.exe to another location in Windows.
  {% endhint %}

Petoi Desktop App works on both Nybble and Bittle controlled by NyBoard based on ATmega328P or Bittle X controlled by [BiBoard](https://docs.petoi.com/biboard/biboard-v0) based on ESP32.

{% hint style="info" %}
For [**NyBoard**](https://docs.petoi.com/nyboard/overview), more detailed documentation can be found at [NyBoard V1\_0](https://docs.petoi.com/nyboard/nyboard-v1_0), [NyBoard V1\_1, or NyBoard V1\_2](https://docs.petoi.com/nyboard/nyboard-v1_1-and-nyboard-v1_2) (which *is similar to NyBoard V1\_1)*.
{% endhint %}

## Connect the mainboard to the computer

You can connect the computer to the mainboard using a USB cable, following the instructions on the subsequent sub-pages, which are specific to the robot's mainboard model. To see the sub-pages as in the following picture:

<figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FO8lRShakpLBPxos0fXmL%2Fimage.png?alt=media&#x26;token=45268ddf-4013-45b1-8b7b-568a2f5e15d2" alt=""><figcaption></figcaption></figure>

## Upload the firmware using the Petoi Desktop app

### Open the PetoiDesktopApp

**After** properly connecting the USB uploader, open the PetoiDesktopApp (for Windows: UI.exe / for Mac: Petoi Desktop App), and select your **Model** and **Language**.

#### Menu bar in Petoi Desktop APP

<div align="left"><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FVQTlNbzc5Tup3qZYCKdK%2FModel_UI.jpg?alt=media&#x26;token=abf73521-fdc8-4020-81b3-b78b9dcd2325" alt="Model"> <img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FCjOSMOwdxUQAYXWqVCLJ%2FLanguage_UI.jpg?alt=media&#x26;token=b0adf541-70cc-41b3-bb7f-9d5b2ca7a00e" alt="Language"> <img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FphnMstSH1DyG7qUgJqMw%2FAbout_UI.jpg?alt=media&#x26;token=0cb20380-38a5-4043-a098-c4d59ec69c94" alt="Help"></div>

### Click the Firmware Uploader button

<div align="center"><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FPGNjQBbj4NfEw9c1Bs68%2FMain_FU-en.png?alt=media&#x26;token=78f9145f-c5a4-485e-bfbb-bb9327b30fb6" alt="Main interface"></div>

### Auto Detect the Serial Port&#x20;

If there is **no** serial port or **more than one** serial port are detected by the desktop app:

<figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2F4RrwugZiYl21h58avOpU%2Fimage.png?alt=media&#x26;token=fc8968fd-6ce8-4794-8bda-b1a7cef62eb9" alt=""><figcaption></figcaption></figure>

After clicking the **Firmware Uploader** button,  there will be a message box prompt as follows:

<figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2Fx462gWOrQE0Sq29zojB1%2Fimage.png?alt=media&#x26;token=aa6b6fb9-68f5-4413-ace1-5056266cff2f" alt=""><figcaption></figcaption></figure>

Please follow the prompts in the message box. \
After clicking the **Confirm** button, If you complete the prompts within 10 seconds, the desktop app will automatically identify the serial port name connecting the robot to the computer.\
If you complete the operation of unplugging and plugging the USB interface on the computer for more than 10 seconds, the desktop application will enter the manual selection of the serial port name mode：

<figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FnbMTEKV2nBcu2AEaXUvf%2Fimage.png?alt=media&#x26;token=f0056444-1a87-445f-aa16-42037ddce4ec" alt=""><figcaption></figcaption></figure>

Click the **OK** button in the Warning message box first, then you can refresh the serial port list or select one of them (e.g. **COM3**) and click the **OK** button in the **Manual mode** window to open the Firmware Uploader interface as follows:

<figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2Fv9H3qSWwyJNDF8xWEl19%2Fimage.png?alt=media&#x26;token=2acfcf71-5ef1-4355-818f-ff6c9bbb5c34" alt=""><figcaption><p><strong>Firmware Uploader interface</strong></p></figcaption></figure>

Once the Firmware Uploader interface is opened, you can also unplug and replug the USB cable from the COMPUTER side. The desktop app will automatically identify the serial port name connecting the robot to the computer.

<figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FEwnii1tymQzBByvuq9XT%2Fimage.png?alt=media&#x26;token=29b6be35-9810-41fb-a30f-f85e78dfb6b6" alt=""><figcaption></figcaption></figure>

If unplug the **COM5** and replug it on the computer side, it will be discovered by the desktop app as follows:

<figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FsLcQM4DXs7UmO4CS1vhf%2Fimage.png?alt=media&#x26;token=914ab063-6a9d-41b7-957b-18f2560e8c70" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2Foh2NBmj06RqJcXXoQ0uR%2Fimage.png?alt=media&#x26;token=be57c1dc-f567-445c-999e-59eab0c96a88" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FAXXHloPSvbFSaQzH1tDX%2Fimage.png?alt=media&#x26;token=3502eac0-d9a4-4edd-a4e9-48f793ec2923" alt=""><figcaption></figcaption></figure>

### Select the correct options to upload the latest firmware.&#x20;

{% hint style="warning" %}
The 1.0 software won't work properly with the Joint Calibrator, the Skill Composer, and other APIs. Only use it when you want to use CodeCraft (a graphical coding interface by our partner, TinkerGen).&#x20;
{% endhint %}

<table><thead><tr><th width="176">Options</th><th width="293">Values</th><th>Note</th></tr></thead><tbody><tr><td>Software version</td><td><p>1.0</p><p>2.0 (default)</p></td><td>The 1.0 version is obsolete.</td></tr><tr><td>Board version</td><td><p>NyBoard_V1_0 (default<em>)</em><br>NyBoard_V1_1<br>NyBoard_V1_2<br>BiBoard_V0_1</p><p>BiBoard_V0_2<br>BiBoard_V1_0</p></td><td>BiBoard_V0_1 or BiBoard_V0_2  is for Bittle X.  <br>BiBoard_V1_0 is for Bittle X V2 only.</td></tr><tr><td>Product</td><td>Bittle (default)<br>Nybble<br>Bittle X</td><td></td></tr><tr><td>Mode</td><td>Standard (default)<br>RandomMind <br>Voice<br>Mind+<br>Camera <br>Ultrasonic <br>RandomMind_Ultrasonic<br>Light<br>Touch<br>PIR<br>Gesture<br>IR distance</td><td><p>For NyBoard, these 12 modes can be selected. All of these modes apply to both <strong>Bittle</strong> and <strong>Nybble</strong>.</p><p>For <strong>BiBoard</strong>, You only need to upload the <strong>Standard</strong> mode firmware, and you can switch between different modes via serial port commands. [1]</p></td></tr><tr><td>Serial port</td><td>Auto detection or by manual selection. </td><td>You can find the correct one through unplug and replug the USB socket on the computer side</td></tr></tbody></table>

{% hint style="info" %}

1. You can use the serial commands to [switch modes](https://docs.petoi.com/arduino-ide/upload-sketch-for-biboard#id-2.8-swith-mode-via-the-serial-commands) for **BiBoard**:\
   For **BiBoard,** Mind+ mode is supported by default, so it doesn't require a serial command to switch on.\
   You can learn about the function of each module through the [**EXTENSIBLE MODULES**](https://docs.petoi.com/extensible-modules/introduction).
   {% endhint %}

{% hint style="warning" %}
There's no correlation between the board (hardware) version and the code (software) version.
{% endhint %}

### Finish uploading the firmware

After the upload, the status bar will update the corresponding result, such as the success or failure of firmware uploading. If the uploading is successful, a message window of "Firmware upload complete!" will pop up simultaneously.

<figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FpTBfa3xAO3ZJ7bj0VkrH%2Fimage.png?alt=media&#x26;token=9e449571-75db-4a88-ac56-890723ee06f9" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
Note:&#x20;

1. For NyBoard, when you open the software and upload the firmware for the first time, the program will first upload the "**Parameters**" firmware and then the "**Main function**" firmware.&#x20;
2. After uploding the firmware, if the NyBoard or BiBoard V1 is not connected to the battery and powered on, you will hear repetitive descending melodies, indicating that the battery is low or disconnected. You need to connect the battery and turn on its power.&#x20;
   {% endhint %}

### Check the log file

If the uploading fails, the following message box will pop up:

<figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FmDUCRMAVq9Dhe1H3n0ix%2Fimage.png?alt=media&#x26;token=d44ff609-3746-47ee-b8f2-e2a890c6c40b" alt=""><figcaption></figcaption></figure>

The log file is located at:

* For Windows: \
  The log file is in the same directory as **UI.exe**<br>

  <figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FNl61Gr6RNtDYEuJek7Gm%2Fimage.png?alt=media&#x26;token=0e0ea071-11e4-48e7-9f80-cbfbca10ccac" alt=""><figcaption></figcaption></figure>
* For macOS:\
  You can check the log file as follows:<br>

  <figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FGLeXErV4KpBrfbJQhO3o%2Fimage.png?alt=media&#x26;token=ee485581-cf60-4008-aba7-5c4a91b16ee3" alt=""><figcaption></figcaption></figure>

  <figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FL7O8qDstl6NwlwRQ4ZmJ%2Fimage.png?alt=media&#x26;token=972abd2e-b715-4f05-8601-baa99d22ad17" alt=""><figcaption></figcaption></figure>

When you contact our **<support@petoi.com>**, please attach the log file to your email.&#x20;

{% hint style="info" %}
There may be some OS platform compatibility issues with different computers.

You can still run the app directly from your terminal:

1. Go to OpenCat/pyUI/ in your terminal.
2. Install ***pyserial*** and ***pillow*** for your Python. You may get a clean Anaconda environment and `pip3 install pyserial pillow`
3. Run `python3 UI.py`

For **NyBoard**, the firmware uploader calls the application **avrdude** to upload firmware files to the mainboard.&#x20;

**Linux OS**

For Linux system users, in addition to the above steps, you also need to perform the following steps:

1\. Install **avrdude**&#x20;

* Fedora: dnf install avrdude
* CentOS: yum install avrdude
* Debian / Ubuntu: apt install avrdude

2\. Modify the variable **avrdudeconfPath** in FirmwareUploader.py

* Fedora / CentOS : `avrdudeconfPath = '/etc/avrdude/'`
* Debian / Ubuntu : `avrdudeconfPath = '/etc/'`

For **BiBoard**, the firmware uploader calls the application **esptool** to upload firmware files to the mainboard.&#x20;
{% endhint %}

{% hint style="info" %}
If you have Arduino IDE programming experience, you can see the same log message when uploading.

* For NyBoard, you can refer to [Upload Sketch For NyBoard](https://docs.petoi.com/arduino-ide/upload-sketch-for-nyboard).
* For BiBoard, you can refer to [Upload Sketch For BiBoard](https://docs.petoi.com/arduino-ide/upload-sketch-for-biboard).
  {% endhint %}
