I plan to use the Arduino Uno in two modes, 1) as a standalone microcontroller with an RFID interface using a serial interface along with a LCD display and 2) as a slave to a PC, USB connected, which is required to write required RFID data. Is this possible, ie, can the Arduino detect if input comes via the PC or via serial?
can the Arduino detect if input comes via the PC or via serial?
The only way for a PC to talk to an arduino is through serial so I don't think you have the question right.
You can't connect the serial port to two things. If you want another serial connection either use a Mega or newSoftwareSerial to make one of the other pins into a serial input for the RFID device.
If you don't need all the pins offered by a mega, can use a uC like a '1284 which has 2 serial ports.
(I really need to populate one of my '1284 duemilanove style boards & post a picture!
See post #224 on page 14 http://arduino.cc/forum/index.php/topic,80483.210.html )
Code to tell which serial port data comes from is then simple:
if (Serial.available() >0){ // port 0 - check if data is received
incomingByte0 = Serial.read(); // byte received, read it
}
if (Serial1.available() >0){ // port 1 - check if data is received
incomingByte1 = Serial1.read(); // byte received, read it
}