ParseFloat

Hey guys, I have connected three accelerometers of Xio Technologies to Arduino Mega through hardware serial 1,2 and 3. I will be receiving floating point values in each co-ordinates from each imus but I want only the x coordinates and so I have programmed the sensor to send obtain that. However, at random intervals I receive values very high all of sudden.

The arduino powers the sensors and Tx of the sensors are connected to Rx1, Rx2 and Rx3.
This is the code:

void setup() {
// put your setup code here, to run once:
Serial.begin(57600);
Serial1.begin(57600);
Serial2.begin(57600);
Serial3.begin(57600);
}

void loop() {
if(Serial1.available() > 0){
float val1 = Serial1.parseFloat();
}
if(Serial2.available() > 0){
float val2 = Serial2.parseFloat();
}
if(Serial3.available() > 0){
float val3 = Serial3.parseFloat();
}

Serial.print(val1);
Serial.print(",");
delay(1);
Serial.print(val1);
Serial.print(",");
delay(1);
Serial.print(val1);
Serial.print(",");
delay(1);
}

How often does the accelerometer send data? Perhaps your serial input buffers are overflowing and the decimal point occasionally gets lost.

You do know that you are printing val1 three times, right?

It doesn't mention it in the parseFloat documentation, but in that for the parseInt, there is a timeout of 1000ms that terminates the parsing. It looks to me as though parseFLoat does the same thing, which means that each call will take ~ one second unless some non-numeric character is sent after the number data.

If not, that means that you're reading each accelerometer's data once every three seconds. If the accelerometers send more often, you may be reading combined data from them. How often do they send and what does that data look like. Specifically, does it always send decimal points?

@ johnwasser: Yeah I am sorry for the mistake. I am printing val1, val2, and val3. It sends at a baudrate of 57600. So I have kept the arduino baudrate of all the hardware serial at 57600.

wildbill:
It doesn't mention it in the parseFloat documentation, but in that for the parseInt, there is a timeout of 1000ms that terminates the parsing. It looks to me as though parseFLoat does the same thing, which means that each call will take ~ one second unless some non-numeric character is sent after the number data.

If not, that means that you're reading each accelerometer's data once every three seconds. If the accelerometers send more often, you may be reading combined data from them. How often do they send and what does that data look like. Specifically, does it always send decimal points?

johnwasser:
How often does the accelerometer send data? Perhaps your serial input buffers are overflowing and the decimal point occasionally gets lost.

You do know that you are printing val1 three times, right?

@ johnwasser: oh I didnt notice it. I have copied the first command and pasted it thrice. I am sorry for the mistake. I am printing val1, val2, and val3. It sends at a baudrate of 57600. So I have kept the arduino baudrate of all the hardware serial at 57600.

@wildbill: The sensor sends at a baudrate of 57600 and hence I have kept the arduino baudrate the same. It receives two decimal values. I have attached an image of my serial monitor

I'm curious about how often the accelerometer sends data and what format it's in. Your screenshot is showing the results of your parseFloat, as formatted by Serial.print.

Perhaps you could provide a pointer to the specifications for the accelerometers you are using. The X-IO website only shows a 3-axis IMU and it doesn't use serial I/O.

wildbill:
I'm curious about how often the accelerometer sends data and what format it's in. Your screenshot is showing the results of your parseFloat, as formatted by Serial.print.

@wildbill : I am sorry for the late reply. Yes you are right. The X-IO Technologies, sends the data to arduino using XimuReceiver Library. The data is encoded and so I am not able to decode it. I will attach the library files.

johnwasser:
Perhaps you could provide a pointer to the specifications for the accelerometers you are using. The X-IO website only shows a 3-axis IMU and it doesn't use serial I/O.

@johnwasser : No while you need to interface it with arduino, you can program the ximu to uart mode and connect to arduino. This is the ximu website. x-IMU – x-io Technologies

And by the way, let me tell you the entire project. I have only explained the problem. And yeah the problem specifically lies in the uart serial ports in Arduino.

I am building an interface system that connects 9 imus to RX1, rx2, rx3 of 3 megas and then the rx0 of those 3 megas are connected to rx1, rx2, rx3 of another mega. I am getting data from former three megas properly. However, from those former megas to latter mega, I am facing this problem.

XimuReceiver.cpp (8.74 KB)

XimuReceiver.h (2.98 KB)

@johnwasser: I guess my above post is kind of ambiguous, on this one i shall try being more specific. :stuck_out_tongue:

The interface I am building consists of 9 x-imu's. In 3 sets of 3 x-imu's each, the physical port made available is connected to Rx1,2 and 3 of every Mega. and each of these Mega's Tx0 pins are connected to another Mega where i will be receiving the accelerometer values from all 3 mega.

When I connect the o/p via the Tx0 pins to the 4th Mega, the values are getting corrupted.

I have attached a small block diagram of our circuit, the complete program on all the 3 megas. In the program I am trying

Please Help

MultiWii_code_12thMarch.ino (3.92 KB)

WiitoMegai_code_9thMarch.ino (4.11 KB)

This is the block diagram of the circuit

images.pdf (654 KB)

I even tried to read the string of data. But even there I am the problem. I get erroneous characters in the middle. I have attached the code.

megatomultiwii.ino (680 Bytes)

Your code seems rather complex for something that isn't working - i.e. it looks like you're indulging in a little big bang testing. I'd suggest you reduce the scope a bit until you have something that works and then put the missing components back bit by bit.

I'd reduce your test program to listening on one serial port and just read and echo char by char - forget readStringUntil. Probably best to echo the character and its ascii value if you're getting stuff you don't recognize.

Hey I was reading in one of the forum and I read that the hardware serial drop bytes while reading huge strings of data. It was mentioned that the hardware serial library code must be modified as per the application. So any one of you guys know anything about this.

Not entirely accurate. The hardware serial library has input and output buffers. If the input buffer fills up, any additional data that arrives at the UART is thrown away.

You need to ensure that your sketch is reading fast enough to prevent this happening. Given how slow serial data transmission is compared to the speed of an arduino, this isn't usually a problem, unless you are using delay() for anything more lengthy than debouncing in your code.

Since you have the library source code, you can increase the size of the buffer, but since the most arduinos don't have much RAM, you can't increase it much and in most cases, it isn't necessary.

Don't forget that if you do increase the buffer size in the standard library, it will affect ALL of your sketches that use serial.