BLDC hdd motor with ESC

ok, I'm finally throwing in the towel and asking for help.

here is what I have:

a Maxtor diamondMax vl 40 that is broken down to just the 4 wires from the BLDC

I also got a E-flite 10amp pro BL ESC http://www.e-fliterc.com/ProdInfo/Files/EFLA1010_manual.pdf

at first i was just running 5v from the arduino. and the disk would pulse, speed up for about 2 second at maybe 1500 rpms. then it would turn off and it would slowdown for about 2 seconds.

the manual says something about a soft cut off where if the voltage is 70% of startup then it would begin to pulse... I don't know if this is where my problem is or not.
i even tied it with a battery where the voltage measured at 11.2 volts and didn't stop the pulsing

so no i'm thinking it's with my code, or the motor is just speeding faster than the code. since i don't have anyway of checking how fast it is going..

is there a way to calculate speed from the control pin of the hdd or from the ESC?
is the pulsing coming from the drive outrunning the code?

here is the current sketch I'm using:

#include <Servo.h> 
 
Servo myservo;  
 
int potpin = 0;  
int val;    
 int analogPin = 3;
 
 void arm(){


  myservo.write(0); 
  delay(2000); 
}
void setup() 
{ 
   Serial.begin(9600);
  myservo.attach(9);  
  arm();
} 
 
void loop() 
{ 
  for (int i = 0; i < 180; i++){
  val = i;    
 myservo.writeMicroseconds(1200);
  myservo.write(val); 
int a = analogRead(analogPin);    
  Serial.println(a);   
  delay(15);    
} 
}

here is another one i've use but still does the same thing.

// this uses the Arduino servo library included with version 0012

// caution, this code sweeps the motor up to maximum speed !
// make sure the motor is mounted securily before running.

#include <Servo.h>

Servo myservo;
int analogPinLow = 3;     // potentiometer wiper (middle terminal) connected to analog pin 3
int analogPinHigh = 4;                       // outside leads to ground and +5V
int val = 0;           // variable to store the value read
int pwmpin = 6;


void arm(){
  // arm the speed controller, modify as necessary for your ESC  
  setSpeed(0);
  delay(2000); //delay 1 second,  some speed controllers may need longer
}

void setSpeed(int speeda){
  // speed is from 0 to 100 where 0 is off and 100 is maximum speed
  //the following maps speed values of 0-100 to angles from 0-180,
  // some speed controllers may need different values, see the ESC instructions
  int angle = map(speeda, 0, 360, 0, 360);
  myservo.write(angle);    
}

void setup()
{
    Serial.begin(9600);
  myservo.attach(9);
  arm();  
}


void loop()
{
         // debug value
  int speeda;

  // sweep up from 0 to to maximum speed in 20 seconds
  if (speeda < 360){
  for(speeda = 0; speeda <= 360; speeda += 1) {
   setSpeed(speeda); 
   delay(20);
  
  }
    speeda = 0;

  }

//  // sweep back down to 0 speed.
//
//  for(speeda = 175; speeda > 0; speeda -= 5) {
//
//
//    setSpeed(speeda);
//    analogWrite(pwmpin, 255);
//    delay(30);
//  }
//  setSpeed(0);  

}

It appears that your motor could be a stepper, other than that i have no idea.

What are you trying to achieve with the motor? Just to get it running?

The 'pulse' from the motor just after applying power is an audio beep. The different beeps are feedback from the ESC to indicate its status.

The reason the motor speeds up and then slows down is because the value 'val' passed to myservo.write(val); is generated from the loop for (int i = 0; i < 180; i++){ which basically counts from 0 to 179 relating to min to max motor power. ie the motor pulses every 2 seconds because your sketch is controlling it this way. :sweat_smile:

Because you are attaching an analogue signal I guess you want the motor to speed up and slow down from a potentiometer?
I've reworked your sketch so it does this and added some annotation.

/*
DEMO sketch for arming  and running a generic ESC brushless motor controler from an Arduino and using a potentiometer to vary the motor speed.

Tested and working.
http://www.youtube.com/watch?v=V7gYbXBKhXs


19 Feb 2011
*/

#include <Servo.h> 
 
Servo myservo;  
 
int val;                                   //Value for motor speed.
int analogPin = 3;                         //Potentiometer on pin 3
int servoPin = 9;                          //Servo on pin 9
int armValue=20;                           // "zero" position for arming ESC. As some wont arm with a '0' value fromthe arduino. 

void arm(){                                //Arming sequence of sending a minimum or 'joystick zero' for 2 seconds to simulate radio gear is ON and operational.  
  myservo.write(armValue); 
  delay(2500); 
}
  
void setup() { 
  
  Serial.begin(9600);
  myservo.attach(servoPin);  
  arm();
} 
 
void loop(){ 
  int val = analogRead(analogPin);         //Make a analogue reading. This is from 0-1023
  val = map(val, 0, 1023, armValue, 180);  //Scale input to use it with the servo ie from the arming value to 180.
  myservo.write(val);                      //Send servo position - Motor speed to ESC.
  Serial.println(val);                     //Send servo 
  delay(100);                              //pause for 1/10 second.
}

I also did a short video because I'm hung over and got nothing better to do of it working with a broken hard drive I was hoarding.

The status beep just after powerup is more prominent on a larger motor and can be heard in this video I did a few days ago.

Other points to note are:....

There should be three wires from the hard drive motor to the controller. If there are four wires have you correctly identified the centre tap? It will be the one made from 3 wires twisted together. This should be left unconnected as the ESC doesn't need it.

Experience also tells me that the ESC will not arm on a 0 servo position and a value of between 15 and 20 is needed (dependant on controller) I then use this value as zero motor speed.

Model RC system have no feedback so there is no way of getting the motor speed from the ESC. If you need the motor speed you will have to use the Arduino to either measure the motor rotation or monitor the electrical signal from one of the three phases powering the motor.

Hope this helps

thanks for the reply,

i tried your code, and i don't have a pot handy at the moment so i set the servo to 100 but the motor does the same thing as it did before except doesn't loop it will spin up for a second then it just shuts off and won't do anything unless i upload the sketch again.. reset button does nothing.

the only time i get the arming beep is after i pull the power to the ESC and plug it back in. I get a tone for the power, then a tone for armed. but i don't get the armed beep after i upload. so this could be my problem.

finally, one the 150th thread i read i found this

// zoomkat 11-27-10 serial servo test
// type servo position 0 to 180 in serial monitor
// for writeMicroseconds, use a value like 1500
// for IDE 0019 and later
// Powering a servo from the arduino usually DOES NOT WORK.

String readstring; //string to be captured from serial port
#include <Servo.h>
Servo myservo;  // create servo object to control a servo

void setup() {
  Serial.begin(9600);
  myservo.attach(7);  //the pin for the servo control
  Serial.println("servo-test-21"); // so I can keep track of what is loaded
}

void loop() {

  while (Serial.available()) {
    delay(10);
    if (Serial.available() >0) {
	char c = Serial.read();  //gets one byte from serial buffer
	readstring += c; //makes readstring from the single bytes
    }
  }

  if (readstring.length() >0) {
    Serial.println(readstring);  //so you can see the captured string
    char carray[readstring.length() + 1]; //determine size of the array
    readstring.toCharArray(carray, sizeof(carray)); //put readStringinto an array
    int n = atoi(carray); //convert the array into an Integer
    myservo.writeMicroseconds(n); // for microseconds
    //myservo.write(n); //for degees 0-180
    readstring="";
  }
}

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1291280774

I guess the trick it to use writeMicroseconds...

also i get back voltage from the ctrl pin so is there a way an algorithm to calculate speed off the voltage?

thanks for you help guys.

:stuck_out_tongue:
i have a stupid Question want to know.
can i use the signal from 3 wires of the ESC to feedback to the CPU to have a close-loop
i want to know the speed of motor and dispplay in ldc