Robotic Musical Instruments with NXC

The website for NXC and Bricx Command Center:

More Online Resources:

Overview of Bricx Command Center IDE:

Basic Bricx / NXC Commands:

Motor (Output) Commands:

OnFwd("ports", "pwr");
OnRev("ports", "pwr");
OnFwdSync(“ports”, “pwr”, “turnpct”);
RotateMotor(“ports”, “pwr”, “angle”);

Flow Commands:

Wait(4000);     (milliseconds)
until (“condition”);
repeat (“value”)

Task and Sub Commands:

Sub methodName()

task main()

Structure of NXC Commands:

Process and Tutorial:

Building Your Musical Instrument

Links to Other Music and Robotic Instruments:

Pitched Percussion

Twinkle on BoomWhackers

Musical Robot Links:

Human-Robot Jazz

Animusic "Pipe Dream"

Asimo Robot Conductor

Robotic Band

Music InfoFlash Piano - Frere Jacques
Music InfoFlash Piano - Twinkle Twinkle Little Star
Music InfoFlash Piano - Ode to Joy

1. Build your instrument:

Work with the given instruments and your robotics kit. Try to have your robot play at least three pitches or three different non-pitched percussion instruments.

2. Getting Started with programming:
  • Start Bricx Command Center
  • Select “usb” and “NXT”
  • Turn On Robot
  • Plug Robot Into Computer
  • Wait short time for computer to recognize Robot
  • Click “OK”

3. Basic Motor commands

Motor Commands:

OnFwd("ports", "power");
OnRev("ports", "power");
OnFwd("ports", "power", "degrees");
OnRev("ports", "power", "degrees");

Port Codes

OUT_A = motor A
OUT_B = motor B
OUT_C = motor C
OUT_BC = motors B and C
OUT_ABC = motors A, B, and C

power = range from 0 to 100.

Sample Program to Play Pitch:

Another Sample Program using Motor Rotations:

4.  Compile and Download!
  • Save Your Program (File -> Save)
  • Select “Compile->Compile” from menu bar. (Or “F5”)
  • Turn On Robot
  • Select Compile -> Download
  • Wait for Beep
  • Unplug Robot and Test! (Use Orange Button)
    • Robot: Software -> My Files -> Your Program
    • Select Program with Orange Button

5. How to create a "sub" to simplify programming.

To play longer sequences of notes - group patterns together into subroutines ("subs"). Then you can call the subs in the "task main ()" method and reuse them in your programming.

Here is a sample program to play a pitch 3 times using a "sub"

6. Using the Brick to play pitches.

The brick can also play pitches. Here is a link to the pages in the NXC programming tutorial outlining how to play pitches with the brick.

Playing pitches with NXT Brick using NXC.

Email Mr.Michaud

Copyright ©2011 Mr. Michaud.