I need to learn how to determine string character in serial.

Hi to everyone. I see in the reference guide that it is possible. I need to learn how to read and write characters like as a string. For example: 's''p''e''e''d' then read an float at the next bytes or equivalent. 'a''l''t' means altitude then read a float by altitude. And write too.

To read: Serial Input Basics

To write, just use the Serial.print() function.

Have reading superficial through this guide which I understood much better. Is it possible to programming such order: That way: if characters 'speed' match then value if this 'altmr' match then value if no word 'engin' then jump to next five characters then value and so on. Read exactly five characters, no more or less each, time and always check if it match then read value then read next string in order, not confusing. Is it possible?

you can set it like this. char in array is like string
char test[20] = “123456”;
so the value is set at test[0] = 1, test[1] = 2 and so on according to its sequence. so that’s for reading
the way to write, you may use loop to make it possible.

there’s simple coding attached

so, once you key in 20 letters. it will print out the letters that you’ve had pressed
correct me if im wrong

1.h (116 Bytes)

That kind of comparison is what strcmp() is for.

If I am correct, the Serial buffer is just 128 bytes. How to get more than 128 bytes? First receive 128 bytes, then send a unique identifier so the PC can recognize to send more bytes to Arduino?

Begraphics: If I am correct, the Serial buffer is just 128 bytes. How to get more than 128 bytes?

It is only 64 bytes.

If you use the code in Serial Input Basics you can receive as much stuff as you want. The demo uses a 32 byte array but you can easily increase that.

If you have the choice you should reduce your commands to single charaters - for eaxmple 's' rather than "speed" and 'a' rather than "alt". Then the Arduino code will be much simpler.

As @aarg said use strcmp() to compare strings.

...R

I see that I need to prestore character to determine which string it is, OK. Where in arduino reference is written strcmp() ?

I have found a guide how to increase serial buffer to for example 512 bytes which takes 1024 bytes of RAM; so, I am waiting to see if I need but probably is not necessary.

Begraphics: Where in arduino reference is written strcmp() ?

Nowhere. It's normal C. You can google for 'man strcmp'. Other related function are strchr (find character) and strstr (find string).

Begraphics: I have found a guide how to increase serial buffer to for example 512 bytes which takes 1024 bytes of RAM; so, I am waiting to see if I need but probably is not necessary.

Probably not necessary. Better way is to pamper the code than waste the memory.

Understood!

Let us say I need four characters and one float function which takes 8 bytes; then, 128 / 8 means 16 different values that I can receive each time which is not a lot as my own demand for simpit project. So how to send four times in serial? Do I need to write println in serial to request new 128 byte serial if the 128 bytes is finished? Let us say for example 16 bytes: spd 3 characters value float alt 3 characters value float Sum 14 bytes. Then using 2 available bytes only send to ask more data or let PC recognize when it shall receive from Arduino.

Is this configuration possible ?

With the 115200 baud rate, 115200/8 = 14400 bytes then divide with 20 frames per second plus five as safety = 576 characters thus divide it with 7 bytes as I described above; thus, the answer is 82 for only input to Arduino. So, therefore 41 for output and 41 for input. That means I might receive 41 communication source between simpit and X-Plane 10. Then Arduino is using significant instruction to determine string. But I have another way. Not determine but jump if the next string do not match the previous string so the X-Plane and my software must send sources in order with exact 3 characters with float value = 7 bytes.

Begraphics:
I see that I need to prestore character to determine which string it is, OK.
Where in arduino reference is written strcmp() ?

I have found a guide how to increase serial buffer to for example 512 bytes which takes 1024 bytes of RAM; so, I am waiting to see if I need but probably is not necessary.

You seem to have missed Reply #6 which dealt with both of those issues.

…R

sterretje: Nowhere. It's normal C. You can google for 'man strcmp'. Other related function are strchr (find character) and strstr (find string).

Not quite nowhere. It's very well hidden, though. Follow the "AVR Libc" link, under the heading, "Looking for something else?" on the reference page. :)

Begraphics: Let us say I need four characters and one float function which takes 8 bytes; then, 128 / 8 means 16 different values that I can receive each time which is not a lot as my own demand for simpit project. So how to send four times in serial? Do I need to write println in serial to request new 128 byte serial if the 128 bytes is finished? Let us say for example 16 bytes: spd 3 characters value float alt 3 characters value float Sum 14 bytes. Then using 2 available bytes only send to ask more data or let PC recognize when it shall receive from Arduino.

Is this configuration possible ?

With the 115200 baud rate, 115200/8 = 14400 bytes then divide with 20 frames per second plus five as safety = 576 characters thus divide it with 7 bytes as I described above; thus, the answer is 82 for only input to Arduino. So, therefore 41 for output and 41 for input. That means I might receive 41 communication source between simpit and X-Plane 10. Then Arduino is using significant instruction to determine string. But I have another way. Not determine but jump if the next string do not match the previous string so the X-Plane and my software must send sources in order with exact 3 characters with float value = 7 bytes.

Maybe you're trying to solve a problem that is not a problem or a problem that is not solvable at all. So what is your requirement (demand)? What's your project about (simpit and xplan don't mean anything to me).

Robin already gave pointers in an earlier reply. If speed is a concern, he did mention not to use a full 'word' but just a character (or code); 26 letters (not taking case into account) or 256 binary codes. You are aware that you can start processing before a complete message is received. Processing is relatively fast so while receiving the second part (alt) you might have been able to process the first part (speed).

By the way, depending on parity and stopbit settings, you need at least 10 bits per byte. So your absolute maximum transfer is 11520 bytes per second (at 115200 baud), not 14400. That is quite a bit; if at the end it's not enough, maybe serial communication is not the way to go (and e.g. an Uno (or 328 based board) might not be the board of choice).

My requirement is that MEGA2560 receive a few information that is necessary to processing the instruments with precision as X-Plane is without error. Such as feet per minute climb instead both feet per minute and altitude and barometer at sea level, and coordinate position, speed, and heading but just receive position one time then continous speed and heading; another example, MEGA2560 provide lookup table about the aerodynamic characteristics to provide the instruments, than always receive the information from X-Plane 10 flight simulator in PC, but receive correct total weight, flight yaw, pitch, roll, etc positions when I am activate the correction in navigation which is an option, when I change the course heading, when I click stabilizer mode when it hold at altitude, and when I change the throttle value.

I am trying to be creative to reduce the data amount.

I have found a solution. USB to SPI. http://no.rs-online.com/web/p/multiprotocol-transceivers/7617204/ So, with this connect to SPI in pins at the MEGA2560; thus, this method is 100 times faster. Now I do not worry.

Begraphics: So, with this connect to SPI in pins at the MEGA2560; thus, this method is 100 times faster. Now I do not worry.

I am intrigued.

Your title mentioned nothing about speed being an issue.

And I presume it is still necessary to use strcmp() to figure out what is in the message.

...R

Robin2: I am intrigued.

Your title mentioned nothing about speed being an issue.

And I presume it is still necessary to use strcmp() to figure out what is in the message.

...R

Thank you that you are intrigued. Maybe it will be an issue while the code is completed but it is better to have faster communication.

Yes, I understood that strcmp necessary but. I think for example alt amp thr tem lig The strcmp detect in order. While the new value to send, every details send one time to next time all updating data shall be sent one time each time. For example alt amp thr temp lig next time if I need temp and alt and lig then the PC will send: alt, temp, lig, not temp, alt, lig. if I need alt and lig then it send: alt, lig, not repeat lig then alt.

Not values that do not need to become updated but only these that need updating, but always in order. Understood?

Begraphics: Not values that do not need to become updated but only these that need updating, but always in order. Understood?

No. I'm completely lost.

...R

Robin2: No. I'm completely lost.

...R

In your signature, you mentioned: Two or three hours spent thinking and reading documentation solves most programming problems.

That is true.

variables: speed 5 character then float (4-byte) altitude 8 character then float (4-byte) throttle1 9 characters then float (4-byte) throttle2 9 characters then float (4-byte) For example loop #1 speed, altitude loop #2 altitude, throttle2 loop #3 speed, altitude, throttle1 loop #4 throttle1, throttle2 As you see, it is always in order.

Not in such configuration: loop #1 throttle1, speed, throttle2 loop #2 throttle2, throttle1, speed, altitude loop #3 altitude, throttle2, speed.

Do you understood this explanation ?