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
  • Nybble
  • Bittle
  • 1. Config Raspberry Pi serial port
  • 2. Change the permission of ardSerial.py
  • 3. Use ardSerial.py as the commander of robot

Was this helpful?

Export as PDF
  1. API

การสื่อสารผ่านพอร์ตซีเรียลของ Raspberry Pi

Previousการใช้โปรโตคอล ESP-NOWNextROS

Last updated 2 years ago

Was this helpful?

หุ่นยนต์ไม่ต้องการ PI เพื่อเคลื่อนไหว

คุณต้องถอดปลั๊ก USB Adpter 6 พินสำหรับ NYBoard ก่อนที่จะติดตั้ง PI ไปยังบอร์ด

คุณสามารถประสานซ็อกเก็ต 2x5 บน Nyboard เพื่อเสียบ Raspberry Pi PI 3A+ เป็นแบบที่ดีที่สุดสำหรับ มิติของ Nyboard

Nybble

Bittle

หลังจากที่คุณประสานบนซ็อกเก็ต คุณจะไม่สามารถติดตั้งฝาหลังด้านหลังของ Bittle ได้

  • Ascii: ใช้ 2 ไบต์เพื่อเก็บอักขระ Ascii '6' และ '5'

  • Binary: ใช้ 1 byte เพื่อจัดเก็บค่า 65 ซึ่งเปรียบเสมือนกับตัวอักษร Ascii 'A'

ถ้าเป็นค่า -113 แบบ Ascii string จะใช้พื้นที่หน่วยความจำ 4 bytes แต่จะเหลือเพียง 1 byte เมื่อเข้ารหัสแบบ binary โดยภายในจะไม่สามารถแสดงผลเป็นตัวอักษรได้ แต่ยังคงเก็บค่าได้เป็นจำนวนเต็ม 1 byte

1. Config Raspberry Pi serial port

In Pi's terminal, type sudo raspi-config

ในตัวเลือก Interface ให้ค้นหา Serial แล้วปิดการเข้าสู่ระบบ shell ผ่านทางซีเรียลและเปิดใช้งานอินเทอร์เฟซซีเรียลเพื่อใช้พอร์ต UART หลัก:

  1. Run raspi-config with sudo privilege: sudo raspi-config.

  2. Find Interface Options -> Serial Port.

  3. At the option Would you like a login shell to be accessible over serial? select 'No'.

  4. At the option Would you like the serial port hardware to be enabled? select 'Yes'.

  5. Exit raspi-config and reboot for changes to take effect.

ถ้าคุณเชื่อมต่อ Pi เข้ากับช่อง 2x5 ของ NyBoard แล้ว พอร์ตซีเรียลของพวกเขาควรจะเชื่อมต่อโดยอัตโนมัติที่แรงดัน 3.3V อย่างไรก็ตามหากไม่ได้เชื่อมต่อแบบนี้ คุณควรใช้หลอดสายขนาดเล็กเพื่อเชื่อมต่อ Rx และ Tx ของชิป AI ของคุณกับ Tx และ Rx ของ NyBoard โดยให้แรงดันตรงกัน

Note: If you installed Ubuntu OS on Raspberry Pi, please config it as follows:

  • add enable_uart=1 to /boot/config.txt

  • remove console=serial0,115200 from /boot/firmware/cmdline.txt on Ubuntu and similar to/boot/cmdline.txt on Raspberry Pi OS

  • disable the serial console: sudo systemctl stop serial-getty@ttyS0.service && sudo systemctl disable serial-getty@ttyS0.service

  • make sure you have pyserial installed if you're using the python serial library, not python-serial from apt.

  • create the following udev file (I created /etc/udev/rules.d/50-tty.rules):

KERNEL=="ttyS0", SYMLINK+="serial0" GROUP="tty" MODE="0660"
KERNEL=="ttyAMA0", SYMLINK+="serial1" GROUP="tty" MODE="0660"
  • reload your udev rules: sudo udevadm control --reload-rules && sudo udevadm trigger

  • change the group of the new serial devices:

sudo chgrp -h tty /dev/serial0
sudo chgrp -h tty /dev/serial1
  • The devices are now under the tty group. Need to add the user to the tty group and dialout group:

sudo adduser $USER tty
sudo adduser $USER dialout
  • update the permissions for group read on the devices:

sudo chmod g+r /dev/ttyS0
sudo chmod g+r /dev/ttyAMA0
  • reboot

Or just create a script that will do this automatically.

ถ้าคุณต้องการรันโปรแกรมเป็นคำสั่ง bash คุณต้องทำให้โปรแกรมสามารถรันได้:

chmod +x ardSerial.py

คุณอาจจะต้องเปลี่ยน path ที่ถูกต้องของ Python binary บนบรรทัดแรก:

#!/user/bin/python

3. Use ardSerial.py as the commander of robot

NyBoard มีพอร์ตซีเรียลเดียวเท่านั้น หากต้องการควบคุม Bittle ด้วยพอร์ตซีเรียลของ Raspberry Pi คุณจะต้องถอดอะแดปเตอร์ USB ออกก่อน

พิมพ์ ./ardSerial.py <args> เทียบเท่ากับการพิมพ์ ใน Arduino's serial monitor โดยตัวอย่างเช่น ./ardSerial.py kcrF หมายความว่า "ทำการเคลื่อนที่ด้วยทักษะคลานไปข้างหน้า".

การทำงานของ ardSerial.py และการแยกวิเคราะห์ใน OpenCat.ino ต้องการการปรับปรุงเพิ่มเติมเพื่อรองรับคำสั่งซีเรียลทั้งหมดในโปรโตคอล

For Nybble:

การเชื่อมต่อกับ Pi อาจทำให้ความสามารถในการเคลื่อนไหวลดลง! จำเป็นต้องใช้แบตเตอรี่ที่มีกำลังมากขึ้น

เมื่อเชื่อมต่อกับ Pi แล้ว Nybble อาจจะมีความสามารถในการเคลื่อนไหวที่ลดลง โดยเฉพาะการเคลื่อนไหวที่มีความเข้มข้น เช่นการเดินเหยียบ (โทเคน isktr) ระบบจะถูกจ่ายไฟด้วยแบตเตอรี่ 14500 สองเลเยอร์ คุณอาจจะคิดหาวิธีการจ่ายไฟที่ดีกว่า เช่น การใช้แบตเตอรี่ 7.4 ลิโพแบตเตอรี่สูงสุด หรือ 2S-18650 มีมากมายข้อควรพิจารณาในการร่วมมือซอฟต์แวร์และฮาร์ดแวร์เพื่อให้ได้ประสิทธิภาพที่สมดุลกัน ด้วยตัวขนาดเล็กของ Nybble นั้น จะดีกว่าใช้เป็นแพลตฟอร์มสำหรับเริ่มต้นกรอบการสื่อสารและต้นไม้พฤติกรรมมากกว่าเป็นสัตว์แข่งขัน

ชิ้นส่วนสีแดง สามารถใช้ 3D print ได้

ดังที่แสดงใน แสดงว่าอาร์ดูโนไอดีเอสเป็นตัวกลางที่รองรับโทเค็นทั้งหมดที่ถูกเข้ารหัสเป็นตัวอักษร ASCII char string เพื่อให้มนุษย์สามารถอ่านได้ ในขณะที่คอมพิวเตอร์หลัก (เช่น RasPi) รองรับคำสั่งเพิ่มเติมที่เข้ารหัสเป็น binary string เพื่อให้การเข้ารหัสมีประสิทธิภาพมากขึ้น ตัวอย่างเช่น เมื่อเข้ารหัสมุม 65 องศา:

แน่นอนว่าการเข้ารหัสแบบไบนารีจะมีประสิทธิภาพมากกว่าการเข้ารหัสแบบสตริง Ascii อย่างไรก็ตาม ข้อความที่ถูกส่งไปจะไม่สามารถอ่านได้โดยตรงโดยมนุษย์ ใน OpenCat repository ฉันได้ใส่สคริปต์ Python ที่เรียกว่า ที่สามารถจัดการการสื่อสารซีเรียลระหว่าง NyBoard และ Pi ได้ง่ายดาย

You also need to DISABLE the to avoid repeating reset signals sent by Pi's GPIO 4.

ถ้าคุณใช้ระบบ Linux ทั่วไป หลังจากเชื่อมต่ออุปกรณ์แบบ uploader เข้ากับคอมพิวเตอร์ของคุณ คุณจะเห็น "ttyUSB#" ในรายการพอร์ตซีเรียล แต่อาจมีข้อผิดพลาดของพอร์ตซีเรียลเมื่อทำการอัปโหลด คุณจะต้องให้สิทธิ์การเชื่อมต่อพอร์ตซีเรียลก่อน โปรดไปที่ลิงค์นี้และทำตามคำแนะนำ:

2. Change the permission of

🍓
Pi standoff
serial protocol
ardSerial.py
1-wire interface of Pi
A good tutorial on the Pi Serial
https://playground.arduino.cc/Linux/All/#Permission
ardSerial.py