Petoi Doc Center
🇹🇭 Thai
🇹🇭 Thai
  • ยินดีต้อนรับสู่ Petoi Doc Center
  • Infrared Remote
    • รีโมทคอนโทรล
  • Mobile App
    • คาลิเบเตอร์และคอนโทรลเลอร์
  • Desktop APP
    • การแนะนำเบื้องต้น
    • ตัวอัปโหลดเฟิร์มแวร์
    • การคาลิเบรทข้อต่อ
    • สกิลคอมโพสเซอร์
  • Arduino IDE
    • อัปโหลด Sketch สำหรับ NyBoard
    • อัปโหลด Sketch สำหรับ BiBoard
    • การคาลิเบรทด้วย Arduino IDE
    • ซีเรียลมอนิเตอร์
  • API
    • 🖇️ซีเรียลโปรโตคอล
    • 🐍คู่มือผู้ใช้ Python SerialMaster
    • 🐛MicroPython คอนโทรลเลอร์
      • การเรียกใช้ MicroPython บน ESP8266
      • ติดตั้ง WebREPL
      • การใช้โปรโตคอล ESP-NOW
    • 🍓การสื่อสารผ่านพอร์ตซีเรียลของ Raspberry Pi
    • 🤖ROS
  • Nyboard
    • NyBoard V1_0
    • NyBoard V1_1
  • BIBOARD
    • คู่มือเริ่มต้นใช้งาน BiBoard ฉบับรวบลัด
    • Demo Applications
      • 1.GPIO port
      • 2.Serial port
      • 3.Analog-digital converter
      • 4.Digital-Analog Converter
      • 5.EEPROM (Electrically Erasable Programmable read only memory)
      • 6.Gyro IMU(MPU6050)
      • 7.Infrared remote control
      • 8.PWM(Pulse Width Modulation)
      • 9.Servo(under construction)
      • 10.Classic Bluetooth serial port SPP
      • 11.Bluetooth low energy (BLE) serial port pass-through
      • 12.File system SPIFFS
      • 13.Add hardware partition configuration option in Arduino IDE
      • 14.Play MP3
      • 15.The usage of Wi-Fi OTA(Over-The-Air)
  • Communication Modules
    • Introduction
    • USB Uploader (CH340C or CH343G)
    • Dual Mode Bluetooth
    • WiFi ESP8266
      • ESP8266 + Python Scripts Implement wireless crowd control
  • Extensible Modules
    • Introduction
    • MU Camera
    • Ultrasonic Sensor
    • Light Sensor
    • Touch Sensor
    • Gesture Sensor
    • PIR Motion Sensor
  • Applications
    • Skill Creation
    • OpenCat Imitation Tutorial
    • Programmable Puppet Character
  • History
    • Upload Sketch For NyBoard (software 1.0)
  • Technical Support
    • 🛠️Supporting Application and Software
    • 🙋‍♂️FAQ(Frequently Asked Questions)
  • Useful Links 🕸
    • 🔭Official Site of Petoi
    • 💿GitHub of OpenCat
    • 🎪PetoiCamp (Forum)
Powered by GitBook
On this page
  • 1. Bluetooth protocol
  • 2. Classic Bluetooth serial port (SPP)

Was this helpful?

Export as PDF
  1. BIBOARD
  2. Demo Applications

10.Classic Bluetooth serial port SPP

โค้ดตัวอย่างส่วนใหญ่แสดงให้เห็นถึงการส่งต่อข้อมูลร่วมกันระหว่างพอร์ตอนุกรม Bluetooth และพอร์ตอนุกรม ซึ่งได้มาจากการตัวอย่าง อย่างเป็นทางการของ ESP32 ซึ่งเรียบง่ายและเข้าใจได้ง่าย คำอธิบายจึงอธิบายแนวคิดที่ปรากฏในโค้ดเป็นหลัก

1. Bluetooth protocol

ในปัจจุบัน โปรโตคอล Bluetooth หลักแบ่งออกเป็นสองประเภท ได้แก่ Bluetooth แบบดั้งเดิม (HS/BR/EDR) ตาม RFCOMM และ Bluetooth พลังงานต่ำ (BLE) ตาม GATT

Bluetooth แบบดั้งเดิมนั้นเร็วกว่าและมีโปรโตคอลแอปพลิเคชันเฉพาะมากมาย เช่น A2DP ที่เน้นเสียง, พอร์ตอนุกรม Bluetooth SPP เป็นต้น อย่างไรก็ตาม การใช้พลังงานสูง และการเข้าถึงอุปกรณ์ Apple ต้องใช้ชิป MFi (Made For iOS) และการรับรอง

Bluetooth Low Energy (BLE) สามารถกำหนดโปรไฟล์ GATT ต่างๆ ได้ด้วยตัวเอง และยังมีโปรไฟล์ที่ใช้กันทั่วไป (เช่น ข้อมูลอุปกรณ์ แบตเตอรี่ ฯลฯ) มีการใช้พลังงานต่ำและใช้กันอย่างแพร่หลาย สามารถใช้กับอุปกรณ์ Apple ข้อเสียคือช้ากว่าบลูทูธแบบเดิม บลูทูธพลังงานต่ำส่วนใหญ่จะใช้กับอุปกรณ์ที่มีปริมาณข้อมูลน้อยแต่ไวต่อการใช้พลังงาน เช่น สร้อยข้อมือ/นาฬิกาอัจฉริยะ/บีคอน

2. Classic Bluetooth serial port (SPP)

การสาธิตนี้ใช้โปรโตคอล SPP ตามบลูทูธแบบดั้งเดิม ซึ่งมาพร้อมกับโปรโตคอลพอร์ตอนุกรมทั้งหมด เมื่อคอมพิวเตอร์หรือโทรศัพท์ Android เชื่อมต่อและจับคู่ หมายเลขพอร์ตอนุกรมจะถูกสร้างขึ้นโดยอัตโนมัติในระบบสำหรับการสื่อสาร และประสบการณ์การใช้งานจะไม่แตกต่างจากพอร์ตอนุกรมแบบมีสายทั่วไปมากนัก

//This example code is in the Public Domain (or CC0 licensed, at your option.)
//By Evandro Copercini - 2018
//
//This example creates a bridge between Serial and Classical Bluetooth (SPP)
//and also demonstrate that SerialBT have the same functionalities of a normal Serial

#include "BluetoothSerial.h"

#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif

BluetoothSerial SerialBT;

void setup() {
  Serial.begin(115200);
  SerialBT.begin("BTSPP_Test");          //Bluetooth device name
  Serial.println("The device started,");
  Serial.println("Now you can pair it with bluetooth!");
}

void loop() {
  if (Serial.available()) {
    SerialBT.write(Serial.read());
  }
  if (SerialBT.available()) {
    Serial.write(SerialBT.read());
  }
  delay(20);
}

พอร์ตอนุกรมบลูทูธพลังงานต่ำจะแสดงให้เห็นในบทถัดไป โดยพื้นฐานแล้ว เป็นโปรไฟล์ที่กำหนดค่าด้วยพอร์ตอนุกรมและต้องการ การสนับสนุนของโฮสต์ซอฟต์แวร์

Previous9.Servo(under construction)Next11.Bluetooth low energy (BLE) serial port pass-through

Last updated 2 years ago

Was this helpful?