CaissonBlog

Making a Bambu A1 play music on its stepper motors

The Bambu A1 can play notes through its X, Y and Z stepper motors with the M1006 command. Which notes actually sound, how to fit a piano piece onto three motors, and the file wrapper that makes it play.

Published
3 min
To read
Other builds
Project

A stepper motor driven at an audible frequency sings, and the Bambu A1 has a G-code command for it: M1006 plays notes on the motors. Caisson's printer music scripts turn MIDI files, Guitar Pro files and hand-written scores into G-code so the printer plays a tune on its motors. These are the things that took trial and error on a real printer.

The command

One M1006 line plays one step of music on up to three voices, one per motor. Each voice takes a note, a duration and a volume:

M1006 A B L C D M E F N

A, B and L are the first motor, C, D and M the second, and E, F and N the third. Notes are numbered like MIDI notes, the duration unit is 10 ms, and note 0 is a rest. The printer's sound setting has to be switched on, or nothing plays at all.

Only a narrow band sounds

Keyboard from note 24 to 84 with the notes from about 37 to 61 highlighted as the range the A1 can play243648607284Sounds on the A1: about 37 to 61
Note numbers as written in M1006, on a keyboard from 24 to 84 with each C labelled. Only the orange keys produce a tone on the printer.

Only notes from about 37 to 61 produce a tone. Ask for a melody at its written concert pitch, which puts it somewhere in the 70s, and the printer stays silent apart from its own start and finish chirps. So every voice is shifted by whole octaves until it fits the band.

The numbers also do not mean what they mean in MIDI. A recording of one run suggests the printed notes sound about two octaves higher than the same MIDI numbers would on a piano. In practice that is convenient: a vocal line written two octaves below the staff lands in the band and sounds close to where it was written.

Three motors, one piano

A piano part can have many notes sounding at once, and the printer has three voices. The first approach ranked each note by onset and gave the highest sounding note to the first motor. That put bass-register notes on the melody voice whenever the melody rested, and once every voice was shifted into the band, 24%, 36% and 54% of the notes on the three motors had to be folded by an extra octave to fit.

Splitting by register works far better. The source notes are cut into thirds by pitch, high to the first motor, middle to the second, low to the third, with one note per onset per motor. On the same file that folded 0%, 6% and 8% of the notes and kept 87% of everything in the score. Chordal right hands lose their inner notes, which is the price of three voices.

Because every M1006 line carries one step for all three motors, the voices are time-sliced: wherever any voice changes note, a new line starts, and the others carry their note across it.

No gap between notes

The first versions left 40 ms of silence at the end of every note, so that repeated notes would re-attack. On the printer it sounded abrupt. With the gap removed, notes run into each other and the result is much smoother. Gapless is now the default.

The file wrapper

A file the printer will play has to claim the machine, enable the motors, play, wait for the queue to finish, and release the motors:

M1002 gcode_claim_action : 0
M17
M400 S1
M1006 S1
; one M1006 line per step of music
M1006 W
M18

The same block also plays when pasted into the machine start G-code. A print job only ends when its file runs out, so a music test sent that way needs a hold at the end and a cancel from the printer.

The rest of the list

Printer music is one of five smaller Caisson builds. The others are Quiblet, a codec between binary data and audio; zodiac, a cipher solver aimed at the Zodiac ciphers; gflive, a live AFL win-probability server; and Wharfie, which detects the game horn in a stadium feed and replays the hooter in its place. All five are on the other builds page, with Windows downloads for Quiblet and zodiac.

Written by Caisson AI. Questions or corrections go to hello@caissonai.co.