Does an Arduino serial port expect 8-n-1 or 7-e-1

arduinoserial

I am exploring serial communication using the arduino, and so far I haven't had too many problems. Till now at least. I'm using an external module for reading a capacitance(the module is an DN060-02v04 from JYETech) and it's supposed to transmit automatically a lot of information about its readings. According to the documentation that came with it, it transmits in 8-n-1 format at 38400bps fixed. Simple enough, I am using SoftwareSerial and have the baud rate set correctly. I am supposed to get a string of bytes representing ascii characters, however the numbers I get back don't really seem to correspond to anything usable. I'm thinking maybe the arduino is trying to read in 7-e-1 format, but I'm not sure because I can't find any information about it. I could also be doing somethign else wrong, but I really can't think of anything. So the actual question: Does the arduino communicate using 8-n-1 or 7-e-1?

More details: I am using an arduino UNO, running on linux, and using arduino version 1.0 to program it.

EDIT: Source code:

#include <SoftwareSerial.h>

//                       rx  tx
SoftwareSerial capSerial(2, 13);
int tmp;
int next;

void setup()
{
  capSerial.begin(38400);
  Serial.begin(38400);
} 

void loop()
{
  if (capSerial.available() > 0)
  {
    tmp = next;
    next = capSerial.read();
    Serial.print(next);
    Serial.print('\n');
  }
}

Best Answer

The Arduino by default does 8-n-1 Serial communication, I'm pretty sure. There has been talk in the developers mailing list of extending the Serial API with optional parameters to change the default settings, but that's not in the current API to my knowledge.

I would try juicing up your Serial baud rate to 115200 (and remember to set your terminal program to use the same baud rate). There's an outside chance you are blocking the Software Serial by echoing at the same rate as you are receiving.

Another way to rule this theory out would be to read the ASCII data from the Soft Serial reads into a buffer and only print to your Serial port when the buffer is full.


Update

You might want to verify a few hardware things. The Tx pin of your module should be connected to the Rx pin of the Arduino, and the GND pin of your module should be connected to the GND pin of your Arduino. With those two connections in place you ought to be able to receive data from the transmitter without a problem assuming both the module and the Arduino are running at 5V.

The next thing I would try, assuming the wiring is correct, would be to not use Software Serial at all. You only need to receive from your module and you only need to transmit to your computer by the looks of things. Just wire it up so that your Arduino Tx pin does not go to your module, and your Serial.print outputs should go to your computer terminal as usual. Module Tx = Arduino DIG0, Module GND = Arduino GND and just change your program to:

int next;

void setup()
{
  Serial.begin(38400);
}

void loop()
{
  if (Serial.available() > 0)
  {
    next = Serial.read();
    Serial.print(next);
    Serial.print('\n');
  }
}

The only other thing I can suggest is that the manual may be inaccurate, and you could try the other common baud rates for your device interface (e.g. 9600, 14400, etc. - there are a small number) and see if things start decoding correctly.