Go Down

Topic: Processing to Arduino, mistakes while transfering data (Read 1 time) previous topic - next topic

Uptown

#5
Mar 14, 2013, 12:25 am Last Edit: Mar 14, 2013, 12:29 am by Uptown Reason: 1
PaulS I are right I didnt pay enough attention on this effect that serial monitor can cause. Good that you mentioned it, somehow I forgot it.

Quote
But how can I know then whether the data is sent correct or not, if I' can't open the Serial monitor?
You have to find another way. Say a software serial emulator with a TTL level USB interface.
-> no idea about it

Quote

Or echo back what you recieve and use processing to see what is recieved, it should be the same as what you sent.
-> just did it, the result you can see beneath

Processing said:

Stable Library
=========================================
Native lib Version = RXTX-2.1-7
Java lib Version   = RXTX-2.1-7
RXTX Warning:  Removing stale lock file. /var/lock/LK.012.011.028
sent 234
recieved -1
sent 234
recieved -1
sent 234
recieved -1
sent 234
recieved -1
sent 234
recieved -1
sent 234
recieved -1
sent 234
recieved -1
sent 234
recieved -1
sent 234
recieved -1
sent 234
recieved -1
sent 234
recieved 234
sent 234
recieved 234
sent 234
recieved 234
sent 234
recieved 234
sent 234
recieved 234


Well the first recieved data I can't explain why, normaly when there is no data sent back it returns -1. But after a while it became more stable.

PaulS

Showing us output without showing the sending and receiving isn't all that helpful.

Uptown

the code

arduino
Code: [Select]

byte recieve;
void setup()
{
  Serial.begin(9600);
}

void loop()
{
  if(Serial.available() > 0 )
  {
    recieve=Serial.read();
    delay(50);
    Serial.write(recieve);   
  }



processing

Code: [Select]

import processing.serial.*;
int val;
Serial myPort;
int send=234;

    void setup()
    {
      String arduinoPort = Serial.list()[0];       
       myPort = new Serial(this, arduinoPort, 9600);
       myPort.write(2);
    }
   
    void draw()
    {
     myPort.write(send);
     print("sent ");
     println(send);
     delay(50);
     val = myPort.read();
     print("recieved ");
     println(val);
    }

Grumpy_Mike

Why the delay in the arduino side? Get rid of it.
Why are you not checking serial availability on the processing side?
Those two points address your perceived problem.

Zaplady

#9
Mar 16, 2013, 09:15 am Last Edit: Mar 16, 2013, 09:20 am by Zaplady Reason: 1
Hi
I have just written my first (and only) processing sketch myself and had similar problems as you but solved them when I noticed the following:

The type has to be the same i.e. if you want to receive a byte, you have to send a byte as they are stored differently. A byte is one byte and an int is 2 bytes etc. I notice you have mixed these.

If you want to send something longer than a byte then you need to know when you have all of its component parts before converting it into something else such as an integer.

I used an I2C 16x2 LCD display connected to the Arduino to print any debugging messages as the serial monitor won't work at the same time as processing has the port.

I hope this helps
Mrs Z

Go Up