Hairyloon
Posts: 30
Joined: Wed Jan 20, 2016 10:42 am

Using disk drive motors.

Fri Oct 27, 2017 6:16 pm

I expected this subject to be widely covered somewhere, but I have not found it. I admit that I've not looked terribly hard, but the search engine here isn't working just now and in any case I thought a conversation might be helpful.

Anyway, as I am sure we all know, disk drives have various motors inside them and there are endless possible uses to which they could be put, if you can work out how to control them.

Does anybody have any top tips or pointers?
Always code as if the chap who ends up maintaining your code will be a violent psychopath who knows where you live.

User avatar
B.Goode
Posts: 8271
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Using disk drive motors.

Fri Oct 27, 2017 6:24 pm

Does anybody have any top tips or pointers?
Don't connect a motor directly to the gpio pins of an RPi.

(Starting the motor up may be fine. But without additional protection, as the motor slows down and stops it may push current back up the cable in the 'wrong' direction: that current may be sufficient to destroy not only the gpio pin to which it is connected, but can escalate within the chip to destroy the entire RPi processor.)

User avatar
OutoftheBOTS
Posts: 711
Joined: Tue Aug 01, 2017 10:06 am

Re: Using disk drive motors.

Fri Oct 27, 2017 6:45 pm

I think that you will find that disk drive motors r stepper mototrs so you will need a dual h bridhe to run them and you will need to create the stepping pattern

User avatar
joan
Posts: 14196
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Using disk drive motors.

Fri Oct 27, 2017 8:37 pm

You would need to check the motor. They are probably brushless DC motors which need to be driven by a three phase signal.

Video of a disk being spun up after an idea by Dan Perron.

http://abyz.me.uk/videos/bldc-djp.mp4

Code: Select all

#!/usr/bin/env python

import time

import pigpio

# bldc-djp.py
# 2015-09-21

"""
Code to spin a BLDC (brushless DC motor).  The code has no serious
purpose other than to show a motor spinning up.

The code assumes that a L293D or similar is connected to GPIOs
P0, P1, P2.  M0, M1, M2 are the outputs and should be connected
to phases 0, 1, and 2 of the motor.

The following is okay for my 5V laptop 2.5" drive.

5V  EN   1  16 VCC1 5V
P0  1A   2  15 4A  --
M0  1Y   3  14 4Y  --
GND GND  4  13 GND GND
GND GND  5  12 GND GND
M1  2Y   6  11 3Y  M2
P1  2A   7  10 3A  P2
5V  VCC2 8   9 EN  5V

    +-----+     +-----+
P0  |     |     |     |
    +     +-----+     +-----
        +-----+     +-----+
P1      |     |     |     |
    ----+     +-----+     +-
    --+     +-----+     +---   
P2    |     |     |     |       
      +-----+     +-----+   
"""

P0=21
P1=20
P2=16

END_MICROS=1000 # micros per phase (3*poles, 6 states per cycle and 4 cycles per revolution
#7200 RPM =  1.0/((7200RPM/60sec)* 6 states * 4 cycle) = 347 usec per state


END_REPEAT=1000 # the number of cycles at final micros

def calcRampDelay(From_delay, to_delay, cycles, currentCycle):
  if currentCycle >= cycles:
    return to_delay
  f1 = 1.0 / From_delay
  f2 = 1.0 / to_delay
  deltaF = (f2-f1) / cycles
  newF = f1 + (deltaF *  currentCycle)
  return int(1.0 / newF)


def ramp(from_delay, to_delay, cycles, forward=True):
   wf=[]



   inc = ((to_delay - from_delay)/6.0)/cycles
   delay = float(from_delay)
   for i in range(cycles):
      if forward:
         wf.append(pigpio.pulse(1<<P0, 0    , calcRampDelay(from_delay, to_delay,cycles *6, i*6)))
         wf.append(pigpio.pulse(0    , 1<<P2, calcRampDelay(from_delay, to_delay,cycles *6, i*6 + 1)))
         wf.append(pigpio.pulse(1<<P1, 0    , calcRampDelay(from_delay, to_delay,cycles *6, i*6 + 2)))
         wf.append(pigpio.pulse(0    , 1<<P0, calcRampDelay(from_delay, to_delay,cycles *6, i*6 + 3)))
         wf.append(pigpio.pulse(1<<P2, 0    , calcRampDelay(from_delay, to_delay,cycles *6, i*6 + 4)))
         wf.append(pigpio.pulse(0    , 1<<P1, calcRampDelay(from_delay, to_delay,cycles *6, i*6 + 5)))
      else:
         wf.append(pigpio.pulse(1<<P0, 0    , calcRampDelay(from_delay, to_delay,cycles *6, i*6)))
         wf.append(pigpio.pulse(0    , 1<<P1, calcRampDelay(from_delay, to_delay,cycles *6, i*6 + 1)))
         wf.append(pigpio.pulse(1<<P2, 0    , calcRampDelay(from_delay, to_delay,cycles *6, i*6 + 2)))
         wf.append(pigpio.pulse(0    , 1<<P0, calcRampDelay(from_delay, to_delay,cycles *6, i*6 + 3)))
         wf.append(pigpio.pulse(1<<P1, 0    , calcRampDelay(from_delay, to_delay,cycles *6, i*6 + 4)))
         wf.append(pigpio.pulse(0    , 1<<P2, calcRampDelay(from_delay, to_delay,cycles *6, i*6 + 5)))

   pi.wave_add_generic(wf)
   return pi.wave_create(), to_delay
pi = pigpio.pi() # Connect to local Pi.

forward = True

if pi.connected:

   pi.set_mode(P0, pigpio.OUTPUT)
   pi.set_mode(P1, pigpio.OUTPUT)
   pi.set_mode(P2, pigpio.OUTPUT)

   pi.wave_add_new()

   r, delay = ramp(10000, END_MICROS, 500, forward)

   print("end delay", delay)

   wf=[]
   if forward:
         wf.append(pigpio.pulse(1<<P0, 0    , delay))
         wf.append(pigpio.pulse(0    , 1<<P2, delay))
         wf.append(pigpio.pulse(1<<P1, 0    , delay))
         wf.append(pigpio.pulse(0    , 1<<P0, delay))
         wf.append(pigpio.pulse(1<<P2, 0    , delay))
         wf.append(pigpio.pulse(0    , 1<<P1, delay))
   else:
         wf.append(pigpio.pulse(1<<P0, 0    , delay))
         wf.append(pigpio.pulse(0    , 1<<P1, delay))
         wf.append(pigpio.pulse(1<<P2, 0    , delay))
         wf.append(pigpio.pulse(0    , 1<<P0, delay))
         wf.append(pigpio.pulse(1<<P1, 0    , delay))
         wf.append(pigpio.pulse(0    , 1<<P2, delay))


   pi.wave_add_generic(wf)
   f = pi.wave_create()

   wc = [r, 255, 0, f, 255, 1, END_REPEAT&255, (END_REPEAT>>8)&255]

   print("final delay", delay, wc)

   pi.wave_chain(wc)

   while pi.wave_tx_busy():
      time.sleep(0.05)

   pi.wave_delete(r)
   pi.wave_delete(f)

   pi.write(P0, 0)
   pi.write(P1, 0)
   pi.write(P2, 0)

   pi.stop() # Disconnect from local Pi.


AJB2K3
Posts: 215
Joined: Sun Aug 11, 2013 3:25 pm

Re: Using disk drive motors.

Sun Oct 29, 2017 8:38 pm

Look for Raspberry pi laser engraver.
Uses the stepper motors found in older optical drives (newer ones use motors and encoder wheels.)
Back in the old days, we were smarter then the technology.
Nowadays technology makes us look like villages fools in front of the children!

Hairyloon
Posts: 30
Joined: Wed Jan 20, 2016 10:42 am

Re: Using disk drive motors.

Sun Oct 29, 2017 11:28 pm

piglet wrote: There are some very inventive people out there using disk drive motors e.g:

https://www.youtube.com/watch?v=jEzXjJN1RH0

https://www.youtube.com/watch?v=e0NVFbBVFXw

https://www.youtube.com/watch?v=zsVjCZG4cyI
No, sorry that is just too silly...
OutoftheBOTS wrote:
Fri Oct 27, 2017 6:45 pm
I think that you will find that disk drive motors r stepper mototrs so you will need a dual h bridhe to run them and you will need to create the stepping pattern
There are various motors depending what drives you are looking at. Some of them are certainly steppers.
AJB2K3 wrote:Look for Raspberry pi laser engraver.
Uses the stepper motors found in older optical drives (newer ones use motors and encoder wheels.)
That was the kind of thing I was thinking about...
Always code as if the chap who ends up maintaining your code will be a violent psychopath who knows where you live.

User avatar
piglet
Posts: 903
Joined: Sat Aug 27, 2011 1:16 pm

Re: Using disk drive motors.

Mon Oct 30, 2017 9:38 pm

Hairyloon wrote:
Sun Oct 29, 2017 11:28 pm
No, sorry that is just too silly...
I read that in my head in a Monty Pythonesque voice and laughed out loud. Thanks :)

Return to “Automation, sensing and robotics”