I am working on my final year project these days which is Arduino based hexapod. I am using Ubuntu 12.04 operating system. Everything was going perfect till last night but today when i tried to check my code its showing me errors and I am unable to communicate with arduino. I am using Arduino Mega 2560.
Here is my code:
#include <Servo.h>
const int normal_angle = 90;
Servo leg1_servo_1;
Servo leg1_servo_2;
Servo leg1_servo_3;
void setup() {
Serial.begin(9600);
leg1_servo_1.attach(2);
leg1_servo_2.attach(4);
leg1_servo_3.attach(6);
leg1_servo_1.write(normal_angle);
leg1_servo_2.write(normal_angle);
leg1_servo_3.write(normal_angle);
}
void loop() {
if (Serial.available()) {
byte incomingByte = Serial.read();
while (incomingByte != '\n') {
if (incomingByte == 'w' || incomingByte == 'W')
move_forward();
if (incomingByte == 'd' || incomingByte == 'D')
move_right();
incomingByte = Serial.read();
}
}
}
void move_forward() {
leg1_servo_2.write(normal_angle - 20);
delay(200);
leg1_servo_1.write(normal_angle + 20);
delay(200);
leg1_servo_2.write(normal_angle);
delay(200);
leg1_servo_1.write(normal_angle);
delay(200);
}
void move_right() {
leg1_servo_2.write(normal_angle - 20);
delay(200);
leg1_servo_3.write(normal_angle + 20);
delay(200);
leg1_servo_2.write(normal_angle);
delay(200);
leg1_servo_3.write(normal_angle);
delay(200);
}
and here are my errors
java.io.IOException: Input/output error in writeArray
at gnu.io.RXTXPort.writeArray(Native Method)
at gnu.io.RXTXPort$SerialOutputStream.write(RXTXPort.java:1173)
at processing.app.Serial.write(Serial.java:469)
at processing.app.Serial.write(Serial.java:492)
at processing.app.SerialMonitor.send(SerialMonitor.java:197)
at processing.app.SerialMonitor.access$100(SerialMonitor.java:31)
at processing.app.SerialMonitor$3.actionPerformed(SerialMonitor.java:86)
at javax.swing.JTextField.fireActionPerformed(JTextField.java:508)
at javax.swing.JTextField.postActionEvent(JTextField.java:721)
at javax.swing.JTextField$NotifyAction.actionPerformed(JTextField.java:836)
at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1662)
at javax.swing.JComponent.processKeyBinding(JComponent.java:2878)
at javax.swing.JComponent.processKeyBindings(JComponent.java:2925)
at javax.swing.JComponent.processKeyEvent(JComponent.java:2841)
at java.awt.Component.processEvent(Component.java:6282)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1895)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:762)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:1027)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:899)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:727)
at java.awt.Component.dispatchEventImpl(Component.java:4731)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:708)
at java.awt.EventQueue$4.run(EventQueue.java:706)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
I have tried small block of codes to check if the board is working properly, and everything is fine.