Pages: [1]   Go Down
Author Topic: Debugging an application that uses the serial port  (Read 3698 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 546
Posts: 27363
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You could always add another UART for comm's.
http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=MAX3100CPD%2B-ND
SPI interface, nice little package to work with.
Don't know if its 0-5V levels are ipad compatible.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 546
Posts: 27363
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ...
« Last Edit: February 18, 2011, 05:06:12 pm by CrossRoads » Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 546
Posts: 27363
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Erfurt, Germany
Offline Offline
Newbie
*
Karma: 1
Posts: 42
IPC Certified Interconnect Designer (C.I.D.), hustling around in electronics since 1971
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: April 05, 2011, 12:12:17 pm by Ulli » Logged

2b || !2b
Shakespeare, Hamlet

Pages: [1]   Go Up
Jump to: