I am about to attempt to use a fingerprint scanner over RS-232, with my Arduino Duemilanove. I also want to read serial data from the Arduino on my computer simultaneously.
Just checked out the documentation about serial:
"Used for communication between the Arduino board and a computer or other devices. This communication happens via the Arduino board's serial or USB connection and on digital pins 0 (RX) and 1 (TX). Thus, if you use these functions, you cannot also use pins 0 and 1 for digital i/o."
To me this is a little ambiguous. Can someone with more experience please clarify?
Does this mean that I can't use RS232 over the USB port also use and RS232 with Pin 0 and 1?
Or are they telling me that I can't use Pin 0 and 1 for digital IO and also for RS232?
Or, both?
I think I found my answer in the Playground. The Parallax GPS is connected to Pin 0 for serial RX and sending the data from the GPS back to the serial port which can be read by the computer. I'm not certain though that you can't interrupt one with the other or not though?
You can use both the 0 and 1 pins as well as the USB serial simultaneously, it can just get really noisy. The only times problems will arise is if you were to try to "contact" the Arduino at the same time the sensor was. If you're strictly receiving from the sensor, and strictly receiving on the computer you won't have any issues. If you have needs outside of that, the solution I've used is a multiplexer which will select which serial lines I'm going to use to communicate.
In your setup it could be something like:
switch MUX to 0 and send request for data to reader
switch MUX to 1 and receive data
switch MUX to 3 and send data to computer
(might be needed) switch MUX to line 4 and wait for computer commands.
I understand what you're saying about it being noisy. Initial testing has already shown signs of this.
When you refer to the multiplexer that will select which serial lines you're going to communicate with...how is this achieved? Are you referring to physical lines or just declaring MUX as a variable whose value you're changing depending on what you're doing on the Arduino?
Also can't you just just leave pins 0 & 1 for the PC only as normal and use the software serial routines, which I think you can use any other of the I/O pins for the sensor communications?
@retrolefty: Well that would be nice, but how do you set up serial communications on other pins? I thought that portion of it was hardcoded? Nothing in the reference for Serial.begin to specify other pins (that I can spot anyway). I'd be very interested to know if you can though!
I've mislead a bit I believe.. essentially you'll need two 2 channel mux's to setup what I was describing when I think about it. Interestingly... a search on digikey doesn't turn up the right part. However, there are chips with 4 2-channel mux's on board available with DIP configuration. Example http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail?name=MC10H158L-ND.
Essentially you would use two digital pins to control which set of data was coming and going from the serial interfaces. Check out the data sheet to see if that gives you a little clearer understanding.
Only data received while Serial.read() is being called will be received. Data received at other times will be lost, since the chip is not "listening".
I just got my Duemilanove today and have not written a single line of code yet, so forgive my ignorance. I have at least one project in mind where I'd like to be able to com through serial AND have the bluetooth serial port available at the same time. The 'SoftwareSerial' sounds to be a bit banged serial port, so couldn't hardware flowcontrol through an interrupt be used to access the SoftSerial port reliably?
@John: I had a look at it. I'm not sure how I actually implement it, since it isn't documented? I'm a newbie to the Arduino scene, so please excuse my idiocy!
AFSoftwareSerial is cool. It does implement interrupt-driven rx, thereby reducing your chances of missing incoming characters. Usage is nearly the same as SoftwareSerial, except that AFSoftSerial has an available() function like HardwareSerial:
#include <AFSoftSerial.h>
AFSoftSerial s(rxpin, txpin);
void setup()
{
s.begin(9600);
s.println("Hello!");
}
void loop()
{
if (s.available())
... do something with s.read();
}
I have been using AFSoftSerial to reliably communicate with my GPS library for some time. I don't think I've lost any data, but I have to run some further tests to make sure.
@Mikal: AFSoftSerial does look good. When I feel like hitting my head against the wall some more, I'll give it a shot over standard SoftSerial.
What GPS are you using? I take it that it's not the same one I have from Parallax, or else you'd know the answer to my problemo!
@RedBinary: Of course! I'd put the BT serial on the UART pins and perform other comms via SoftSerial perhaps. It really just depends on which is more mission critical.
I've been playing with this little baby: GNSS Receiver - EM-506N5 - GPS-19629 - SparkFun Electronics. It's surprisingly receptive. I booted it up in my closed garage a good 15' from any exterior wall and it detected the signal. It differs from yours in that it has both an RX and TX line.
The only complaint I have is that its performance drops permanently by ~100% when you accidentally hook a 9V battery to its +5Vin line :-/
Looks very similar to mine. I went with the model from Parallax because of the article in the playground. I still can't get the darn thing to communicate asynchronously.
LOL re: 9v battery. Did you happen to make an official complaint to SF? Hehe. I shouldn't laugh though, I've blown plenty of things up in my time.