Serial.read mask?

Hi All.

I am reading data sent from a a PC over the serial port and I am getting the expected output on the LCD compared to what my comport scanner tells me and what the PC Satellite Tracking software tells me.

The message arrives in this format:

W123 021||

The W represents the command that the manufacturers original PIC read to activate the motor in a particular mode. W being, step to these degrees and elevation on Serial.read.

The first set of 3 numbers is degrees of the compass.

The second set of 3 numbers is degrees of elevation.

Then there is two (carriage returns?)

There is no space after the W, there is no space after the last third digit. There is a space in between the numbers

So,

Wxxx xxx||

An emergency stop command can also be sent which is a single C character.

My Question therefore is....

Is there a way to use a mask or a special way to read the int values and separate them into, for instance, DEGROTATION, DEGELEVATION ?

Thanks in advance.

#include <LiquidCrystal.h>


LiquidCrystal lcd(12, 11, 5, 4, 3, 2); 



     
void setup() 
{
Serial.begin(9600);
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("Rotator Software");
delay(1000);
lcd.setCursor(0,0);

delay(1000);


}

void loop() {
  if(Serial.available()){
    lcd.setCursor(0, 1);
    lcd.print("                ");
    delay(100);
    lcd.setCursor(0, 1);
    while(Serial.available() > 0){
      lcd.write(Serial.read());
    }
  }
}

Have a look at the strtok() function. An example can be found in the serial input basics thread.

That thread might also give you ideas how to receive data and store it in a character array for further processing.

Another option might be parseInt()

Thanks all for your help. I eventually found a script that wrote the incoming data to an array. It used start and end char to choose what characters to drop and what to save.

I then used a simple math formula to write the single byte values into 100, 10 and 1 units as an int.

Getting used to the language now. I'm a complete noob.

I have the rotator tracking now, but I am being plagued by missed pulses on the elevator because the arduino is busy trying to get the heading right.

Can I use 1 arduino for the 'brain' and send the data to 2 nano's (1 for each heading and elevation) with MOSI? i.e., 1 master and TWO slaves?

Cheers
Adrian

I have the rotator tracking now, but I am being plagued by missed pulses on the elevator because the arduino is busy trying to get the heading right.

Nothing in the code you posted does anything remotely like "get the heading right". Care to try again?

Mind to share your new code?