Combatraffi

I am working on a program for an autopilot that reads data from a sparkfun 9dof razor. The problem I am having is a stupidly simple one I believe, but I cant seem to get things to work right. I need to read in the angles from the serial stream, into a String type variable. So essentially what it boils down to is how do I get the serial data into a character string and then into a String.

Combatraffi

Hey, thanks for the quick response. I have it covered from the point that the data is in a String object. I can parse it and convert it using atoi, gots all of that down. The problem i am having is that the data comes in as a pre arduino -0019 character array string and I am trying to get it into the newer String object so that I can more easily manipulate it. Once it is in the String I have the rest of the program working.

Combatraffi

thanks rob, thats what I was thinking but im getting garbage out, maybe something else is set up wrong. I just found out about the String class today actually. some of the aspects of it are very well explained and some are not, this was one (at least in my research) that was not. There is a method of taking a String and turning it into a character array but not vice versa.

Dan

Combatraffi

The data from the razor appears as !ANG:-xxx.xx,-xxx.xx,-xxx.xxX in a character string. (the uppercase X on the end is my simple end sign) Of course the data could be positive as well but negative I thought of as a catch all scenario. So what I want to do is do a serial read, put that into an array. make that array a String and parse it/convert it etc from there.

You have the classic issue with reading the serial port - you check serial.available and if there is anything there, start reading until you get an 'X'. Problem is, serial comms are very slow, so what you will get is one character followed by a large number of -1s from serial.read while the next character is being transmitted. You almost certainly overflow your dataset array and stamp all over whatever is next to it in memory. Check that serial.available > length of string you're reading or better, check it before you read every character. This issue comes up often - search the forums for serial.available and you'll get a number of similar explanations.