That sketch does not compile, nor would it print anything. You should always post the code that produces the output for your question.
[OK, you edited your post so my answer is quite different. This is called "post vandalism". :-/ It's ok to make minor changes, but completely changing the sketch should have been in a second post.]
I think the main problem is understanding the difference between "a pointer to a char", "a char array" and "a char".
- a char is one byte of RAM, typically used to store the ASCII value of a character:
char oneChar = 'A';
Serial.print( oneChar ); // prints an 'A' on the Serial monitor window
- a pointer to a char is the address of the char in RAM:
char oneChar = 'A';
char *ptr = &oneChar; // the "address" of oneChar
- a char array is declared as
char array[ dimension ]; // all zero bytes
char array[] = "initial value, dimension is length+1";
char array[ 128 ] = "initial value fills the first length+1 bytes of the array, remainder are zero bytes";
The array's name is, well, a name for the address of the first element. Array indices start at 0, so the first element can be accessed with
Serial.print( array[0] ); // print one element, a char
Because the array name is also an address, you can get the RAM value stored at that address by "dereferencing" it with the '*' operator:
Serial.print( *array ); // print one element, a char
Complicating the char/array/pointer topics is the concept of a C string. When you use a "double-quoted" string constant (not the String
class), the compiler adds an extra zero byte at the end. That's called the NUL terminator. Many routines can use these "C strings" (e.g., Serial.print). They all know to access sequential elements until a zero byte is encountered. That's the end of the string.
You can pass a char array or a char pointer to Serial.print, and it will print the sequential RAM locations until a zero byte is encountered.
If you pass a char to Serial.print, it will only print one character. Passing *section will only print the first character of the field.
I think you wanted to do this:
void setup() {
Serial.begin( 9600 );
}
void loop() {
const size_t UDP_TX_PACKET_MAX_SIZE = 64;
char packetBuffer[UDP_TX_PACKET_MAX_SIZE] = "ROW1 255 1 2 3 4";
char *ptr;
char *section = strtok_r(packetBuffer, " ", &ptr);
Serial.print( F("section = '") );
Serial.print( section );
Serial.println( '\'' );
char *r = strtok_r(NULL, " ", &ptr);
Serial.print( F("r = '") );
Serial.print( r );
Serial.print( "', r value = " );
Serial.println( atoi(r) );
char *g = strtok_r(NULL, " ", &ptr);
char *b = strtok_r(NULL, " ", &ptr);
char *w = strtok_r(NULL, " ", &ptr);
char *deltaTime = strtok_r(NULL, " ", &ptr);
Serial.print( F("deltaTime = '") );
Serial.print( deltaTime );
Serial.println( '\'' );
delay(1000);
}