Problem with Sensor data via RX/TX

Hello!

I am trying to connect a sensor (polulu um7-lt) to the YUN on digital pins 10/11:

#define Rx    10
#define Tx    11
SoftwareSerial UM7Data(Rx, Tx);

The problem is, that I only receive crap-data as long as the sensor is connected. What I get are only some numbers but not the data the sensor actually sends.

When I connect the sensor to a teensy and run exactly the same sketch, everything works fine. I receive correct sensor-data that i can work with.

Does anyone have an idea whats wrong?

http://arduino.cc/en/Reference/SoftwareSerialBegin

SoftwareSerial: begin(speed)

Description

Sets the speed (baud rate) for the serial communication. Supported baud rates are 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 31250, 38400, 57600, and 115200.

...
mySerial.begin(9600);
...

Setup matching baud rates.

baud rate is not the problem I think (and of course I had to set the baud rate..)

as described in my first post the complete sketch works on teensy but doesn't work on yun.

here is the complete code: http://pastebin.com/7KFm39rN

Teensy v.s. Yun is hardware UART v.s. Software UART. first one is far more reliable.

Possible solution:

  • Try different SoftwareSerial Library.
  • Yunshield with Mega

What version of the IDE are you using? I think I read that there was a problem with SoftwareSerial under the recently released version 1.6.0. The latest IDE version 1.6.1 says that it includes a better SoftwareSerial library.

ShapeShifter I have tried version 1.6.1 now and that doesnt change anything.
Sonnyyu, I already tried SoftwareSerial and AltSoftSerial. Both dont work.

Any other suggestions?

le_tmp: ShapeShifter I have tried version 1.6.1 now and that doesnt change anything.

Well, it was worth a try... :(

Can you try other baud rates?

Do you have an oscilloscope or logic analyzer to check the actual baud rate that the sensor is using, and compare it to the baud rate that the Arduino is using?

Have you tried a loopback test? Just connect your Tx and Rx pins together at the Arduino (disconnect the sensor) then write a simple sketch that sends some characters out, reads them in, and then displays them on the Serial Monitor. Do you get the right characters back?

I just took a look at the product page for the sensor. One thing I notice is this comment about the output:

3.3 V TTL serial interface (UART) with baud rates up to 921,600 bps can stream data or provide updates on request

Note: the main UART pins, TX, and RX, are 5V-tolerant and can be directly connected to 5 V systems that are guaranteed to read 3.3 V as high

Maybe the Yun is having trouble detecting the signal as high? If it's right on the threshold, it could be reading high sometimes and low others, which could affect the communications reliability.

le_tmp: When I connect the sensor to a teensy and run exactly the same sketch, everything works fine.

I'm not sure which Teensy module you are using, but don't they use 3.3V I/O? If so, and if this is a level problem, that could explain why it works so well on that processor. Or maybe they're just more tolerant of 3.3V signals?

Perhaps it's worth a try using a 3.3V to 5V level shifter?

On second though, maybe it’s not a level problem. According to the '32U4 datasheet, the minimum input voltage that’s guaranteed to be read as high is 0.2Vcc+0.9V, which for a 5V Vcc comes out to 1.9 volts. So the Yun should have no problem reading 3.3V as high. Well, it was an idea…

Yunshield with Mega, since Mega has 3 Hardware UART. The worst case use Yunshield with teensy, setup Yunshield with 3.3 Volt jumper.

Plan B:

Use Arduino Mega as buffer, connect it between sensor and Yun.

sonnyyu: Use Arduino Mega as buffer, connect it between sensor and Yun.

That seems excessive. How about a USB to logic level serial adapter (FTDI cable or board) and read the sensor serial data from the Linux side?

Thanks alot for your help!

I tried nearly all suggestions but in the end it was a stupid mistake. I changed the baudrate of the UM7 with the included tool via USB and forgot to change the new baudrate in my sketch. So everything works now as expected on teensy, yun and mega+redfly ;)

Oops! Don't you hate it when it turns out to be something like that?

Thanks for the update.