We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am facing some problems sending and using a byte from arduino to processing. My goal would be to make an array of boolean from this byte. If you can, tell me if i am doing something wrong:
In arduino i send a single byte using Serial.write(); In processing I receive using Serial.read();
Problems:
1) looks like that i have a problem of comunication because i reveice much more bytes than i wait. Baudrate is the same and the port is correct.
2) There must be something that i miss because i am forced to use an int to store the value of Serial.read(), why can't i use a byte?
3) i have also problems in working on this byte using the normal | & and ^ operations, same problem as point 2, why am i fprced to use an int to use them? Them are bitwise operations and i would like to use bytes not int!
4) how can i use directly binary data? For example in arduino i use 'B101010' but here seems that i can use only hex
Answers
1) Not much to go on about here. Are you sending the values continuously? What do those other bytes look like? Can you maybe retrieve the bytes you want and ignore the extra?
2) Serial.read() returns an int. If you need bytes instead you can either convert the int to a byte by casting it:
byte b = (byte) Serial.read();
or use
Serial.readBytes()
orSerial.readBytesUntil()
, see: https://www.processing.org/reference/libraries/serial/3) Bitwise operations should work on ints
4) That's similar as in Java. Use the prefix "0b":
or if you want to use bytes:
yes continuously
thanks for point 4, i was used to arduino's 'B' and i didn't know this formatter about point 3, yes they work good with int but not with byte (i would like to understand why but it is not important for my project)
arduino code:
tipical byte i send from it: 1011101 1010101
processing code that doesn't work at all:
I misunderstood your point 3. Hmmm, you're right, that never bothered me before. You can do
int c = a|b
where a and b are bytes, but c has to be int. If it's really bothering you, you can cast them back to byte.In your Arduino code you are using both write() and print(). Write sends a byte but print sends an ASCII string. After each state byte you send it the ":" symbol in bytes (0x3a or 00111010), possibly with some more bytes. Are you just trying to get the state byte or do you want more? If it's just the state byte you're after you could get rid of the
Serial.print(":");
statement all together and just read bytes. Otherwise you could do aSerial.print()
statement instead of write() and do some string parsing in Arduino and Processing to get the bytes you want.just the state byte nothing more, i thought that i needed the ':' to separate the bytes. as you suggested i removed the Serial.print(":"); but nothing happens :(
i had already tried to send the byte with the Seria.print(); and it works, but i would like to use a byte
https://forum.Processing.org/two/discussion/17900/out-of-control-y-axis-rolling-graph#Item_1
yeppppp it worked! i was using wrong the redBytes. thanks to both of you! (gotoloop if i m not wrong it is the second time you help me here, thank you!)
is here a way to fill an array of values? i tried this without good results:
isLow.fill(isLow[], boolean.false);
http://docs.Oracle.com/javase/8/docs/api/java/util/Arrays.html#fill-boolean:A-boolean-
i was trying to use it before asking here but I don't know why it doesn't work
fill(boolean[]isLow, boolean false);
isLow is my array
Perfect!