Trouble with Serial3.read on Mega

Hi, I am running a Seeeduino Mega and have another serial device downline sending data to the Mega on Serial3. I receive data at the right times, but it's all garbled. All the characters correspond to ASCII characters that are >127 (for the most part).

Does the Serial.read() command read one BYTE at a time? One INT at a time? Do I need to split the INT? How do I convert the int's I am reading into char's? I am slightly confused, if you can't tell. I would appreciate any suggestions anyone might have.

Thanks a bunch.

Serial.read() returns an int representing 1 byte of data, one int at a time.
If there is no data in the rx buffer, Serial.read() returns -1.

There are many things which could cause the problem you are describing.

What is the baud rate, parity setting, stop bit setting of both the Arduino and the other device, and what is the received data expected to look like?

Are you sure you are feeding it with TTL signals and not RS232 signals. That sounds typical of that sort of fault because the logic is inverted.

So I don't know how to set the settings for the Serial ports... only Serial.begin(9600). Could you tell me how to play with those settings? The device is set for no parity, 9600 baud. A typical data package should look something like this:

T01=09/13/22, 08:37:04
D01=A1 3.4685 Mo-cm 1B R= 1000000
D01=B1 21.4632 oC 09 R= 1000000
D01=K1 0.2930 uS/cm 13 R= 1000000
D01=L1 0.1100 PPM 56 R= 1000000

I know I need to parse the data after receiving it (into floats and chars and whatnot) but I don't see ANY recognizable bytes... :o

I'm pretty sure it's RS232. I had another daq device logging the data before and that worked fine off the serial port there...

So the Serial.read() returns an int, which is 2 bytes, but that int only represents 1 byte of the serial data buffer?

Thanks again guys, I appreciate the help!

Compared to RS232 signals which can range from -12V (1) to +12V (0), the TTL signal expected by the Arduino is inverted and smaller in range: +5V (1) to 0V (0).

You need some circuitry like a MAX232 or derivative, or an inverter circuit, to invert the voltage levels. And possibly protect your Arduino from the higher voltage range.

OK I will look into that chip and report my findings... but it sounds like there could be a software fix if it's just inverted logic. Anyone else want to weigh in?

Thx, P

P.S. I still would like to know how to set the serial pot settings for any given port... parity, stop bits, etc///

A software fix could be done, but I suspect it would be much more time-consuming (and aggravating) to write (and debug), than to use a simple TTL / RS232 signal shifter.

If you're not interested in writing to the device, then all you need is 1 transistor and 2 resistors to make a simple inverting switch.

Even if you don't need to write to the device, consider getting a proper converter anyway. They are not expensive, less than $10, and you will use it a lot if you are doing much work with micro-controllers.