Problem with file "pitches.h" in tutorial sketch "Melody".

Recently I bought an Arduino Uno board (version 3). I am working with Arduino IDE 1.0.4. I am trying to execute the sketch "Melody" (http://arduino.cc/en/Tutorial/Tone). The sketch begins with the statement: #include "pitches.h". In this file "pitches.h" the frequencies of the musical notes are defined by #define statements. In the following program line the array "melody[]" is declared and initialised with some of the contstants defined in "pitches.h". Compiling the sketch results in a number of error messages saying that the compiler does not know these constants. Apparently the statement #include "pitches.h" doesn't work.

I have tried a number of things, but nothing worked:

  • Located the file "pitches.h" in the same folder (named "Melody") as "melody.ino". This provides the IDE with a second tab "pitches.h", but didn't work either.
  • Located the file "pitches.h" in the folder "libraries".
  • Chanched the statement into #include <"pitches.h">
  • Tried to change "pitches.h" into a proper library as described here http://arduino.cc/en/Hacking/LibraryTutorial. This is difficult because "pitches.h" has neither variables nor functions. I am not sure I did this the right way.

Hopefully any of you can help me?

Pim Veld.

You can make libraries/pitches/pitches.h

you can also copy and paste all of those constants at the beginning of your melody sketch. Make sure to delete the #include "pitches.h".

Thanks for your reaction.
I understand that I can circumvent the problem by copying the constants at the beginning of the melody sketch. But I should like to know what is wrong with the code in the tutorial-sketch (because I want to learn how this should be done). I tried putting the file pitches.h in a folder pitches in the libraries-folder, but that didn't work either.

Any other idea's?

I followed the directions on that page (copy the sketch, paste the sketch, create a new tab called pitches.h, copy the code, paste the code), and I got this "error" message:

Binary sketch size: 3,396 bytes (of a 30,720 byte maximum)

To PaulS: That's not an error message, that is a normal message after a successful compilation. So, apparently you had no difficulties in making it work. Can you please tell me how you created an new tab, because I can't find the button indicated in the tutorial to make a new tab.

As far as I know, the line should be:

#include <pitches.h>

without any """""" 's Or am I misreading the problem?

EDIT: Btw might be an issue indeed that the 'library' only has an .h file. All libraries Ive worked with consisted of a map with at least .h and .cpp file....

That's not an error message, that is a normal message after a successful compilation.

That's why error was in quotes.

Can you please tell me how you created an new tab, because I can't find the button indicated in the tutorial to make a new tab.

Which version of the IDE are you using? On 1.0+, there is an icon on the right side of the dialog (on Windows, anyway) that looks like the one in the tutorial (an arrow pointing to the right) that is used to create a new tab.

Thanks again for your responses!

To jzuidema:
Indeed, according to the "Reference" it should be #include <pitches.h> (without quotes around pitches.h). I think I tried that too, but I am not sure. I will try that again (but then I still wonder why the tutorial doesn't show it like that). And indeed, the .ccp file is missing. But the pitches.h file as shown in the tutorial is not a proper library at all and trying to make a .ccp file with it is not possible or too difficult for me (see my first post).

To PaulS:
As I stated, I use IDE version 1.0.4. I don't know what you mean by "dialog", but just above the window in which you type the statements of the program there are 5 buttons on the left side and 1 at the utmost right side. The first two utmost left buttons are round, the other 4 buttons are square. The buttons are (from left to right): Verify, Upload, New, Open, Save and Serial Monitor. So no button with a right arrow for New Tab.

(but then I still wonder why the tutorial doesn't show it like that).

Because pitches.h belongs in the same directory as the sketch, so the double quotes are correct, not <>.

And indeed, the .ccp file is missing.

Because there is no code to put in it.

But the pitches.h file as shown in the tutorial is not a proper library at all

Exactly. Only you thought it might be.

As I stated, I use IDE version 1.0.4.

I just fired it up. Looks exactly like 1.0.3.

I don't know what you mean by "dialog",

What else would you call the window that pops up? In computer program parlance, that's a dialog.

but just above the window in which you type the statements of the program there are 5 buttons on the left side and 1 at the utmost right side.

On the top row, yes. There is also a tab where you enter the sketch, and on the same level as the tab, on the far right (just under the serial monitor icon) there is an icon with a downward triangle (the tutorial is showing an old icon). Click that icon.

To Paul S:
Thank you for your efforts and patience, I do really appreciate it!

The explanation of the #include statement only talks about libraries (<library.h>) and not about the possibility to include a piece of program from a file in another tab ("file.h"). That's why I assumed it should be a library.
I know what a dialog window is, but a window for typing in program statements I would rather call an editing window than a "dialog". I know my description was childischly clear, but I am new to Arduino and didn't want to leave any doubts. When a program is called a "sketch" it could well be that other parts of the IDE have funny names as well.

I found the "arrow-down" button and the menu-item "New Tab"! It never occurred to me that this is a menu-button. Again I downloaded the text of pitches.h from the website and pasted it into the new tab. And now it works!!!!

Thank you all for helping me out. I learned a couple of useful things from this experience.!

after uploading/upgrading to IDE 1.6.4 I was able to drag and drop the pitches.h file from explorer (windows 7) to the tabbed area. I found it also interesting that simply adding the pitches.h to my code did not increase the program storage space after compiling, however after i put in a tone(); line - the program storage space increased about 1.5k of space. The next thing I did was comment out "pitches.h" and in the tone line, used only numbers > tone(8, 440, 100); and this worked....

So all the header is doing is translating what we know of as the note to a frequency number, the actual work is being done in ..arduino\hardware\arduino\avr\cores\arduino\Tone.cpp