Pages: [1]   Go Down
Author Topic: Processing serial to Arduino Mega 2560  (Read 1239 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello I am trying to get the single servo example from the arduino playground (http://www.arduino.cc/playground/Learning/SingleServoExample) working on my arduino mega 2560. The sketches work on/with my uno (after removing the refresh) but when using the mega, the RX light on the mega remains on 100% of the time when processing connects and no servos move. The arduino sketch works when the commands are sent via the the serial monitor but not when the processing it used.

If the sketch's are changed to send and receive a character eg 's' to trigger a switch case event to move the servo to a preset position they work. It appears to have trouble when data sent continually (based on RX remaining on) with the update of the servo position based on the mouse position from processing.

Can someone help with this? I would prefer to use the mega board for this project as there will be a number of servos used.

I am using the arduino 0.22 and processing 1.5.1 IDE's with RXTX version 2.1-7 and have tested in both linux and windows


**EDIT UPDATE**
I just tried the Dimmer example from the learning section of this site and experience the same problem, with the RX light remaining on.
I just checked the firmware version and appears my new mega is not so new, it has been shipped with the rev0000 not the rev0001 firmware, would this cause this problem?
« Last Edit: November 17, 2011, 04:58:38 pm by mawmillar » Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 638
Posts: 50319
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've confirmed that Processing does not talk to the Mega 2560. This problem needs to be reported on the Processing site, since the problem is not with the Arduino. Other apps are able to talk to the Mega just fine.
Logged

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

But if I send single characters from processing I can trigger switch case events in the arduino. The project is a robot/rover, and can send W A S D to move the robot it only the continuous sending of the the instructions for the can pan tilt that processing or the arduino not working with.
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 638
Posts: 50319
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
But if I send single characters from processing I can trigger switch case events in the arduino. The project is a robot/rover, and can send W A S D to move the robot it only the continuous sending of the the instructions for the can pan tilt that processing or the arduino not working with.
This does not match with my experience, but it does go along with the fact that I think there is some kind of timing issue. Perhaps your crystal is a tiny bit faster or slower than mine.
Logged

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

Ok I updated the mega 2560 firmware to rev0001 and installed the arduino 0.23 and the alpha processing 2.0a4 IDE on a windows 7 netbook (in work shhh) and still no luck with everything updated and clean install. The board still shows a continuous RX light when processing connects.
Logged

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

OK done some more testing and found the limits of my setup. I can send commands from processing once every 840 milliseconds.
The Arduino code:
Code:
void setup()
{
  // initialize the serial communication:
  Serial.begin(9600);
}

void loop() {
  byte inByte;

  // check if data has been sent from the computer:
  if (Serial.available()) {
    inByte = Serial.read();
     Serial.println(inByte);
  }
}

The Processing code:
Code:
import processing.serial.*;
Serial port;

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

void draw() {
  while (port.available() > 0) {
  String inString = port.readString();
  println(inString);
  }
  port.write('w');
  delay(840);
}
/*
void keyPressed() {
  port.write(key);
}
*/

I just changed the delay value until I got a response from the arduino. It not the best solution but at least it working. I will try adding this delay to the pan tilt of my robot/rover to see if this solution can be scaled up to a full scale project.
Logged

Pages: [1]   Go Up
Jump to: