Guys...
How to read data as it was send lets say from one arduno to another like that:
byte Str[6];
Str[0]=0x01;
Str[1]=0x0F;
Str[2]=0x00;
Str[3]=0x00;
Str[4]=0x14;
Str[5]=0x1A;
Serial.write(Str, sizeof(Str));
so how to read this 6 char array on other hand... I can see it coming couse I can count the number of bytes exactly 6...
But Serial prints some how you see it;s comin couse the screen scrolling down.. but actually you don see anything....
and also if you please
tall me
how can I assign the value of single byte to Str[4]??? from integer 20
So I have to Send it as 0x14 but I do have this int 20 so how to add this 0x.. I can't use Serial.print function.
What you are shwing is not a string. It's a array of chars. A string in c is a array of chars where the string of characters is delimited by a '\0'. String function will stop processing beyond this delimiter. Any string processing function will process the first two chars in your array and stop at the third. Strings are noramlly used for printable chars (>= 32) but others like tabs newline and carriage returns are also common.
In your case, you are right, you have to count the chars you are receiving. If you want to assign a value to a member of the array you do this by specifying the index (which can be a variable, but make sure its within the array bounds) Str[4] = x; Or Str[ i ] = x;
And Str[] is not a good name in your case since you are not processing strings
Yes Yes arrays I know it... It's just a ....
How to read it though?
you didn't get what I ask... Str[4] = x; not just like that what to do with 0x.. couse it needs to be that way...
How to do Str[4] = 0xx;
When assigning you treat each element of an array as it where a variable of the base type:
Str[ 4 ] = x;//assigning with a variable
Str[ i ] = 30;//assigning with a decimal constant
Str[ i+1 ] = 0x20;//assigning with a hexadecimal constant
Str[ i+j ] = 'c';//assigning with a char constant
You also have the option of assigning a string literal to a char array
Str = "Hello";
This will insert the final delimter ('\0') for you
O boy... Sorry.. I can't explain myself more clearly i guess
here is the thing I need to send byte in the sequence in the array of bytes...
0x01, 0x0F, 0x00, 0x00, 0x14, 0x1A
Str[0], Str[1] Str[2] Str[3] Str[4] Str[5]
Where is Str[3] and Str[4] chageable data....
So I got that data in INT ... And everytime I sending this array the Str[3] and Str[4] will be diefrent
I can not use nothing but Serial.write because it sending the string in binary
and it works only like i found when I assigned the value as 0x
Let's say I got in INT 20
it doesn't work Serial.print(20,BIN)
it works only like Serial.write(0x14)
So i got int 20
How do I from int 20 assigning to byte Str[4] = 0x14;
How to get that 0x14 from int 20 ????
how to get 14 from 20 I know but how to add '0x' to that 14 i don't know
int ch = 20;
byte Str[4] = 0x(ch); So this is a problem
You are absolutely right. I cannot understand what you mean, First of all you are NOT sending a string. You are sending the contents of an array.
Secondly 0x14 and 20 are exactly the same value. As are B00010100 or octal 024. the computer doesn't care but humans might, thats why there are different ways of writing numerals.
If you want to transfer the contents of an int(16 bits) variable you will need to use two 8bit variables (char or byte) and split the 16 bit value between them. This can be done in several ways. One is to use the LowByte() and HighByte() functions. An other is to write the expressions yourself:
Str[3] = x>>8;//high byte of x
Str[4] = x&0xff;//low byte of x
...how can I assign the value of single byte to Str[4]??? from integer 20
You are trying to pour 2 bytes of data (as stored in an int) into a 1 byte bucket, which runs the risk of losing data. To prevent the data loss, use a cast operator:
Str[4] = (byte) 20;
This tells the compiler to squeeze your 2-byte int into a 1-byte byte. When you go to view the data using the Serial object, use:
Serial.println(Str[4], DEC);