Controlling multiple servos

Hi Everyone,

First, I'd like to state that I just started messing around with Arduino and its forums, so I'm sorry if this post is in the wrong category.

I'm currently trying to control 6 servos with an Arduino Uno, which is connected to my Macbook. I have a java program which detects key-presses and sends the keys to the Arduino, which then controls the servos based on which keys I pressed.

The program worked fine for 2 servos, but when I connected all 6 to the Arduino, I got the error message "java.io.IOException: Device not configured in writeArray". In addition, the servos seemed to jitter a lot for no reason.

My question is: Is this problem caused by software or hardware? The system is setup with 6 servos powered by the Arduino, which is powered via USB by my computer. Would I need to use a separate power source to power the Arduino?

Thanks for reading my super long post guys :slight_smile: Any feedback would be appreciated

That error message seems to point to a problem with your Java program. If so you should probably look for advice on a Java Forum.

It is impossible to give useful feedback without seeing your program code.
And please use the code button </> so your code looks like this and is easy to copy to a text editor

You may find Serial Input Basics useful.

...R

Thanks for your input Robin2, I'll check out the Java forum and your tutorial.

The system is setup with 6 servos powered by the Arduino, which is powered via USB by my computer.

That is the most frequent mistake people make with servos.

Hi zoomkat, may you tell me what part of my setup is incorrect, or not recommended? Thanks!

kso678:
Hi zoomkat, may you tell me what part of my setup is incorrect, or not recommended? Thanks!

Powering servos from the Arduino 5V output. The voltage regulator on the Arduino cannot supply enough current.

zoomkat:
That is the most frequent mistake people make with servos.

Shoot. I missed that.

But it would not give rise to the error message the OP was getting.

...R

Hmmm, I messed around with the servos a couple more times, and I noticed that the error message is only given if I use a specific set of servos. Assuming I use an external power supply, would these issues be resolved?

Also, would the external power supply be connected to the Arduino or the servos?

kso678:
I noticed that the error message is only given if I use a specific set of servos.

Just to clarify this: Assume I have servo1, servo2, servo3....servo6. If I connect only 1 servo the the Arduino and control it with my keyboard, servo1 never crashes the program, but servo6 and servo4 always send me this heaping load of errors:

java.io.IOException: Device not configured in writeArray
	at gnu.io.RXTXPort.writeArray(Native Method)
	at gnu.io.RXTXPort$SerialOutputStream.write(RXTXPort.java:1124)
	at SerialComm.sendData(SerialComm.java:79)
	at SerialComm.keyPressed(SerialComm.java:173)
	at java.awt.Component.processKeyEvent(Component.java:6483)
	at java.awt.Component.processEvent(Component.java:6302)
	at java.awt.Container.processEvent(Container.java:2234)
	at java.awt.Window.processEvent(Window.java:2029)
	at java.awt.Component.dispatchEventImpl(Component.java:4881)
	at java.awt.Container.dispatchEventImpl(Container.java:2292)
	at java.awt.Window.dispatchEventImpl(Window.java:2750)
	at java.awt.Component.dispatchEvent(Component.java:4703)
	at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1954)
	at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:806)
	at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:1074)
	at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:945)
	at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:771)
	at java.awt.Component.dispatchEventImpl(Component.java:4752)
	at java.awt.Container.dispatchEventImpl(Container.java:2292)
	at java.awt.Window.dispatchEventImpl(Window.java:2750)
	at java.awt.Component.dispatchEvent(Component.java:4703)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
	at java.awt.EventQueue.access$500(EventQueue.java:97)
	at java.awt.EventQueue$3.run(EventQueue.java:709)
	at java.awt.EventQueue$3.run(EventQueue.java:703)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)
	at java.awt.EventQueue$4.run(EventQueue.java:731)
	at java.awt.EventQueue$4.run(EventQueue.java:729)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

If I connect only 1 servo the the Arduino and control it with my keyboard, servo1 never crashes the program, but servo6 and servo4 always send me this heaping load of errors:

Kind of like keep hitting your hand with a hammer and wondering why your hand keeps hurting.

zoomkat:
Kind of like keep hitting your hand with a hammer and wondering why your hand keeps hurting.

Though I do appreciate your response, I don't see how that contributes to my question or problem...

kso678:
Though I do appreciate your response, I don't see how that contributes to my question or problem...

Per your previous statements you indicate you are trying to power the servos from the arduino, which will probably crash the arduino. If your pc also makes a sound when this happens, you are also overloading the pc USB port. Servos need an external power supply.

Edit: attached is a pix of powering a servo from an external power supply.

servo power.jpg

I see... Thanks for your help zoomkat :slight_smile: I'll test this as soon as I can.

Robin2:
Shoot. I missed that.

But it would not give rise to the error message the OP was getting.

...R

Yes it would - over-current would hard-close the USB device and lead to the Java serial
driver seeing it unconfigured when it next tried I/O.

Powering a motor or servo from the USB 5V is asking for very expensive damage to your
computer - never do this.

MarkT:
Yes it would - over-current would hard-close the USB device and lead to the Java serial
driver seeing it unconfigured when it next tried I/O.

I stand corrected - and thank you for pointing it out.

It had not occurred to me he could be drawing that much power. Probably because I would never have thought of powering several servos from an Arduino.

...R

Thank you all for your responses, they are all extremely helpful and gave me a lot more insight to Arduino. I'll try using an external power supply as soon as possible. Hopefully it works!