iPodSerial Questions

Hi,

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
{
}

Thanks,

Loren

How do you have the iPod connected to the Arduino?

The code you posted would need some major enhancements in order to support NewSoftSerial, too. It certainly should.

A logic converter connects the iPod to pins 0 & 1.

Would it be better to use something else (like a serial LCD)to debug instead of a bunch of reprogramming?

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

Does anyone have any insight?

Thank you very much,

Loren

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.

Loren,

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.

Cheers,
Dave

As a follow-up to my other post:

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.

Cool,

Thanks to you both for clearing both of those issues up. I think I now have the info that I need to continue on!

Loren

Sorry to be such a pain but I think I have misunderstood somewhere.

// enable debugging (this #define should go at the top of the file)
#define IPOD_SERIAL_DEBUG

This goes in iPodSerial.h Right?

// (create your NewSoftwareSerial)

This also goes in iPodSerial.h Right?

If I have it in the right places then something is weird because I'm getting multiple definition errors.

Any thoughts?

Thanks again,

Loren

Sorry, I should have tried this - it's been a while.

Looks like what you need to do is put the #define in iPodSerial.h, somewhere above the class definition.

…
#define IPOD_SERIAL_DEBUG
class iPodSerial
{
public:
    iPodSerial();

    /**
…

Then your sketch can be something like:

#include <AdvancedRemote.h>
#include <NewSoftSerial.h>

AdvancedRemote advancedRemote;
NewSoftSerial nss(3,4);

void setup()
{
  advancedRemote.setLogPrint(nss);
  advancedRemote.setDebugPrint(nss);
  advancedRemote.setup();
}

void loop()
{
  advancedRemote.loop();
}

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.)

No need to apologize, I'm just grateful for your help. I got it to compile. Now I just need a TTL to serial adapter and I should be set to get going.

Thanks again,

Loren