Hi, I have a questions about building libraries.
I can’t get spi transfer or SoftwareSerial to work within some libraries I’ve written. Everything compiles and uploads without complaints but my devices don’t seem to pick anything up so the communication is not working properly. Identical code works fine when I have it all in my sketch instead of the libraries… The libraries run fine (I log things out) it’s just the spi and software serial that don’t work…
I’m thinking that the spi transfer / SoftwareSerial issue could have something to do with me not including Wprogram.h, or some linkage confusion. Some of the library tutorials recommend including Wprogram.h in libraries, but when I try to compile libraries that include Wprogram.h I get:
/Applications/arduino-0011/hardware/cores/arduino/WProgram.h:13: error: default argument given for parameter 3 of ‘long unsigned int pulseIn(uint8_t, uint8_t, long unsigned int)’
/Applications/arduino-0011/hardware/cores/arduino/WProgram.h:13: error: after previous specification in ‘long unsigned int pulseIn(uint8_t, uint8_t, long unsigned int)’
/Applications/arduino-0011/hardware/cores/arduino/WProgram.h:13: error: default argument given for parameter 3 of ‘long unsigned int pulseIn(uint8_t, uint8_t, long unsigned int)’
/Applications/arduino-0011/hardware/cores/arduino/WProgram.h:13: error: after previous specification in 'long unsigned int pulseIn(uint8_t, uint8_t, long unsigned int)
If I change the pulseIn prototype in arduino/WProgram.h to unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout) it compiles but I get this warning (and neither spi or SoftwareSerial still don’t work):
In file included from /Applications/arduino-0011/hardware/cores/arduino/WProgram.h:6,
from AudioMixer.h:29,
from AudioMixer.cpp:26:
/Applications/arduino-0011/hardware/tools/avr/bin/…/lib/gcc/avr/4.0.2/…/…/…/…/avr/include/avr/signal.h:36:2: warning: #warning “This header file is obsolete. Use <avr/interrupt.h>.”
I’ve worked around this by not including WProgram but still, something strange is going on here…
I use this spi transfer code in my library:
http://www.arduino.cc/en/Tutorial/SPIDigitalPot
since I don’t use WProgram.h I include this in my library:
#include <inttypes.h>
#include “wiring.h”
#include <avr/pgmspace.h>
I use a software serial instance in my library that is given the rx tx parameters via the library constructor, like this:
UMP3Player::UMP3Player(int rx, int tx, int busy): _sSerial(rx, tx)
{
…
}
and I have these includes:
extern “C” {
#include “stdlib.h”
}
#include “wiring.h”
#include <SoftwareSerial.h>
#include <HardwareSerial.h>
Any ideas would be greatly appreciated, I’m having a hard time debugging the spi transfer and software serial problems since the libraries compile fine and tidentical code works fine when I don’t use it within libraries…
thanks // e