Pages: [1]   Go Down
Author Topic: Processing to Arduino, mistakes while transfering data  (Read 1037 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 44
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
byte recieve;
void setup()
{
  Serial.begin(9600);
}

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


my processing code

Code:
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
« Last Edit: March 13, 2013, 05:02:47 pm by Uptown » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 44
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?!
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 597
Posts: 33328
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 44
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: March 13, 2013, 06:29:41 pm by Uptown » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 44
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

the code

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

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


processing

Code:
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);
    }
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 597
Posts: 33328
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

UK
Offline Offline
Newbie
*
Karma: 0
Posts: 34
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: March 16, 2013, 03:20:38 am by Zaplady » Logged

Westbrook, CT
Offline Offline
Full Member
***
Karma: 2
Posts: 139
"Why should I bother with made-up games when there are so many real ones going on." (c) Kurt Vonnegut
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You should check the Serial Monitor baud rate too. It is supposed to be 9600bps.
Logged

Arduino Uno R3
Mac OSX Lion


Pages: [1]   Go Up
Jump to: