Pages: [1]   Go Down
Author Topic: USB2SERIAL Converter and Processing Troubleshooting  (Read 604 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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  smiley

~Thanks Idan

Here is the code that I am using

Processing code
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
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);
               
 
}
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13739
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Read the page about Serial.available()  - http://arduino.cc/en/Serial/Available - should help you out
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

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

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
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");
 
}

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

Pages: [1]   Go Up
Jump to: