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
~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);
}
Well, I'm still running into problems :'( When I set some servos to move to a postion coming from the PC they move to the a different place then what is being sent. On these particular servos a 0 corresponds to all the way one way and 1023 all the way the other direction, so if a 511 would be about center. When the PC writes 511 to the board the servo doesn't move to that postion... But when the if a 2 is written to the board it moves to a different postion then a 511, but still the wrong place. Any ideas on what is happening here would be helpful, I'm kind of in the dark on this one.
~Thanks Idan
Here is the Arduino code
int incomingByte = 0; // for incoming serial data
#include <SoftwareSerial.h>
#include <DynamixelSerial.h>
SoftwareSerial mySerial(9,8);
void setup() {
mySerial.begin(9600); // opens serial port, sets data rate to 9600 bps
Dynamixel.begin(1000000,2); // Inicialize the servo at 1Mbps and Pin Control 2
}
void loop() {
// send data only when you receive data:
if (mySerial.available() > 0) {
// read the incoming byte:
incomingByte = mySerial.read();
Dynamixel.moveSpeed(1,incomingByte,300); // Move the Servo 1, 2, and to what is read from the serial port at a move speed
Dynamixel.moveSpeed(2,incomingByte,300); //of 300
Dynamixel.moveSpeed(3,incomingByte,300);
}
}
Here is the Processing code
import processing.serial.*;
Serial port;
void setup()
{
println(Serial.list());
port = new Serial(this, Serial.list()[4], 9600);
}
void draw()
{
port.write(511);
delay(1000);
println("testing");
}