Problen with serial data acquisition

Hi everybody!

I've a problem in acquiring data by a IMU sensor (xsens MTi) through the serial port of my Arduino Mega 2560 (arduino release is 1.0).

The problem is that output data on serial monitor are not those i'm expecting to receive but completely different numbers.

The output volt level of the serial that i connect on Arduino is 5 V; so it has nothing to do with level attenuation through MAX232.

The code i'm uploading is :


void setup() {
Serial.begin(115200);
Serial1.begin(115200);
Serial1.flush();
}

void loop() {
while (Serial1.available() > 0) {
int incomingByte = Serial1.read();

Serial.print(incomingByte, DEC);
Serial.print(" ");
}
}


Is there something wrong in here?

I was expecting for a structure like:

| HEADER (fixed) | DATI | checksum byte |

250 255 50 50 .... (50 changing data) .... checksum

Instead i receive:

0 129 179 179 ...... (this structure is cyclic but it's not correct!)

Any suggestion about this? Thank tou very much!

Bye!

You don't specify the exact type of the device you have and I cannot find a link to a datasheet in you post too. I have to guess therefor. On the producers web site I cannot find a type of the sensor putting out TTL level signals. You may get 5V with a multimeter but most of the interfaces are differential or have at least positive and negative voltage levels. If you're connecting this device directly to your Arduino you may have already burned some of your pins, at least you won't get what you expect.

Post a link to the datasheet of the exact device you're connecting to and a photo or a drawing of the circuitry. The code you posted is very basic (but nevertheless badly formatted, try the auto format feature of the IDE) and probably not the problematic part in your project.

ok you're right. The datasheet is here:

http://www.xsens.com/en/general/mti

Thank you!

Which of the 4 versions do you use?

This is the precise version:

http://www.xsens.com/images/stories/products/PDF_Brochures/mti%20leaflet.pdf

thanks

This leaflet is for 18 different version. They have a product code MTi-xx Ayy Gzz. Tell us what your sensor has as xx, yy an zz.

Ok:

MTi-28-A53-G35

Sorry!

This meanns you have a RS232 version of the device. You need some kind of converter (e.g. MAX232) to generate the negative voltages even if you measure a 5V level with your multimeter for a logical 1, the logical 0 has to be negative and your Arduino cannot generate such levels itself, you may even destroy it's ports if you connect such a device directly.

ok, I see.

I have 4 wires as output by the serial wire. 2 for power and the other two are RX and TX.

I already have here the MAX232. I can't understand in which hole of the RS232 side I've to put the VCC wire.

Could you kindly describe the right connection (with the rights volts for each link)?

I'm a newbye with electric items!

Thank you for helping me. It's very important for me!

Get a MAX232 data sheet from just about anywhere, they have schematics in them.

You will also need 4 capacitors.


Rob

Ok, but I already have a MAX232 ; I haven't to build it. So, why should I use 4 capacitors?

Couldn't someone link me to a scheme of the right connection on the MAX232? I'm asking it because I'm not very sure about.

Thank you very much!

I already have here the MAX232.
but I already have a MAX232
I haven't to build it.

Houston we have a (communication) problem.

A MAX232 is a chip, unless you have a billion-dollar fabrication facility you can't build one. You buy one, plug it into a circuit board with 4 capacitors, and connect it to an RS-232 line on one side and 5v serial on the other.

I will assume that you are really referring to the sensor when you say MAX232, please say "sensor" or something so there's no confusion.

That sensor communicates using three things.

  1. RS-232 voltage levels (about +-12v)
  2. Certain pin connections on a connector.
  3. A protocol that defines the format of the data that is exchanged between the sensor and your computer (the Arduino in this case).

The RS-232 voltages are well defined and can be converted for your Arduino with a MAX232 chip which you will have to buy (do not connect the sensor directly to your Arduino).

However you need to determine the connector type, the pins used on the connector, and most importantly the protocol used before you have a hope of interfacing with this sensor.

That PDF is a sales brochure that tells us nothing useful, you need to get the above information from somewhere before we can do anything.


Rob

Ok I've this:

http://www.microbot.it/en/product/1/Serial-Adapter-RS232-TTL-3-5,5V-.html

Is it what you're talking about?

That's a start and it can replace the MAX232 chip I mentioned, but it has a DB9 connector (or headers) and your sensor does not, you still need to figure out how to connect it to the sensor and you still need to know the protocol used by the sensor.

Unless someone else has done this and is willing to divulge the information you have to get it from the sensor's manufacturer, I had a look around their web site and such details were not forthcoming so I suspect they consider it proprietary. They do have a development kit for the sensor, presumably that has the details.

Another alternative is to try and reverse engineer the sensor, this may not be too difficult if you have access to the inside of the box.


Rob

Ok but I have access to the protocol used by the sensor. Which information do we need?

Out of the specific problem, could you explain me why I need to put a circuit between the sensor with RS232 and the Arduino board to obtain the right voltage?
I ask this because on the data sheet they say that the IMU sensor could work between 4,5 V and 30 V.
So if I connect the red wire to the 5V pin (on the Arduino) where is the problem? I shouldn't have 12 V anywhere, isn't it?
In my reasonment there is surely something wrong but I can't see it for now.

I ask it to learn this things, I'm not an expert in electronics...so be patient please!

Thank you!

Ok but I have access to the protocol used by the sensor. Which information do we need?

All of it :), can you post the document?

So if I connect the red wire to the 5V pin (on the Arduino) where is the problem? I shouldn't have 12 V anywhere, isn't it?

It may do, if it is true RS-232 the voltage levels are +-12v even if you only supply 5v to the sensor. This is done with some magic circuitry that is normally inside a MAX232 chip.

As they call it an RS-232 sensor we have to assume that those voltages are present until it's proven otherwise. And +-12v will kill your Arduino.


Rob

Ok i post the document. Thanks for the explaination!

The setting of my sensor is: calibrated data and oriented data (Euler); I should receive a message of this type: FA FF 32 32 [ 50 DATA ] [Checksum]

The total lenght of the message is 55 values.

Thank you!

MT Low-Level Communication Protocol Documentation.pdf (846 KB)

So that looks like a pretty easy protocol to deal with, but you're a way's from that yet.

You need to get data into the Arduino and to do that you have to get the hardware working.

  1. Identify the three wires you need from the sensor, GND, VCC (5V) and the RS-232 signal.
  2. Connect GND and VCC to the Arduino and the RS-232 dongle.
  3. Connect the serial signal from the sensor to either pin 2 or 3 or the DB9 connector on the RS-232 dongle. I don't know if it will be pin 2 or 3 because the stupid Microbot documentation doesn't have the pinout and there's no way of telling if they conform to the standard.
  4. Connect Tx of the RS-232 dongle to Rx (digital pin 0) of the Arduino. Note that this connection will stop you from programming the Arduino so it must be removed every time you download a new program, another option is to use SoftwareSerial on another pin.

So the first thing to do is get some wires hooked up to the sensor, to do that you need more information about connecting to it.


Rob

Ok, I have to say that I already have a driver that is able to read the protocol. I've projected it in simulation, with the recorded signal of the sensor in input.

Now I have to try the driver in the real case substituting the simulated input with the real input arriving from the sensor through Arduino. I can't do it correctly if Arduino reads wrong values from the sensor.

For the connection, sorry again, I've just 4 wires arriving from the sensor without any DB9 connected to them; the 4 wires are ready to be connected.
These wires are: GND, VCC, TX, RX and I already have identified them.

At your 2) point: ok i connect the GND and VCC to Arduino ; but what do you mean with RS232 dongle? As I wrote upper in this post I've 4 "free" wires. So i could connect the wires directly inside the pins of the DB9 F if this is what you suggest.

With these new information, could you explain to me the points 2) and 3) of your post?

Thank you!

RS-232 dongle == that Microbot serial adapter you have.

So i could connect the wires directly inside the pins of the DB9 F if this is what you suggest.

Yes, at least for testing, eventually you should make up a male connector or attach the wires in a more permanent manner.

Sensor Tx ---> dongle RS232 Rx pin 2 (or 3) ----> dongle Tx ----> Arduino input (pin 0)
Sensor Rx <--- dongle RS232 Tx pin 3 (or 2) <---- dongle Rx <---- Arduino output (pin 1)

The yellow bits are only needed if you have to transmit to the sensor as well as read from it, is that the case?

The "Arduino in/output" pins are for using the hardware serial port with the restriction I mentioned before about programming the Arduino, if you use SoftwareSerial substitute 0 and 1 for any other pins, in this case there are no restrictions to programming.

I cannot tell you exactly which pins to connect to on the RS-232 gadget because it was/is common for people to swap pins 2 and 3. You will have to determine that by other means, measure with a DVM or get the data from Microbot.


Rob