Page 1 of 1

How to Make Music on power on with your 3d printer - WITH LINKS FOR MIDI to GCODE conversion how to.

Posted: Thu Jan 10, 2019 8:42 am
by buttervonwaffle
Today we are making music. Not just any kind of music… no we are making the kind of music to inspire to prototype to… to print stupid vases to! (you know if your into that sort of stuff)

Well anyways it's time to get your 8 bit music machine up and going, because we all know that's why you bought a 3d printer for right? I got a method that you can use to give your 3D printer some custom ditty's for your power on, start of print and end of print! It'll take some work but its not that bad honestly super simple and it will not require you to rev up stepper motors or touch your firmware.

First for this example we are gonna write the 1UP Sound effect from Super Mario. Its 8 bit it's simple and its iconic so it makes the perfect candidate for this little project of ours. Our notes just happen to be C-D-E-C-D-G and I did mine around the octave of 6. Which if you didn't learn any music theory and dont understand dont worry I will be including a chart for note to hertz conversion below so you don't have to google it as well as some nice sheet music resources to translate the cryptic language. Plus I already wrote the example code for the 1UP Sound so you dont even have to do any “hard” work.

Now the method I went about this is perfect for the Ender 3 and Geeetech A10 platform and any 3d printer that Accepts the M300 G-Code Command such as the prusa. If you don't know if your printer will work just google your printer model and see the g code libraries for it, that should tell you if you can do this or not. This nifty little command allows you to make a beep at the Hertz and length you want without really knowing programming. What that means you got your own little retro synthesizer waiting to be orchestrated. One note at a time of course.

We can write some little tunes real easy and without really any coding knowledge because we will be writing it all in G code. We will do this all Without having to rev up your stepper motors like I have seen others do.

So open yourself a little notepad file, and put this code in it.

Code: Select all

M300 S 1138 P 150
M300 S 1567 P 150
M300 S 2637 P 150
M300 S 2093 P 150
M300 S 2349 P 150
M300 S 3135 P 150
Now I am going to break this code up so you understand exactly what we are doing here. Which this is really straight forward and makes it simple to turn sheet music into your own custom startup tone.

M300 - Is the G Code we use to turn the speaker on, on your 3d printer. This initiates the Beep sequence if you will. Nothing more to it than that. Just a simple directive, informing the printer on what action to take.
S - Is what sets the Hertz followed by the numbers which specify the hertz, or in this case the note the speaker will be playing. Here is a nice Notes To Hertz Chart - Here - this nifty little chart will make sure you have the Hertz value for any note your needing.
P - Sets the time in Milliseconds. Which If your converting music from sheet music I have this nice chart that shows you how to convert the notes to milliseconds. Link here If you don't understand the notes here's a nice little sheet music cheat sheet that literally shows you everything you need to know about sheet music - Sheet Music Cheat Sheet

Also another nifty code for this method is a pause - say you have a pause you need to implement in your tune you can use the code

Code: Select all

G04 P100
G04 is just simply a pause G-code and again P sets how long of a pause in milliseconds, so you will calculate your pause in milliseconds using the same sheet music algorithm from earlier, and apply it to this value, the above example is a 100 millisecond pause. For our 1 UP Example we won't be needing a pause at all so don't worry about this for this project.

MIDI to GCODE (Really MIDI to RTTTL to GCODE) for the M300 code
So if you really want to be lazy and dont want to convert sheet music, you can use these two online programs, that when used in combination. you can take MIDI Files and upload them here then take the resulting RTTTL Code and convert it here over to Gcode using this converter that works with a beeper or speaker. You can also just take RTTTL Files and convert them over to MIDI files. RTTTL Files are just ringtone files that are used for Cellphones back in the day that specify the notes. So you can just take that Gcode you just generated and throw it in our text file if you want.

Alright So that little text file we just made take your sd card you use for your 3D Printer save this file to it under the name and file format - auto0.g make sure you select all file types, or else it will save your file as a text file and that wont work.

What the auto0.g file is, is a G code file that automatically runs on printer start up when your sd card is installed. So when you put your sd card in your printer, and turn it on. You should hear a nice little 1 UP tune play. Now if you want to have other auto G code files run afterwards just take the file name and replace the 0 with a 1 and just keep going through numbers if you add more.


Now how to apply this to start and end of print? Just take the G Code we just wrote or whatever song you want and apply it to your printer settings in the start and end G code area of your software before any of the other g code runs. And boom your ready to roll! Cura makes it real nice and easy under the printer settings to do this.

Anyways I hope this was helpful to people, I know I like having the tune so I know when my prints are finished. I will be making a video for this process soon on you tube. But honestly its so simple of a process a video might not even be necessary.

Re: How to Make Music on power on with your 3d printer - WITH LINKS FOR MIDI to GCODE conversion how to.

Posted: Mon Jul 15, 2019 12:14 am
by skirbysmall
This is great, just happened across this post as I was looking for something else! I tried it on my a10, it's got the rhythm (timing of the notes) down but only one tone, why do you think this would happen? By the way, here's the code I wrote:

1 - UP (for start g-code)

Code: Select all

M300 S2637 P150
M300 S3135 P150
M300 S5274 P150
M300 S4186 P150
M300 S4698 P150
M300 S6271 P150 ;1-UP
Mario Flagpole Finish (for end g-code)

Code: Select all

M300 S1046 P150
M300 S1318 P150
M300 S1567 P150
M300 S2093 P150
M300 S2637 P150
M300 S3135 P400
M300 S2637 P400
M300 S1046 P150
M300 S1244 P150
M300 S1661 P150
M300 S2093 P150
M300 S2489 P150
M300 S3322 P400
M300 S2489 P400
M300 S1174 P150
M300 S1396 P150
M300 S932 P150
M300 S2349 P150
M300 S2793 P150
M300 S1864 P150
M300 S0 P400
M300 S1864 P120
M300 S0 P60
M300 S1864 P120
M300 S0 P60
M300 S1864 P120
M300 S0 P60
M300 S4186 P900 ;Congrats
Megalovania (for startup ;) )

Code: Select all

M300 S1174 P125
M300 S1174 P125
M300 S2349 P125
M300 S0 P125
M300 S880 P187
M300 S0 P187
M300 S1661 P125
M300 S1567 P125
M300 S0 P125
M300 S1396 P250
M300 S1174 P125
M300 S1396 P125
M300 S1567 P125
M300 S1046 P125
M300 S1046 P125
M300 S2349 P125
M300 S0 P125
M300 S880 P187
M300 S0 P187
M300 S1661 P125
M300 S1567 P125
M300 S0 P125
M300 S1396 P250
M300 S1174 P125
M300 S1396 P125
M300 S1567 P125
M300 S493 P125
M300 S493 P125
M300 S2349 P125
M300 S0 P125
M300 S880 P187
M300 S0 P187
M300 S1661 P125
M300 S1567 P125
M300 S0 P125
M300 S1396 P250
M300 S1174 P125
M300 S1396 P125
M300 S1567 P125
M300 S466 P125
M300 S466 P125
M300 S2349 P125
M300 S0 P125
M300 S880 P187
M300 S0 P187
M300 S1661 P125
M300 S1567 P125
M300 S0 P125
M300 S1396 P250
M300 S1174 P125
M300 S1396 P125
M300 S1567 P125

Re: How to Make Music on power on with your 3d printer - WITH LINKS FOR MIDI to GCODE conversion how to.

Posted: Mon Jul 15, 2019 5:51 am
by skirbysmall
NVM, Fixed! Go into the Marlin firmware, open up Configuration.h and uncomment this line:

Code: Select all

//#define SPEAKER
Reupload and works like a charm! Did find that very high frequencies come out very quiet, so if you plan on using any of the code I posted up top just divide the numbers by 2 and it'll sound a lot better ;)

Re: How to Make Music on power on with your 3d printer - WITH LINKS FOR MIDI to GCODE conversion how to.

Posted: Mon Jul 15, 2019 10:33 pm
by _kaktus_
:mrgreen:

Re: How to Make Music on power on with your 3d printer - WITH LINKS FOR MIDI to GCODE conversion how to.

Posted: Tue Jul 16, 2019 10:00 am
by Admin
this is good ideal

Re: How to Make Music on power on with your 3d printer - WITH LINKS FOR MIDI to GCODE conversion how to.

Posted: Tue Jan 05, 2021 3:12 am
by Erasmusoie
A perfect mobile choice.

Re: How to Make Music on power on with your 3d printer - WITH LINKS FOR MIDI to GCODE conversion how to.

Posted: Mon Mar 15, 2021 6:52 pm
by AaronButt
Ruder man establishment is doing extraordinary in managing the destitute and meriting individuals. The work they are doing is incredible. And I prefer them to use bid4papers review and get more quality in their work. Such liberal activities they ate appearing to us should be valued at a more significant level to propel individuals. That they additionally participate in such sort of exercises.