Go Down

Topic: Sending data from Processing to arduino with handshake  (Read 1 time) previous topic - next topic

Robin2

as I was pretty stupid, and was trying to send bytes with the print function. Changed it to "write()" and got it to work fine by then reading the serial input as a byte on the uno side
I do not consider that stupid. My preferred approach is to use the PRINT function to send data in human readable form as it makes debugging very much easier. I would only send data in binary format if it was the only way I could get the performance I needed.

Also, for reliable serial communication is it a very good idea to enclose a message between start- and end-markers and that can be a lot more difficult with binary data because you have to allow for some the data bytes being the same as the markers.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

tactfulyeti

If I wanted to use integers as bytes, could I write a function to exclude 0 and 256 from the possible values being sent, then set those two values as the start-end points? A range of 1-255 is plenty for the motor control i'll be working with.

Robin2

You cannot send the value 256 as a single byte. The max is 255. A simple suggestion would be to use 254 for the start-marker and 255 for the end-marker and just send values from 0 to 253.

I have never considered using 0 as a start-marker so I don't know if it would work. It probably would.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

tactfulyeti

After a bit of testing and messing around with code, I found an issue. I'm going to run through the entire process to try and make it easier fro someone who knows what im doing wrong to identify where. So, just to test sending data to the arduino, I am just trying to send the int 1 from processing to the arduino. I have the line "myPort.write(1);" I believe this should send a 1 to the arduino. I wrote code for the arduino that goes like this
"
  void loop(){
  int test;
  if(Serial.available() > 0){
    test = Serial.read();
    lcd.setCursor(0,1);
    lcd.print(test);}
    }"
 
I have an lcd to display the int that comes in from processing, however, no number gets displayed. I also tested the code by sending a number from another arduino, and it did work. Therefore, I believe the issue is on the processing side of things. I just don't know where.

Robin2

I have the line "myPort.write(1);" I believe this should send a 1 to the arduino.
I am not familiar with Processing but it probably sends the binary value 0b00000001 whereas the character '1' is the binary value 0b00110001

If you use Serial.print() in the Arduino program to print the binary value 0b00000001 you won't see anything.


Have you tried using print rather than write in your Processing program?

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

tactfulyeti

I solved the problem with a few things. So, for anyone who is here for the issue I first had, First try a higher baudrate, 19200 worked for me. Also, there is a library that simplifies the transfer of variables, It is called "VSync for processing" there is also a library for arduino that you will find a download for with the processing library. It worked perfectly for me, and I would try out these two things before pulling all your hair out. Hope this was helpful.

Go Up