I'm working on a IpodSerial project. I'm using an Uno and would like to use the serial monitor to debug. Which leads me to the fact that I need to communicate with my iPod on pins other than 0 & 1. Could I use Software Serial for this? If so would the definition for the port go in the iPodSerial.cpp here:
iPodSerial::iPodSerial()
: receiveState(WAITING_FOR_HEADER1),
dataSize(0),
pData(0),
checksum(0),
pSerial(&Serial) // default to regular serial port as that's all most Arduinos have
#if defined(IPOD_SERIAL_DEBUG)
,
pDebugPrint(0), // default to no debug, since most Arduinos don't have a spare serial to use for debug
pLogPrint(0) // default to no log, since most Arduinos don't have a spare serial to use for debug
#endif
{
}
I started to attempt to use NewSoftSerial for interfacing with the iPod. I have inserted this:
#include "iPodSerial.h"
#include "NewSoftSerial.h"
#include <ctype.h>
#define rxPin 6
#define txPin 7
NewSoftSerial nss(rxPin, txPin);
static const char *STATE_NAME[] =
{
"Waiting for Header 1",
"Waiting for Header 2",
"Waiting for length",
"Waiting for data",
"Waiting for checksum"
};
iPodSerial::iPodSerial(): receiveState(WAITING_FOR_HEADER1),
dataSize(0),
pData(0),
checksum(0),
pSerial(nss)
#if defined(IPOD_SERIAL_DEBUG)
,
pDebugPrint(0), // default to no debug, since most Arduinos don't have a spare serial to use for debug
pLogPrint(0) // default to no log, since most Arduinos don't have a spare serial to use for debug
#endif
{
}
A couple of things puzzle me first if I use #include <NewSoftSerial.h> I get a file not found error. Can someone explain what the difference between " " and <> for including files.
Second if I use #include "NewSoftSerial.h" I get this error:
error: cannot convert 'NewSoftSerial' to 'HardwareSerial*' in initialization
Loren:
A couple of things puzzle me first if I use #include <NewSoftSerial.h> I get a file not found error. Can someone explain what the difference between " " and <> for including files.
It will be influenced by compiler configuration (ie. "switches" passed to it) but the basic idea is:
#include - search for "foo" in the "system include file path"
#include "foo" - search for "foo" in the "local include file path"
So generally speaking you would use the double-quotes if your file is in the same directory as the program. But you would use if the file is in the "shared" include file area.
You have to do the #define IPOD_SERIAL_DEBUG to enable debugging in my iPodSerial library: because it's faster to have it compiled out it's not available by default.
If you look at iPodSerial.h you will see where setDebugPrint and setLogPrint are defined:
#if defined(IPOD_SERIAL_DEBUG)
/**
* Sets the Print object to which debug messages will be directed.
* By default there isn't one and so debug messages are off.
*/
void setDebugPrint(Print &newDebugSerial);
/**
* Sets the Print object to which log messages will be directed.
* By default there isn't one and so log messages are off.
*/
void setLogPrint(Print &newLogSerial);
#endif
So you can do something like:
// enable debugging (this #define should go at the top of the file)
#define IPOD_SERIAL_DEBUG
// (create your NewSoftwareSerial)
Then in setup() do:
// (configure your NewSoftwareSerial)
…
advancedRemote.setLogPrint(myNewSoftwareSerial);
advancedRemote.setDebugPrint(myNewSoftwareSerial);
That will tell the iPodSerial library to send its logging and debugging messages to your NewSoftwareSerial instance.
By changing the iPodSerial class's initializer list to set "pSerial" to "nss" you've made it try and use your NewSoftwareSerial object to talk to the iPod, which isn't going to work. That's also why you get the error about "HardwareSerial": if you look in iPodSerial.h you will see that pSerial is of type "HardwareSerial*" (a pointer to an instance of HardwareSerial). "NewSoftwareSerial" is not the same as that, and not a derived class of that (and also you didn't pass a pointer), so it won't compile.
You shouldn't need to edit the library code at all to get debugging to a NewSoftwareSerial going. You should continue to let the library use the real serial port for communicating with the iPod.
I tried this here and it at least compiles. (There may be a way to tell Arduino to pass -DIPOD_SERIAL_DEBUG to avr-gcc, and if so you wouldn't need to edit iPodSerial.h, but I'm not sure if the Arduino IDE lets you do that.)