Turning off usb powering of arduino

I am working on a project where my uno is controlling 8 servos. Occationally there is a problem with the serial communication which controls the motors and i have to unplug the arduino to "fix" it. Then everything is back to normal. The problem is that i am making an interactive installation, so i have to make things work on its own. My plan is to find a way to stop and restart the usb connection between the computer and the arduino automatically when the computer senses that the serial communication is stuck. But now i am stuck trying to find a way to create this usb on/off function. Any help or idea will be highly appreciated!!

Do you know if the problem is with the Arduino or with the host-side serial comms software?

You could post your Arduino sketch so we can try and spot problems with it.

Also you will need to say what operating system you are running and which serial comms
program on the host machine.

If you reset the arduino it should fix the connection problem without needing to unplug the USB.

This is more of a gimmick then anything but wire a output pin to the reset pin. As long as the pin is HIGH everything is fine, when you set it low it will cause itself to reset. For this to work the first line in setup must be to set that output in HIGH or it will forever be in a reset loop. Even then it might not be the most consistent method to use.

Try re-initializing the serial port Serial.begin(XXXX) when you lose connection. It might not work though for several different reasons.

Software reset

asm volatile (" jmp 0");

Kind of the same as the one above it just forces the code back to the start but doesn't clear any of the old register data that might prevent it from resetting a connection.

Google is your friend. :wink:

Thanks!
MarkT: I am not sure if the problem is on the arduino side or Max Msp, but I loose the connection between them and even if i restart Max, nothing happens unless i unplug the Arduino.
and Harddrive123: unfortunally i have tried to reset the arduino instead of unplugging the USB cable, with no luck. But if reseting and unplugging are the same, then this points towards the problems being on Max side?

#include <Servo.h>

Servo servo1; Servo servo2; Servo servo3; Servo servo4; Servo servo5; Servo servo6; Servo servo7; Servo servo8;

void setup() {
  servo1.attach(22); //analog pin 0
  servo2.attach(24); //analog pin 1
  servo3.attach(26); //analog pin 0
  servo4.attach(28); //analog pin 1
  servo5.attach(30); //analog pin 0
  servo6.attach(32); //analog pin 1
  servo7.attach(34); //analog pin 0
  servo8.attach(36); //analog pin 1
  Serial.begin(9600);
}

void loop() 
{
  static int v = 0; //v - which position servo shall move to
   char m = 0;

  if ( Serial.available()) {
    char ch = Serial.read();
    
    switch(ch) 
    {     
      case '0'...'9':   //if serial receive a number btw 0 and 9
        v = v * 10 + ch - '0'; //convert from  ASCII to number
        break;
      case 65:   //A-P tells arduino which motor to run.
        servo1.write(v);
        v = 0;
        break;
      case 66:
        servo2.write(v);        
        v = 0;
        break;
      case 67:
        servo3.write(v);
        v = 0;
        break;
      case 68:
        servo4.write(v);
        v = 0;
        break;
        case 69:
        servo5.write(v);
        v = 0;
        break;
      case 70:
        servo6.write(v);
        v = 0;
        break;
      case 71:
        servo7.write(v);
        v = 0;
        break;
      case 72:
        servo8.write(v);
        v = 0;
        break;
    }
  }
}

I use a macbook, 2,6 Ghz running osx 10.8.5. The host software is Max 6.

Even if i find a problem with the patch it would be nice to be able to cut the power to the arduinos/turn it off at nighttime so they do not burn constantly for half a year…

by the way, when the Max-arduino communication gets stuck, Max puts the word "bsd_path" in front of the serial port when i try to print the serial ports in Max window (for those of you that are familiar with Max). I couldn't even find any info on bsd_path on the Max forum….

Hi,
Can you please post a copy of your circuit, in CAD or picture of hand drawn circuit in jpg, png or pdf format.

How are you powering your servos, not from the 5V of the arduino I hope or the USB port.

Tom...... :slight_smile:

Thanks for replying Tom. Here is a quick sketch of schematics. I do not run from arduino but 5v 2 a power supply for every 2 servos. i also tested current draw, and 2 motors does not draw more than 1,5 a. (Did not find out how to make fritzing software show that + and - are not connected on drawing, but they are not :slight_smile:

Hi, which arduino are you using, and check to see which pins support servo PWM.

Tom...... :slight_smile:

I use an Arduino Uno R3. I did not think that the servo library used PWM?

Hi, yes the library does use any i/o pin.

servo1.attach(22); //analog pin 0
servo2.attach(24); //analog pin 1
servo3.attach(26); //analog pin 0
servo4.attach(28); //analog pin 1
servo5.attach(30); //analog pin 0
servo6.attach(32); //analog pin 1
servo7.attach(34); //analog pin 0
servo8.attach(36); //analog pin 1

Not sure of how you are attaching to servo 24,26,etc on a UNO?

Tom... :slight_smile:

Sorry wrong sketch. That was the one for mega. Anyway, the one for uno is identical, but uses pin 2-9.