# อัปโหลด Sketch สำหรับ BiBoard

## 1. อ่านคู่มือเริ่มใช้งานฉบับย่อ

พารามิเตอร์เฉพาะของแต่ละโมดูลการทำงานของ BiBoard โปรดดู [Chapter 2](https://docs.petoi.com/thai/arduino-ide/pages/-MVugl3T-mwZYPFHdZ3c#2.-modules-and-functions) ของคู่มือเริ่มต้นใช้งานฉบับย่อของ BiBoard

## 2. Set up BiBoard&#x20;

### 2.1 เตรียม environment ในการพัฒนา ESP32

สำหรับรายละเอียด โปรดดู [Chapter 3.2.1](https://docs.petoi.com/thai/arduino-ide/pages/-MVugl3T-mwZYPFHdZ3c#3.2.1-set-up-esp32-development-environment) ของคู่มือเริ่มใช้งานของ BiBoard

### 2.2 แก้ไขไฟล์ code ในแพ็คเกจ

* #### 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
{% endhint %}

ต่อท้ายบรรทัดโค้ดที่ส่วนท้ายของไฟล์:

```cpp
#define CONFIG_DISABLE_HAL_LOCKS 1
```

### 2.3 เพิ่ม hardware partition

อ่านคู่มือผู้ใช้สำหรับตัวเลือกเพิ่มการกำหนดค่า [Add hardware partition configuration option in Arduino IDE](https://docs.petoi.com/biboard/demo-applications/13.-add-hardware-partition-configuration-option-in-arduino-ide)

<figure><img src="/files/wzC46EwxIGDjVcKwEaSw" alt=""><figcaption></figcaption></figure>

### 2.4 ดาวน์โหลด OpenCatEsp32 แพ็คเกจ

{% hint style="info" %}
เราอัปเดต code อย่างต่อเนื่องเป็น Open-source project คุณสามารถติดดาวและติดตาม GitHub repository เพื่อรับฟีเจอร์ใหม่ล่าสุดและการแก้ไขข้อบกพร่อง คุณยังสามารถแบ่งปัน code ของคุณกับผู้ใช้ OpenCatEsp32 ทั่วโลก
{% endhint %}

* ดาวน์โหลด ​OpenCatEsp32 repository จาก GitHub: <https://github.com/PetoiCamp/OpenCatEsp32>. จะดีกว่าถ้าคุณใช้คุณสมบัติการควบคุมเวอร์ชันของ GitHub มิฉะนั้น ตรวจสอบให้แน่ใจว่าคุณดาวน์โหลดโฟลเดอร์ **OpenCatEsp32** ทั้งหมดทุกครั้ง code ทั้งหมดต้องเป็นเวอร์ชันเดียวกันจึงจะทำงานร่วมกันได้
* Iหากคุณดาวน์โหลดไฟล์ Zip ของ code คุณจะได้รับโฟลเดอร์หลักของ **OpenCatEsp32** หลังจากคลาย zip คุณต้องเปลี่ยนชื่อเป็น **OpenCatEsp32** ก่อนเปิด **OpenCatEsp32.ino** เพื่อให้ชื่อทั้งสองตรงกัน\
  .&#x20;

{% hint style="warning" %}
ไม่ว่าคุณจะบันทึกโฟลเดอร์ไว้ที่ใด โครงสร้างไฟล์ควรเป็น:

![](/files/it5Ae2o7Ot6JhN9Hi28A)&#x20;
{% endhint %}

* มี code ที่ชื่อว่า **testX.ino** หลายไฟล์ในโฟลเดอร์ **ModuleTests** คุณสามารถอัปโหลดเพื่อทดสอบบางโมดูลแยกกันได้ เปิด **testX.ino** ใดๆ ที่มีคำนำหน้าว่า “test” (แนะนำให้ใช้ **testBuzzer.ino** เป็น sketch ทดสอบแรกของคุณ)

### 2.5 Compile and upload the sketch

แก้ไข definition ประเภทอุปกรณ์ใน **BiBoard.ino** ตามประเภทอุปกรณ์<br>

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

แก้ไข definition รุ่นของบอร์ดใน **BiBoard.ino** ตามรุ่นของบอร์ด

```cpp
#define BiBoard     //ESP32 Board with 12 channels of built-in PWM for joints
//#define BiBoard2  //ESP32 Board with 16 channels of PCA9685 PWM for joints
```

หลังจากการแก้ไขเสร็จสิ้น คุณสามารถคลิกปุ่มอัปโหลดเพื่ออัปโหลด **BiBoard.ino** และการเปลี่ยนแปลงในโปรแกรมจะถูกบันทึกโดยอัตโนมัติ

<br>

![](/files/P23aKq0OtxP3DQ0DKnNT)

### 2.6 Initialization

เมื่อเปิด BiBoard ที่เพิ่งตั้งค่าใหม่ จะต้องเชื่อมต่อ serial port เข้ากับคอมพิวเตอร์ และเริ่มต้นข้อต่อและ gyroscope accelerometer (IMU) ในหน้าต่าง serial port monitor

{% hint style="warning" %}
ตรวจสอบให้แน่ใจว่าตั้งค่า serial monitor เป็น baud rate **115200** และ **no line ending**
{% endhint %}

![](/files/TRZzpjhqFY7cmuuUk0Qj)

คุณจะเห็นคำถามหลายข้อ:

```cpp
Reset the joints' calibration offsets? (Y/n): 
```

พิมพ์ 'Y' ซึ่งหมายถึงการรีเซ็ตเซอร์โวทั้งหมดเป็นศูนย์

```cpp
- Calibrate the Inertial Measurement Unit (IMU)? (Y/n): 
```

พิมพ์ 'Y' กับคำถาม ซึ่งหมายถึงการ calibrate MPU6050 เช่น gyro/accelerometer sensor

{% hint style="warning" %}
วาง BiBoard FLAT ไว้บนโต๊ะ และห้ามสัมผัสระหว่างการปรับเทียบ บางครั้งโปรแกรมอาจหยุดที่ขั้นตอนการเชื่อมต่อ คุณสามารถปิดจอภาพอนุกรมแล้วเปิดใหม่อีกครั้ง หรือกดปุ่มรีเซ็ตบน BiBoard เพื่อเริ่มโปรแกรมใหม่ โปรแกรมเริ่มการปรับเทียบหลังจากเล่นเมโลดี้ 6 ครั้ง
{% endhint %}

รายละเอียดของข้อมูลการแสดงผลของ serial port มีดังนี้：

```cpp
* Start *
Scanning I2C network...
- I2C device found at address 0x54  !
- I2C device found at address 0x68  !
- done
Set up the new board...
// The device name to use when connecting with bluetooth
- Name the new robot as: BittleED    
Reset the joints' calibration offsets? (Y/n): 
Y

Initializing MPU...
- Testing MPU connections...attempt 0
- MPU6050 connection successful
- Initializing DMP...
- Calibrate the Inertial Measurement Unit (IMU)? (Y/n): 
Y

Put the robot FLAT on the table and don't touch it during calibration.
- Calibrating the Inertial Measurement Unit (IMU)...
>..........>..........
MPU offsets:
//           X Accel  Y Accel  Z Accel   X Gyro   Y Gyro   Z Gyro
//OFFSETS     3752,    -968,     942,     170,      76,      21
- Enabling DMP...
- Enabling interrupt detection (Arduino external interrupt 26)...
- DMP ready! Waiting for the first interrupt...
Bluetooth name: BittleED
Waiting for a client connection to notify...
Setup ESP32 PWM servo driver...
Ready!

```

หลังจากการ calibrate IMU เสร็จสิ้น ทุกครั้งที่เปิดเครื่อง หุ่นยนต์จะเข้าสู่โปรแกรมการเปิดเครื่องตามปกติ

{% hint style="info" %}
โปรแกรมหลักของ Bittle จะตัดสินว่ามันเริ่มต้นโดยการเปรียบเทียบ **BIRTHMARK** ใน EEPROM หรือไม่ และจะไม่เข้าสู่กระบวนการเริ่มต้นอีกเมื่อเปิดใช้งานในครั้งต่อไป หากคุณต้องการปรับเทียบเซอร์โวออฟเซ็ตใหม่หรือปรับเทียบ IMU (MPU6050) ใหม่ คุณสามารถป้อน 'R' ใน serial monitor เพื่อเริ่มต้นใหม่
{% endhint %}

### 2.7 Power on

* กดปุ่มบนแบตเตอรี่ค้างไว้และวางหุ่นยนต์โดยให้ด้านหนึ่งขึ้น มันจะเข้าสู่สถานะ calibration state automatically ภาพด้านล่างแสดงขาบนและขาล่างที่ติดตั้งหลังจากหุ่นยนต์เข้าสู่สถานะการ calibate

![](/files/mzq2t0vK9IyMU6MU2LJG)

โปรดดู [chapter 5 🔌 Connect Wires](https://bittle.petoi.com/5-connect-wires) และ [chapter 6 📐 Calibration](https://bittle.petoi.com/thai-2/6-calibration) สำหรับกระบวนการ calibrate ทั้งหมด

* หากคุณเปิดหุ่นยนต์และหุ่นยนต์ตั้งตรง (โดยหงายหลังขึ้น) หุ่นยนต์จะเริ่มจากท่า " rest " (พับขาและปลดล็อกเซอร์โว)

### 2.8 โหมดมาตรฐานและโหมดพิเศษ

Code จะเริ่มต้นทำงานในโหมดมาตรฐาน หากคุณมีโมดูลที่สามารถขยายได้บางโมดูล คุณอาจยกเลิกข้อคิดเห็น definition ของโมดูลเฉพาะ จะปิดใช้งานรหัส Gyro เพื่อประหยัดพื้นที่ในการเขียนโปรแกรมและเปิดใช้งานการสาธิตของโมดูล

ใน official modules ถูกกำหนดไว้ในไฟล์ส่วนหัวแยกต่างหากใน **OpenCat/src/** คุณสามารถค้นหาได้ใน **OpenCat/src/io.h -> readSignal()** ลักษณะการทำงานของ **OTHER\_MODULES** กำหนดไว้ใน **OpenCat/OpenCat.ino** **-> otherModule()** คุณสามารถศึกษาโค้ดตัวอย่างเพื่อเขียนฟังก์ชันของคุณเองได้<br>

<figure><img src="/files/V7fAEofmb72zn56mA0GE" alt=""><figcaption></figcaption></figure>

### 3. Configuration with App

BiBoard มีบลูทูธในตัว และคุณสามารถเชื่อมต่อกับแอพ Android ได้:

&#x20;[App for BiBoard (Android 4.4+)](https://docs.petoi.com/mobile-app/app-guide)

คุณสามารถตรวจสอบประวัติการอัปเดตและคุณลักษณะเพิ่มเติมได้ใน **ChangeLog.md** (BiBoard\ChangeLog.md)

<br>


---

# Agent Instructions: 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:

```
GET https://docs.petoi.com/thai/arduino-ide/sketch-biboard.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
