receiving a byte from Flash

I’ve some trouble receiving bytes from Flash.
I want to sent an 8bit value to a PWM output. I use the serial examples from Beltran Berrocal Arduino code&examples - by b of Progetto25zero1

The problem is that character above 127 ( so 8bit values instead of 7 ) seems to occupie two index values in the serInString array instead of one.

char serInString[100];
char valchar;

if (serInString[0]==73)  // I
    { for (int i=1; i <= digseq; i++)
     { p = i+digout-1;       // output to the right pins
        char valchar=serInString[i];   // what is the letter
        Serial.print(valchar, BYTE);
      }   
      Serial.println();
    }

This code works perfect when sending 7bit characters.

Here a copy from my Flash output window. The 1st, 3rd etc. row is the string I send to the Arduino.

Iÿ00000
Arduino says -- ÿ0000
Iÿÿ0000
Arduino says -- ÿÿ00
Iÿÿÿ000
Arduino says -- ÿÿÿ
Iÿÿÿÿ00
Arduino says -- ÿÿÿ

The ÿ character is 255 or FF in hexadecimal ( maybe this is the reason? ). The zero’s are ascii zero’s, but I couldn’t display them in the forum (its translated in a breakingrule ).
h
When reading indexnumbers higher than 6 ( since I walk through 1,2,3,4,5,6 with the loop ), I get the other characters.

Why is this happening ?

The problem is with Flash. It stores all strings (which are what you send to Arduino) as UTF8, in which bytes over 128 or 192 are stored as multi-byte sequences.

One solution would be to modify a serial proxy to recognize UTF8 encoded bytes coming from Flash and convert them back to their original one byte values. Another is to use Flash 9, which has support for binary sockets which can read and write bytes from 0 to 255. A third option is to send your data in another format, say as the digits '2', '5', '5' or whatever, following by a separator, like a newline or a space, then put these values back together in Arduino.

Thank you for that answer.
I’ve programmed the following solution :
With flash I send this string : I0,000,000,000,0,0
Or this with maximum pwm values : I1,255,255,255,1,1

Arduino code :

digseq=17;    // extra indexes for pwm
p=8;

if (serInString[0]==73)  // I
{ for (int i=1; i <= digseq; i++)
  { if (serInString[i]==',')
      { p++;
      i++;
      }     
    char valchar=serInString[i];
      if(p==8 || p==12 || p==13)                        // digital outputs 
      { if(valchar=='1') digitalWrite(p, HIGH);
      if(valchar=='0') digitalWrite(p, LOW);            
      }
      else                                           // PWM outputs
      { valpwm = 0;
      valpwm = (serInString[i]-48)*100;
      valpwm = valpwm + (serInString[i+1]-48)*10;
      valpwm = valpwm + (serInString[i+2]-48);
      
        i=i+2;
                                    
        analogWrite(p,valpwm);                   
      } 
  }   
}

Well, this works almost perfect.

Sometimes I see the other pwm outputs going on for a short time. When changing another pwm output.
Any idea what is the cause of that ? To much serial data ( I’m also sending a string with all the inputs to Flash ) or someting ?

IntervalTimer in Flash : 100ms
Arduino : delay(40); Serial.begin(57600);