Pages: [1] 2   Go Down
Author Topic: Serial Communication Problem (Continuous rotation servo)  (Read 1553 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello, I have SpringRC SM-S3317SR continuous servo rotation.
When I send run("r") and stop("s") commands first time, there is no problem. However, if I want to send commands secondly, below error occurs. Please help me.

java.io.IOException: Input/output error in writeArray
   at gnu.io.RXTXPort.writeArray(Native Method)
   at gnu.io.RXTXPort$SerialOutputStream.write(RXTXPort.java:1124)
   at processing.app.Serial.write(Serial.java:517)
   at processing.app.Serial.write(Serial.java:540)
   at processing.app.SerialMonitor.send(SerialMonitor.java:200)
   at processing.app.SerialMonitor.access$100(SerialMonitor.java:32)
   at processing.app.SerialMonitor$4.actionPerformed(SerialMonitor.java:96)
   at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
   at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
   at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
   at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
   at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
   at java.awt.Component.processMouseEvent(Component.java:6263)
   at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
   at java.awt.Component.processEvent(Component.java:6028)
   at java.awt.Container.processEvent(Container.java:2041)
   at java.awt.Component.dispatchEventImpl(Component.java:4630)
   at java.awt.Container.dispatchEventImpl(Container.java:2099)
   at java.awt.Component.dispatchEvent(Component.java:4460)
   at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
   at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
   at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
   at java.awt.Container.dispatchEventImpl(Container.java:2085)
   at java.awt.Window.dispatchEventImpl(Window.java:2475)
   at java.awt.Component.dispatchEvent(Component.java:4460)
   at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
   at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
   at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
   at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

My code is ;
Code:
#include <Servo.h>
 
Servo myservo;  // create servo object to control a servo
 
void setup()
{
  Serial.begin(9600);
  Serial.println("   Continuous Servo Control");
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}
 
void loop()
{
  while (Serial.available())
  {
    delay(10); 
    if (Serial.available()>0)
    {
            char c = Serial.read();  //gets one byte from serial buffer           
            if(c=='s')
            {
               myservo.writeMicroseconds(1500);  // Stop                         
            }
            if(c=='r')
            {
               myservo.writeMicroseconds(1600);
            }           
     }
     delay(1000);
   }
}
Logged

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

Are you sure that those error messages came from the arduino and not something else like Processing? Can you post the code that is generating the error.
Logged

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

Yes, these messages came from Arduino. You can find codes in my first message
Logged

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

You said that the error messages come the second time you use the commands. So if the code is running on the arduino then it can not generate any error messages, that simply is not how it works.
If it is during compilation or upload that is an other matter.
Can you clarify exactly what is running when you see this.
Logged

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

After I send command second time, I can not compile code and I can not send commands again because arduino board can not communicate with PC.

After I unplug the USB cable from usb port and then I connected the USB cable to PC, I can send command and compile code.

Logged

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

Send the command from what? What is running that sends the command?
The Arduino board can not generate error messages.

Have you tried disconnecting the servo, interference could be crashing your computer.
« Last Edit: November 20, 2012, 03:29:31 am by Grumpy_Mike » Logged

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

The commands; run ("r") and stop("s"). You can see this in my code. Please look at attached file

Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25773
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How are you sending the commands?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

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

So you are sending the commands from the serial monitor.

The odd thing is that from the screen dump the last command sent looks like r and yet the arduino is echoing Stop.

What is crashing is the serial monitor program. Have you physically removed the servo and run the code again? Does it still crash?
If so it looks like your installation is wrong. Try reinstalling it.
Logged

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

AWOL, I send commands from the serial monitor.

Grumpy_Mike, to send commands again, USB cable must be unplugged and replugged. I think that problem results from my code because after sending r and s commands the connection between PC and arduino breaks off.

I have tried to reinstrall program bu this did not solve the problem.

Is there anyone who tried to compile,upload codes and send these commands ?
Logged

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

Code:
while(Serial.available())
{
   delay(10);  // We KNOW that there is serial data to read, but, lets sit on our hands for a while anyway

   // Now, even though it is impossible for there to be less data available than last time we looked,
   // (there might be more; there can't possibly be less) let's check again
   if(Serial.available() > 0)
   {

I've added some comments. Perhaps you want to make some code changes after reading them.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25773
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The code compiles and runs on a 2009.
However, I don't have a servo attached.
Do you, and if so, how are you powering it?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

0
Offline Offline
God Member
*****
Karma: 39
Posts: 988
Get Bitlash: http://bitlash.net
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Another possibility: maybe the motor is causing voltage droop and resetting the USB connection uncleanly.

How are you powering the servo?  It needs 700 ma at stall: http://www.phidgets.com/products.php?product_id=3210_0

-br
Logged

UK
Offline Offline
Shannon Member
****
Karma: 222
Posts: 12549
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Another possibility: maybe the motor is causing voltage droop and resetting the USB connection uncleanly.

I think that's a very likely cause. I don't remember the exact wording, but I recall seeing Java stack dumps from the IDE when trying to access an Arduino that had been disconnected, and I think it's very likely the Arduino has crashed/reset down to a power spike or brown-out from the motor.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

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

Reply #8 guys?   smiley-razz
Logged

Pages: [1] 2   Go Up
Jump to: