Converting Serial byte into a string

I would like to send a serial command from Labview, ie. "move". I would like to then read it into arduino and then get arduino to move on command. The arduino currently reads in a byte. How can I convert this into a string?

Many thanks

A simple solution could be:

  String string;
  while (Serial.available()) {
    string = Serial.readString();
  }

It is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. Just use cstrings - char arrays terminated with 0.

@SamRWhite, have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

You will make your life a lot easier if the Labview program just sends “” when it wants to signal a move.

…R

Thank you for your help guys. Goet I have something similar to this in my code. Robin2, that post is very helpful, I am trying to implement this into my code. Do you know how to convert from a hex version "byte" to a readable version ie. a letter?

SamRWhite:
Do you know how to convert from a hex version “byte” to a readable version ie. a letter?

I don’t understand. Can you provide an example, or better still the program that is no doing what you want.

Where is the hex data coming from?

…R

SamRWhite: Do you know how to convert from a hex version "byte" to a readable version ie. a letter?

There is no need to convert anything :)

'Hex' or Ascii characters are just human readable forms of the 8 data bits contained in the 'byte'.

If you use Serial.write() it sends bytes as they are, the Serial Monitor will print any ascii characters as human readable where appropriate depending on the 'value' of the byte, and again that is because of how humans designed the 8bit byte coding format with it's power of 2 binary value system.

Here's a little demo...

byte letterA = 0x41;
byte letterB = 0x42;
byte letterC = 0x43;

void setup() {

  Serial.begin(115200);
}

void loop() {

  Serial.write(letterA);
  Serial.write(letterB);
  Serial.write(letterC);
  Serial.println();
  if (++letterA == 0x5B) letterA = 0x41;
  if (++letterB == 0x5B) letterB = 0x41;
  if (++letterC == 0x5B) letterC = 0x41;
  delay(1000);
}