Music from the printer?

Harking back to the days of "singing disk drives," I am wondering if anyone's written music to be performed on a 3D printer. Most of us have noticed in passing that the servo motors for X and Y drive generate a different pitch depending on motion speed. With some care and experimentation, one could write g-code to produce not only a tone but even a 2-tone chord. So -- has this been done? Does anyone want to do so? (Note that there's no need to simultaneously produce a print, but that would be even classier).

• Followup: an actual object that is musical while it's printing? – Jeroen3 May 13 '19 at 6:43

Yes, it has been done before, see here and here.

The README file of the first repository linked above contains a detailed explanation of the basic idea/calculations involved. A short excerpt:

As you can set the parameters of G1 in such a way as to precisely control the velocity and the distance of a movement along a certain axis, you can control the operation frequency of the stepper motors as well as the actual time to complete a movement.

On another note (pun intended), you can also play music by using the code M300.

I actually did this, on my Malyan M150.

After not that much experimentation at all it turned out that the frequency of the produced tone scales linearly with the speed of the motors. Due to the nature of the way humans perceive music, the actual frequencies do not matter at all, just the relative difference in frequency between the tones. This means that it is actually really easy to let a 3D printer play a tune, you just have to make sure that when the next tone needs to have a frequency that is for example 20% higher than the last one, the motor needs to move 20% faster, no need to actually measure at which speeds the printer produces which tones.

One of the main issues turned out to be the maximum speed of the motors, which wasn't high enough for some of the higher notes, but this issue could be solved by multiplying all the speeds by a number lower than 1, thereby lowering the required speeds while still maintaining the original melody. Playing two tones at the same time proved to be a bit too difficult for my not that great programming skills, while not being worth the effort because somehow there was quite a large difference in volume between the motors.

In the end, I made a MATLAB script that converts MIDI files to G-code with the following result: 3D-printer playing popcorn song

• You could have had 3 instruments at the same time or 3 different volume levels by using the 3 motors – FarO Oct 5 '20 at 12:19