1
\$\begingroup\$

I am a beginner to microcontrollers. I am trying to use Arduino UNO to read data at 115200 Bd. I used SoftwareSerial.h as follows. But I do not think I got correct data. Could you help me take a look?

Thank you so much!

#include <SoftwareSerial.h>

SoftwareSerial mySerial(8,9);  //RX,TX

void setup()
{
  mySerial.begin(115200);
  Serial.begin(115200);
  Serial.println("starting...");

}

void loop()
{
  while(mySerial.available())
  {
    Serial.println(mySerial.read());
  }
}
\$\endgroup\$
2
  • 1
    \$\begingroup\$ please elaborate on 'But I do not think I got correct data.' what is your setup? what is connected to pins 8,9? \$\endgroup\$ Oct 21, 2012 at 15:42
  • \$\begingroup\$ To pass on the incoming data, you probably want serial.write() not serial.println() which would append a newline (and possibly convert to a numeric value?), though there are likely other issues as well. Also make sure the hardware serial baud rate is as fast if not faster than the software one; with serial.println() it would need to be at least twice as fast, possibly many times depending on what it actually ends up sending. \$\endgroup\$ Oct 21, 2012 at 17:04

1 Answer 1

5
\$\begingroup\$

SoftwareSerial only works up to 38400 bps, because running faster, it overloads the computation capability of the CPU. The documentation for SoftwareSerial on the arduino.cc site mentions this.

To read a 115200 kbps signal, you have to use the built-in serial port. If you also use that for programming, you're going to have to do some connecting/disconnecting each time you want to program your part -- or you can get an In-Circuit Serial Programmer and use that rather than the serial port for uploading. I recommend a Avr-ISP-2, which can be had for $35 at digikey. Ignore the CD that comes with it if you're using the Arduino IDE.

In general, a better source of support for Arduino-specific questions is the forums at arduino.cc.

\$\endgroup\$
3
  • \$\begingroup\$ Thanks so much for the suggestions, @JonWatte! To be more precise, I am reading a signal from a gyroscope. In the datasheet, it says "Transmission rate (default) - 115kBod (repetition rate ~ 1.2kHz)". It sends out 8 bytes of data each time. If it is sitting still, I should be able to see some patterns of the data I read from Arduino UNO. However, I couldn't. \$\endgroup\$
    – Peter
    Oct 22, 2012 at 13:21
  • \$\begingroup\$ @Peter you probably won't see much of interest until you fix the mentioned problems with exceeding software serial's limits and using the wrong output function, however you still haven't described the data you are getting, either. Even now that may provide clues, and when you fix the mentioned problems the nature of any remaining difference between the data you do get and the data you expect will help close whatever issues still remain. \$\endgroup\$ Oct 22, 2012 at 13:37
  • \$\begingroup\$ Also, you may want to try directly connecting the gyroscope to your pc with a usb serial (or logic level usb serial) cable to make sure the data actually is what you expect. And speaking of logic level, have you verified that the gyroscope outputs data at logic level and polarity as required by the Arduino, vs the higher voltage and opposite polarity of an RS232 connection? \$\endgroup\$ Oct 22, 2012 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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