Pages: [1]   Go Down
Author Topic: serial communication question  (Read 533 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi everyone,

I'm new to the Arduino world and loving it, but I've been a little confused on one point.  I have an Arduino Diecimila, and for the first time want to use a sensor that outputs serial data (an RFID reader from SparkFun - http://www.sparkfun.com/commerce/product_info.php?products_id=8419).

My question: can you have the RX pin reading from a serial device while the Arduino is hooked up to the computer via USB?  I'd like to monitor the incoming RFIDs on the computer.

Sorry if this is an obvious question, but I've had trouble finding a definitive answer.  Thanks!

 ~ Kim
Logged

Netherlands
Offline Offline
Sr. Member
****
Karma: 0
Posts: 414
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think you can do that through softserial library (search for it), not 100% sure though... others might chime in.
Logged

0
Offline Offline
Faraday Member
**
Karma: 8
Posts: 2526
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
can you have the RX pin reading from a serial device while the Arduino is hooked up to the computer via USB?  I'd like to monitor the incoming RFIDs on the computer.
No, because the FTDI chip is already driving the ATmega's RX line.  You can disable the FTDI chip entirely, but I don't think you can disable just its TX line.

It's (usually) OK to have more than one receiver on a line, but not OK to have more than one driver on a line.  At best you'll get garbage data.

-j
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the replies!  Looks like I'll be using SoftwareSerial then, on pins other than 0 and 1.

By the way this is the picture that led me astray (my RFID reader hooked up to an NG using the RX pin):

http://www.flickr.com/photos/hcgilje/490152422/in/set-72157600192819692/

Either that's a bluetooth dongle (possible?) or he simply doesn't connect the USB while running his program.

 ~ Kim
Logged

0
Offline Offline
Faraday Member
**
Karma: 8
Posts: 2526
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Either that's a bluetooth dongle (possible?) or he simply doesn't connect the USB while running his program.
Could just be luck.

I think the Arduino NG and Diecimila both have 1k resistors in series with the rs232 connections between the ATmega and FTDI chips.  It may be possible for the attached device to simply "overpower" the signal from the FTDI, but it's not a good way to do things.

-j
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes you can have hardware attached to pins 0 and 1 (the hardware rx and tx uart) on the Decimilia - and communicate to them/it while the USB is connected.  You just cant initiate a programming (or other computer-generated conversation) while both the USB and your serial hardware are connected at the same time.

I do exactly this to communicate with my serial GPS and watch the output in the serial debug monitor (can even send arbitrary strings to the connected hardware via the serial debug monitor as well) while connected to and powered by the USB cable.  I only have to disconnect the GPS when uploading new code.

mopowered
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, I ended up using Software Serial.  It took me a few tries to realize that you shouldn't try to print out each byte as you read them - you end up losing bytes in the meanwhile this way, since SoftwareSerial doesn't listen between reads and I/O is slow.  Here's some code that works though, for reading the 16 byte ID from the ID-12 RFID reader:

#include <SoftwareSerial.h>

#define rxPin 2
#define txPin 3

char card[16];
int cardIndex = 0;

SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);

void setup()  {
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  digitalWrite(txPin, HIGH);
  mySerial.begin(9600);
  Serial.begin(9600);
}

void loop() {
  byte val = mySerial.read();
  card[cardIndex] = val;
  cardIndex++;
  if (cardIndex == 1 && card[0] != 2) {
    // wrong header, reset index
    cardIndex = 0;
  }
  if (cardIndex == 16) {
    int i;
    for (i = 1; i < 10; i++) {
      Serial.print(card - '0');
    }
    Serial.println();
    cardIndex = 0;
  }
}
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 15
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm still a little unsure on how to disable the FTDI chip though. Any help?
Logged

Pages: [1]   Go Up
Jump to: