I'm using the Wiring framework for building a custom alarm clock. So far, I've been able to work with several Arduino libraries on Wiring, just by including Wiring.h instead of Arduino.h, as suggested by Wiring's creator.
Regarding audio, I've used the TMRpcm library on Arduino Uno with success. One needs to have an SD or a micro SD configured, convert the audio files to a specific format (WAV, 8-bits, 16kHz), optionally make an amplifier circuit, and the like. I already have that done. All works on the aforementioned Arduino.
However, since Wiring S gives me twice the memory than Arduino Uno (my script already exceeds Arduino UNO's memory), I'd like to implement my project on Wiring. I'm working with a Wiring S, Wiring v.1.0.1-dev as IDE, and already changed all include <Arduino.h>
by include <Wiring.h>
on all files in the TMRpcm library.
When I run the basic example (adjusting the audio file name and setting the SD_ChipSelectPin to 20, and the speaker pin to 16) I get the following error message:
core.a(WHardwareTimer.cpp.o): In function `__vector_15':
C:\Users\toshiba\Downloads\wiring-v1.0.1-dev\cores\AVR8Bit/WHardwareTimer.cpp:140: multiple definition of `__vector_15'
TMRpcm\TMRpcm.cpp.o:C:\Users\toshiba\Downloads\wiring-v1.0.1-dev\libraries\TMRpcm/TMRpcm.cpp:650: first defined here
core.a(WHardwareTimer.cpp.o): In function `__vector_12':
C:\Users\toshiba\Downloads\wiring-v1.0.1-dev\cores\AVR8Bit/WHardwareTimer.cpp:145: multiple definition of `__vector_12'
TMRpcm\TMRpcm.cpp.o:C:\Users\toshiba\Downloads\wiring-v1.0.1-dev\libraries\TMRpcm/TMRpcm.cpp:569: first defined here
collect2.exe: error: ld returned 1 exit status
If I comment these definitions in the library (TMRpcm.cpp file) or in the WHardwareTimer.cpp file included in Wiring, the code does compile and I can upload it to my Wiring S, but the audio file is not reproduced or it cannot be heard.
Here you can get a 31KB sample audio file (already converted to the required format).
Could you please help me solve this problem? What am I missing? I can provide you with more details if needed.
Best Answer
For completeness, you can work out that the errors are related to interrupts by the fact that the function names being referenced in the error are
__vector_(n)
, these refer to specific interrupt vectors. To find out exactly which ones you have to refer to the vector table in the AVR datasheet. Just to be awkward, in the compiled code the vectors are 0 indexed but in the datasheet they are 1 indexed, so to identify the correct vector, add 1 to the(n)
in the error message and look it up in the datasheet.For the ATMega644(P):
So they are vectors for Timer 1 Overflow and Input Capture. I believe in the standard Arduino Core, this is unused, but in the Wiring S core it must already be used by something.
The good news is that the ATMega1284(p) will work with the standard Arduino core, though unofficially. As the 644(p) is from the same series, just an earlier one, the Arduino core should work without modification with the 644. The only two things that are required are:
By creating these entries, you should be able to compile code for the WiringS board using the standard Arduino IDE and core (for which the library was designed).
For the boards.txt entry, the following should work:
For the pins_arduino.h file, create a 'wirings' folder inside the 'variants' folder of the Arduino core, then create a pins_arduino.h file with the following contents: