หากหุ่นยนต์ยังคงส่งเสียงบี๊บหลังจากที่คุณเชื่อมต่อตัวอัปโหลด USB โดยมีตัวเลขพิมพ์อยู่บนจอภาพซีเรียล แสดงว่ามีการเรียกใช้งานสัญญาณเตือนแรงดันไฟฟ้าต่ำ คุณต้องจ่ายพลังงานให้กับเมนบอร์ดด้วยแบตเตอรี่เพื่อให้ผ่านเกณฑ์
The sensor contains two touch parts (left and right) and can detect changes in capacitance when a finger approaches. This means that the touch sensor will output a high level whether your finger touches lightly or presses hard. You can realize the function you want by judging the detected value (1 for high level, 0 for low level).
พอร์ตซีเรียล 1 บน P16 สามารถเชื่อมต่อกับตัวดาวน์โหลด USB และอุปกรณ์ซีเรียลภายนอกได้ โปรดอย่าใช้ตัวดาวน์โหลดและอุปกรณ์ซีเรียลภายนอกพร้อมกัน การแบ่งแรงดันพอร์ตซีเรียลจะนำไปสู่ข้อผิดพลาดในการสื่อสาร
ในการสาธิต Arduino นั้น Serial แทนพอร์ตซีเรียล 0 Serial1 แทนพอร์ตซีเรียล 1 Serial และ Serial1 นั้นส่งถึงกัน
PIR Motion Sensor
Function introduction
This sensor allows you to detect the movement of animals, usually the movement of humans within its detection range. Just connect it to the NyBoard and program it, and when anyone moves within its detection range, the sensor will output a high potential on its SIG pin.
/* In this demo, we use TX2, RX2 as general purpose IO
* TX2 : IO17
* RX2 : IO16
*/
void setup() {
// initialize digital pin 16 & 17 as an output.
pinMode(16, OUTPUT);
pinMode(17, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(16, HIGH); // GPIO 16 & 17 HIGH
digitalWrite(17, HIGH);
delay(1000); // wait for a second
digitalWrite(16, LOW); // GPIO 16 & 17 LOW
digitalWrite(17, LOW);
delay(1000); // wait for a second
}
/* In this demo, we use Serial and Serial1
* Serial and Serial1 send to each other
*/
void setup() {
// initialize both serial ports:
Serial.begin(115200);
Serial1.begin(115200);
}
void loop() {
// read from port 1, send to port 0:
if (Serial1.available()) {
int inByte = Serial1.read();
Serial.write(inByte);
}
// read from port 0, send to port 1:
if (Serial.available()) {
int inByte = Serial.read();
Serial1.write(inByte);
}
}
Hardware setup
Connecting to the NyBoard with wire as shown in the following picture:
For specific use, the end connected to the sensor can be fixed on the robot's head (included in Bittle's mouth, or attached to the top of Nybble's head), of course, you can also use your creativity according to actual needs.
Software setup
You can use the Arduino IDE to upload the demo code (doubleTouch.ino) or compile and upload your own code.
This demo sketch (doubleTouch.ino) implements real-time printing of the detection values of D6 and D7 pins in the serial monitor:
Connecting to the NyBoard with wire as shown in the following picture:
For specific use, the end connected to the sensor can be fixed on the robot's head (included in Bittle's mouth or attached to the top of Nybble's head), of course, you can also use your creativity according to actual needs.
Software setup
You can use the Arduino IDE to upload the demo code (test_Touch_Reflection_PIR.ino) or compile and upload your own code.
This demo sketch (test_Touch_Reflection_PIR.ino) implements real-time printing of sensor detection results in the serial monitor - when anyone moves within its detection range, print 1; otherwise, print 0.
The demo code
The demo code is in the OpenCat code repository on GitHub (specific path: OpenCat/ModuleTests/test_Touch_Reflection_PIR). You can visit our GitHub code repository https://github.com/PetoiCamp/OpenCat to download the complete code, as shown in the following figure:
เชื่อมต่อ USB Adapter เข้ากับเมนบอร์ดและเลือก serial port ที่ถูกต้อง โปรดดูส่วน Connect NyBoard section เชื่อมต่อ NyBoard ในโมดูล USB Uploader สำหรับขั้นตอนเฉพาะ
คุณสามารถเลือก "Serial Monitor" ในแถบเมนู "Tools" หรือคลิกปุ่ม … เพื่อเปิดหน้าต่าง Serial Monitor:
เปิด serial monitor และตั้งค่า baud rate บน NyBoard V1_* ให้ตั้งค่า " No line ending " และ baud rate เป็น 115200 ใน serial monitor
เชื่อมต่อ Bluetooth uploader (optional)
สำหรับขั้นตอนเฉพาะ โปรดดูที่ ใน Dual-Mode Bluetooth Module
จากนั้นคุณสามารถเลือก Tools->Port บน Arduino IDE และใช้งานในลักษณะเดียวกับ USB Adapter
บน Mac บลูทูธอาจขาดการเชื่อมต่อหลังจากอัปโหลดหลายครั้ง ในกรณีดังกล่าว ให้ลบการเชื่อมต่อและเชื่อมต่อใหม่เพื่อให้ฟังก์ชันทำงานต่อ
หาก Bluetooth dongle ไม่เจออยู่ในชุดหุ่นยนต์โดย Seeed Studio หรือ partner ของเราโปรดส่งอีเมลถึง [email protected] เพื่อทราบข้อมูลเพิ่มเติม
ด้วย USB adapter / Bluetooth module ที่เชื่อมต่อ NyBoard และ Arduino IDE คุณจะมีอินเทอร์เฟซที่ดีที่สุด - Serial Monitor เพื่อสื่อสารกับ NyBoard และเปลี่ยนทุก byte บนนั้น (ผ่านการส่ง serial commands ตาม ).
13.Add hardware partition configuration option in Arduino IDE
The sensor integrates two photoresistors (depending on the light intensity adjustment resistance) to detect the light intensity. The photoresistor is a special resistance that uses the photoconductive effect, and its resistance is directly related to the intensity of the incident light. When the light intensity increases, the resistance decreases; when the light intensity decreases, the resistance increases. The output signal is an analog value, the brighter the brightness, the larger the value. You can realize the function you want by judging the value of the detected light intensity, such as the function of a robot tracing light.
Hardware setup
Connecting to the NyBoard with wire as shown in the following picture:
For specific use, the end connected to the sensor can be fixed on the robot's head (included in Bittle's mouth, or attached to the top of Nybble's head), of course, you can also use your creativity according to actual needs.
Software setup
You can use the to upload the demo code (doubleLight.ino) or compile and upload your own code.
This demo sketch (doubleLight.ino) implements real-time printing of the analog values of the two analog pins (A2 and A3) in the . You can also use the serial plotter to view the two analog pins (A2 and A3) more intuitively. The waveform graph generated by the analog value of the pin output along the time axis.
The demo code
Gesture Sensor
Function introduction
The sensor features advanced gesture detection, proximity detection and digital ambient light sensing. Gesture detection can accurately sense "up, down, left and right" and more complex movements.
Software setup
Install the latest version of the Arduino_APDS9960 library using the
2. Upload the demo sketch (gesture.ino)
Of course, you can also compile and upload your own sketch for the gesture sensor.
Hardware setup
After uploading the the demo sketch, connecting to the NyBoard with wire as shown in the following picture:
For specific use, the end connected to the sensor can be fixed on the robot's head (included in Bittle's mouth or attached to the top of Nybble's head), of course, you can also use your creativity according to actual needs.
This demo sketch (gesture.ino) implements real-time printing of various directional gestures (up, down, left, and right) made by the user in front of the gesture sensor in the .
หุ่นยนต์ Nyboard v1 ใช้ Controller Atmel ATMEGA328P ซึ่งรองรับแค่ Serial port เท่านั้น โดยมีการแยก Serial port ของหุ่น Nyboard ให้รองรับหลายๆ Module โดย Pin ของ Serial port สามารถต่อกับ Arduino Pro Mini 6 Pin โดยรายละเอียดของ Pin ต่างๆแสดงอยู่ในตารางด้านล่าง
ESP8266 + Python Scripts Implement wireless crowd control
Install Python3, and download to control the robot.
Ultrasonic Sensor
Function introduction
RUS-04 is a new module that integrates RGB LED and ultrasonic ranging. Only one GPIO is needed to operate the ultrasonic transceiver, and while the ultrasonic probe is measuring the distance, the left and right probes can emit 7 colorful lights.
"""
In Python 3.8 and earlier, the name of the collection type is
capitalized, and the type is imported from the 'typing' module
"""
# from typing import Union, Optional # for Python 3.9+
from typing import Union, Dict, List, Optional # for Python 3.7
# ip = "192.168.0.108" # for only one robot
ip = ["192.168.0.110", "192.168.0.108"] # for multiple robots
สำหรับผู้ใช้ระบบ Linux หากคุณพบข้อความแสดงข้อผิดพลาด "_tkinter.TclError: no display name and no $DISPLAY environment variable", คุณสามารถลง python3-tk, tk-dev,เป็นคำสั่งสำหรับ Ubuntu/Debian โดยใช้คำสั่งต่อไปนี้:
Currently only supports the product Nybble, the software version 2.0, the mode can choose "Ultrasonic" or "RandomMind_Ultrasonic".
You can use the Firmware Uploader within the Petoi Desktop App to finish the configuration.
You can also use Arduino IDE for the most freedom to upload and modify the codes.
Use the latest OpenCat code to finish the setup. As shown below:
If you have already uploaded the latest OpenCat code to make Nybble walk, you only need to uncomment the #define ULTRASONIC at the beginning of OpenCat.ino then upload the code.
If you are not sure, you need to finish the upload process for the standard mode to ensure everything is configured correctly, then upload the code in the Ultrasonic mode.
If the Ultrasonic code is uploaded correctly, you can see success messages printed on the serial monitor of Arduino IDE. As shown below:
Ultrasonic module code realization function: According to the different distances monitored by the ultrasonic module in real-time, the probe inside the ultrasonic module lights up with lights of different colors, and Nybble will make different action responses at the same time.
The demo video is as follows:
หมายเหตุ:
Arduino IDE 2.0 ไม่สามารถเพิ่มตัวเลือกการกำหนดค่า large_spiffs_16MB (4.5MB APP with OTA/6.93MB SPIFFS) ได้ในขณะนี้
ปลั๊กอินอัปโหลดไฟล์ SPIFFS file upload plugin ใน Arduino IDE 1.8.* เขียนด้วยภาษาจาวา และ Arduino IDE 2.0 เขียนด้วยภาษาอื่น (TypeScript + Golang) ดังนั้นปลั๊กอินอัปโหลดก่อนหน้านี้จึงไม่สามารถใช้ใน Arduino IDE 2.0 ได้ ขณะนี้ยังไม่รองรับปลั๊กอินอัปโหลดไฟล์ Arduino IDE 2.0 SPIFFS
ดังนั้นขอแนะนำให้คุณติดตั้งและใช้ Arduino IDE 1.8.* IDE ชั่วคราวเพื่ออัปโหลดไฟล์ร่างและ .mp3
แน่นอน คุณยังสามารถใช้ VS Code + PlatformIO เพื่ออัปโหลดไฟล์ร่างและ .mp3 สำหรับรายละเอียด โปรดดูเอกสารต่อไปนี้:
#include <Arduino.h>
#include <IRremote.h>
int RECV_PIN = 23;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup() {
Serial.begin(115200);
irrecv.enableIRIn();
Serial.println("IR Receiver ready");
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
Serial.print(" - ");
irrecv.resume(); // Receive the next value
}
delay(300);
}
Only 4% of flash is used on BiBoard
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 ข้อเสียคือช้ากว่าบลูทูธแบบเดิม บลูทูธพลังงานต่ำส่วนใหญ่จะใช้กับอุปกรณ์ที่มีปริมาณข้อมูลน้อยแต่ไวต่อการใช้พลังงาน เช่น สร้อยข้อมือ/นาฬิกาอัจฉริยะ/บีคอน
MU Vision Sensor is an intelligent vision sensor that can recognize many kinds of objects with a deep-learning algorithm inside. For example, it can detect color blocks, balls, the human body, and cards. Its detect result can be transmitted through UART or I2C interface. MU is compact, has low power consumption, processes all algorithms locally, and can be widely used in intelligent toys, AI+STEAM lessons, creators, and other products or fields.
Software setup
Currently only supports the product Bittle, software version 2.0, please select "Camera" for the mode.
You can use the within the Petoi Desktop App to finish the configuration.
You can also use for the most freedom to upload and modify the codes.
First, download and install the into your Arduino IDE.
2. Use the latest OpenCat code to finish the setup.
If you have already uploaded the latest OpenCat code to make Bittle walk, you only need to uncomment the #define CAMERA at the beginning of OpenCat.ino then upload the code.
If you are not sure, you need to finish the to ensure everything is configured correctly, then upload the code in the camera mode.
Hardware setup
After uploading the firmware, switching the dial switches on the MU Vision Sensor and connecting to the NyBoard with wire as shown in the following picture:
Note: The position of the left and right switches (left: down and up; right: down and down) must be dialed to the position shown in the figure.
Fix the end connected to the camera to the robot's head (included in Bittle's mouth).
If the camera code is uploaded correctly, Bittle maintains a squat position basically, you can see success messages printed on the of Arduino IDE. When the MU Vision Sensor recognizes a target, the two LEDs will turn blue, and Bittle's head can follow the target and swing left and right. The demo code will auto-switch the target between a yellow tennis ball and a human body if it fails to find any object.
If the MU Vision Sensor has not been able to identify the target object, please press the reset button on the camera, then press the reset button on the main board.
For more details, please refer to .
The demo video is as follows:
การคาลิเบรทข้อต่อ
Robots can be precisely calibrated using the Petoi Desktop App.
PWM ของ ESP32 เรียกว่าตัวควบคุม LED (LEDC) ตัวควบคุม LED PWM ส่วนใหญ่จะใช้เพื่อควบคุม LED และยังสามารถสร้างสัญญาณ PWM สำหรับการควบคุมอุปกรณ์อื่นๆ ตัวควบคุมมีตัวจับเวลา 8 ตัว ซึ่งสอดคล้องกับช่องความเร็วสูง 8 ช่อง และช่องความเร็วต่ำ 8 ช่อง รวมเป็น 16 ช่อง
MicroPython คอนโทรลเลอร์
คู่มือการใช้โมดูล WiFi เป็นตัวควบคุม MicroPython
Part 1: Hardware Setup
1.1 hardware list
Introduction
The head of Bittle is designed to be a clip to hold extensible modules. We compiled a sensor pack with some popular modules, but its contents may change in the future. You can also wire other add-ons thanks to the rich contents of the Arduino and Raspberry Pi communities.
You can find the demo codes of these modules in our GitHub repository. They should be in the folder if you download the whole OpenCat repository.
//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);
}
API คอนโทรลเลอร์ LED PWM สามารถรายงานข้อผิดพลาดเมื่อความถี่ที่ตั้งไว้และความละเอียดรอบการทำงานเกินช่วงฮาร์ดแวร์ของคอนโทรลเลอร์ LED PWM ตัวอย่างเช่น หากคุณพยายามตั้งค่าความถี่เป็น 20 MHz และความละเอียดรอบการทำงานเป็น 3 บิต ข้อผิดพลาดจะถูกรายงานบนจอภาพพอร์ตซีเรียล
2. Configure the PWM frequency on BiBoard in Arduinoin Arduino
The touch, reflection, PIR sensors can generate digital 1 or 0 as a switch signal. So they should be connected to the digital Grove socket. In the demo code, we use the fourth socket with D6 and D7.
เสียบขา 6 ขา (H1) ของ USB uploader เข้ากับช่อง Uploader ของ NyBoard แล้วใช้สาย USB data ที่มากับอุปกรณ์ นำหนึ่งข้างเสียบเข้ากับพอร์ต MicroUSB ของโมดูล USB upload และอีกข้างเสียบเข้ากับพอร์ต USB ของคอมพิวเตอร์
Download the Arduino IDE(e.g. 1.8.19) for Linux from
Install it on the Chromebook. Please refer to the video at
11.Bluetooth low energy (BLE) serial port pass-through
พอร์ตอนุกรม Bluetooth Low Energy (BLE, Bluetooth Low Energy) ใช้กันอย่างแพร่หลาย บนแพลตฟอร์ม iOS ของ Apple Classic Bluetooth ต้องมีใบรับรอง MFi เพื่อเชื่อมต่อกับอุปกรณ์ iOS ของ Apple อุปกรณ์บลูทูธพลังงานต่ำไม่มีข้อจำกัดนี้
โปรโตคอลสแต็คและหลักการของบลูทูธพลังงานต่ำจะไม่ถูกทำซ้ำที่นี่ มีบทความและวิดีโอที่เกี่ยวข้องมากมาย กล่าวโดยย่อ บริการบลูทูธมีให้ในรูปแบบของโปรไฟล์ และมีอักขระ N ตัวที่มี ID อิสระ (UUID) อยู่ใต้โปรไฟล์ของแต่ละบริการ อักขระแต่ละตัวมีสิทธิ์ต่างกัน (อ่าน เขียน แจ้ง ระบุ) หลังจากที่ผู้ใช้กำหนดอักขระและรวมเข้ากับสิทธิ์แล้ว ก็สามารถให้บริการที่สมบูรณ์ได้
BLE pass-through คืออะไร คือเพื่อสร้างบริการ BLE และมีอักขระ 2 ตัวอยู่ใต้โปรไฟล์นี้
ครั้งแรกที่คุณใช้พอร์ตอนุกรมเพื่อดาวน์โหลด เครื่องมือไพธอน "esptool" จะถูกเรียก คุณสามารถใช้ OTA ได้หลังจากการดาวน์โหลดเสร็จสิ้น ในตัวเลือกพอร์ต คุณจะพบพอร์ตพิเศษตามที่อยู่ IP ซึ่งเป็นที่อยู่ OTA
เลือกที่อยู่นี้ มุมขวาล่างคือที่อยู่ IP ของ ESP32 Dev Module บน BiBoard ของคุณ (192.168.1.178)
ในเวลาเดียวกัน คำเตือนจะปรากฏขึ้น: "ไม่รองรับการมอนิเตอร์แบบอนุกรมบนพอร์ตเครือข่าย เช่น 192.168.1.178 สำหรับโมดูล ESP32 Dev ในล่าสุดนี้"
ESP32 OTA ของ Arduino เหมาะสำหรับการอัปเดตโปรแกรมเท่านั้น และไม่สามารถทำงานดีบักพอร์ตอนุกรมได้ หากคุณต้องการดีบัก BiBoard โปรดเชื่อมต่ออินเทอร์เฟซ USB-C
ดาวน์โหลดโปรแกรม ดังรูป
import network
import time
import webrepl
def do_connect():
# WiFi SSID and Password
wifi_ssid = "YOUR SSID" # YOUR WiFi SSID
wifi_password = "YOUR PASSWORD" # YOUR WiFi PASSWORD
# Wireless config : Station mode
station = network.WLAN(network.STA_IF)
station.active(True)
# Continually try to connect to WiFi access point
while not station.isconnected():
# Try to connect to WiFi access point
print("Connecting...")
station.connect(wifi_ssid, wifi_password)
time.sleep(10)
# Display connection details
print("Connected!")
print("My IP Address:", station.ifconfig()[0])
if __name__ == "__main__":
do_connect()
webrepl.start()
Connected!
My IP Address: 192.168.xxx.xxx
WebREPL daemon started on ws://192.168.xxx.xxx:8266
Started webrepl in normal mode
const int freq = 5000; // PWM frequency
const int ledcChannel = 0; // ledc channel, 0-15
const int resolution = 8; // resolution of PWM,8bit(0~255)
ledcSetup(ledcChannel, freq, resolution);
ledcAttachPin(ledPin, ledcChannel);
ledcWrite(ledcChannel, dutyCycle);
/* In this demo, we show how to use PWM in BiBoard(ESP32)
* It's different from the Arduino UNO based on the ATMega328P
*/
// define the PWM pin
const int ledPin = 2; // 16 corresponds to GPIO16
// setting PWM properties
const int freq = 5000; // PWM frequency
const int ledcChannel = 0; // ledc channel, in ESP32 there're 16 ledc(PWM) channels
const int resolution = 8; // resolution of PWM
void setup(){
// configure ledc functionalitites
// channels 0-15, resolution 1-16 bits, freq limits depend on resolution
// ledcSetup(uint8_t channel, uint32_t freq, uint8_t resolution_bits);
ledcSetup(ledcChannel, freq, resolution);
// attach the channel to the GPIO to be controlled
ledcAttachPin(ledPin, ledcChannel);
}
void loop(){
// increase the LED brightness
for(int dutyCycle = 0; dutyCycle <= 255; dutyCycle++){
// changing the LED brightness with PWM
ledcWrite(ledcChannel, dutyCycle);
delay(15);
}
// decrease the LED brightness
for(int dutyCycle = 255; dutyCycle >= 0; dutyCycle--){
// changing the LED brightness with PWM
ledcWrite(ledcChannel, dutyCycle);
delay(15);
}
}
class MyServerCallbacks: public BLEServerCallbacks {
void onConnect(BLEServer* pServer) {
deviceConnected = true;
};
void onDisconnect(BLEServer* pServer) {
deviceConnected = false;
}
};
class MyCallbacks: public BLECharacteristicCallbacks {
void onWrite(BLECharacteristic *pCharacteristic) {
std::string rxValue = pCharacteristic->getValue();
if (rxValue.length() > 0) {
Serial.println("*********");
Serial.print("Received Value: ");
for (int i = 0; i < rxValue.length(); i++)
Serial.print(rxValue[i]);
Serial.println();
Serial.println("*********");
}
}
};
Plug the Bittle USB adapter into the robot and the Chromebook.
Set the Chromebook Linux VM to recognize the USB port
Settings => Advanced => Developers => Linux development environment => Manage USB devices => USB Serial (turn on)
หมายเหตุ: ขั้นตอนที่ 4 จะต้องทำซ้ำทุกครั้งเมื่อมีการเชื่อมต่อ USB อีกครั้งหรือมีการเปิดเครื่องใหม่
if (deviceConnected) {
pTxCharacteristic->setValue(&txValue, 1);
pTxCharacteristic->notify();
txValue++;
delay(10); // bluetooth stack will go into congestion, if too many packets are sent
}
// disconnecting
if (!deviceConnected && oldDeviceConnected) {
delay(500); // give the bluetooth stack the chance to get things ready
pServer->startAdvertising(); // restart advertising
Serial.println("start advertising");
oldDeviceConnected = deviceConnected;
}
// connecting
if (deviceConnected && !oldDeviceConnected) {
// do stuff here on connecting
oldDeviceConnected = deviceConnected;
}
#include <Wire.h>
#define EEPROM_ADDRESS 0x54
#define EEPROM_CAPACITY 8192 // 64Kbit
#define EEPROM_TESTBYTES 16
// write 1 byte EEPROM by address
void writeEEPROM(int deviceaddress, unsigned int eeaddress, byte data )
{
Wire.beginTransmission(deviceaddress);
Wire.write((int)(eeaddress >> 8)); // MSB
Wire.write((int)(eeaddress & 0xFF)); // LSB
Wire.write(data);
Wire.endTransmission();
delay(5);
}
// read 1 byte EEPROM by address
byte readEEPROM(int deviceaddress, unsigned int eeaddress )
{
byte rdata = 0xFF;
Wire.beginTransmission(deviceaddress);
Wire.write((int)(eeaddress >> 8)); // MSB
Wire.write((int)(eeaddress & 0xFF)); // LSB
Wire.endTransmission();
Wire.requestFrom(deviceaddress,1);
if (Wire.available())
rdata = Wire.read();
return rdata;
}
void testI2CEEPROM(){
byte tmpData = 0;
Serial.println("EEPROM Testing...");
// write EEPROM from 0 to EEPROM_TESTBYTES
for(int i = 0; i < EEPROM_TESTBYTES; i++){
writeEEPROM(EEPROM_ADDRESS, i, i % 256);
delay(1);
}
Serial.println();
// read from 0 to EEPROM_TESTBYTES
for(int i = 0; i < EEPROM_TESTBYTES; i++){
tmpData = (int)readEEPROM(EEPROM_ADDRESS, i);
Serial.print(tmpData);
Serial.print("\t");
}
}
void setup(){
Serial.begin(115200);
Wire.begin();
testI2CEEPROM();
}
void loop(){
}
อัปโหลด Sketch สำหรับ BiBoard
This chapter is for Advanced users with programming experience.
เมื่อเปิด BiBoard ที่เพิ่งตั้งค่าใหม่ จะต้องเชื่อมต่อ serial port เข้ากับคอมพิวเตอร์ และเริ่มต้นข้อต่อและ gyroscope accelerometer (IMU) ในหน้าต่าง serial port monitor
ตรวจสอบให้แน่ใจว่าตั้งค่า serial monitor เป็น baud rate 115200 และ no line ending
// Port defaults to 3232
// ArduinoOTA.setPort(3232);
// Hostname defaults to esp3232-[MAC]
// ArduinoOTA.setHostname("myesp32");
// No authentication by default
// ArduinoOTA.setPassword("admin");
// Password can be set with it's md5 value as well
// MD5(admin) = 21232f297a57a5a743894a0e4a801fc3
// ArduinoOTA.setPasswordHash("21232f297a57a5a743894a0e4a801fc3");
ArduinoOTA
.onStart([]() {
String type;
if (ArduinoOTA.getCommand() == U_FLASH)
type = "sketch";
else // U_SPIFFS
type = "filesystem";
// NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
Serial.println("Start updating " + type);
})
.onEnd([]() {
Serial.println("\nEnd");
})
.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
})
.onError([](ota_error_t error) {
Serial.printf("Error[%u]: ", error);
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
else if (error == OTA_END_ERROR) Serial.println("End Failed");
});
ArduinoOTA.begin();
void loop() {
ArduinoOTA.handle();
analogWrite(2, 127); // test OTA firmware
}
เราเพิ่มพอร์ต Grove 4 ช่องเพื่อให้ใช้งานง่ายกับโมดูลขยาย Seeed Studio โดยไม่ต้องใช้สายเสียบเพิ่มเติม ในขณะเดียวกันยังมีพอร์ตหลักที่ผ่านมาตลอดอยู่เหมือนเดิมที่ขนาด 2.54 มม.
ไฟ LED สองดวงในโลโก้ Petoi แสดงสถานะการเปิดใช้งานของบอร์ด ดวงตาทางซ้ายสีน้ำเงินแสดงสถานะของชิปต่างๆในเบอร์ด ดวงตาทางขวาสีเหลืองแสดงสถานะของแหล่งจ่ายพลังงานสำหรับเซอร์โว เมื่อ NyBoard ต่อกับแบตเตอรี่แล้ว ทั้งสอง LED จะติด แต่เมื่อ NyBoard ถูกจ่ายพลังงานจากดาวน์โหลด USB จะมีแค่ LED สีน้ำเงินติดอย่างเดียว
มีไดโอดอยู่ระหว่างแบตเตอรี่กับ LM1117-5V เพื่อป้องกันความเสียหายจากการเชื่อมต่อผิดพลาด นอกจากนี้ยังมีฟิวส์ที่สามารถฟื้นตัวเองได้ (6V 500mA) บนตัวอัพโหลด USB เพื่อจำกัดกระแสและป้องกันพอร์ต USB
ขั้นตอนการติดตั้งที่ละเอียดมากขึ้นสามารถพบได้ในส่วนของ mobile app .
Connect the dongle with your computer
ในการตั้งค่า Bluetooth ของระบบของคุณ ค้นหาชื่ออุปกรณ์ Bluetooth ที่เริ่มต้นด้วย Petoi หรือ Bittle และเชื่อมต่อ รหัส PIN สำหรับการจับคู่คือ "0000" หรือ "1234" หลังจากที่การจับคู่สำเร็จ ระบบจะกำหนดชื่อพอร์ตซีเรียลโปรต์ให้.
เมื่ออยู่บน Mac ให้ไปที่ System Preference -> Bluetooth ค้นหาชื่ออุปกรณ์ที่เริ่มต้นด้วย Petoi หรือ Bittle แล้วเชื่อมต่อกับอุปกรณ์นั้นได้เลยค่ะ
บนระบบ Windows ให้เพิ่มอุปกรณ์ Bluetooth ในการตั้งค่าระบบดังนี้
สำหรับผู้ใช้ Win10 ระบบจะกำหนด COM port ขาเข้าและขาออกให้กับบลูทูธ โปรดใช้ COM port ขาออก ("outgoing") และสำหรับรายละเอียดเพิ่มเติมโปรดดูใน "More Bluetooth options" ของ Win10 ดังรูปภาพต่อไปนี้:
หลังจากนั้น คุณสามารถเลือกพอร์ตนั้นได้ในเมนู Tools->Port ใน Arduino IDE โดยใช้วิธีเดียวกับกับ USB Uploader หลังจากเปิด Serial Monitor โปรดเลือก: No line ending และอัตราการสั่งโอนข้อมูล (baud rate) ตั้งไว้ที่ 115200.
การเชื่อมต่อ Bluetooth กับคอมพิวเตอร์อาจขาดหายได้บ้างครั้ง การเปิดอ่านข้อมูลผ่านซีเรียลมอนิเตอร์อาจช่วยให้การเชื่อมต่อมีความเสถียรขึ้น แต่โปรดทราบว่าการเปิดซีเรียลมอนิเตอร์จะเก็บพอร์ตไว้และบล็อกแอปพลิเคชันอื่นที่ต้องการเชื่อมต่อด้วยด้วย
Configure the Bluetooth module
ถ้าคุณต้องการกำหนดค่าโมดูลบลูทูธโปรดอ้างอิงไปที่ "JDY-23 AT Command List" ใส่โมดูลบลูทูธเข้ากับอินเตอร์เดบั๊กของแอดาพเตอร์ USB เช่นที่แสดงในรูปด้านล่าง:
คำสั่งที่ใช้งานบ่อยแสดงด้านล่างนี้:
Usage
Command
Demo
Check BT module version
AT+VER
AT+VER
>+VER=JDY-23A-V2.21,Bluetooth V3.0+BLE
(BT module version infomation)
Check BT broadcast name
AT+NAME
AT+NAME
>+NAME=BITTLE
Change BT broadcast name
AT+NAME(名字)
AT+NAMEPiggy
>+OK
AT+NAME
>+NAME=Piggy
Check serial baud rate
เมื่อคุณใช้เทอร์มินัลซีเรียลเช่น "Arduino serial monitor" เพื่อตั้งค่า JDY-23 ด้วยคำสั่ง AT คุณต้องตั้งค่า "NL และ CR" และอัตราการส่งข้อมูล (baud rate) ต้องตั้งเป็น 115200 หรือโมดูล JDY-23 จะไม่รับรู้คำสั่ง AT ใดๆที่คุณส่งเข้ามา
ถ้าคุณเป็นนักพัฒนา คุณสามารถใช้ Lightblue หรือเครื่องมืออื่นๆ เพื่อเชื่อมต่อกับบริการ BLE ของ dongle ได้
M หมายถึงคำสั่งในการหมุนของเซอร์โวข้อต่อหลายตัว โดยจะทำการหมุนข้อต่อลำดับที่กำหนดไว้ มุมของข้อต่อถูกเข้ารหัสเป็นเลขฐานสองเพื่อเพิ่มประสิทธิภาพในการส่งข้อมูล
อาเรย์ของทักษะจะถูกส่งไปยังหุ่นยนต์และทำงานโดยการประมวลผลที่ตัวหุ่นยนต์ (execute locally on the robot) โดยไม่ต้องส่งข้อมูลกลับมายังคอมพิวเตอร์หรืออุปกรณ์อื่น ๆ อาทิเช่น Raspberry Pi หรือเซิร์ฟเวอร์
#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
#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
Reset the joints' calibration offsets? (Y/n):
- Calibrate the Inertial Measurement Unit (IMU)? (Y/n):
* 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!
# Simple script:
print("Hello MicroPython")
from machine import Pin
import time
# GPIO LED IO2
def blink():
led = machine.Pin(2, machine.Pin.OUT) # Pin 2 ,Output mode
while(True): # loop
led.on() # light on LED
time.sleep(1) # delay 1s
led.off() # light off LED
time.sleep(1) # delay 1s
if __name__ == "__main__":
blink()
from machine import UART
import time
uart = UART(0, baudrate=115200,timeout=5)
# walk
def walk(time_ms):
print("walk")
uart.write("kwkF") # walk cmd
time.sleep_ms(time_ms) # keep time
uart.write("d") # stop
time.sleep_ms(1500)
# backward
def back(time_ms):
print("back")
uart.write("kbk")
time.sleep_ms(time_ms)
uart.write("d")
time.sleep_ms(1500)
# stop
def stop():
uart.write("d")
def initConnection():
connected = False
while True:
uart.write("d")
for t in range(30):
uos.dupterm(None, 1) # disable REPL on UART(0), detach the REPL from UART0
time.sleep_ms(5) #delay is a must
result = uart.read(1)
uos.dupterm(uart, 1) # enable REPL on UART(0), reattach REPL
if result != None:
# uart.write(result) # for debug
if result == b"d":
connected = True
break
time.sleep_ms(10)
if connected:
break
uart.write("b22 4 24 4 26 4")
def actSeq():
initConnection()
time.sleep_ms(2000)
walk(3000)
back(3000)
uart.write("m0 90")
time.sleep_ms(3000)
uart.write("i8 -20 9 -60")
time.sleep_ms(2000)
uart.write("b26 4 24 4 20 4")
time.sleep_ms(1000)
uart.write("d")
uos.dupterm(None, 1) # disable REPL on UART(0), detach the REPL from UART0
if __name__ == "__main__":
actSeq()
__main__ - INFO - port[0] is COM11
__main__ - INFO - port[1] is COM5
__main__ - INFO - port[2] is COM10
Waiting for the robot to booting up
Waiting for the robot to booting up
['b', '\n* Start *\nBittle\nReady!\np\n']
Adding COM5
['b', '\n* Start *\nBittle\nReady!\np\n']
Adding COM11
__main__ - INFO - Connect to usb serial port:
__main__ - INFO - COM5
__main__ - INFO - COM11
Kbalance # Command to control the robot to stand normally
m 0 -30 0 30 # Command to control the robot head to swing left and right
หากดองเกิล Bluetooth กะพริบในขณะที่แผงการเชื่อมต่อภายในแอพแสดงรายการการเชื่อมต่อ Bluetooth ที่ว่างเปล่า ก่อนอื่นให้ตรวจสอบว่าคุณได้ให้สิทธิ์ Bluetooth และตำแหน่งแก่แอพหรือไม่ หากยังคงแสดงรายการว่าง คุณอาจลองติดตั้งเวอร์ชันเสถียรก่อนหน้า
เชื่อมต่อกับหุ่นยนต์ของคุณ
คุณต้องเสียบ Bluetooth dongle เข้ากับซ็อกเก็ต 6 พินบน NyBoard ให้ความสนใจกับลำดับพินของดองเกิลบลูทูธ กดปุ่มบนแบตเตอรี่ค้างไว้เพื่อเปิดพลังงานของหุ่นยนต์
* play a short tone (beep tone duration, duration is 0~256)
b12 100
* play a melody (beep tone1 duration1, tone2 duration2, tone3 duration3, .... only 64 characters are allowed, the actual duration is calculated as 1/duration)
b14 4 14 4 21 4 21 4
สามารถดูตารางคำสั่งโดยละเอียดเพิ่มเติมได้ใน Serial Protocol.
There are two calibration steps for different components.
Because the controller board has limited resources, we divide the program into two stages.
In the first stage, we upload the program and large data to the onboard EEPROM (hard disk) and use the remaining programming space to calibrate the IMU, a sensor that measures the body orientation. The board should be leveled and untouched during the (IMU) calibration.
In the second stage, we upload the standard functional code. For the first-time configuration, we need to enter the (joint) calibration state and attach the legs in the right direction.
If you use the Arduino IDE to set up the board, you will handle those stages explicitly. The Petoi Desktop App can finish the two-stage uploading in the background. The smartphone app can work only with an already configured board. Its (joint) calibration is only for attaching the legs.
When using the smartphone app, I found that Bittle was walking very slowly.
Try turning off the Gyro in the mobile app, as shown in the following picture:
When using the smartphone app, Bittle cannot turn back up now.
Try turning on the Gyro in the mobile app, as shown in the following picture:
Bittle doesn't walk very stable.
Make sure you calibrate the joints with the included L-shaped tuner and understand the references
If to buy the preassembled bittle does it still have to be calibrated?
Yes, you still need to use the desktop app or smartphone app or Arduino IDE to fine-tune the joints.
If to buy the main board alone, do you have to buy a separate software program to make it work?
Our main board is specifically designed for our robots. The code is free to download on GitHub.
Could Python be used to control the robot?
You can use python to control the robot. The scripts can work either on your computer and connects to the robot wired or wirelessly.
Can your little robot (Bittle / Nybble) function on its own? Or, it only works with the commands I give it? Also, can it learn?
It follows your instructions via the infrared remote, smartphone app, or desktop app. It can also do random behaviors if you upload the random mode. Best of all, the program is open source on GitHub and you can refer to the relevant technical documents to create new skills for the robot.
Hardware
How can I easily install the springs into the upper legs of Bittle?
Please check out the forum post discussing installing springs with varies tools.
I can't find the toe covers. What are the toe covers for?
The toe covers are for special experiments that require more friction. They are not required for regular walking and performance. We have removed them from the standard kit recently and you may order them as optional accessories.
Some frame structures are broken. Where can I get replacement parts?
You may contact [email protected]. Show the picture of the broken pieces and explain how they broke. You may find the 3D-printable files or get a replacement directly from us.
Where can I get the bone shown in Bittle's picture?
Can I use Codecraft/block-based coding with the basic Bittle package or do I need to purchase add-on components/modules?
Bittle can be programmed with a Scratch-like web-based IDE Codecraft. You may find some complementary materials: online help and curriculum.
Note that CodeCraft hasn't provided support for our 2.0 version. But you may roll back to the supported version within CodeCraft or through the desktop app.
You don't need to buy add-on components to use the basic functions in Codecraft. However, several extension functions require add-on components. If you are comfortable with coding with Arduino, you can have a much wider selection of third-party components.
หมายเลข MAC คือหมายเลขที่ใช้ในการยืนยันตำแหน่งของอุปกรณ์เครือข่าย และรับผิดชอบในชั้นที่สอง (data link layer) ของโมเดลเครือข่าย OSI หมายเลข MAC ยังเรียกว่าที่อยู่ฟิสิกส์ (physical address) และที่อยู่ฮาร์ดแวร์ (hardware address) มันถูกเขียนลงบนหน่วยความจำที่ไม่สูญเสีย (เช่น EEPROM) ของการ์ดเครือข่ายเมื่อผู้ผลิตอุปกรณ์เครือข่ายผลิตอุปกรณ์นั้นๆ ขึ้นมา
ที่อยู่ MAC เป็นที่อยู่ที่ใช้สำหรับยืนยันตำแหน่งของอุปกรณ์เครือข่าย และรับผิดชอบด้านชั้นที่สอง (data link layer) ของโมเดลเครือข่าย OSI ที่อยู่ MAC ยังเรียกว่าที่อยู่ฟิสิกส์และที่อยู่ฮาร์ดแวร์ จะถูกเขียนลงในหน่วยความจำที่ไม่สูญเสีย (เช่น EEPROM) ของการ์ดเครือข่ายเมื่อมันถูกผลิตโดยผู้ผลิตอุปกรณ์เครือข่าย
เพียงแค่คุณไม่เปลี่ยนที่อยู่ MAC ของคุณ ที่อยู่ MAC จะเป็นเอกลักษณ์ในโลก ด้วยภาพการมองเห็น ที่อยู่ MAC เหมือนหมายเลขบัตรประชาชนบนบัตรประชาชน เป็นเอกลักษณ์
วิธีที่ง่ายที่สุดในการใช้ ESPNOW คือการส่งข้อมูลด้วย MAC address โดยเราจะใช้โปรแกรมเล็ก ๆ เพื่อสอบถาม MAC address ของโมดูล
หลังจากการรันโปรแกรมใน Thonny เสร็จสิ้น โปรแกรมจะแสดง MAC address บน terminal ออกมา ในขณะนี้ คุณสามารถใช้สติ๊กเกอร์สำหรับเขียน MAC address ของโมดูลแล้ววางไว้บนโมดูลได้เลย
import network
import espnow
import time
sta = network.WLAN(network.STA_IF) # Enable station mode for ESP
sta.active(True)
sta.disconnect() # Disconnect from last connected WiFi SSID
e = espnow.ESPNow() # Enable ESP-NOW
e.active(True)
peer1 = b'\xe8\x68\xe7\x4e\xbb\x19' # MAC address of peer1's wifi interface
e.add_peer(peer1) # add peer1 (receiver1)
peer2 = b'\x60\x01\x94\x5a\x9c\xf0' # MAC address of peer2's wifi interface
e.add_peer(peer2) # add peer2 (receiver2)
print("Starting...") # Send to all peers
e.send(peer1, "walk", True) # send commands to pear 1
e.send(peer2, "walk", True) # send commands to pear 2
time.sleep_ms(2000)
e.send(peer1, "walk", True)
e.send(peer2, "back", True)
time.sleep_ms(2000)
import network
import espnow
from machine import UART
def espnow_rx():
#config UART
uart = UART(0, baudrate=115200)
# A WLAN interface must be active to send()/recv()
sta = network.WLAN(network.STA_IF)
sta.active(True)
sta.disconnect() # Disconnect from last connected WiFi SSID
e = espnow.ESPNow() # Enable ESP-NOW
e.active(True)
peer = b'\x5c\xcf\x7f\xf0\x06\xda' # MAC address of peer's wifi interface
e.add_peer(peer) # Sender's MAC registration
while True:
host, msg = e.recv()
if msg: # wait for message
if msg == b'walk': # decode message and translate
uart.write("kwkF") # to the NyBoard's command
elif msg == b'back':
uart.write('kbk')
elif msg == b'stop':
uart.write('d')
if __name__ == "__main__":
espnow_rx()
บางครั้งบอร์ด USB ของคุณจะตรวจจับกระแสไฟขนาดใหญ่จากอุปกรณ์และปิดใช้งานบริการ USB ทั้งหมด คุณจะต้อง restart บริการ USB ของคุณใหม่ หรือแม้แต่ reboot เครื่องคอมพิวเตอร์ของคุณ
คุณต้องติดตั้ง driver สำหรับ FTDI USB 2.0 ไปยังตัวอัปโหลด UART
คุณไม่ได้เลือกพอร์ตที่ถูกต้อง
หากคุณตัดสินใจที่จะเบิร์น bootloader ใหม่:
ด้วย NyBoard V1_* คุณสามารถเลือก Arduino Uno ภายใต้เมนูเครื่องมือของ Arduino IDE
เลือก ISP ของคุณ (ภายใน System Programmer) ยอดนิยม 2 ตัว: USBtinyISP หรือ Arduino as ISP !
Connect your Bittle to IoT platforms with HTTP restful APIs.
MQTT and node-red.
OTA with WiFi.
Make ESP8266 a strong co-processor for NyBoard for motion data fusion.
#define BITTLE //Petoi 9 DOF robot dog: 1x on head + 8x on leg
//#define NYBBLE //Petoi 11 DOF robot cat: 2x on head + 1x on tail + 8x on leg
//#define NyBoard_V0_1
//#define NyBoard_V0_2
#define NyBoard_V1_0
//#define NyBoard_V1_1
// #define MAIN_SKETCH
Reset joint offsets? (Y/n):
Calibrate the IMU? (Y/n):
Optional: Connect PWM 3 -> Grove pin A3 to calibrate PCA9685
#define MAIN_SKETCH
// WiFiManager
WiFiManager wifiManager;
// Start WiFi manager, default gateway IP is 192.168.4.1
wifiManager.autoConnect("Bittle-AP");
# start core
roscore
# start service server
rosrun opencat_server opencat_service_node
# examples using oppencat ros service in C++
rosrun opencat_examples opencat_examples_client_cpp
# examples using opencat ros service in python
rosrun opencat_examples opencat_examples_client_py
Give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime.
Preparation
Familiar with upload the firmware (Chapter 3 of the Nybble/Bittle User Manual), the assembly process (Chapter 4 of the Nybble/Bittle User Manual) and calibrate the servo (Chapter 6 of the Nybble/BittleUser Manual). Use an IR remote to verify that the following functions work as expected.
Press the button on 's 2nd row, 2nd column (as shown in the picture below). Later it will be expressed by (2, 2). You can also connect a USB adapter and enter the serial command "kbalance" in . The robot will stand up.
Press the (7, 3) button on . You can also connect a USB adapter and enter the serial command "kzero" in . All the servos of the robot are turned to the 0-degree position, which is the "Zero" skill (as shown in the figure below).
Understand the code
All skill arrays of the robot are defined in the Instinct***.h file.
Nybble: InstinctNybble.h
Bittle: InstinctBittle.h
Here is an abbreviated example of an Instinct***.h file:
Data structure
The meaning of the data structure of the skill array is shown in the figure below:
Total # of Frames
The 1st element in the skill array indicates the total number of all action frames contained in the skill. If there is a minus sign (-) before the value, it means that the skill is a .
In the above data structure figure, the rest is a . It has only 1 action frame (1 row of data).
the crF (Crawl forward) is a . It contains 36 action frames (36 rows of data).
Expected Body Orientation
The 2nd and 3rd elements in the skill array represent the expected value of the body direction, that is, the inclination angle of the robot's body when performing skill actions, corresponding to the body's roll angle (Roll) and pitch angle (Pitch) respectively. When the robot is performing a skill action, if the body tilt deviates from the expected value, the balance algorithm will make some adjustments to the angle value of the relevant leg servos to keep the body tilt as close as possible to the expected value.
The pitch angle (Pitch) and roll angle (Roll) of the robot shown in the figure above are both at 0 degrees. In the picture on the left, the robot body rotates counterclockwise from the 0-degree position around the center point, and the pitch angle is positive; when it rotates clockwise, the pitch angle is negative. In the picture on the right, the robot body rotates counterclockwise from the 0-degree position around the center point, and the roll angle is positive; when it rotates clockwise, the roll angle is negative.
Take a look at the following sample code, standing:
Sitting:
The 2nd and 3rd elements in the array represent the expected value of the body direction (corresponding to the roll angle and pitch angle of the body), and the unit is degree.
When the gyroscope is activated, Bittle's body is slightly rotated, and when the body tilts away from the expected value of the body direction, the balance algorithm will keep the body in this posture as much as possible.
Indexed Joint Angles
The index numbers of the servo are shown in the figure below:
Please control the rotation angle range of the joint servo between [-125~125]. For the leg servo, when viewed from the left side of the robot, the leg rotates counterclockwise from the 0 degree position around the joint center point (the screw fixing position) , the angle is a positive value; clockwise rotation, the angle is a negative value; viewed from the right side of the robot, the leg rotation angle is mirror-symmetrical to the left side (rotating clockwise from the 0 degree position around the joint center point, the angle is a positive value; Rotate counterclockwise, the angle is negative). For the robot's neck servo, looking down from the top of the robot's head, the neck rotates counterclockwise from the position of 0 degrees around the joint center point (the position where the screw is fixed), and the angle is a positive value; when it rotates clockwise, the angle is a negative value.
For the Nybble head servo (No. 1 servo) observed on the right side of the robot, the head rotates counterclockwise from the 0-degree position around the joint center point (screw fixed position), and the angle is positive; when it rotates clockwise, the angle is negative.
For the Nybble tail servo (No. 2 servo) facing the tail and looking down, the tail rotates counterclockwise from the 0-degree position around the center point (screw fixing position), and the angle is positive; when it rotates clockwise, the angle is negative.
Each action frame in the skill array contains the rotation angle values of multiple servos.
In the above data structure figure, the rest action frame contains 16 joint servo angle values, and the corresponding servo index numbers are arranged from small to large starting from 0.
Each action frame in the crF (crawling forward) contains 8 joint servo angle values, and the corresponding servo index numbers are arranged from small to large starting from 8.
Angle ratio
The 4th element in the skill array represents the angle ratio. The angle ratio value can be increased when it is necessary to store angle values outside the range of -128 to 127. For example, if the angle ratio is set to 2, the angle value of all joint servos in the skill array multiplied by 2 is the actual rotation angle of the servo.
Take a look at the following example skill array rc (return to standing after being on all fours):
The 4th element (2) in the array represents the angle ratio. This means that the actual angle value of all joint rotations is equal to the angle value of each joint in the array (starting from the 8th element) multiplied by this angle ratio.
Posture array
The posture array contains only one action frame. Taking Bittle as an example, find the zero posture array in InstinctBittle.h:
Modify some of the joint servo angle values:
Save the modification and upload the main function program OpenCat.ino to the Bittle mainboard. After the upload is complete, click the button (7, 3) on the IR remote to see the modified zero skill, and the new posture is shown in the figure below:
The first element (1) in the array represents the total number of frames of the skill, and 1 means it is a posture skill.
The 4th element (1) in the array represents the angle ratio. This means that all index joint angles below are actual angles (because each of them is multiplied by 1).
The 5th to 20th elements in the array represent the respective angle values of the 16 joints in the current frame.
For Bittle, the 5th element in the array (70, corresponding to the No.0 servo) means that the servo on Bittle's neck rotates 70 degrees counterclockwise. Bittle's head turned to the left side of the body.
The 13th element in the array (-60, corresponding to No.8 servo) indicates that Bittle's left front thigh rotates 60 degrees clockwise around the joint center point.
The 17th element in the array (60, corresponding to No.12 servo) indicates that Bittle's left front calf rotates 60 degrees counterclockwise around the center of the joint.
The other joint angles remain unchanged at 0 degrees.
Gait array
The gait array contains multiple coherent action frames, and these action frames are executed repeatedly in a sequential cycle, unless the robot receives a new skill command, it will stop executing. For example, the bk(draw back) gait array is defined as follows:
The 1st element in the array (35) means the skill has 35 action frames. Starting from the second line of data, each line is an action frame, which contains the angle values of 8 joint servos, and the corresponding servo index numbers are arranged from small to large starting from 8 (a total of 35 lines).
For gait skills, each action frame in the future may contain 12 joint servo angle values, and the corresponding servo index numbers will be arranged from small to large starting from 4, depending on the number of leg servos participating in the movement.
Behavior array
The behavior array also contains multiple coherent action frames, and all the action frames are only executed for one round in order, but some of the continuous action frames can be executed multiple times in a loop. For example, the pu(push-up) behavior array is defined as follows:
This data structure contains more information than pose and gait:
The meanings of the 4 elements in line 1 are as mentioned above, and the first element (total number of frames) is a negative number, indicating that this skill is a behavior.
The 3 elements in line 2 indicate the loop structure contained in this behavior: start frame, end frame, and loop times:
6, 7, 3 in the example means that this behavior is executed 3 times from the 7th frame to the 8th frame (the frame index number starts from 0). The motion sequence of the entire behavior is performed in one round, rather than in a continuous loop-like gait.
Each action frame contains 20 elements. The first 16 elements represent the angles of the joint servos as mentioned above, and the corresponding servo index numbers are arranged from small to large starting from 0. The last 4 elements have the following meanings:
The 1st represents the speed factor. The default speed factor is 4, which can be changed to an integer from 1 (slow) to 127 (fast). Units are degrees per step. If set to 0, the servo will rotate to the target angle at maximum speed (about 0.07 seconds/60 degrees). Values greater than 10 are not recommended unless you understand the risks.
The 2nd represents the delay time. The default delay is 0. The range that can be set is 0 to 127, and the unit is 50 milliseconds (if it is set to 2, the actual delay is 100 milliseconds).
The 3rd represents the trigger axis. It is used to set the body rotation direction when the robot triggers the next frame of action. There are the following 5 setting options:
Note:
The trigger axis and trigger angle need to be used together: only when the robot completes the frame of motion and rotates in accordance with the set body rotation direction to exceed the trigger angle, the next frame of motion will be triggered. If the trigger axis is set to 0, the trigger angle is meaningless. Therefore, when the trigger axis is set to 0, the trigger angle is generally also set to 0.
Skill storage type
The erasing and writing times of EEPROM are limited (1,000,000 times). In order to minimize write operations, two skills are defined: Instinct and Newbility. Their addresses are stored in the built-in EEPROM (1KB) of the chip (ATmega328P) as a lookup table, but the data of the main body exists in different storage units:
I2C EEPROM (8KB) memory Instincts.
Instincts are fixed skills (or occasional fine-tuning), which can be thought of as "muscle memory".
Flash (shares 32KB storage space with Arduino program code) Storage Newbilities.
Newbilities refer to user-defined skills (possibly modified, added, or deleted). They will not be written into the static EERPOM but uploaded to the flash memory (Flash) together with the Arduino program code. Their addresses are assigned in real-time when the code is executed, and this value rarely changes as long as the total number of skills (including all instincts and newbilities) remains the same.
The specific sample code is as follows:
Add a suffix to each skill array name in the character pointer array skillNameWithType, "N" means Newbility, and "I" means Instinct.
const char* progmemPointer[] = {crF, pu, rest, zero, }; This part of the code is active when uploading the configuration mode sketch. It contains data and pointers for all abilities.
const char* progmemPointer[] = {zero}; This part of the code is active when uploading the major functionalities sketch. Since the instincts are already saved in the external I2C EEPROM, their data is omitted here to save space. If you only need to adjust the actions of existing new skills (such as zero), you don't need to re-upload the configuration mode sketch.
Create new skills
Debug the skills
The following two methods can be used when authoring or debugging skill actions:
Control the robot to make actions by Python scripts. For details, please refer to the .
Use in the Desktop App to control the robot to do actions, and then use the "" function to copy and paste the contents of the debugged skill array to the Instinct***.h file for use. Please refer to the for the specific format.
This is a good starting point if you want to develop a customized gait. If you are going to do some inverse kinematics calculation, you may use the following key dimensions to build your model:
The "SkillLibrary" folder in is a collection of new skills that OpenCat robots can perform, which can be used for your reference.
You are also welcome to share your new skills by sending merge requests to this folder.
Another direction is to set up a simulation for Bittle then test the model in reality. You may use this for Bittle to set up an NVIDIA Omniverse simulation.
Add skill array
Add Instinct
To add a new skill(testI) array ending with I, you need to add the skill array variable name (test) to the first branch of the sample code macro judgment. The specific code modification is as follows:
Add Newbility
To add a new skill(testN) array ending with N, you need to add the skill array variable name (test) to both branches of the sample code macro judgment. The specific code modification is as follows:
After adding the skill array In the Instinct***.h file, for NyBoard, use the data cable to connect the USB uploader and the computer, use the Arduino IDE to upload the configuration mode sketch, open the serial monitor when the serial port prompts the following content:
After inputting 'Y' or 'n', all instinct arrays will be stored in the I2C EEPROM at one time, and the index addresses of all skills will also be generated and stored in the built-in EERPOM of the chip, and then upload the major functionalities sketch. For the specific operation process, please refer to in uploading the sketch for NyBoard.
When verifying the skill action, you can open and call through the serial port command with 'k' token. For example, "ksit" can be transformed into a sitting posture by Bittle.
Intelligent
By adding some (such as a gesture sensor), it can help the robot to better perceive the environment and even make decisions. By accumulating these automatic behaviors and designing a decision tree, robot's fully automatic intelligent operation is finally realized!
ก่อนอื่นให้เชื่อมต่อตัวอัปโหลด USB เข้ากับแผงวงจรหลักของหุ่นยนต์ จากนั้นใช้สายเคเบิลข้อมูลเพื่อเชื่อมต่อกับอินเทอร์เฟซ USB ของคอมพิวเตอร์
Bluetooth
ขั้นแรกให้เสียบโมดูล Bluetooth เข้ากับบอร์ดหลักของหุ่นยนต์ (ไม่จำเป็นต้องใช้บอร์ดที่ใช้ ESP32) จับคู่บอร์ดกับอินเทอร์เฟซการตั้งค่า Bluetooth ของคอมพิวเตอร์ แอปเดสก์ท็อปจะตรวจจับว่ามีการเชื่อมต่อพอร์ตอนุกรมใหม่หรือไม่ เมื่อเชื่อมต่อพอร์ตอนุกรมหลายพอร์ตสำเร็จ ปุ่มตัวเลือกพอร์ตอนุกรมในพื้นที่ "State Dials" จะเปลี่ยนเป็น "All" คลิกรายการแบบเลื่อนลงเพื่อดูพอร์ตอนุกรมทั้งหมดที่เชื่อมต่อสำเร็จ หุ่นยนต์ทั้งหมดจะถูกซิงโครไนซ์แบบเรียลไทม์ด้วยวิธีนี้ คุณยังสามารถเลือกพอร์ตอนุกรมใดก็ได้เพื่อควบคุมหุ่นยนต์ที่เกี่ยวข้อง
หากคุณถอดปลั๊กซีเรียลพอร์ต USB บนคอมพิวเตอร์ (หรือเลือกที่จะตัดการเชื่อมต่อโมดูล Bluetooth ในอินเทอร์เฟซการตั้งค่า Bluetooth) พอร์ตอนุกรมที่เกี่ยวข้องจะถูกลบออกจากรายการแบบหล่นลงตามเวลาจริง
In this tutorial, we will introduce how to use the Ailia in python language to implement an OpenCat robot to imitate various human body movements.
To clone or download the code from the GitHub repository, you can clone the code with the following command:
1. Run on a regular computer (Mac/Linux)
Requirements
Python 3.6 and later
It is recommended to install the IDE. For the specific installation method, please refer to the following link:
Open the Anaconda Prompt (Windows) or the Terminal (Linux / macOS) and enter the following commands to create and activate a virtual environment (the environment name is "venv", and can also be customized to other names):
conda create --name venv
conda activate venv
You can execute run.sh within OpenCat-Imitation/ with your shell command directly. It wraps up the above commands.
2. Run on the Jetson Nano 2GB Developer kit
You may want to run the demo on a Jetson Nano to experiment with some GPU features.
The developer kit uses a microSD card as a boot device and for main storage. It’s important to have a card that’s fast and large enough for your projects; the minimum requirement is a 32GB UHS-1 card. Many projects with Jetson Nano 2GB Developer Kit will utilize swap space on the MicroSD Card due to only 2GB physical memory. For this reason, we recommend 64GB or larger microSD cards. High-endurance microSD cards are also recommended.
Please refer to to record the system image file () into the microSD card and complete the system initialization.
The system image file link in the user guide () points to JetPack 4.6.1, download and burn it to a microSD card After that, system initialization may fail when the Jetson Nano is started. So we recommend using the earlier version: JetPack 4.6.
2. Use a network cable to connect the Jetson Nano development board to a router or other computer hosts so that it can access the Internet.
3. Clone or download the code from , and install the Ailia SDK according to , the specific method is the same as the above step 3 in Run on the host computer, but NO need to execute the statement:
pip install -r requirements.txt
4. Install the relevant python library files using the following command:
5. Connect the camera and complete its configuration by referring to .
Please refer to the technical documentation to complete the setup if you use a USB camera to complete the setup.
To connect the USB uploader, you need to use the following command:
sudo usermod -a -G dialout $USER to increase user rights.
6. Start the program, please refer to step 4 and 5 of .
Now the OpenCat imitation program can run on the Jetson Nano development board. You can refer to other relevant technical documents to improve the program's performance, such as .
0 means there is no trigger axis and the trigger angle condition setting
1 means positive pitch, the robot body is bent forward and rotated in the downward direction
-1 means negative pitch, the robot body rotates backwards
2 indicates positive roll, the robot rolls to its left side
-2 means negative roll, the robot rolls to its right side
The 4th represents the trigger angle. Angle values have the same positive and negative meanings as body orientation expectations. Trigger angle setting range: an integer value between -125 and 125.
If a delay time is also set in the action frame, then when the robot runs this action frame, it must not only meet the trigger conditions set by the trigger axis and trigger angle but also reach the delay setting time before triggering the next frame of action.
Follow the guide to install the Ailia SDK, it will be used for pose detection. The guide mainly includes the following steps: download and install the ailia SDK and the related python library files.
When downloading the Ailia SDK, you need to enter the correct email address to receive the download link address and license file. The free license is valid for only one month. The SDK is about 2GB, so it takes time to download.
Move the downloaded license file (AILIA.lic) to the directory where bootstrap.py is located ({ailia sdk directory}/python), and then follow the steps to continue installing the Ailia SDK.
cd {ailia sdk directory}/python
python3 bootstrap.py
pip3 install .
Download the requirements.txt from this page (https://github.com/axinc-ai/ailia-models) to the directory where bootstrap.py is located before running the following command:
pip install -r requirements.txt. It may take 30 minutes.
Use the USB uploader or Bluetooth module to connect the robot and power it on. The computer needs to be connected to a camera device.
Run the following command to start the OpenCat Imitation program:
You can use Arduino IDE to config the NyBoard and upload sketch.
The following video shows the software configuration using our robot dog Bittle. The steps are identical to Nybble except that you need to change the model definition in OpenCat.h to Nybble.
1. NyBoard
1.1 Read the user manual
Find the version information for your board on NyBoard. As shown below:
Nybble
Find the version info on NyBoard. Read the user manual for , , , or (a light revision) accordingly.
Bittle
Find the version info on NyBoard. Read the user manual for or (a light revision) accordingly.
Take NyBoard V1_0 as an example, as shown in the following figure:
Wrong operations may damage your NyBoard!
1.2. Dial the slide switch to Arduino.
The slide switch changes the master of I2C devices (gyro/accelerometer, servo driver, external EEPROM).
On default “Arduino”, NyBoard uses the onboard ATmega328P as the master chip;
On “Pi”, NyBoard uses external chips connected through the I2C ports (SDA, SCL) as the master chip.
Sometimes if you cannot go through the bootup stage, maybe you have accidentally dialed the switch to "RPi".
The following section is kept for Nybble older versions (V0)
1.3. Dial the potentiometer clockwise to start from the lowest voltage.
NyBoard powers the metal-geared servos directly with the 7.2V battery. It's 8.4V when fully charged. You CANNOT use NyBoard to drive your own plastic geared servos directly.
2. Downloads and installations
You will need the newest to set up the environment. Older versions tend to compile larger hex files that may exceed the memory limit.
If you have previously added other libraries and see an error message "XXX library is already installed", I would recommend you delete them first (instruction: ). Due to different configurations of your Arduino IDE installation, if you see any error messages regarding missing libraries during later compiling, just google and install them to your IDE.
If you downloaded the code from GitHub after Jan 3, 2022, you can skip all the following libraries.
2.1. Install through the library manager
2.3. Add NyBoard support to Arduino IDE
With NyBoard V1_*, you can simply choose Arduino Uno.
The following section is kept for Nybble older versions (V0)
If you have NyBoard V0_* which runs at 20MHz, you need to add our customized configuration file following the next steps:
Only if the bootloader of NyBoard collapsed, which is very unlikely to happen
2.4. Burn the bootloader (no need for normal use)
2.5. Connect the uploader (sometimes referred to as the programmer)
This step does not require the Nyboard to be mounted on the robot.
The following picture shows two FTDI boards in previous kits for Nybble.
On the red board, the jumper selector should be put on 5V (not 3.3V) on the uploader for Arduino. Match the GND on both the uploader and the 6-pin socket on NyBoard.
Connect your computer with the uploader through USB to micro-USB cable. The uploader has three LEDs, power, Tx, and Rx. Right after the connection, the Tx and Rx should blink for one second indicating initial communication, then dim. Only the power LED should keep lighting up. You can find a new port under Tool->Port as “/dev/cu.usbserial-xxxxxxxx” (Mac) or “COM#” (Windows).
If Tx and Rx keep lighting up, there’s something wrong with the USB communication. You won’t see the new port. It’s usually caused by overcurrent protection by your computer, if you’re not connecting NyBoard with an external power supply and the servos move all at once.
For Linux, once the uploader is connected to your computer, you will see a “ttyUSB#” in the serial port list. But you may still get a serial port error when uploading. You will need to give the serial port permission. Please go to this link and follow the instructions:
If you cannot find the serial port after connecting to your computer, you may need to install the driver for the CH340 chip.
2.6. Connect Bluetooth uploader (optional)
It’s possible to program and communicate with Bittle wirelessly. You can even control Nybble / Bittle with a or from there!
We include our official in the standard Nybble / Bittle kit. It can be used for wirelessly uploading sketches and communicating with the robot. The baud rate is set to 115200.
You need to connect it to your computer like what you do with a Bluetooth AirPod. The default passcode is 0000 or 1234. Then you can select it under Tools->Port of Arduino IDE, and use it in the same way as the wired uploader.
For the specific connection method, please refer to of the Dual-Mode Bluetooth module.
You will need to set its baudrate to 57600 to use it on NyBoard V0_* for Nybble.
On Mac, the Bluetooth may lose connection after several uploads. In that case, delete the connection and reconnect to resume the functionality.
The Bluetooth dongle is not included in the kit sold by Seeed Studio or its partners. Please write to [email protected] for more information.
2.7. Download the OpenCat package
Download the 1.0 OpenCat repository from GitHub:
If you download the Zip file of the codes, you will get an OpenCat-1.0 folder after unzipping. You need to rename it to OpenCat before opening the OpenCat.ino.
No matter where you save the folder, the file structure should be:
There are several testX.ino codes in ModuleTests folder. You can upload them to test certain modules separately. Open any testX.ino sketch with prefix “test”. (I recommend using testBuzzer.ino as your first test sketch)
Open up the serial monitor and set up the baudrate:
For Linux machines, you may see the error message like "permission denied".
You will need to add execution privilege to the avr-gcc to compile the Arduino sketch:sudo chmod +x filePathToTheBinFolder/bin/avr-gcc
Furthermore, you need to add execution permission to all files within /bin, so the command would be : sudo chmod -R +x /filePathToTheBinFolder/bin
3. Arduino IDE as an interface
With the USB/Bluetooth uploader connecting NyBoard and Arduino IDE, you have the ultimate interface to communicate with NyBoard and change every byte on it.
I have defined a set of serial communication protocol for NyBoard:
All the token starts with a single Ascii encoded character to specify its parsing format. They are case-sensitive and usually in lower case.
Some commands, like the c and m commands can be combined.
For example:
Successive "m8 40", "m8 -35", "m 0 50" can be written as "m8 40 8 -35 0 50". You can combine up to four commands of the same type. To be exact, the length of the string should be smaller than 30 characters. You can change the limit in the code but there might be a systematic constraint for the serial buffer.
Some tokens haven't been implemented, such as 'h'. Token 'i' and 'l' still have some bugs in software version 1.0.
4. Raspberry Pi serial port as an interface
Only when using Pi as a master controller. Nybble / Bittle doesn't need a Pi to move.
You need to disconnect the serial uploader to communicate with Pi's serial port.
You can solder a 2x5 socket on NyBoard to plug in a Raspberry Pi. Pi 3A+ is the best fit for Nybble / Bittle's dimension.
Nybble
Bittle
After you solder on the socket, you won't be able to install the back cover of Bittle.
You need to unplug the 6-pin programmer for the NyBoard before mounting the Pi to the board.
The red can be 3D printed.
As shown in the , the arguments of tokens supported by Arduino IDE's serial monitor are all encoded as Ascii char strings for human readability. While a master computer (e.g. RasPi) supports extra commands, mostly encoded as binary strings for efficient encoding. For example, when encoding angle 65 degrees:
Ascii: takes 2 bytes to store Ascii characters '6' and '5'
Binary: takes 1 byte to store value 65, corresponding to Ascii character 'A'
What about value -113? It takes four bytes as an Ascii string but still takes only one byte in binary encoding, though the content will no longer be printable as a character.
Obviously, binary encoding is much more efficient than the Ascii string. However, the message transferred will not be directly human-readable. In the OpenCat repository, I have put a simple Python script that can handle the serial communication between NyBoard and Pi.
4.1. Config Raspberry Pi serial port
In Pi's terminal, type sudo raspi-config
Under the Interface option, find Serial. Disabled the serial login shell and enable the serial interface to use the primary UART:
Run raspi-config with sudo privilege: sudo raspi-config.
Find Interface Options -> Serial Port.
At the option Would you like a login shell to be accessible over serial?
You also need to DISABLE the to avoid repeating reset signals sent by Pi's GPIO 4.
If you plug Pi into NyBoard's 2x5 socket, their serial ports should be automatically connected at 3.3V. Otherwise, pay attention to the Rx and Tx pins on your own AI chip and its voltage rating. The Rx on your chip should connect to the Tx of NyBoard, and Tx should connect to Rx.
Note: If you installed UbuntuOS on Raspberry Pi, please config it as follows:
add enable_uart=1 to /boot/config.txt
4.2. Change the permission of
If you want to run it as a bash command, you need to make it executable:
chmod +x ardSerial.py
You may need to change the proper path of your Python binary on the first line:
#!/user/bin/python
4.3. Use ardSerial.py as the commander of Bittle
NyBoard has only one serial port. You need to UNPLUG the FTDI converter if you want to control Bittle with Pi's serial port.
Typing ./ardSerial.py <args> is almost equivalent to typing <args> in Arduino's serial monitor. For example, ./ardSerial.py kcrF means "perform skill crawl Forward".
Both ardSerial.py and the parsing section in OpenCat.ino need more implementations to support all the serial commands in the protocol.
For Nybble:
Reduced motion capability may happen when connected to Pi! A stronger battery is needed.
5. Battery
Though you can program NyBoard directly with the USB uploader, external power is required to drive the servos.
When powering the NyBoard with only USB FTDI, there's obviously charging and uncharging in the servo's capacitor and cause the yellow LED to pulse. However the USB's current is not sufficient to keep the servos working. The servo circuit has to be powered by external batteries to work properly.
Bittle
5.1. Voltage
NyBoard requires 7.4~8.4V external power to drive the servos. We include our customized Li-ion battery with built-in charging and protection circuit in the Bittle kit. Short press the battery's button will show its status. Blue light indicates it has power, and red means the power is low.
5.2. Connection and Power On
Be careful with the polarity when connecting the power supply. The terminal on NyBoard has an anti-reverse socket, so you won't be able to plug in the wrong direction. See for the detailed connection instruction.
Please long press the button of the battery for 3 seconds to power on the battery.
Reversed connection may damage your NyBoard!
5.3. Battery life varies according to usage
It can last hours if you're mainly coding and testing postures, or less than 30 mins if you keep Bittle running.
The battery light will turn red when the power is low. The power will be cut off automatically.
5.4. Charging
Use a 5V-1A USB charger to charge the battery. We don't recommend using fast chargers. The battery will NOT supply power during charging. Keep the battery in your sight when charging.
5.5. After use
After playing, remember to turn off the battery. It's recommended to unplug the battery from the NyBoard's terminal.
Nybble
5.1. Voltage
NyBoard requires 7.4~9V external power to drive the servos. On Nybble, we are using the 8V standard to configure all the parameters as a whole system. That's usually two Li-ion or Li-poly batteries connected in series. A single battery is 4.2V when fully charged and can work normally until voltage drops to 3.6V. That’s about 7.2V with two batteries connected in series. Before installation, dial the potentiometer on NyBoard clockwise to try minimum output first (about 4.5V), then dial it up until it can make the robot work properly. With our kit servos, it actually works better to connect SW3 between BATT with V_S directly and bypass the step-down chip (so no need to tune the potentiometer).
When looking for batteries, search for keywords “14500 3.7V li-ion battery unprotected”. I’ve noticed that the overcurrent protection of some batteries could be triggered by peak current draw-(usually >2.5A), causing NyBoard to reset or malfunction. Try to find batteries with higher discharge ratings.
Read this to find batteries that work on Nybble.
5.2. Dimensions
The included battery holder is sized for 14500 batteries, which is 14 mm in diameter, and 50 mm in length. 50 ± 1 mm should still fit in. They are the same size as AA batteries, but much more powerful. Make sure not to use them in regular AA devices. If you are in the US, we have tested with EBL 14500 li-ion batteries.
You can also design other battery holders to carry larger batteries for better performance. That’s especially necessary if you mount a Raspberry Pi or want Nybble to run faster.
5.3. Connection
Be careful with the polarity when connecting the power supply. Make sure you can find the positive (+) and negative (-) sign on both the NyBoard's power terminal and your power supply.
Reversed connection may damage your NyBoard!
Loosen the screws of the power block. Insert the wires of the battery holder then tighten the screws. When turning the switch on, both the blue LED (for the chip) and the yellow LED (for servo) should lit up.
In the kit shipped after Jan.1st, the terminal is replaced with an anti-reverse socket, so you won't be able to plug in the wrong direction.
5.4. Battery life varies according to usage
It can last hours if you're mainly coding and testing postures, or less than 30 mins if you keep Nybble running.
When the battery is low, the yellow LED will blink slowly. Although NyBoard can still drive one or two servos, it will be very unstable to drive multiple servos at once. That will lead to repeatedly restarting the program or awkward joint rotations. In rare cases, it may even alter the bits in EEPROM. You will need to reupload the codes and re-save the constants to recover.
5.5. Charging
You will need compatible smart chargers for the batteries. Keep batteries attended during charging.
5.6. After use
After playing, remember to remove the batteries from the battery holder to avoid over-discharging.
5.7. Signal interference
It's ok to connect both FTDI and battery at the same time. You can type in serial commands while the battery is connected. I do notice that the USB serial port could be disabled randomly. I think that's due to the sudden current draw by servos. It will trigger the computer’s overcurrent protection and disable the USB port. In that case, you can change the USB port you're connecting to, reset the USB bus, or restart the computer. So actually it’s better to power the board by battery before plugging in the FTDI.
//#include "InstinctBittle.h" //activate the correct header file according to your model
#include "InstinctNybble.h"
From NyBoard V0_2, we provide a jumper selector to bypass the potentiometer. If you are using the metal servos in a standard Nybble kit, this section can be skipped.
Higher voltage will increase the servos’ torque and make Nybble move faster. The downside is it will increase current draw, reduce battery life, affect the stability of the circuit, and accelerate the wearing of the servos. Based on my tests, 5.5V seems to result in a balanced performance.
For the initial installation, don’t put screws on the NyBoard as you may need to take it out for tuning the potentiometer. Make sure all the servos can rotate fine in normal working conditions before making fine calibrations.
1.4. Adjust the NyBoard for optimized performance (no need for NyBoard V1_0).
NyBoard is designed for two use cases. One is for Nybble that uses metal-geared servos, the other is for DIY robots that may use plastic geared servos. Plastic servos can only stand 6V so there is a step-down chip on NyBoard. The chip is rated for 5A maximal output, but can only be achieved with multiple proper settings and careful tuning.
When using NyBoard with the metal-geared servos of Nybble, optimized performance can be achieved by some adjustment. For NyBoard_V0_1, you will need to do some soldering work as discussed in the forum post. For NyBoard_V0_2, you can connect the jumper switch SW3 between BATT and V_S (Considering safety for plastic servos, by default NyBoard comes with SW3 connecting V_S and V+).
V_S means power for the servo. The jumper switch chooses whether to power the servos (V_S) by the step-down chip (V+) or by the batteries (BATT) directly. So BATT and V+ should never be connected directly.
It turns out that NyBoard works more stable when powering the metal-geared servos directly with BATT rather than V+. However, if you are using NyBoard to drive your own plastic geared servos, you do need to use the step-down circuit.
The IRremote library was updated recently. And for some reason, they even changed the encoding of the buttons. You MUST roll back the library's version to 2.6.1 in the library manager.
To save programming space, you MUST comment out the unused decoder in IRremote.h. It will save about 10% flash!
Find Documents/Arduino/libraries/IRremote/src/IRremote.h and set unused decoders to 0. That is, only DECODE_NEC and DECODE_HASH are set to 1, and others are set to 0.
In the Additional Boards Manager URLs field, add https://raw.githubusercontent.com/PetoiCamp/OpenCat/master/Resources/NyBoard/boardManager/package_petoi_nyboard_index.json. If there are already URLs listed in this field, separate them with commas or click on the icon next to the field to open up an editor and add this URL to a new line. Make sure there's no space in the address when you copy-paste the link.
Click on the OK button to close the Preferences panel (you have to close the previously opened Additional Boards Manager URLs editor first, to close the Preference panel)
Open the Boards Manager... window with the Tools -> Board: XXXX -> Boards Manager... menu item.
In the Filter your search... field, type NyBoard
Select the entry and click on Install
Click on the Close button
Select ATmega328P (5V, 20 MHz) NyBoard from the Tools -> Board: XXXX menu (NyBoardV0_1 and NyBoardV0_2 are using the same board settings.)
IMPORTANT! If you have installed the Arduino IDE via the Microsoft Store, you likely will not have access to the folder where critical configuration files are stored. The easiest solution is to uninstall the IDE and download/re-install it directly from https://www.arduino.cc.
Linux
Downloading from the terminal or from the software manager might not give you the latest version which can be an issue. Please download the latest version from Arduino’s site: https://www.arduino.cc/en/Main/Software
Edit your boards.txt with admin privilege. Find the section of
pro.name=Arduino Pro or Pro Mini
and insert the
code block in the Arduino Pro or Pro Mini section as below. Save and quit your editor.
● Download ATmega328_20MHz.hex and put it in your Arduino folder ./bootloaders/atmega/. You should see other bootloaders with the .hex suffix in the same folder.
Restart your Arduino IDE. In Tools->Boards, select Arduino Pro or Pro Mini. You should find ATmega328P (5V, 20 MHz) in the Processor menu.
If you cannot find the board, your Arduino IDE may be using the boards.txt in another path. Search boards.txt in all the folders on your computer. Find out the right file that's in effect.
Every NyBoard has to go through functionality checks before shipping, so they should already have a compatible bootloader installed. However, in rare cases, the bootloader may collapse then you won't be able to upload sketches through Arduino IDE.
Well, it's not always the bootloader if you cannot upload your sketch:
Sometimes your USB board will detect a large current draw from a device and deactivate the whole USB service. You will need to restart your USB service, or even reboot your computers;
You need to install the driver for the FTDI USB 2.0 to the UART uploader;
You haven't selected the correct port;
Bad contacts;
Bad luck. Tomorrow is another day!
If you really decide to re-burn the bootloader:
With NyBoard V1_*, you can simply choose Arduino Uno under the Tool menu of Arduino IDE.
If you have NyBoard V0_* which runs at 20MHz, you need to choose NyBoard (ATmega328P 5V, 20MHz).
Select your ISP (In-System Programmer). The above screenshot shows two popular programmers: the highlighted USBtinyISP is a cheap bootloader you can buy, while the checked Arduino as ISP can let you use a regular Arduino as ISP!
Connect the programmer with the SPI port on NyBoard. Notice the direction when connecting. Make sure they have good contact.
Burn bootloader. If it's your first time doing so, wait patiently until you see several percent bars reach 100% and no more messages pop up for one minute.
First connect the computer and the FTDI uploader with a miniUSB-USB cable. The red model uploader has three LED lights, power, Tx and Rx, and the blue model uploader has no power light. At the moment when the computer USB is connected, the Tx and Rx lights will flash and then go out, indicating that there is an initial information transmission. Then you can find the corresponding serial port “/dev/cu.usbserial-xxxxxxxx” (Mac OS) or “COM#” (Windows OS) in Tools->Port of Arduino IDE.
For NyBoard V1_*, choose the board as Arduino Uno and later set the baudrate to 115200 in both the code and the serial monitor.
For NyBoard V0_*, choose the board as NyBoard (ATmega328P 5V, 20MHz) and later set the baudrate to 57600 in both the code and the serial monitor.
Compile the code. There should be no error messages. Upload the sketch to your board and you should see Tx and Rx LEDs blink rapidly. Once they stop blinking, messages should appear on the serial monitor.
Make sure you set "No line ending" to before entering your commands. Otherwise, the invisible '\n' or '\r' characters will confuse the parsing functions.
select 'No'.
At the option Would you like the serial port hardware to be enabled? select 'Yes'.
Exit raspi-config and reboot for changes to take effect.
remove console=serial0,115200 from /boot/firmware/cmdline.txt on Ubuntu and similar to/boot/cmdline.txt on Raspberry Pi OS
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):
reload your udev rules: sudo udevadm control --reload-rules && sudo udevadm trigger
change the group of the new serial devices:
The devices are now under the tty group. Need to add the user to the tty group and dialout group:
update the permissions for group read on the devices:
reboot
Or just create a script that will do this automatically.
With the additional current drawn by Pi, Nybble will be less capable for intense movements, such as trot (the token isktr). The system is currently powered by two 14500 batteries in series. You may come up with better powering solutions, such as using high drain 7.4 Lipo batteries, or 2S-18650. There are a bunch of considerations to collaborate software and hardware for balanced performance. With Nybble's tiny body, it's better to serve as a platform for initiating the communication framework and behavior tree rather than a racing beast.
#define DECODE_RC5 0
#define SEND_RC5 0
#define DECODE_RC6 0
#define SEND_RC6 0
#define DECODE_NEC 1
#define SEND_NEC 0
#define DECODE_SONY 0
#define SEND_SONY 0
...
set zeros all the way down the list
...
#define DECODE_HASH 1 // special decoder for all protocols
## Arduino Pro or Pro Mini (5V, 20 MHz) w/ ATmega328P
## --------------------------------------------------
pro.menu.cpu.20MHzatmega328=ATmega328P (5V, 20 MHz) NyBoard
pro.menu.cpu.20MHzatmega328.upload.maximum_size=30720
pro.menu.cpu.20MHzatmega328.upload.maximum_data_size=2048
pro.menu.cpu.20MHzatmega328.upload.speed=57600
pro.menu.cpu.20MHzatmega328.bootloader.low_fuses=0xFF
pro.menu.cpu.20MHzatmega328.bootloader.high_fuses=0xDA
pro.menu.cpu.20MHzatmega328.bootloader.extended_fuses=0xFD
pro.menu.cpu.20MHzatmega328.bootloader.file=atmega/ATmega328_20MHz.hex
pro.menu.cpu.20MHzatmega328.build.mcu=atmega328p
pro.menu.cpu.20MHzatmega328.build.f_cpu=20000000L
## Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega328P
## --------------------------------------------------
##############################################################
pro.name=Arduino Pro or Pro Mini
pro.upload.tool=avrdude
pro.upload.protocol=arduino
pro.bootloader.tool=avrdude
pro.bootloader.unlock_bits=0x3F
pro.bootloader.lock_bits=0x0F
pro.build.board=AVR_PRO
pro.build.core=arduino
pro.build.variant=eightanaloginputs
## Arduino Pro or Pro Mini (5V, 20 MHz) w/ ATmega328P
## --------------------------------------------------
pro.menu.cpu.20MHzatmega328=ATmega328P (5V, 20 MHz) NyBoard
pro.menu.cpu.20MHzatmega328.upload.maximum_size=30720
pro.menu.cpu.20MHzatmega328.upload.maximum_data_size=2048
pro.menu.cpu.20MHzatmega328.upload.speed=57600
pro.menu.cpu.20MHzatmega328.bootloader.low_fuses=0xFF
pro.menu.cpu.20MHzatmega328.bootloader.high_fuses=0xDA
pro.menu.cpu.20MHzatmega328.bootloader.extended_fuses=0xFD
pro.menu.cpu.20MHzatmega328.bootloader.file=atmega/ATmega328_20MHz.hex
pro.menu.cpu.20MHzatmega328.build.mcu=atmega328p
pro.menu.cpu.20MHzatmega328.build.f_cpu=20000000L
## Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega328P
## --------------------------------------------------