Pages: [1]   Go Down
Author Topic: tone() with sanguino  (Read 934 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am trying to use the tone() function with a sanguino board. When I complie the example code toneMelody.pde I get this error:

toneMelody.cpp: In function 'void setup()':
toneMelody:35: error: 'tone' was not declared in this scope
toneMelody:42: error: 'noTone' was not declared in this scope

I can compile as long as a Duemilanove is selected as the board (or any other board for that matter.) I can also upload the sketch, play the tune etc. This is only a problem with the Sanguino board.

I have searched for this problem, and seen several posts, but none have a definate answer. I have tried deleting the Arduino folders, re-downloading, recopying/downloading the Sanguino Hardware folder. and I have tried both Version 22 and 23 of Arduino.

Does anyone know how to fix this issue?

Thanks
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think I may have figured this out for myself. I do not know too much about changing around the arduino hardware - but after reviewing a lot of forums about this issue and some trial and eerror. This is what I did to make it work.

Open the file named WProgram.h in the arduino-0022\hardware\Sanguino\cores\arduino folder.

add the following two lines:


void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0);
void noTone(uint8_t _pin);

save the file, Close Arduino, reopen Arduino, Upload and it did compile for me.

I do not know why this works but it does. If anyone else knows why, I would like to know so that I could solve a similar issue in the future, and understand what I am doing.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 616
Posts: 49433
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Since you are not actually implementing the tone and noTone functions with the change you made, the tone and noTone functions must actually be defined somewhere (they are). So, you should find the header file in which they are defined, and include that, not modify WProgram.h.
Logged

Seattle, WA
Offline Offline
God Member
*****
Karma: 11
Posts: 673
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Since you are not actually implementing the tone and noTone functions with the change you made, the tone and noTone functions must actually be defined somewhere (they are). So, you should find the header file in which they are defined, and include that, not modify WProgram.h.

Actually, no.  Sanguino doesn't declare tone or noTone.  His solution is actually the right one.
Logged


Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 616
Posts: 49433
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Sanguino doesn't declare tone or noTone.  His solution is actually the right one.
Declaring something in a header file is only part of making something happen. There must also be an implementation. If adding the statements to one header file results in no undefined external references then the functions are implemented somewhere. If that is the case, then there must also be a declaration for them, somewhere.

I still contend that finding where they are declared, and including that header file is a better solution. But, whatever works...
Logged

Seattle, WA
Offline Offline
God Member
*****
Karma: 11
Posts: 673
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

there must also be a declaration for them, somewhere.

You would think so.  There certainly should be.  But in fact there is not.  Sanguino includes implementations for tone/noTone but does not bother to declare them.  Check the files.
Logged


Belgium
Offline Offline
Edison Member
*
Karma: 68
Posts: 1920
Arduino rocks; but with my plugin it can fly rocking the world ;-)
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

all
I agree with manicbug that the files do not contain the function prototype in  a header.
I agree with Paul that you should not declare these functions in WProgram.
Therefore I think it is best to create a file called tone.h and add the prototypes there or simply add them at the top of your code.
Best  regards
Jantje
Logged

Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 616
Posts: 49433
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There is considerable difference between the WProgram.h file delivered with the Arduino IDE and the WProgram.h file delivered with the Sanguino package. Almost like the Sanguino package is not being maintained.
Logged

Pages: [1]   Go Up
Jump to: