Debugging an application that uses the serial port

Hello everybody,
I am new to Arduino. I am working with Arduino nano under Linux Fedora 14.

In my application I need to talk to a device (an iPad, if you are interested) through the serial port, receiving commands from the device, analyzing them and replying to them from Arduino.

The problem is that this is quite hard to debug, because, if I have understood correctly, when I issue a Serial.write (or Serial.print, Serial.println) command, this has a double effect: it sends the bytes both to my device, attached to port 0, but also to the Serial Monitor (internal USB-serial port), is this correct?
So if I send a command to the Ipad, and I listen for its reply ...but if I do a Serial.print to have a look at this reply, I am also sending some garbage to the iPad (that of course is not what it is expecting to receive next). So how can I analyze (see/print/save in a file, anything!) what I have received in the serial port without sending unwanted commands back to the iPad?
I hope I have made myself clear.

I have tried using the NewSoftSerial library to do the Arduino-Ipad serial communication, and keep Arduino's true serial port only for debugging ... unfortunately NewSoftSerial does not seem to be able to properl handle the baudrate of 57600 bps that I need.

So what other alternatives do I have to debug the serial communication?
Thank you very much for any help.
A newbie.

The problem is that the USB/serial converter is, literally, plugged in to the same wires as your iPad.

When you issue a serial write command, it sends that out a wire plugged in to two devices. Both devices can also transmit to the arduino CPU, and if they both try at the exact same moment you'll get junk. If there is a delay you will get both characters but won't know which is which.

I can think of a couple things you could do:
Gat an Arduino Mega. It has four hardware serial ports.
2. Get a separate USB to serial device ($15 board with an FTDI chip, or similar - spakfun among others sells them) and hook that up to your Arduino for sending messages via soft serial to your computer
3. Don't know how well this would work, but you might be able to use soft serial to transmit to the iPad but hardware serial for receive:
iPad transmits to the standard hardware serial port.
Arduino hardware serial port transmits via USB for debug
Arduino software serial port transmits to iPad

(often, transmitting software serial is easier than receiving, but I don't use that on the Arduino much)

Please double check my ideas before buying stuff: I haven't used soft serial on arduino, and my Mega boards are on order, so my ideas are theoretical.

You could always add another UART for comm's.

SPI interface, nice little package to work with.
Don't know if its 0-5V levels are ipad compatible.

I just ordered a couple of free samples of these, will have to write a little code to talk to it & get a crystal.
Maybe this would be a good shield project. This chip, RS232 level adapter like a MX231, and a USB converter for USB/RS232 options.

Gonna look into that ...

Well, thank you all for your quick and insightful replies.
I think I will order an Arduino Mega for development, even if the final application will use the Arduino nano.
While it arrives, I will try to use the NewSoftware serial port just for transmission to the iPad and see if it works.

By the way, Crossroads, just for information, iPad's serial port works at 3.3V, so I am using a voltage divider to talk to it and an op amp to boost it signals for the Arduino.
Thanks again.

You probably don't need to boost it coming back. If it is switching at 0 & 3.3V and you are connected to D1, that should be plenty high enough to be seen as logic 1.

Thanks, I also thought it might work, so I tried first without the amplifier; it didn't work, at least at this data rate (57600).
I don't know however if Arduino's serial port would work correctly receiving only 0-3.3V for lower data rates (most iPad/iPod/iPhone accesories that use the serial port communicate at 19200 bps).

ajimenezp:
Thanks, I also thought it might work, so I tried first without the amplifier; it didn't work,iPad2case
ipad 2 cases leather
iPad2 case at least at this data rate (57600).
I don't know however if Arduino's serial port would work correctly receiving only 0-3.3V for lower data rates (most iPad/iPod/iPhone accesories that use the serial port communicate at 19200 bps).

You probably don't need to boost it coming back. If it is switching at 0 & 3.3V and you are connected to D1, that should be plenty high enough to be seen as logic 1.

I checked that without the amplifier first. The truth is that the iPad signals through the serial port switching between 0 V and 3 V (well, at least closer to 3.0 V than to 3.3 V). Most of the time it was not working without amplifying to 5 V.
On the other hand, I have decided to switch from Arduino Uno/Mega to the Arduino Mini Pro 3.3V, it works perfectly (no need to amplify or divide the voltage) together with iPhone 3GS, iPad and iPhone 4G, which are the devices I have been able to test. I am drawing the power from the iPad itself, no need for any external power supply.
Thought this might be useful to somebody. True, I have just one serial port in the Pro Mini, but after the initial phase of debugging/reverse engineering, just one serial port is ok for my application.

I had the same problem, in my case with some SRF02 ultrasonic sensors. I had to use the serial because of too long wires for the I²C.
So I used the LED (Pin13) to make the same behavior like a camera with self triggering. This part of program I put in the beginning of void setup() before Serial.begin().
You need just some delay() and set LED on and off. So you can plug the cable off before and while uploading and plug it back during the blink phase...
For debug purposes, you also can use several "blink codes".
So you don't need to add more stuff to your Arduino.
An other way is to use e.g. 74HCT244 in order to switch the RX and TX between your sources/targets.

I know this is an old post, but want to add another idea (may help someone).
Logic analysers are so cheap now, and they make a great tool for debugging; Serial, SPI, I2C, … - ports.

Look for “USB Logic Analyzer 24Mhz 8 channel” on ebay.
Then download a free copy of PulseView (sigrok). Works like magic!

That way you can use the Logic Analyzer to check the comms on the serial port and get rid of “Serial.println >> Serial Monitor” on the Arduino.

1 Like