Arduino Serial write -


i trying use arduinon serial.write(buf, leng). here code

byte buf[] = {125, 126, 127, 128, 129};  void setup() {   // initialize serial:   serial.begin(9600);  }  void loop() {   int = serial.write(buf, sizeof(buf));   serial.println(i);   delay(1000); } 

however, when open serial monitor prints out

}~   5 }~   5 }~   5 }~   5 

first off, read write writes binary data serial port , print ascii characters. how come see ascii characters?

the second question how come nothing on 127 appears?

whenever serial.write(>127) shows in serial monitor goofy output?

is because of computer's side of serial?

my main goal write 32 bytes serial @ once in same payload of xbee transmitting package. ??

the output correct. writing binary data, trying see them ascii, that's why see example } instead of 125, because 1 byte 125 represents } in ascii. 125 take 3 bytes show ascii.

you seeing weird stuff when write byte greater 127, because ascii includes definitions 128 characters (0 127).

if on receiving circuit want read exact same array have on code here, sketch fine. you'll have use kind of "serial read", , use numbers want, keeping in mind each number has byte size.

on other hand, if want see numbers on serial monitor, represented ascii characters, either have convert these numbers ascii code, or use loop printing numbers integers println function:

int numbers[] = {125, 126, 127, 128, 129}; for(int = 0; < (sizeof(numbers) / sizeof(numbers[0])); i++)     serial.println(numbers[i]); 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -