Arduino Forum

Using Arduino => Interfacing w/ Software on the Computer => Topic started by: Uptown on Mar 13, 2013, 11:01 pm

Title: Processing to Arduino, mistakes while transfering data
Post by: Uptown on Mar 13, 2013, 11:01 pm
Hello everyone, I allready tried to send data from processing to arduino. The problem is that not all numbers arrive at arduino.

I see this Serial Monitor
Quote

2234
42
42
242
2242
4
2
4
instead of every line repeating 234

My arduino code

Code: [Select]

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

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



my processing code

Code: [Select]

import processing.serial.*;
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(2000);
    }


Thanks

P.S. I know that I can only send from Processing to Arduino 8byte on data. 234<255.

I have some doubts about it. It seems to me that arduino dont get the data because of some reasons. 
The one is maybe the cable issue, contact or the length of it ??? I allready tried with another one, doesnt work

another ideas?


2nd p.s. the strange thing is if i send data from arduino to processing it works perfectly
Title: Re: Processing to Arduino, mistakes while transfering data
Post by: PaulS on Mar 13, 2013, 11:07 pm
Quote
I see this Serial Monitor

Maybe you ought to close the Serial  Monitor, then. Windows will (properly) only allow one application to connect to the serial port at a time. Having Processing AND Serial Monitor connected to the serial port, at the same time, on wonky operating systems is not a good thing.
Title: Re: Processing to Arduino, mistakes while transfering data
Post by: Uptown on Mar 13, 2013, 11:41 pm
well, I do all this on Mac and you are probably right. But how can I know then whether the data is sent correct or not, if I' can't open the Serial monitor?

I was allready thinking about the processing program. I think it doesn't depend on it, because I use the newest one. And also don't need a library for communication with arduino, it's in processing implemented.

Should I try asking people on Processing Forum?! I dont know, seems to me that is a hardware issue. hm?!
Title: Re: Processing to Arduino, mistakes while transfering data
Post by: Grumpy_Mike on Mar 13, 2013, 11:45 pm
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.
Or echo back what you recieve and use processing to see what is recieved, it should be the same as what you sent.
Title: Re: Processing to Arduino, mistakes while transfering data
Post by: PaulS on Mar 14, 2013, 12:22 am
Quote
But how can I know then whether the data is sent correct or not, if I' can't open the Serial monitor?

You don't seem to be aware that Processing can READ from the serial port, too, and print in its window.
Title: Re: Processing to Arduino, mistakes while transfering data
Post by: Uptown on Mar 14, 2013, 12:25 am
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.
Title: Re: Processing to Arduino, mistakes while transfering data
Post by: PaulS on Mar 14, 2013, 12:33 am
Showing us output without showing the sending and receiving isn't all that helpful.
Title: Re: Processing to Arduino, mistakes while transfering data
Post by: Uptown on Mar 14, 2013, 08:30 am
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);
    }
Title: Re: Processing to Arduino, mistakes while transfering data
Post by: Grumpy_Mike on Mar 14, 2013, 08:52 am
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.
Title: Re: Processing to Arduino, mistakes while transfering data
Post by: Zaplady on Mar 16, 2013, 09:15 am
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
Title: Re: Processing to Arduino, mistakes while transfering data
Post by: mixania on Mar 18, 2013, 03:21 pm
You should check the Serial Monitor baud rate too. It is supposed to be 9600bps.