# Petoi Web Coding Blocks

## 1. Upgrade the firmware

You can [upgrade the firmware](https://docs.petoi.com/desktop-app/firmware-uploader) for BiBoard, which supports web block-based programming via the latest version (≥ 1.2.6 beta) of the Petoi Desktop App.

## 2. Open the Petoi Web Coding Block

Download the source code from the GitHub repository ([OpenCatEsp32-Quadruped-Robot](https://github.com/PetoiCamp/OpenCatEsp32-Quadruped-Robot/tree/redesignWeb)).

<figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FlwARygTWRiSFxWjuRVEq%2Fimage.png?alt=media&#x26;token=09a75be2-72a2-49a4-bed1-85bf31d602fa" alt=""><figcaption></figcaption></figure>

Open **OpenCatEsp32 > PetoiWebBlock > programblockly.html** to start programming with Petoi Web Coding Block on web.

<figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2Fp0XqoxIwx7EMPibOcIs4%2Fimage.png?alt=media&#x26;token=8e9745fe-089b-4024-b0df-239ef95844e2" 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%2FST5apzPcCjNAISgC5n9I%2Fimage.png?alt=media&#x26;token=fa605a18-eb49-4d9f-9b7b-10b038976426" alt=""><figcaption></figcaption></figure>

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

1. You'd better open **programblockly.html** using:
   1. **Edge** on Windows
   2. **Chrome** on Chromebook
2. Ensure the browser is in **direct connection mode.**
3. It's best not to use a VPN, as it may slow down the response speed and impact the experience. Please turn off the VPN extension.\
   ![](https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FP5hT19ggW6PVjNAmYCjl%2Fimage.png?alt=media\&token=23785822-f697-432f-b9e5-98e95c90fec6)
   {% endhint %}

## 3. The principle and process

The Petoi Web Coding Block allows you to control the robot via WiFi without compiling and uploading code to its main board. Simply click the "Run Code" button to execute the program at the graphical block level, sending instructions wirelessly to the robot through your local network. The process involves three key steps:

1. &#x20;Open the serial port
2. &#x20;Control the robot
3. &#x20;Close the serial port

{% hint style="danger" %}
When you plug in the USB data cable on the computer side of the Chromebook, if a **USB device detected** message window pops up in the bottom-right corner of the screen, as shown in the figure below, please <mark style="color:red;">DO NOT</mark> click the **Connect to Linux** button in the window.

![](https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2F8bgCymW3wPC1HsBAp3jk%2Fimage.png?alt=media\&token=a7d9bbb7-c2c5-462c-95a9-1f857c309429)

If you accidentally click this button, Chrome will not detect the serial port. To resolve the issue, go to the settings interface below, **turn off** the **USB Single Serial** option, and then unplug and reconnect the USB cable. This will cause the **USB device detected** message window to pop up again.

![](https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2Fj5yfmVb0cpMrdddqTeEC%2Fimage.png?alt=media\&token=b1cab91e-3c62-469b-ba24-3283bbdb86a9)
{% endhint %}

{% hint style="warning" %}
If you use the **Chrome**, please make sure to turn on the permission settings first:\
![](https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FyJO0XzSMgtJ2f0HhCGa2%2Fimage.png?alt=media\&token=bc032bb6-94c7-4815-a5d3-d8b1456f399c)\
\
![](https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FjgBQ7GdoC4YkOuhIZoye%2Fimage.png?alt=media\&token=baf2bc4b-d0fe-4696-8d49-21713557a6e8)\
\
![](https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2Fa7R0p5LnnHtoHyTxx4ME%2Fimage.png?alt=media\&token=34db7ee3-8153-4c4b-ac46-0356e8b3341f)
{% endhint %}

The Petoi web coding block interface is shown below:

<figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FJJeoDkckY1o1kS9c9QE6%2F2761751970619_.png?alt=media&#x26;token=b38cd849-5003-443f-8322-78cfffe021dd" alt=""><figcaption></figcaption></figure>

① [Quick Connect](#id-3.1-initial-setup-and-quick-connect) ② [Language Switch](#id-3.2-language-switch) ③ [Workspace](#id-3.3-workspace) ④ [Action Buttons](#id-3.4-action-buttons) ⑤ [Console](#id-3.5-console) ⑥ [Serial Monitor](#id-3.6-serial-monitor) ⑦ [Toolbox & Blocks](#id-3.7-toolbox-and-blocks)

### **3.1 Initial Setup & Quick Connect**

For first-time use, you need to establish a connection between your robot and computer. **Both must be on the same WiFi network, and the robot can only connect to 2.4GHz WiFi networks.** Therefore, you need to split your WiFi SSID into two frequency bands.&#x20;

**Follow these steps to split your WiFi bands:**

1. Access your router’s Wireless Settings page (access method typically found on the router’s label).
2. In the **2.4GHz settings**, change the Wi-Fi name (SSID) to `xxx-2.4G` and save.
3. In the **5GHz settings**, change the SSID to `xxx-5G` and save.
4. After renaming, both `xxx-2.4G` and `xxx-5G` will appear in your device’s WiFi list.

{% hint style="info" %}
Note: Since the Wi-Fi names have changed, all devices connected to this router need to reconnect. If you didn’t change the password, it remains the original password.
{% endhint %}

#### **Connection Procedure**

Connect the robot’s mainboard to your computer via **USB cable**.

<figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FI20sAGYzpZsrsJDC1YfX%2Fimage.png?alt=media&#x26;token=75403de3-1231-4402-869a-b41a9bdb4125" alt=""><figcaption></figcaption></figure>

There are two methods to connect the robot to your 2.4GHz WiFi network:

1. (Recommended)
   * Click ![](https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FgAMw4ZtepnMsngmDJOrr%2F2631751858746_.pic.jpg?alt=media\&token=3366baf6-b559-454e-ad87-18c0fd639b60) button on the webpage, select a serial port of the robot in the pop-up window and click "Connect" button. *(For Mac user, different from* [*firmware upload*](#id-1.7-connect-to-biboard-via-usb-type-c-data-cable)*, any serial port of the robot works here)*
   * Enter your `xxx-2.4G` WiFi credentials when prompted. The robot will connect to your network like any standard device, then automatically reboot its mainboard. \
     Once rebooted, the red block `Connect with IP:192.168.4.1` in the workspace will auto-update with your actual IP, indicating successful connection. You can use Petoi Web Coding Block to send real-time signals to the robot via WiFi from now!
2.

```
* Click ![](https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2F3mAvk3rIdwnN0PZXdFs3%2Fimage.png?alt=media\&token=eb4a96c4-d5cd-4d32-8dec-bf9bb5c4a8f0) button in the serial monitor on the webpage to establish a serial connection with the robot.&#x20;
```

```
* Press and hold the BOOT button on the robot’s mainboard until the 10-second countdown in the serial monitor’s output ends. This will initiate the network reset procedure.&#x20;
* When the serial output displays "wm:Starting Web Portal", the serial output will pause. This indicates that the robot has created a new hotspot and entered **a waiting state for connection**.\
  ![](https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2F3H0EhzEpK010ad4Cru60%2Fimage.png?alt=media\&token=160743ac-ccf0-4aef-a397-754434c53040)
* At this point, open your computer’s WiFi network list and locate the newly appeared, password-free network. The network name is typically "**UII WifiConfig**." \
  ![](https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FsgJ6fmetop7DxZvDhiCt%2Fimage.png?alt=media\&token=3af6652d-6df0-4678-8e13-a74dae229297)
*   After connecting, a WiFi Manager window will open. Follow the prompts to select your 2.4GHz network, enter the username and password, and wait for the connection to complete. The window will close automatically once connected.

    <figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FCoXDhH2qnpsDJghi6Vh9%2Fimage.png?alt=media&#x26;token=0a7564ae-6c24-4faa-a357-29c8d735c18c" 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%2FZDk9mRDjO6tL5f9VOElQ%2Fimage.png?alt=media&#x26;token=4f9e0500-cef4-475b-b33c-3b89f2883ce9" 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%2FZRkTXuNjgyfB9TOdOjda%2Fimage.png?alt=media&#x26;token=5416daf8-e4aa-4923-8563-d1aa6a8e948c" 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%2FUF48VYWGkkkBVwPtbztL%2Fimage.png?alt=media&#x26;token=27bf9624-de86-41e4-a63d-0e2046d4c40e" alt=""><figcaption></figcaption></figure>
```

{% hint style="info" %}
**Note:** If you cannot find the new password-free network in the WiFi list, please try refreshing the list multiple times. If it still does not appear, check the robot’s serial output to confirm whether the robot remains in **the waiting state**. If not, the hotspot has been deactivated, and you will need to restart the network reset procedure.
{% endhint %}

#### **Persistent Connection**

**This entire process only needs to be set up once.** The robot remembers your WiFi credentials.

For future connections, You only need to use **either one** of the following methods to connect :

* **Wireless**: Enter the current IP in the `Connect with IP` block (check via USB if IP changes).
* **Wired**: Connect the robot to the computer via USB cable, then send command `w` to the serial port for auto-connection.

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

The connection relies on the local network environment. Ensure it is always on the same WiFi network as your computer during every subsequent connection. Your network IP address **may not always remain unchanged**. If you entered the IP address directly in the workspace block but failed to connect, please consider possible IP address changes. You may:

Connect the robot’s serial port to the computer via USB cable. Send command **w** through Petoi Web Coding Block to the serial port to check and update the IP address.
{% endhint %}

### **3.2 Language Switch**

<div align="left"><figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FSUHQVqZ6jmdQuFgkK8rH%2Fimage.png?alt=media&#x26;token=5d0e96fa-44c5-4a50-9700-2331964d343b" alt=""><figcaption></figcaption></figure></div>

You can switch language systems here anytime.

### 3.3 **Workspace**

This is the area where you assemble block programs. You can scroll the mouse wheel to zoom in/out.

<figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FSbzhSr3LYMLrGqFJMFdX%2Fimage.png?alt=media&#x26;token=e92a9b1b-0ad6-4e88-9cda-388f52387872" alt=""><figcaption></figcaption></figure>

Press and hold the left mouse button on a blank area to pan the view. Right-click to perform actions like undoing block operations.

<div align="center"><figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FYIPsnkwE1DAHwQrBcfCy%2Fimage.png?alt=media&#x26;token=fbe5dbe2-9c6c-45b8-afa6-6a994185084d" alt=""><figcaption></figcaption></figure></div>

Left-click and hold a block to drag its position. Right-click a block to copy or delete it.

<div align="center"><figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FcnrPCX9zvQxyTrcriS2M%2Fimage.png?alt=media&#x26;token=0c2050f1-3b5f-4116-a353-8470b00d6c8b" alt=""><figcaption></figcaption></figure></div>

The buttons at the bottom-right :

<p align="center"><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2Fh4Az0obXOBTeQcR00xxl%2Fimage.png?alt=media&#x26;token=6a42b929-7038-46a4-be34-4eb0751212bb" alt=""></p>

From top to bottom: **Undo • Redo • Center View • Zoom In • Zoom Out • Trash Bin**

You can drag blocks onto the Trash Bin here to delete them. Click the Trash Bin to view deletion history, the blocks inside can be dragged back to the workspace.

{% hint style="info" %}
Alternative deletion methods:

* Right-click a block → choose "delete block".
* Drag blocks to the **Toolbox** area.
* Left-click a block → press "Delete" on your keyboard.
  {% endhint %}

The Workspace contains two default blocks that **cannot be deleted** :

`Connect with IP`: Essential block for program execution. Only blocks connected **under** it will run.\
`Gyroscope` : Disables robot's gyroscope during program execution by default.

{% hint style="info" %}
Robots' gyroscope status varies by users' usage habits. If it's enabled during runtime, the robot will automatically adjusts balance in real-time, which may interfere with your program's intended behavior. To ensure consistency, gyroscope is disabled at program start.

*To enable*: Simply change "disable" to "enable".
{% endhint %}

### **3.4 Action Buttons**

<figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FygKRxJsfJsNCe9V7bgD9%2Fimage.png?alt=media&#x26;token=e66bb4fc-5b4d-44af-8010-0ecdb9f31eda" alt=""><figcaption></figcaption></figure>

![](https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FYYv97UkqjINBBlihqNIe%2Fimage.png?alt=media\&token=1c240813-5e26-4abf-926f-c0c0508a8512) **Show Code**: Displays source code of blocks connected under the `Connect with IP` block.

![](https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FFJvCACMl3954Lfa3nBdA%2Fimage.png?alt=media\&token=ef811357-313c-42b9-aefe-e7d5774f8f56) **Run Code**: Executes all blocks connected under the `Connect with IP` block.

![](https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FXWNCflaeePYpmG8kP7U9%2Fimage.png?alt=media\&token=85c596f9-c5a4-426b-9d82-880f5c8daa37) **Save Program**: Saves current project state (all blocks + skills) as a **.json** file.

![](https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FP4mg5QpsbMMYbZym7WYJ%2Fimage.png?alt=media\&token=5e38d62a-6291-49fb-8f7b-e7da825781ed) **Load Program**: Loads the **.json** project you saved.

![](https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FtuEhmUQyRtUSC2dXai6f%2Fimage.png?alt=media\&token=8573a21a-2641-4429-aa7c-31361c4bc613) **Upload Skill Files**: Adds skill files to project (details: xxx).

![](https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2F3sYw3oCAW4qDWvIFHpW0%2Fimage.png?alt=media\&token=9fc97925-31c0-496c-92e4-b43424072f8d) **Clear All**: Removes all blocks **except** default blocks `Connect with IP` and `Gyroscope` on the workspace. Cleared blocks will appear in Trash Bin history.

### **3.5 Console**

<figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2Fen3BWAgpvFa03Dlx97bj%2Fimage.png?alt=media&#x26;token=a47acb7a-42c0-4a91-9a5a-a9c9c7cb2454" alt=""><figcaption></figcaption></figure>

You can view real-time program execution messages here. It's critical when controlling wirelessly, console can provides vital feedback as serial port data is inaccessible.

![](https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2Fx31bgMyrg7Dl1rvUOQ4L%2Fimage.png?alt=media\&token=c0ed9249-d54c-4deb-b715-aa0d1b5b60e5) Use this button to toggle the timestamp display in the Console on/off. When you need to copy batches of sensor data output to the console, turning off timestamps makes it easier.

### **3.6 Serial Monitor**

<figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FMaXL3iuRA5PoxGa5pU4e%2Fimage.png?alt=media&#x26;token=85b4ef41-8ed3-4835-99e4-98ce6efa7c4f" alt=""><figcaption></figcaption></figure>

View serial print messages from connected robots here and send commands directly to the serial port.

When you successfully connect to the robot's serial port, the Serial Monitor window will automatically open as shown above.

{% hint style="info" %}
Note:

Without a USB cable connection between the robot and computer, serial data cannot be accessed or sent here.
{% endhint %}

### **3.7 Toolbox & Blocks**

<figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FmCM35BW7i59SpqymiAuU%2Fimage.png?alt=media&#x26;token=8d47d50b-0f21-43e7-8be3-baa15d2fd656" alt=""><figcaption></figcaption></figure>

Left-click any category in the Toolbox to reveal all its blocks. Drag and place them in the Workspace, then link to blocks under `Connect with IP` to assemble your program.

The **Communication**, **Motion**, **Console**, and **Music** categories contain blocks created and provided by Petoi. All other blocks are default functional blocks from Blockly.<br>

## 4 The instructions for blocks

### 4.1 Communication

The blocks in **Communication** are used for interacting with various modules of the robot.

For detailed instructions on sensor connections, please refer to the individual sensor documentation in the "[EXTENSIBLE MODULES](https://docs.petoi.com/extensible-modules)" section. Only basic connection diagrams and pin number references are provided here for your guidance.

<figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FjYBrHxTPPBx8ykmkFSRV%2F%E4%BC%A0%E6%84%9F%E5%99%A8%E8%BF%9E%E6%8E%A5%E5%9B%BE%E7%AE%80%E6%B4%81%E7%89%88.png?alt=media&#x26;token=9cf7f4c4-0d02-469f-95b8-9c9f587442d2" alt="" width="563"><figcaption></figcaption></figure>

The pin numbers required when using building blocks can be referenced against the labels next to the Grove Sockets on your BiBoard.

<figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2F8pFzHjr4gt8Zo5d8AUGZ%2Fimage.png?alt=media&#x26;token=6c875746-4d84-4301-9865-641ec455ce78" alt="" width="563"><figcaption></figcaption></figure>

* For **general modules** (Light Sensor, Touch Sensor, Gesture Sensor, PIR Motion Sensor, IR Distance Sensor), You can use the above four blocks to **digitally/analog read/write signals** and see the results in both the serial monitor and console. \
  Analog value range: 0\~255\
  Digital value range: High-level: 1; Low-level: 0

* ![](https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FaLkSyNZT0Z3qewdBF3pr%2Fimage.png?alt=media\&token=0096113b-a0bb-4642-806d-689c185cf95d)

* For the **Ultrasonic Sensor**, use this block to read the distance value. You can set the two pins ( Trigger and Echo) like this: (BiBoard V1 connects to the Rx and Tx pins)

  <div align="left"><figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FcbaZoYc24W5v0ZahvFiH%2Fimage.png?alt=media&#x26;token=b221361e-4312-4e23-b678-6b75b622cd0d" alt=""><figcaption></figcaption></figure></div>

* For **camera modules** (MU Camera, Petoi AI Vision Module), use this block to Read the coordinates of the identified target from the camera module.

  <div align="left"><figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2Fv2UCsnL0P2ISF2guim4a%2Fimage.png?alt=media&#x26;token=374cc979-3bef-4b6c-bfb9-22aa9ace4ec2" alt=""><figcaption></figcaption></figure></div>

* If you are familiar with Petoi's **serial commands** (e.g., `m 0 60` rotates servo #0 to 60°), you can use this block to send serial commands to robot during program execution.

  ![](https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FngpoC4SoIXGuiVbqq3Ma%2Fimage.png?alt=media\&token=f36e724a-7580-447b-9948-7c15b456e4ba)\
  You can also input "**kkcL**" (kick the left front leg), and "**khiR**" (raise the right front leg to say hello). For more serial port commands, please refer to [the serial protocol](https://docs.petoi.com/api/serial-protocol).&#x20;

* Use this block to enable/disable the robot's gyroscope:

  <div align="left"><figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2F6AUeFmtaTVbkmPhUVlfv%2Fimage.png?alt=media&#x26;token=d8e0f895-e874-4619-a127-8820f6479c4b" alt=""><figcaption></figcaption></figure></div>

  Enabled: The robot adjusts motion balance in real-time and performs self-righting when tilted over.

  Disabled: The robot executes only specified movements without auto-balancing.

### 4.2 Motion

The blocks in **Motion** are used for controlling robot actions and reading/writing servo joint angle signals.

#### **Preset Actions**:

* This block enables the robot to execute various preset gaits for movement in various directions/poses. You can modify the  `delay` duration for continuous walking.

  <div align="left"><figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2F8EWhzPi4oIYpFx5x577t%2Fimage.png?alt=media&#x26;token=0bed316d-0b1e-4404-b47c-dd33cbf0d76e" alt=""><figcaption></figcaption></figure></div>

* This block makes the robot perform various preset poses.

  <div align="left"><figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FvnkKAODA7J3uO8tSN9CS%2Fimage.png?alt=media&#x26;token=6772ae1b-896a-450d-affc-3a51813b8bb4" alt=""><figcaption></figcaption></figure></div>

* This block performs advanced preset motions. Due to large movement ranges, please use cautiously especially when using with USB-connected robot or Bittle X+Arm.

  <div align="left"><figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FPBDaNMiKMiShx738BxZq%2Fimage.png?alt=media&#x26;token=4d36352f-af75-4ca9-bc3c-18c1bff5fa66" alt=""><figcaption></figcaption></figure></div>

* This block controls preset robotic arm motions (Bittle X+Arm only).

  <div align="left"><figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FOXfyqjHh6dHGNp5gVhuf%2Fimage.png?alt=media&#x26;token=baf77970-4576-4e53-979b-89976d416116" alt=""><figcaption></figcaption></figure></div>

**Custom Actions**:

* Use these two blocks to get the robot's current joint angles. You can assign it to a variable first and then use the variable and algorithm to control other joints to rotate.

  <div align="left"><figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FQXWp3fcb2nbC0U2oms0J%2Fimage.png?alt=media&#x26;token=f0e40414-85bc-4595-9371-b56b5cd7e824" alt=""><figcaption></figcaption></figure></div>

{% hint style="info" %}
The return value of the blocks are only angle values, which cannot be filled in the "Turn sequentially" and "Turn simultaneously" blocks alone.
{% endhint %}

* These two blocks can both set a single joint angle individually. You can set the joint angle to an absolute value, or  to a relative angle value. increase it, or decrease it by a specific number.&#x20;

  You can even creatively make the angle change using a formula or variable instead of a fixed number.

  <div align="left"><figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FeRIadhaVdKBtvxRvopy3%2Fimage.png?alt=media&#x26;token=892fab10-cfdf-4f4b-adab-385cf0bc3767" alt=""><figcaption></figcaption></figure></div>

* Combine these four blocks to move **multiple joints** sequentially or simultaneously.

  <div align="left"><figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FjwFrQHlIpUtwquNQzqbt%2Fimage.png?alt=media&#x26;token=c50937e2-bd23-419b-aee6-db0c95a97d26" alt=""><figcaption></figcaption></figure></div>

  \
  You can click the **gear icon**![](https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2F8hYo7drzRK2fLjq1AgMC%2Fimage.png?alt=media\&token=118d29a5-b325-46fe-93ce-435cf23ca4ed), then change the list length in the pop-up window to apply it to the actual block.

  <div align="left"><figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2F6QPFvhNAqzWrixmeuc6B%2Fimage.png?alt=media&#x26;token=4ad969e9-62b0-4289-ae7a-430e17982be0" alt=""><figcaption></figcaption></figure></div>

* Use these two blocks to control all joints to rotate at the same time.&#x20;

  <figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FgBBF0GrkmotoyMX438X5%2Fimage.png?alt=media&#x26;token=e1d92f74-7661-47d2-b6af-56519b574021" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
The "Action frame" block represents a list of 16 angle values. Each angle value corresponds to the absolute angle value to which the corresponding [joint index](https://app.gitbook.com/o/-M-_eWZUjFA4usjshHcZ/s/-MQ6a951Q6Jn1Zzt5Ajr-887967055/~/changes/285/petoi-robot-joint-index) servo rotates.
{% endhint %}

* This block executes **uploaded skill files** by entering the full filename (e.g., `test.md`).

  <div align="left"><figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2F7U5Qd2pV3A5gvWGDu6cT%2Fimage.png?alt=media&#x26;token=c0df6013-ad75-44c1-883a-d60ad23022f8" alt=""><figcaption></figcaption></figure></div>

  You can create skill files by using the [Skill Composer](https://docs.petoi.com/desktop-app/skill-composer#export-the-skill).&#x20;

{% hint style="info" %}
Tips: you can also copy & paste the [SkillLibrary](https://github.com/PetoiCamp/OpenCat/tree/main/SkillLibrary) folder from the source code of the OpenCat project on GitHub to the ***.config/Petoi*** directory. Therefore, you can use some sample skills for your program, and there is no need to use the export function in the Skill Composer.

![](https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FnHCJfsOcrwEK9P8NXYny%2Fimage.png?alt=media\&token=c4d0ac7b-0761-4406-9f1c-6b231cbe4c20)
{% endhint %}

{% hint style="info" %}
The folder **.config** is a hidden directory on MacOS/Linux but can be visited in the terminal or through a specific view setting:

* MacOS\
  open the directory /Users/{username} in Finder, then press the “**Command**” + “**Shift**” + “**.**” (period) keys at the same time.<br>

  <figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2Fi1bvYygyLl333W4wYYCI%2Fimage.png?alt=media&#x26;token=4835c116-be30-46f8-9e7d-053249b580e3" alt=""><figcaption></figcaption></figure>

{% endhint %}

### 4.3 Console

* Use this block to add console output, to observe runtime status and test programs in the console.

  <div align="left"><figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FGbMArs3cbcSdnSHKdcrH%2Fimage.png?alt=media&#x26;token=ddfebcaa-c0da-4a92-b1af-e4e03199e534" alt=""><figcaption></figcaption></figure></div>
* Use this block to insert a delay after statement execution, to observe program flow or achieve timing effects.

  ![](https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FEThiawLj850KOxvV8HWH%2Fimage.png?alt=media\&token=2a4f1d35-4abd-4372-a890-162aa01d1a7f)

### 4.4 Music

<figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FOlYERb1nxiYxudTArI0v%2Fimage.png?alt=media&#x26;token=1a217bcb-2548-4954-9958-b23047394b09" alt=""><figcaption></figcaption></figure>

You can combine these two blocks to make the robot **play continuous melody**.&#x20;

{% hint style="warning" %}
You may use the **play note** block alone, but please note:

Petoi web blocks send instructions **one by one in real-time over the network**; using only *play note* during network congestion may cause **discontinuous tones**. Unless this effect is desired, we recommend using both blocks together for smooth melody playback.
{% endhint %}

### 4.5 Demo code

<figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FKD79iKQGaz1GUpY8PP8C%2Fimage.png?alt=media&#x26;token=e2dd6fb6-728a-460a-95da-a18e5a9f14b2" alt=""><figcaption></figcaption></figure>

{% file src="<https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FPfu00oNyFN7znmt6Jzn3%2FDemoCode.json?alt=media&token=c5d73e47-d6bc-4fd8-8ccd-8ea42efe4ca1>" %}

<figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FhRR8rMA9bSEwEh2ZWBLL%2Fimage.png?alt=media&#x26;token=0ee3c0ad-5554-48c6-b3bc-598a99c7a04e" alt=""><figcaption></figcaption></figure>

{% file src="<https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2F91uH0tjorO3gfSq02UjB%2FTestCamera.json?alt=media&token=9efb81e4-1b95-4510-9a60-73a5411a745a>" %}

## 5 Appendix - Full WiFi Connection Logic

During the program’s runtime, press the BOOT button to reboot the robot and start the Wifi Manager. It will create a Wi-Fi hotspot with your machine-specific name. Connect it in your system’s Wifi settings, and a Wifi configuration page will automatically open to let you connect to your router. Only a 2.4G network is supported. The personal hotspot of your smartphone is also applicable, but you must connect your computer to the same hotspot during later operations. If the Wi-Fi configuration doesn’t open automatically after 5 seconds, you can try to connect to 192.168.4.1 manually in your browser. Alternatively, you can enter the Wifi credential in the serial monitor, formatted as “w%wifiname%password”. Click the Quick Connect button on the block coding page to enter the Wifi credentials.

If the Wifi connection is established successfully, the robot will automatically connect to the same router every time after reboot. If it fails, it won’t auto-connect during the future reboot. You can start over the connection operation as your first operation.

To clear the previously saved Wi-Fi credentials, hold the BOOT button for more than 2 seconds. This will reboot and start the Wi-Fi manager to connect to a new router.
