char * pch;uint32_t nResult= 0;byte nPos= 0;pch= strtok(buffer, " ");while(pch){ if(nPos > 1) // ignore first and second hex value { nResult= (nResult << 8) | (strtoul(pch, NULL, 16) & 0xff); } nPos++; pch= strtok(NULL, " ");}The code is not efficient or fail save. Basically your string is divided into smaller substrings and in the loop the first two "bytes" are skipped and the following bytes are combined to the result by reading a single byte (result from stroul is 32 bit, hence the mask to 8 bit) and shifting the previous value of the result by 8 bits and placing the read byte into this now free space.

Another approach would be to modify the buffer directly to get those two bytes of interest together without the space in between and then use strtoul().

loved the 68000 assembler back then and now I have to deal with THIS 8 bit thingy

void setup() { Serial.begin(9600); Serial.flush();}Serial.flush() changed in Arduino 1.0. Before it cleared the receive buffer. Since v1.0 it waits for the transmit buffer to be empty / the transmission to be finished. Not really necessary in setup().

while(serialrx != NULL) buffer[i++] = strtoul (serialrx, NULL, 16); i = 6;}And this code is bogus. serialrx is a pointer to an array of characters. serialrx[pos] means one of the characters in the array. This looks like a try in using pointer arithmetics or maybe some very old code for reading the serial receive buffer. The way it is now serialrx is never NULL because it is defined as a global array - the pointer to the array stored in serialrx is not NULL.

From my point you need to learn some of the C programming basics and some C++ to use libraries supplied with Arduino.

Lets go through all step by step. Let us assume all input via serial connection looks like your example string - four hex coded values with spaces between and at the end of the command an "return" ("\n" or "\n\r"). First step is to get the input from Serial. All data arrives bytewise and the ATmega328 on the Arduino is a lot faster than the transmission via Serial. You could use a buffer for the incoming data and when a "return" arrives the whole string is evaluated. While reading data you could filter the spaces out and ignore any '\r' only looking for '\n'. This helps for the second step using strtoul like bubulindo did in his post. For the reading you need some kind of a loop which collects and filters incoming data.

boolean bWaitingInput= true; while(bWaitingInput) { uint8_t nBufferPos= 0; // position in the array where a new character is saved if(nBufferPos >= BUFFER_MAX) // is the buffer full? { serialrx[BUFFER_MAX - 1]= '\0'; // make a valid string by setting the last buffer character to '\0' Serial.print("buffer overflow: "); Serial.println(serialrx); // transmit what the buffer holds for debugging nBufferPos= 0; // reset the buffer } if(Serial.available()) // something arrived via serial connection? { char c= Serial.read(); // read the new character switch(c) { case '\r': case ' ': break; // do nothing with space or '\r' case '\n': serialrx[nBufferPos++]= '\0'; // a string must have 0 at the end, so we add it here bWaitingInput= false; // we have data for evaluation break; default: // all other characters go into the buffer serialrx[nBufferPos++]= c; } } Serial.print("received: "); Serial.println(serialrx);

Now strtoul could be used on serialrx (no spaces to interfere are in the buffer). BUFFER_MAX is a define for the buffer size. Search for "post increment" to understand the filling of the buffer with the position variable. This is for a start. If you have no idea what's going on then use Serial.println() to show you results in the serial monitor. PaulS proposes to use a pen and paper and think of what you would do step by step to get your problem solved - I like this idea.

loved the 68000 assembler back then and now I have to deal with THIS 8 bit thingy