Serial.read() to Integer

GoForSmoke:

  if (masterMessage[0] >= 'A' && masterMessage[0] <= 'F'){

thanks for this XD

"AF1-45,78,#"
atoi sees the A and stops, returning 0.

Your code can get those 2 values out in a number of ways.
With the state machine you can read until "-" then evaluate digits until ',' and again until ','.
Or you can pull the digits out by position (IF they will Always Be The Same Number of Digits, Same Place) into a buffer, tack on a terminating zero unless the buffer was filled with 0's (use memset) and atoi(buffer) each time.
Or you can learn to use strtok() to tokenize TempBuffer which means learning pointers and strtok and then you can atoi(pointer) for each value.
Or.... well there's always another way!

position won't work because the temperatures are coming from my master and they will vary in length and may include the sign.

Can I read the chars (use isDigit) into an integer array and atoi an entire array?. I can then assemble the integer from the individual digits, I guess.

Literally, I am guessing.

BulldogLowell:
position won't work because the temperatures are coming from my master and they will vary in length and may include the sign.

Can I read the chars (use isDigit) into an integer array and atoi an entire array?. I can then assemble the integer from the individual digits, I guess.

Literally, I am guessing.

As someone here used to point out, serial data has no guarantees. You want to make/check "road signs" just to be more sure of what you get, and the dash and commas provide those. And be sure that your code expects everything that might get fed to it.

Check out the linked blog and see if the state machine couldn't work. There's damned little you can't do with state machines using less code and less nested code and less RAM as well than other ways.

One thing you won't see much of in examples is error handling. It adds code, adds time and work and debugging, and makes lessons harder for beginners but IMO it doesn't teach people to code for the unexpected which makes the difference between a crash or bad data and some sort of report or procedure or retries. If you're doing this for a job-related thing then put serous thought into error checking and handling at every logical place an error can happen even when you "know" (unless you've really constrained values) it won't.
A lot of my early stuff 30+ years ago cranked out tapes for NC and CNC cutting machines. Making airtight code was not just a hobby for me! A bad goof could have cost more than I made in a month. WTH, we needed new clamps.... right?

GoForSmoke:
Check out the linked blog and see if the state machine couldn't work. There's damned little you can't do with state machines using less code and less nested code and less RAM as well than other ways.

Brilliant! I read through it and understand.
I should have gone back further in this thread.
Cheers!!

BulldogLowell:
Brilliant! I read through it and understand.

No surprise. That's a Nick Gammon blog!

GoForSmoke:

BulldogLowell:
Brilliant! I read through it and understand.

No surprise. That's a Nick Gammon blog!

Well, it worked out well. I built the engine right from his example and it is great, I can transmit any of the variables I want together or independently . That is perfect because I can avoid collecting all of the variables on the Master device and transmit when I have the number.

Instead of sending : AF1-45,78,#

I'm sending: W1S1M1I72N1O95F1x

Where I have: W, S, M, I, N, O, F states

Thanks so much for helping me!

Jim

Okay. Have you learned how to do multiple things at once through this or would like the rest?
You've not far to go unless you're already there, at least to this basic first level.

The code you have acts whenever Serial delivers a character. the rest of the time loop() goes around and other pieces of code triggered for other reasons (than Serial available) has a chance to run.
My standard to include is to have the pin 13 led blink as a status light. If the blink rate is 'off' then I know something in my code is hanging up. I can also change the blink rate (generally, to faster) as a means of error notification.

This real time coding will let you run sensors, motors and user I/O without weaving the code for any one part into the same block as another part. Instead of a sensor read in an if changing the running of a motor, the sensor code sets a state that the motor code reads and acts upon. Then if you change one part, sensor or motor, you can rip that code out cleanly and insert code for the new thing to read and pass states as the old did rather than hunting for lines and pieces of function calls all through the whole sketch and moving functionality piece by piece with extra debugging for the bits missed or not quite done right. You won't just save hours over a year, more like weeks.

Here's another of Nick's blogs. It's kind of his BlinkWithoutDelay with a full easy teaching explanation. It shows how to make things happen on time and is very clear about what is blocking code and why you don't want that.

How to do multiple things at once ... like cook bacon and eggs

To end this topic also solved for me, I'll post the code I use now and which works well below:

byte colors[3] = {0, 0, 0}; //array to store led brightness values
byte lineEnding = 0x0A; //10 in decimal, ASCII newline character

if (Serial.available() > 2) {
      int bytesRead = Serial.readBytesUntil(lineEnding, (char*)colors, 3);
}
analogWrite(red1, colors[0]);
analogWrite(green1, colors[1]);
analogWrite(blue1, colors[2]);

I send an byte array with my application which consists of the three values and the escape sign. If I would like to receive a single Integer I would have also been albe to write int number = Serial.parseInt(); this returns one number.(as seen in the examples.) Thanks to everyone.

GoForSmoke:
Okay. Have you learned how to do multiple things at once through this or would like the rest?
You've not far to go unless you're already there, at least to this basic first level.

The code you have acts whenever Serial delivers a character. the rest of the time loop() goes around and other pieces of code triggered for other reasons (than Serial available) has a chance to run.
My standard to include is to have the pin 13 led blink as a status light. If the blink rate is 'off' then I know something in my code is hanging up. I can also change the blink rate (generally, to faster) as a means of error notification.

This real time coding will let you run sensors, motors and user I/O without weaving the code for any one part into the same block as another part. Instead of a sensor read in an if changing the running of a motor, the sensor code sets a state that the motor code reads and acts upon. Then if you change one part, sensor or motor, you can rip that code out cleanly and insert code for the new thing to read and pass states as the old did rather than hunting for lines and pieces of function calls all through the whole sketch and moving functionality piece by piece with extra debugging for the bits missed or not quite done right. You won't just save hours over a year, more like weeks.

Here's another of Nick's blogs. It's kind of his BlinkWithoutDelay with a full easy teaching explanation. It shows how to make things happen on time and is very clear about what is blocking code and why you don't want that.

How to do multiple things at once ... like cook bacon and eggs

Gammon Forum : Electronics : Microprocessors : How to do multiple things at once ... like cook bacon and eggs

this is very interesting to me. I am using a slave arduino pro mini to control some weather 'skits' with flashing LEDs and flashing temperatures and message indicators. I have attached the code but you can see it is the prototype of what you just described.

Let me look through Nick's blog on this and perhaps it can help me develop a more robust code. I understand quite well using the mills() function to eliminate delays, however the attached will show you why i think that is a daunting task considering what I have going on in here.

Looking forward to learning...

ClockSlaveWeatherSkitsFinalStateEngine.ino (18.2 KB)

Do what you do but be aware that this line blocks all execution until it's done:

      int bytesRead = Serial.readBytesUntil(lineEnding, (char*)colors, 3);

The reason to run things like state machines is so that user entry can be done while other things are happening.
Like having a status light.

BulldogLowell:

GoForSmoke:
Okay. Have you learned how to do multiple things at once through this or would like the rest?
You've not far to go unless you're already there, at least to this basic first level.

The code you have acts whenever Serial delivers a character. the rest of the time loop() goes around and other pieces of code triggered for other reasons (than Serial available) has a chance to run.
My standard to include is to have the pin 13 led blink as a status light. If the blink rate is 'off' then I know something in my code is hanging up. I can also change the blink rate (generally, to faster) as a means of error notification.

This real time coding will let you run sensors, motors and user I/O without weaving the code for any one part into the same block as another part. Instead of a sensor read in an if changing the running of a motor, the sensor code sets a state that the motor code reads and acts upon. Then if you change one part, sensor or motor, you can rip that code out cleanly and insert code for the new thing to read and pass states as the old did rather than hunting for lines and pieces of function calls all through the whole sketch and moving functionality piece by piece with extra debugging for the bits missed or not quite done right. You won't just save hours over a year, more like weeks.

Here's another of Nick's blogs. It's kind of his BlinkWithoutDelay with a full easy teaching explanation. It shows how to make things happen on time and is very clear about what is blocking code and why you don't want that.

How to do multiple things at once ... like cook bacon and eggs

Gammon Forum : Electronics : Microprocessors : How to do multiple things at once ... like cook bacon and eggs

this is very interesting to me. I am using a slave arduino pro mini to control some weather 'skits' with flashing LEDs and flashing temperatures and message indicators. I have attached the code but you can see it is the prototype of what you just described.

Let me look through Nick's blog on this and perhaps it can help me develop a more robust code. I understand quite well using the mills() function to eliminate delays, however the attached will show you why i think that is a daunting task considering what I have going on in here.

Looking forward to learning...

Look up more on state machines, or the full name is finite state machines but I like to keep it simple.

For responsive real time code, loop needs to run often with time-critical tasks up top and human-speed tasks at the bottom. People don't notice much above 30 FPS except for flashes and then persistence of vision works the opposite way. Try blinking a led 995 ms ON and 5 ms OFF, you won't see it OFF but 995 ms OFF and 5 ms ON, you will. Or measure a button touch where it take 10 ms to debounce, the human "just touched" it. Low Priority.

So inside loop() there's like separate programs to read or control devices and the data and algorithm parts, you keep them separate and if need be break them into pieces that run fast, each changes a state variable to trigger the next when it's time to run that piece, the sub-task.
Especially break a function that has a delay() or other blocking code in it and change the block into a check in the new sub-task so that something else can run of that one is not ready.
Make it run fast. If some process does take a lot of cycles then do a return (to loop()) at the end so that some other trigger doesn't hold up critical time checks. It might only be the human who can't notice being kept for less than about 50-100ms.
If some task has a loop inside of a trigger then turn that loop into a sub-task that runs until it changes the meaningfully named task state to run the sub-task that continues the process next time through loop() maybe.
Write you code as if each piece will be gotten to quickly and you will want to keep it that way.

Triggers: time, inputs, state values and flags.
Time can be millis() or micros(). Micros() is always rounded to 4. You have to count loops to get smaller.
Inputs are pins and ports. I/O makes Arduino Real World. MCU's are designed to be RWRT and so is Arduino.
Each piece of code communicates to others through values and flags rather than using intertwined code. The latter starts out simpler in its directness but once things get complicated, it becomes spaghetti aka can of worms.

BTW looking through your code, is shiftout and shiftin for SPI because I don't find a #include.
Which Arduino are you using? Not an UNO.

also these

int pwmPin  =  40;   //PartlyCloudy
int pwmPin2 =  41;   //PartlyCloudy
int pwmPin3 =  42;   //OverCast
int pwmPin4 =  43;   //Overcast
int pwmPin5 =  44;   //Thunderstorms
int pwmPin6 =  45;   //Thunderstorms
int pwmPin7 =  46;   //Sunny
int pwmPin9 =  47;   //Cloudy
int pwmPin10 = 48;   //Cloudy
int pwmPin11 = 49;   //Rain
int pwmPin12 = 50;   //Rain
int pwmPin13 = 51;   //Snow
int pwmPin14 = 52;   //Snow

could be this and save on RAM

const byte pwmPin0 = 39; // and the pins are pwmPin0 + pin #

All of these ... soft-SPI blocks. The only difference is the data. You only need one function, without the delay().

        digitalWrite(latchPin, LOW);
        shiftOut(dataPin, clockPin, LSBFIRST, 0x00);  
        shiftOut(dataPin, clockPin, LSBFIRST, 0x00);  
        shiftOut(dataPin, clockPin, LSBFIRST, 0x01);   
        digitalWrite(latchPin, HIGH);
        delay(100);

And you have a lot of functions that could be generalized and run on fed data.

What's the functional difference in the 2 below?

  if (masterMessage[0] >= 'A' &&  masterMessage[0] <= 'E' || masterMessage[0] == 'F'){
  if (masterMessage[0] >= 'A' &&  masterMessage[0] <= 'F' ){

GoForSmoke:
Do what you do but be aware that this line blocks all execution until it's done:

      int bytesRead = Serial.readBytesUntil(lineEnding, (char*)colors, 3);

The reason to run things like state machines is so that user entry can be done while other things are happening.
Like having a status light.

I send values through the Java RXTX library. I'm trying to build the state machine as you pointed out before, but I'm unsure how I should send my values.

// pins for the LEDs:
const int red1 = 2;
const int green1 = 3;
const int blue1 = 4;

const int red2 = 5;
const int green2 = 6;
const int blue2 = 7;

const int red3 = 8;
const int green3 = 9;
const int blue3 = 10;

const int red4 = 11;
const int green4 = 12;
const int blue4 = 13;

typedef enum {NONE, GOT_R, GOT_G, GOT_B, GOT_M} states;

states state = NONE;

unsigned int currentValue;

void setup() {
  // initialize serial:
  Serial.begin(9600);
  
  state = NONE;
  // make the pins outputs:
  pinMode(red1, OUTPUT);
  pinMode(red2, OUTPUT);
  pinMode(red3, OUTPUT);
  pinMode(red4, OUTPUT);
  
  pinMode(green1, OUTPUT);
  pinMode(green2, OUTPUT);
  pinMode(green3, OUTPUT);
  pinMode(green4, OUTPUT);
  
  pinMode(blue1, OUTPUT);
  pinMode(blue2, OUTPUT);
  pinMode(blue3, OUTPUT);
  pinMode(blue4, OUTPUT);
}

void processR(const unsigned int value){
  analogWrite(red1, value);
  analogWrite(red2, value);
  analogWrite(red3, value);
  analogWrite(red4, value);

}
void processG(const unsigned int value){
  analogWrite(green1, value);
  analogWrite(green2, value);
  analogWrite(green3, value);
  analogWrite(green4, value);
}
void processB(const unsigned int value){
  analogWrite(blue1, value);
  analogWrite(blue2, value);
  analogWrite(blue3, value);
  analogWrite(blue4, value);
}
void processM(const unsigned int value){
  //Nothing happens here yet.
}

void handlePreviousState(){
  switch (state)
  {
  case GOT_R:
    processR (currentValue);
    break;
  case GOT_G:
    processG (currentValue);
    break;
  case GOT_B:
    processB (currentValue);
    break;
  case GOT_M:
    processM (currentValue);
    break;
  }  // end of switch  

}
void processIncomingByte(const byte c){
  if (isdigit (c))
  {
    currentValue *= 10;
    currentValue += c - '0';
  }  // end of digit
  else 
  {

    // The end of the number signals a state change
    handlePreviousState ();

    // set the new state, if we recognize it
    switch (c)
    {
    case 'R':
      state = GOT_R;
      break;
    case 'G':
      state = GOT_G;
      break;
    case 'B':
      state = GOT_B;
      break;
    case 'M':
      state = GOT_M;
      break;
    default:
      state = NONE;
      break;
    }  // end of switch on incoming byte
  } // end of not digit  
}
void loop() {      
  if (Serial.available ()){
    processIncomingByte (Serial.read());
  }    
}

Until now I send a byte[] in Java to my COM port, but because I (possibly) made a mistake in my sketch it won't read the values as expected.

This has got very confused, even without the totally irrelevant interventions by and on behalf of @BulldogLowell.

@binux, if this was my project I would divide my Arduino sketch into more separate functions.

First, I would have a function whose ob is to receive and save whatever comes from the PC without making any attempt to act on it. Among other things this would facilitate debugging because it would be short, specific and would allow the received contents to be viewed on the Serial Monitor.

Second, I would design the format of the data that will be sent by the PC so it can be sent from the Serial Monitor for testing purposes.

Third I would design the format of the data from the PC so that it would be easy for the Arduino to identify the start and end of the data without being confused. One simple way is to send a "<" to mark the start of the data and a ">" to mark the end.

Fourth when I could reliably receive whatever needs to be sent from the PC I would move on to create a function that interprets the received data and calls the appropriate action code.

Trying to debug the communications while HOPING the action code will respond appropriately is just a waste of time.

...R

Robin2:
This has got very confused, even without the totally irrelevant interventions by and on behalf of @BulldogLowell.

@binux, if this was my project I would divide my Arduino sketch into more separate functions.

First, I would have a function whose ob is to receive and save whatever comes from the PC without making any attempt to act on it. Among other things this would facilitate debugging because it would be short, specific and would allow the received contents to be viewed on the Serial Monitor.

Second, I would design the format of the data that will be sent by the PC so it can be sent from the Serial Monitor for testing purposes.

Third I would design the format of the data from the PC so that it would be easy for the Arduino to identify the start and end of the data without being confused. One simple way is to send a "<" to mark the start of the data and a ">" to mark the end.

Fourth when I could reliably receive whatever needs to be sent from the PC I would move on to create a function that interprets the received data and calls the appropriate action code.

Trying to debug the communications while HOPING the action code will respond appropriately is just a waste of time.

...R

Good point. I guess you already saw that I came up with a function that worked out well, but as GoForSmoke is right that it blocks my execution (even if it's a really short block) I was thinking to take his advice and create a sketch that is able to receive data independently(or at least a bit more, since the processor can only run one operation at a time). As I understand you, you kinda want that I do the same. Splitting up the read from the main function. I will do that and report. In the end I want a code that works. I need a sketch that receives the RGB values and another independent value that can for example run another function (trigger patterns etc). I want to send those values from a Java GUI. As you might know Java can only send either a byte[] or an integer.

@GoForSmoke,

thanks.

GoForSmoke:
BTW looking through your code, is shiftout and shiftin for SPI because I don't find a #include.
Which Arduino are you using? Not an UNO.

Yeah, the pins are wrong, I intended to do this with a mega before I split it to two smaller Ardiuinos. I have not been to the hardware to get this working yet. I needed to process the serial first. I'm going to start the wiring this week, so I'll have to get that sorted.

On the Master Arduino, I am using shiftOut() as an alternative to SPI because I have a crowded pin 10 with the radio i am using, I opted for the shortcut to learning how to get the shift register working with the Radio. that being said, I just went right to shiftOut on the slave.

also these

int pwmPin  =  40;   //PartlyCloudy

int pwmPin2 =  41;   //PartlyCloudy
int pwmPin3 =  42;   //OverCast
int pwmPin4 =  43;   //Overcast
int pwmPin5 =  44;   //Thunderstorms
int pwmPin6 =  45;   //Thunderstorms
int pwmPin7 =  46;   //Sunny
int pwmPin9 =  47;   //Cloudy
int pwmPin10 = 48;   //Cloudy
int pwmPin11 = 49;   //Rain
int pwmPin12 = 50;   //Rain
int pwmPin13 = 51;   //Snow
int pwmPin14 = 52;   //Snow



could be this and save on RAM 


const byte pwmPin0 = 39; // and the pins are pwmPin0 + pin #

thanks. as above point, I'll clean that up too, thanks for the shortcut.

All of these ... soft-SPI blocks. The only difference is the data. You only need one function, without the delay().

        digitalWrite(latchPin, LOW);

shiftOut(dataPin, clockPin, LSBFIRST, 0x00);  
       shiftOut(dataPin, clockPin, LSBFIRST, 0x00);  
       shiftOut(dataPin, clockPin, LSBFIRST, 0x01);  
       digitalWrite(latchPin, HIGH);
       delay(100);




And you have a lot of functions that could be generalized and run on fed data.

yeah, I wanted to get it all working then lean it out.

What's the functional difference in the 2 below?

  if (masterMessage[0] >= 'A' &&  masterMessage[0] <= 'E' || masterMessage[0] == 'F'){
  if (masterMessage[0] >= 'A' &&  masterMessage[0] <= 'F' ){

As i suspect you already know :), none. I inserted your shortcut code and didn't grab the 'E' part, and the mistake was lucky!

Thanks.

@BulldogLowell - since you admit to being the interloper here

I'm not trying to hijack this thread, but I'm having a similar issue.

how about taking a copy of all of the posts relevant to your concerns, pasting them into a new Thread of your own and deleting them from here?

Your hijacking has mde it very difficult to help @binux.

...R

Robin2:
@BulldogLowell - since you admit to being the interloper here

I'm not trying to hijack this thread, but I'm having a similar issue.

how about taking a copy of all of the posts relevant to your concerns, pasting them into a new Thread of your own and deleting them from here?

Your hijacking has mde it very difficult to help @binux.

...R

Is it that confusing about who wrote which post? To split a thread, ask a moderator because it might be fairly easy (or not) for them.

It's fiddly, so I'd prefer to ask Bulldog Lowell not to do it again.

@AWOL,

Right, I read this:

binux:
To end this topic also solved for me, I'll post the code I use now and which works well below:

and having my original question (directly related to topic) answered, it just begged a follow-on conversation. I didn't see it as 'making it difficult' or 'confusing' since the OP was satisfied. Sometimes it happens that a fruitful conversation may evolve from a basic question/answer rapport.

However, I'm a gentleman and can move other elements to another thread. :slight_smile: I maintain that I reject the 'interloper' comment; I thought this was a "forum."

Cheers!

binux:
Until now I send a byte[] in Java to my COM port, but because I (possibly) made a mistake in my sketch it won't read the values as expected.

You were missing 1 line that set currentValue to zero after writing the value to the pins. That's how close you were.

I want to express again that Nick's example has no error checks, you have to feed it good data, I added something to keep the serial writes in range 0-255.

This copy runs on Serial Monitor with the alternate PWM writes commented out.
However I also commented out but otherwise left the Old Code in as well, so don't uncomment everything!

Remember that input is letter-number with no space between. However
R200 G100 B0
works.

Tested and working on serial monitor.

// This is based on the sketch:
// Example state machine reading serial input
// Author: Nick Gammon
// Date: 17 December 2011

// pins for the LEDs:
typedef enum { 
  RED, GREEN, BLUE } 
color;
const byte rgb[ 4 ][ 3 ] = { 
  2,3,4, 5,6,7, 8,9,10, 11,12,13 };
/*
const int red1 = 2;
 const int green1 = 3;
 const int blue1 = 4;
 
 const int red2 = 5;
 const int green2 = 6;
 const int blue2 = 7;
 
 const int red3 = 8;
 const int green3 = 9;
 const int blue3 = 10;
 
 const int red4 = 11;
 const int green4 = 12;
 const int blue4 = 13;
 */

typedef enum {
  NONE, GOT_R, GOT_G, GOT_B, GOT_M} 
states;

states state = NONE;

#define MAXIMUMVALUE 255
unsigned int currentValue;

void setup() {
  // initialize serial:
  Serial.begin(9600);

  state = NONE;
  // make the pins outputs:
  for ( byte i = 0; i < 4; i++ )
  {
    for ( byte j = 0; j < 3; j++ )
    {
      pinMode( rgb[ i ][ j ], OUTPUT);
      /*
       pinMode(red2, OUTPUT);
       pinMode(red3, OUTPUT);
       pinMode(red4, OUTPUT);
       
       pinMode(green1, OUTPUT);
       pinMode(green2, OUTPUT);
       pinMode(green3, OUTPUT);
       pinMode(green4, OUTPUT);
       
       pinMode(blue1, OUTPUT);
       pinMode(blue2, OUTPUT);
       pinMode(blue3, OUTPUT);
       pinMode(blue4, OUTPUT);
       */
    }
  }
}

void processR(const unsigned int value)
{
  for ( byte i = 0; i < 4; i++ )
  {
    //    analogWrite( rgb[ i ][ RED ], value );
    Serial.print( "RED " );
    Serial.println( value );
  }
  /*
   analogWrite(red1, value);
   analogWrite(red2, value);
   analogWrite(red3, value);
   analogWrite(red4, value);
   */
}
void processG(const unsigned int value){
  for ( byte i = 0; i < 4; i++ )
  {
    //    analogWrite( rgb[ i ][ GREEN ], value );
    Serial.print( "GREEN " );
    Serial.println( value );
  }
  /*
   analogWrite(green1, value);
   analogWrite(green2, value);
   analogWrite(green3, value);
   analogWrite(green4, value);
   */
}
void processB(const unsigned int value){
  for ( byte i = 0; i < 4; i++ )
  {
    //    analogWrite( rgb[ i ][ BLUE ], value );
    Serial.print( "BLUE " );
    Serial.println( value );
  }
  /*
   analogWrite(blue1, value);
   analogWrite(blue2, value);
   analogWrite(blue3, value);
   analogWrite(blue4, value);
   */
}
void processM(const unsigned int value){
  //Nothing happens here yet.
}

void handlePreviousState(){
  switch (state)
  {
  case GOT_R:
    processR (currentValue);
    break;
  case GOT_G:
    processG (currentValue);
    break;
  case GOT_B:
    processB (currentValue);
    break;
  case GOT_M:
    processM (currentValue);
    break;
  }  // end of switch  

  currentValue = 0; // this is in Nick's code and was missing in Binux
}

void processIncomingByte(const byte c){
  if (isdigit (c))
  {
    currentValue *= 10;
    currentValue += c - '0';
    
    if ( currentValue > MAXIMUMVALUE )
    {
      currentValue = 0;
      state = NONE;
    }
  }  // end of digit
  else 
  {

    // The end of the number signals a state change
    handlePreviousState ();

    // set the new state, if we recognize it
    switch (c)
    {
    case 'R':
      state = GOT_R;
      break;
    case 'G':
      state = GOT_G;
      break;
    case 'B':
      state = GOT_B;
      break;
    case 'M':
      state = GOT_M;
      break;
    default:
      state = NONE;
      break;
    }  // end of switch on incoming byte
  } // end of not digit  
}
void loop() {      
  if (Serial.available ()){
    processIncomingByte (Serial.read());
  }    
}

BulldogLowell:
@AWOL,

Right, I read this:

binux:
To end this topic also solved for me, I'll post the code I use now and which works well below:

and having my original question (directly related to topic) answered, it just begged a follow-on conversation. I didn't see it as 'making it difficult' or 'confusing' since the OP was satisfied. Sometimes it happens that a fruitful conversation may evolve from a basic question/answer rapport.

However, I'm a gentleman and can move other elements to another thread. :slight_smile: I maintain that I reject the 'interloper' comment; I thought this was a "forum."

Cheers!

Send me a PM when you're situated or post the location of the new thread so that others may follow along too.