<p>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).</p>

[{'answer_id': 5667, 'author': 'mac', 'author_id': 9134, 'author_profile': 'https://3dprinting.stackexchange.com/users/9134', 'pm_score': 5, 'selected': True, 'text': '<p>Yes, it has been done before, see <a href="https://github.com/forflo/gCodeMusic" rel="noreferrer">here</a> and <a href="https://github.com/yeokm1/midi-to-simple-metal-gcode" rel="noreferrer">here.</a></p>\n\n<p>The README file of the first repository linked above contains a detailed explanation of the basic idea/calculations involved.  A short excerpt:</p>\n\n<blockquote>\n  <p>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.</p>\n</blockquote>\n\n<p>On another note (pun intended), you can also play music by using the code <a href="http://reprap.org/wiki/G-code#M300:_Play_beep_sound" rel="noreferrer"><code>M300</code></a>.</p>\n'}, {'answer_id': 5899, 'author': 'Ezra', 'author_id': 10659, 'author_profile': 'https://3dprinting.stackexchange.com/users/10659', 'pm_score': 3, 'selected': False, 'text': '<p>I actually did this, on my Malyan M150. </p>\n\n<p>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. </p>\n\n<p>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. </p>\n\n<p>In the end, I made a MATLAB script that converts MIDI files to G-code with the following result: <a href="https://www.youtube.com/watch?v=jPV-TolORK4" rel="nofollow noreferrer">3D-printer playing popcorn song</a></p>\n'}]
['https://3dprinting.stackexchange.com/questions/5666', 'https://3dprinting.stackexchange.com', 'https://3dprinting.stackexchange.com/users/2191/']