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 ;
#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);
}
}
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.
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.
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.
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 ?
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.
billroy:
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.