Upload Sketch for NyBoard
Setup Process
OpenCat software works on both Nybble and Bittle, controlled by NyBoard based on ATmega328P. There are three types: NyBoard V1_0, NyBoard V1_1, and NyBoard V1_2.
Dial the I2C switch (SW2) to Arduino.
The I2C 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 “RPi”, NyBoard uses external chips connected through the I2C ports (SDA, SCL) as the master chip.

Notes:
Sometimes, if you cannot go through the IMU (Inertial Measurement Unit) calibration stage, such as repetitively printing "IMU" and restarting, maybe you have accidentally dialed the switch to the "RPi" side.
Before uploading the firmware, please ensure that no I2C device is connected to the I2C interface of the mainboard; otherwise, the firmware upload will fail. The location of the I2C interface is as shown below

Quick Start Tutorial Video
The setup process for Nybble is almost the same, except that you need to change the model definition to #define NYBBLE. Make sure you read through the following detailed steps.
Downloads and installations of Arduino IDE
With NyBoard V1_*, you can simply choose Arduino Uno.

Connect the USB uploader (sometimes referred to as the programmer)
For specific steps, please refer to the Connect NyBoard section in the USB uploader module.
Connect Bluetooth uploader (optional)
You can also use the Bluetooth dongle to upload a sketch for NyBoard. For specific steps, please refer to the Connect NyBoard section in the Dual-Mode Bluetooth Module.
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.
Download the OpenCat source code
Download a fresh OpenCat repository from GitHub: https://github.com/PetoiCamp/OpenCat. It’s better if you utilize GitHub’s version control feature. Otherwise, make sure you download the WHOLE OpenCat FOLDER every time. All the codes have to be the same version to work together.

If you download the Zip file of the codes, you will get an OpenCat-main folder after unzipping. Rename it to OpenCat before opening the OpenCat.ino, so that the two names match.
Arduino requires the .ino file to be put in a folder with the same name. You must rename the OpenCat-main folder as OpenCat (i.e. delete the -main suffix). Otherwise, Arduino will create another OpenCat folder and move OpenCat.ino into it. It will break the path dependency of related files.
No matter where you save the folder, the file structure should be:
There are several testX.ino codes in the 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 baud rate. With NyBoard V1_*, choose the board as Arduino Uno and later set the baud rate to 115200 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.
Upload the sketch
To configure the board, please follow these steps:
1. Configure the robot type and board version
Open the file OpenCat.ino and select your robot and board version. For example:
#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_12. Setup the configuration mode
Comment out #define MAIN_SKETCH so that it will turn the code to the board configuration mode. Upload and follow the serial prompts to proceed.
// #define MAIN_SKETCH3. Plug the USB uploader into your computer
Install the driver if no USB port is found under Arduino -> Tools -> Port.

4. Plug the USB uploader into the NyBoard
For specific steps, please refer to the Connect NyBoard section in the USB uploader module.
5. Upload the configuration mode sketch
Click the Upload button.

If you cannot upload a sketch to the NyBoard (the "not in sync" error) and verify that the serial connection is all good, the NyBoard's bootloader might have crashed during the last upload, which is very unlikely to happen.
Burn the bootloader (no need for everyday use)
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 collapsed, so you won't be able to upload sketches through the 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'll need to restart your USB service or reboot your computer.
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 decide to re-burn the bootloader:
please refer to the chapter Burn Bootloader for NyBoard
6. Open the serial monitor
You can find the button either under Tools; or at the top-right corner of the IDE.
Set the serial monitor to No line ending and 115200 baud rate.

7. Reset joint offsets
The serial monitor prompts:
Reset joint offsets? (Y/n):Input ‘Y’ and hit Enter if you want to reset all the joint offsets to 0.
The program will do the reset and then update the constants and instinctive skills in the static memory.
To pass this step, you must enter ‘Y’ or ‘n’. Otherwise, the following parameters, including the skill data, will not be updated on the board.
8. IMU (Inertial Measurement Unit) calibration
The serial monitor prompts:
Calibrate the IMU? (Y/n): Input ‘Y’ and hit Enter if you have never calibrated the IMU or want to redo calibration.
Please put the robot flat on the table and don't touch it. The robot will long beep six times to give you enough time. Then it will read hundreds of sensor data points and save the offsets. It will beep when the calibration finishes.
When the serial monitor prints "Ready!", you can close the serial monitor to do the next step.
9. Calibrate the servo controller chip PCA9685 on the NyBoard
After the IMU calibration, there's an optional step to calibrate the servo driver.
If later you find one of the servos stops working but can resume working after re-powering it, it's probably due to an inaccurate PWM driver signal. You must redo the previous uploading, and this step CANNOT be skipped.
This calibration makes the servo controller (PCA9685 chip)'s angle signal more precise. Use a short jumper wire to connect the PWM pin 3 (the signal pin of one of the servo pins) and Grove pin A3 and hold the wire steady. It doesn’t have to be a dedicated jumper wire. Any thin metal wire, such as a straightened paper clip, can work as long as it can connect the pins.

The program will measure the pulse width of the signal and automatically calibrate the chip after getting three identical readings successively. It usually takes less than 2 seconds. The board will beep three times to indicate the calibration is done. The calibration offset will be saved to the board for the next time of bootup. The process should be done at least once, and we have calibrated every board after October 2022. But you can still do it by yourself, just in case.
10. Upload the Major Functionalities sketch
Uncomment #define MAIN_SKETCH to make it active. This time the code becomes the normal program for the major functionalities. Then upload the code.
#define MAIN_SKETCHOpen the serial monitor. When the serial monitor prints "Ready!", the robot is ready to take your next instructions.
11. The module macro in the code
The default code runs the standard mode. If you have some extensible modules, you may uncomment the macro definition of a specific module. It will disable the Gyro code to save some programming space and activate the demo of the module.

The behavior of the official modules is defined in separate header files in OpenCat/src/. You can find them in OpenCat/src/io.h -> readSignal(). The behavior of OTHER_MODULES is defined in OpenCat/OpenCat.ino -> otherModule(). You can study the example code to write your own functions.

12. Modify the "joint-pin" mapping
Sometimes, you may want to modify the robot's "joint-pin" mapping. You can change it in OpenCat/src/OpenCat.h. Adjust the code block to match the board version at the beginning of OpenCat.ino. After the modification, remember to save the changes and redo the uploading process from step 2.

Memory arrangement
Congratulations! Now, you have finished the standard setup steps. You can just read the source code to dive deeper into the program. The skills are saved in multiple places on a NyBoard due to ATmega328P's limited resources. The following diagram may give you some hints to help you understand.

Last updated

