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

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.
```