Go Down

Topic: Serial Communication Problem (Continuous rotation servo) (Read 1 time) previous topic - next topic

shadowcand

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: [Select]
#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);
   }
}

Grumpy_Mike

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.

shadowcand

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

Grumpy_Mike

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.

shadowcand

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.


Grumpy_Mike

#5
Nov 20, 2012, 09:27 am Last Edit: Nov 20, 2012, 09:29 am by Grumpy_Mike Reason: 1
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.

shadowcand

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


AWOL

"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.

Grumpy_Mike

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.

shadowcand

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 ?

PaulS

Code: [Select]
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.

AWOL

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?
"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.

billroy

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

PeterH


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.
I only provide help via the forum - please do not contact me for private consultancy.

Grumpy_Mike


Go Up