2
\$\begingroup\$

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');
  }
}
\$\endgroup\$
5
  • \$\begingroup\$ SoftwareSerial has extremely inaccurate timing if I remember correctly. Try the NewSoftSerial library or using the hardware serial port. \$\endgroup\$
    – NickHalden
    Jan 28 '12 at 19:25
  • \$\begingroup\$ It is good practice to copy in the relevant parts of your source code into the question itself. It is helpful now so people don't have to click through links and it is helpful to people in the future if/when the link ever goes dead. \$\endgroup\$
    – Kellenjb
    Jan 28 '12 at 19:49
  • \$\begingroup\$ @JGord: In arduino 1.0 NewSoftSerial actually replaced the core SoftwareSerial library, so that's actually what's being used. \$\endgroup\$
    – Annath
    Jan 28 '12 at 22:50
  • \$\begingroup\$ @Kellenjb: I will keep that in mind for future posts, I just didn't want to make the post overly-long. I'll edit this one to reflect that as well. Thanks! \$\endgroup\$
    – Annath
    Jan 28 '12 at 22:51
  • \$\begingroup\$ @Annath Yeah, you do have to be careful to not make the post overly-long, that is why I said the relevant parts. Your question is perfect though. \$\endgroup\$
    – Kellenjb
    Jan 28 '12 at 23:31
1
\$\begingroup\$

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.

\$\endgroup\$
4
  • \$\begingroup\$ I tried this, but it didn't change what I was receiving. :( Thanks for the suggestion though! Marking this as accepted because it answered my question. More research is required I suppose! \$\endgroup\$
    – Annath
    Jan 28 '12 at 7:43
  • \$\begingroup\$ @Annath I added some more suggestions to my answer \$\endgroup\$
    – vicatcu
    Jan 28 '12 at 18:14
  • \$\begingroup\$ I tried switching to using the hardware UART, but it didn't seem to fix the problem. :( I also tried a couple other baud rates, and I will try more later. I also found the page on sparkfun about this particular module and saw no mention of similar problems. I'm wondering if my particular unit might be faulty, but I don't know. If I can get my hands on another I'll test it. \$\endgroup\$
    – Annath
    Jan 29 '12 at 0:04
  • \$\begingroup\$ Actually, I've tested it by using two arduinos - 1 leonardo, 1 uno r3 and a logic analyzer in-between and resulted with a definite 8-n-1 both when transmitting with leonardo or uno r3. \$\endgroup\$
    – dalimama
    Aug 18 '15 at 22:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.