Libraries within libraries and including WProgram

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

Try including WProgram.h instead of wiring.h (everywhere in your library).

Can you post a minimal example that gives the first error you mention?

Thanks, try making a library out of the code below. I’m only getting the pulseIn error when I compile a sketch using the library. The library builds and the .o file is created, but the sketch won’t build… If I’m not including the library in the sketch I only get the “This header file is obsolete. Use <avr/interrupt.h>.” when the library builds… Anyway, if I change the pulseIn prototype in WProgram.h the error goes away but I’m still not getting software serial to work…

I have gotten spi_transfer to work in a library though. Don’t really know how but I swapped to a brand ne diecimilla and it kicked in. Still is strange though that before it worked in the sketch but not in the library…

UMP3Player2.cpp:

#include “UMP3Player2.h”

UMP3Player2::UMP3Player2(int rx, int tx, int busy): _sSerial(rx, tx)
{

}

UMP3Player2.h:

#ifndef UMP3Player2_h
#define UMP3Player2_h

#include “WProgram.h”
#include <SoftwareSerial.h>

class UMP3Player2 {

public:
UMP3Player2(int rx, int tx, int bx);

private:
SoftwareSerial _sSerial;

};

#endif

ok, I've solved the software serial problem I had, it's probably related to the mp3 player I'm using not software serial. Turns out that the serial communication went to fast when I used the library, I put in some delays and it works.. That WProgram.h error remains though, but it doesn't really matter too me now since it works fine for me by just including wiring.h...

thanks anyway for the help!

//e