Pages: [1]   Go Down
Author Topic: Serial port disconnected when serial monitor is opened  (Read 716 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,

I'am a begginer on Arduino and I have a trouble with the communication between the card and my computer.
I work on windows 7 and I followed the instructions to installt the card driver. After the installation the card (Arduino UNO) is now called "Communication Port (COM3)" on the Windows device manager (Yes I come from France  smiley-lol).
I used the "Arduino Uno.inf" file.

I want to control a servo-motor with instructions of positions that I enter in the serial monitor.
Now I try to upload the folowing code to my board :

#include <Servo.h>

Servo myservo;
int ReceptionOctet=0;
int ReceptionNombre=90;
int SaveReceptionNombre=0;

void setup()
{
  myservo.attach(2);
  myservo.write(90); 
  Serial.begin(9600);
}

void loop()
{
  if (Serial.available()>0)
  {
    ReceptionNombre = 0;
   
    while (Serial.available()>0) {

      ReceptionOctet= Serial.read();
      Serial.print("ReceptionOctet : ");
      Serial.println(ReceptionOctet);
      ReceptionOctet=ReceptionOctet-48;
      Serial.print("ReceptionOctetASCII : ");
      Serial.println(ReceptionOctet);

      if ((ReceptionOctet>=0)&&(ReceptionOctet<=9))     ReceptionNombre = (ReceptionNombre*10)+ReceptionOctet;
     

      delay(1);

    }
  }

  if(ReceptionNombre != SaveReceptionNombre)
  {
    if(ReceptionNombre<0) ReceptionNombre = 0;
    else if (ReceptionNombre>180) ReceptionNombre = 180;

    Serial.print ("Nombre recu= ");
    Serial.println(ReceptionNombre);

    myservo.write(ReceptionNombre);
    SaveReceptionNombre = ReceptionNombre;
    delay(20);
  }
}



--> First I tried the reaction of the program when the servo-motor is not connected to the card.
I write for example "150" in the serial monitor and the card answers good (In French Sorry again ^^ ) :
ReceptionOctet : 49
ReceptionOctetASCII : 1
ReceptionOctet : 53
ReceptionOctetASCII : 5
ReceptionOctet : 48
ReceptionOctetASCII : 0
Nombre recu= 150

But when I connect the servo-motor (Hitec HS-422 : Red wire on 5V, Black wire on GND and Yellow on PWM 2) I immediatly have an error :
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$3.actionPerformed(SerialMonitor.java:89)
   at javax.swing.JTextField.fireActionPerformed(JTextField.java:492)
   at javax.swing.JTextField.postActionEvent(JTextField.java:705)
   at javax.swing.JTextField$NotifyAction.actionPerformed(JTextField.java:820)
   at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1636)
   at javax.swing.JComponent.processKeyBinding(JComponent.java:2851)
   at javax.swing.JComponent.processKeyBindings(JComponent.java:2886)
   at javax.swing.JComponent.processKeyEvent(JComponent.java:2814)
   at java.awt.Component.processEvent(Component.java:6040)
   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.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1848)
   at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:704)
   at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:969)
   at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:841)
   at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:668)
   at java.awt.Component.dispatchEventImpl(Component.java:4502)
   at java.awt.Container.dispatchEventImpl(Container.java:2099)
   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)


Here my serial port has disapeared in the menu and most of time I must disconnect the card from my computer to get it back.

Other things I noted :
- When the motor is connected and the serial monitor is opened the windows device manager screen seems to be refreshed every 5seconds as the card was disconnected and reconnected successively....
- I tried other pins on the card to connect the yellow wire of the servo motor. On pins 2 to 7 I can upload a program to the card when the servo-motor is connected. But on pins 8 to 13 I have the following error message when i try to upload : avrdude: ser_open(): can't open device "\\.\COM3"

Thanks for your help !!!

Olve
Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can't really power servos from the Arduino. Connect the red wire to an external power supply. Make sure that the external power supply ground is connected to the Arduino ground.
Logged

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

Thanks for your reply, I connected the servo motor with external power and it works great !!!   smiley-lol
Logged

Pages: [1]   Go Up
Jump to: