USB2SERIAL Converter and Processing Troubleshooting

Hello, I have been having some trouble getting Processing code to send data though the USB2SERIAL to the Arduino. The SoftwareSerial library is what i'm using to take the incoming information and then mySerial.print(val) the value back to the computer. This is where I run into problems: the Arduino can print things to the computer through the USB2SERIAL converter, but when information is sent to the Arduino from a PC and the Arduino printing them back to the PC is when things stop working correctly. The serial monitor shows a mess of information.

Here is the output:

I Received: -1
I Received: -1
I Received: -1
I Rec255
I Recei
I ReceivedReceived: -1
Ieived: -1
I Reed: -1
I Recei -1
I ReceivedReceived: -1
Ieived: -1
I Reced: -1
I Recei -1
I Received2
I Received: I Received: -1
eceived: -1
I Rece: -1
I Receiv15
I Received:

I'm am rather confused on where the -1 and 255 is coming from, because the number sent to the Arduino from Processing is a 15, which only shows up once and a while. The couple of things I thought that it could be is: packet collisions and Processing is saying: RXTX Warning: Removing stale lock file. /var/lock/LK.059.033.126

Any help would be appreciated

This is being ran on:
OS X 10.8.2 (12C60)
2.2 GHz Intel Core i7
8 GB 1333 MHz DDR3

If this is the wrong place to post this please forgive me :slight_smile:

~Thanks Idan

Here is the code that I am using

Processing code

import processing.serial.*;
int i;
Serial port;

void setup()
{
println(Serial.list());
port = new Serial(this, Serial.list()[4], 9600);

}

void draw()
{

  port.write(15);
  delay(100);
  println("testing");
 
}

Arduino code

#include <SoftwareSerial.h>

int i;

SoftwareSerial mySerial(9,8); //set tx and rx pins

void setup(){ 
  
//set up serial comunication
mySerial.begin(9600);  //speed of serial port used by NewSoftSerial

}

void loop()
{
  
                // read the incoming byte:
                i = mySerial.read();
                //then print it
                mySerial.print("I Received: ");
                mySerial.println(i);
                
  
}

Read the page about Serial.available() - Serial.available() - Arduino Reference - should help you out

That seemed to help, but the output is still a little cut-off. The cut-off "I received" messages seems to indicate that i'm am sending data faster than the 9600 baud connection can transmit it. Is this true? If so how do I go about fixing it?

Here is the output:

Ic
eved: 2
Ieed: 2
IRe
Ic
IReivd
ReIReed
I d2Ie
RecIeed2Ic
ee
Iieved: 2
Ie
Iieved: 2
Iecie d
Rce
RecIRc
IRv:
Ie
RecIe:
Iieved: 2
Ie2I ieved: 2
c
Rd2
Reeci Re

I'm assuming that how i'm slowing down the rate to 9600 baud is incorrect, because the output seems cut-off still. I didn't think that the baud rate can be slowed down on the computer (4800 baud) and still be at 9600 on the Arduino board, right? How would you slow down how fast the data is sent?

~Thanks Idan

Here is the code

import processing.serial.*;
int i;
Serial port;

void setup()
{
println(Serial.list());
port = new Serial(this, Serial.list()[4], 9600);

}

void draw()
{

  port.write(2);
  delay(1000);
  println("testing");
 
}
int incomingByte = 0;   // for incoming serial data
#include <SoftwareSerial.h>
SoftwareSerial mySerial(9,8); 

void setup() {
        mySerial.begin(9600);     // opens serial port, sets data rate to 9600 bps
}

void loop() {

        // send data only when you receive data:
        if (mySerial.available() > 0) {
                // read the incoming byte:
                incomingByte = mySerial.read();

                // say what you got:
                mySerial.print("I Recieved: ");
                mySerial.println(incomingByte, DEC);
                
        }
}