Petoi Doc Center
🇺🇸English
🇺🇸English
  • Welcome to Petoi Doc Center
  • Getting Started Guide
  • 🙋‍♂️FAQ(Frequently Asked Questions)
  • Petoi robot joint index
    • Joint Pins on NyBoard
      • Nybble
      • Bittle
    • Joint Pins on BiBoard V0
      • Bittle X
      • Bittle X+Arm
    • Joint Pins on BiBoard V1
      • Bittle X
      • Bittle X+Arm
      • Nybble Q
  • Bluetooth Connection
    • BiBoard
    • NyBoard
  • Upload Firmware
    • NyBoard
    • BiBoard V0
    • BiBoard V1
  • Joint Calibration
  • Infrared Remote
    • Remote Controller
  • Mobile App
    • Introduction
    • Calibrator
      • Nybble
      • Bittle
    • Controller
  • Desktop APP
    • Introduction
    • Firmware Uploader
      • NyBoard
      • BiBoard V0
      • BiBoard V1
    • Joint Calibrator
      • NyBoard Preparation
      • BiBoard Preparation
      • Nybble
      • Bittle / Bittle X
        • Bittle (NyBoard)
        • Bittle X (BiBoard V0)
        • Bittle X (BiBoard V1)
      • Bittle X+Arm
        • BiBoard V1
        • BiBoard V0
    • Skill Composer
      • NyBoard Connection
      • BiBoard Connection
      • Interface
        • Nybble
        • Bittle / Bittle X
        • Bittle X+Arm
    • Tools
  • Block-based programming
    • Petoi Coding Blocks
      • NyBoard Preparation
      • BiBoard Preparation
    • Block-based Coding Curriculum - Learn Quadruped Robotics for Beginners
    • Python coding mode in Mind+
    • Generic Arduino Uno Blocks
    • Install Mind+ on Chromebook
  • Arduino IDE
    • Upload Sketch for NyBoard
    • Upload Sketch for BiBoard
    • Calibrate the joints with Arduino IDE
    • Serial Monitor
    • C++ Curriculum: Learn Quadruped Robotics for Beginners
    • Install Arduino IDE on Chromebook
  • Free Curriculum
    • 📚Download
  • APIs
    • 🖇️Serial Protocol
      • Feedback servos
      • Nested task queue and signal generator
    • 🐍Python API
    • 🐛8266 MicroPython controller
      • Run MicroPython on ESP8266
      • Setup WebREPL
      • Using the ESP-NOW protocol
    • 🦎8266 Arduino C Controller
    • ©️C++ API
    • 🍓Raspberry Pi serial port as an interface
      • For BiBoard V1
    • 💻Set up Development Environment on Chromebook
    • 🤖ROS
  • Nyboard
    • Overview
    • NyBoard V1_0
    • NyBoard V1_1 & NyBoard V1_2
  • BIBOARD
    • BiBoard V0 Guide
    • BiBoard Extension Hat
    • Demo Applications
      • 1.GPIO port
      • 2.Serial port
      • 3.Analog-digital converter
      • 4.Digital-Analog Converter
      • 5.EEPROM (Electrically Erasable Programmable read only memory)
      • 6.Gyro IMU(MPU6050)
      • 7.Infrared remote control
      • 8.PWM(Pulse Width Modulation)
      • 9.Servo(under construction)
      • 10.Classic Bluetooth serial port SPP
      • 11.Bluetooth low energy (BLE) serial port pass-through
      • 12.File system SPIFFS
      • 13.Add hardware partition configuration option in Arduino IDE
      • 14.Play MP3
      • 15.The usage of Wi-Fi OTA(Over-The-Air)
    • BiBoard V1 Guide
  • Communication Modules
    • Introduction (For NyBoard)
    • USB Uploader (CH340C or CH343G)
    • Dual Mode Bluetooth
    • WiFi module ESP8266
      • ESP8266 + Python Scripts Implement wireless crowd control
  • Extensible Modules
    • Introduction
    • MU Camera
    • Ultrasonic Sensor
    • Light Sensor
    • Touch Sensor
    • Gesture Sensor
    • PIR Motion Sensor
    • IR Distance Sensor
    • Voice Command Module
    • Petoi AI Vision Module
    • Advanced development and application of AI vision modules
      • Model Training
      • Model quantification
      • Model deployment
      • Training on the COCO DIY dataset
    • Robot Arm
      • Upgrade your older Bittle/Bittle X for the robotics arm gripper
    • 🎮Joystick with Micro:Bit
  • Applications
    • Melody Creation
    • Skill Creation
    • OpenCat Imitation Tutorial
    • Programmable Puppet Character
    • Tutorial for simulating Bittle In Isaac Sim
  • History
    • Upload Sketch For NyBoard (software 1.0)
  • Technical Support
    • 💾Supporting Application and Software
    • 🔧Burn Bootloader for NyBoard
    • 🛠️Useful Tools
    • 🔋Battery
  • Useful Links 🕸
    • 🔭Home of Petoi Robots
    • 🛒Shop Coding Robots
    • 💿GitHub of OpenCat
    • 🎪PetoiCamp (Forum)
    • 📽️Petoi Robot Videos
    • 📬Users' repositories
Powered by GitBook
On this page
  • 1. Coding blocks for music in Mind+
  • 1.1 A list comprises multiple "Tone + Duration" blocks connected by the "+" block.
  • 1.2 A list in the format of pairs of Tone + Duration: [tone, duration, tone, duration...]
  • 2. The Serial Protocol for generating melody
  • 2.1 Start Token
  • 2.2 Music Notes
  • 2.3 Duration
  • 2.4 Half-scale vs. Whole-scale
  • 2.5 Command Structure
  • 3. Example: Creating Twinkle, Twinkle, Little Star
  • 3.1 Choose Your Base Tone:
  • 3.2 Plan Your Notes:
  • 3.3 Define Durations:
  • 3.4 Translate to Commands:
  • 3.5 The mind+ version
  • 3.6 The Python version:
  • 4. Experimenting
  • Complete Twinkle, Twinkle, Little Star
  • My Love by Westlife
  • A very long melody for testing on the BiBoard
  • Using other tools

Was this helpful?

Export as PDF
  1. Applications

Melody Creation

PreviousJoystick with Micro:BitNextSkill Creation

Last updated 1 year ago

Was this helpful?

There are two ways to play a melody with the robot:

  1. Using the in Mind+.

  2. Using the in Mind+, Arduino IDE, Python, and the Petoi mobile app.

1. Coding blocks for music in Mind+

You can use this coding block to make one tone.

There are several ways to join multiple tones together to make a melody:

1.1 A list comprises multiple "Tone + Duration" blocks connected by the "+" block.

1.2 A list in the format of pairs of Tone + Duration: [tone, duration, tone, duration...]

To better understand the format, you can continue reading the next section.

2.1 Start Token

The melody starts with the letter 'b', indicating a buzzer command. (No quotation marks are needed in the final command).

2.2 Music Notes

Notes are represented by numbers, with 0 or -1 for silence. Use 1-35 for the best effect on a buzzer.

2.3 Duration

Durations are also numbers, indicating how many parts a whole second is divided into (e.g., 2 = 1/2 second). This plays a single middle C (C3 = 14) for 1/2 second with no delay:

b 14 2

The space between the starting 'b' and the first number can be omitted:

b14 2

A note longer than 1 second can be represented by two notes:

b14 1 14 1

2.4 Half-scale vs. Whole-scale

2.5 Command Structure

2.5.1 In the serial monitor or the mobile app's customized button console:

You can define multiple note-duration pairs separated by spaces or commas. It's easier to read if you use spaces to separate the notes within a sentence and use commas to separate sentences.

For example:

b 14 4 16 4 18 2, 18 4 16 4 14 2

The Serial Monitor uses ASCII encoding and only allows a short melody of around 200 bytes. b 14 4 takes six bytes to store.

2.5.2 In the Python code:

  • Use brackets []to define a list. The numbers should all be separated by ','. The above example becomes:

['b', [14, 4, 16, 4, 18, 2, 18, 4, 16, 4, 14, 2]]

or

['B', [14, 4, 16, 4, 18, 2, 18, 4, 16, 4, 14, 2]]

The Python version with the 'B' token uses a more efficient Binary encoding to allow a longer melody. On NyBoard, it allows around 450 bytes, i.e., 250 notes. On BiBoard, it allows around 2500 bytes, i.e. 1250 notes.

  • After playing the melody, you can add a number at the end to define an optional delay (in seconds).

['b', [14, 4, 16, 4, 18, 2, 18, 4, 16, 4, 14, 2], 2]

2.5.3 In the Mind+ coding blocks

Copy and paste the number part of the command, and separate each number with ',' as the example in section 1.

3. Example: Creating Twinkle, Twinkle, Little Star

3.1 Choose Your Base Tone:

In this example, we'll use C3 (base tone 14). But you can choose any note within the 5-30 range.

3.2 Plan Your Notes:

Write down the sequence of notes you want to play, considering half- and whole-tone jumps. Use numbers based on your chosen base tone (14). Include silent notes (0) for pauses.

3.3 Define Durations:

Decide how long each note should play. Use numbers to represent fractions of a second (e.g., 4 = 1/4 second).

3.4 Translate to Commands:

Command with the 'b' token

b 14 4 14 4 21 4 21 4 23 4 23 4 21 2 0 4, 19 4 19 4 18 4 18 4 16 4 16 4 14 2

It can be used in Arduino IDE's serial monitor or the Petoi mobile app:

The mobile app also supports the binary format with the 'B' token:

B,14,4,14,4,21,4,21,4,23,4,23,4,21,2,0,4,19,4,19,4,18,4,18,4,16,4,16,4,14,2

3.5 The mind+ version

3.6 The Python version:

['b',[14,4,14,4,21,4,21,4,23,4,23,4,21,2,0,4,19,4,19,4,18,4,18,4,16,4,16,4,14,2],2]

or

['B',[14,4,14,4,21,4,21,4,23,4,23,4,21,2,0,4,19,4,19,4,18,4,18,4,16,4,16,4,14,2],2]

4. Experimenting

You can also test the following examples:

Complete Twinkle, Twinkle, Little Star

b14 8 14 8 21 8 21 8 23 8 23 8 21 4,
19 8 19 8 18 8 18 8 16 8 16 8 14 4,
21 8 21 8 19 8 19 8 18 8 18 8 16 4,
21 8 21 8 19 8 19 8 18 8 18 8 16 4,
14 8 14 8 21 8 21 8 23 8 23 8 21 4,
19 8 19 8 18 8 18 8 16 8 16 8 14 4

My Love by Westlife

b15 2 14 2 12 2 12 4 10 2 10 4 8 2 10 2 10 2,
15 2 14 2 12 2 12 4 10 2 10 4 20 2 19 2 19 2, 
19 2 22 2 20 2 19 4 17 1 0 8,
19 2 17 4 15 2 19 4 17 2 17 1 17 1 0 4,15 2 15 1

A very long melody for testing on the BiBoard

b20, 4, 22, 4, 24, 4, 15, 4, 20, 4, 22, 8, 24, 1, 22, 4, 20, 4, 22, 4, 27, 4, 27,
4, 27, 4, 27, 2, 20, 4, 19, 4, 20, 4, 20, 4, 20, 4, 20, 4, 20, 2, 19, 4, 20, 4, 19, 4,
20, 4, 19, 4, 17, 4, 15, 2, 15, 4, 15, 4, 17, 4, 17, 4, 17, 4, 17, 4, 17, 2, 15, 4, 12,
4, 15, 4, 12, 4, 15, 4, 22, 4, 20, 2, -1, 4, 15, 4, 24, 4, 24, 4, 24, 4, 25, 4, 27, 4,
20, 4, 20, 4, 24, 4, 22, 1, 22, 1, -1, 2, 15, 4, 15, 4, 15, 2, 15, 4, 15, 4, 17, 4, 15,
4, 12, 4, 15, 4, -1, 4, 7, 4, 8, 4, 8, 4, 12, 2, 12, 4, 13, 4, 12, 4, 8, 4, 8, 4, 10,
4, 12, 1, -1, 4, 12, 4, 10, 4, 8, 4, 8, 4, 8, 2, 7, 4, -1, 4, 8, 4, 8, 4, 8, 4, 8, 4,
3, 4, 3, 4, 12, 2, 8, 4, 8, 4, 3, 4, 13, 2, 13, 4, 13, 4, 13, 4, 5, 4, 8, 4, 8, 4, 10,
1, 10, 1, 20, 4, 22, 4, 24, 4, 15, 4, 20, 4, 22, 8, 24, 1, 22, 4, 20, 4, 22, 4,
27, 4, 27, 4, 27, 4, 27, 2, 20, 4, 19, 4, 20, 4, 20, 4, 20, 4, 20, 4, 20, 2, 19, 4, 20,
4, 19, 4, 20, 4, 19, 4, 17, 4, 15, 2, 15, 4, 15, 4, 17, 4, 17, 4, 17, 4, 17, 4, 17, 2,
15, 4, 12, 4, 15, 4, 12, 4, 15, 4, 22, 4, 20, 2, -1, 4, 15, 4, 24, 4, 24, 4, 24, 4, 25,
4, 27, 4, 20, 4, 20, 4, 24, 4, 22, 1, 22, 1, -1, 2, 15, 4, 15, 4, 15, 2, 15, 4, 15, 4,
17, 4, 15, 4, 12, 4, 15, 4, -1, 4, 7, 4, 8, 4, 8, 4, 12, 2, 12, 4, 13, 4, 12, 4, 8, 4,
8, 4, 10, 4, 12, 1, -1, 4, 12, 4, 10, 4, 8, 4, 8, 4, 8, 2, 7, 4, -1, 4, 8, 4, 8, 4, 8,
4, 8, 4, 3, 4, 3, 4, 12, 2, 8, 4, 8, 4, 3, 4, 13, 2, 13, 4, 13, 4, 13, 4, 5, 4, 8, 4,
8, 4, 10, 1, 10, 1

Using other tools

Play around with tones and duration sequences to create your own melodies. For more complex pieces, there are online resources and software that can translate musical notation to this format. You may even write prompts to let AI generate a melody for you!

For example, using Gemini to give you a raw melody sequence to start with:

Remember, this is just the beginning—have fun composing!

2. The for generating melody

A difference of 1 in note number represents a half-scale tone (semitone), while a difference of 2 represents a whole-scale tone. You can define any note as the base (e.g., middle C3 = 14). This sets the reference point for your melody. So D3 will be 16, E3 will be 18, F3 will be 19, G will be 21, A will be 23, B will be 25, and C4 will be 26. C4 - C3 = 12. That's the so-called . You may write a map in the code for quick conversion.

Refer to the to send it to the robot using Python.

You may share your prompt, which works directly with our community, at .

Serial Protocol
12-Tone Equal Temperament
example
www.petoi.camp
Petoi Coding Blocks
Serial Protocol
Logo‎Gemini - Convert "twinkle twinkle little star" to A B C notation, and use numbers to represent the duration of each note. For example, 2 means 1/2 of a second. Write the note in the format of a list of note, duration, note, duration, ... Don't add quotation mark around the letters.Gemini
Enter the command in the Serial Monitor and listen
Enter the command in the Serial Monitor and listen
Serial monitor
Mobile app
Screenshot of the AI generated response