It is useful to control actuator peripherals with PWM, such as motor, servo ,LED and speaker. The purpose of LinkIt smart 7688 basic tutorial#3 is to introduce how to use Mraa PWM to access these actuator peripherals, with Grove - Mini Fan as an example.
Things you need:
Grove -Mini Fan *1
Linkit Smart 7688 *1
Breakout for Linkit Smart 7688 *1
USB Cable *1
Here we can just connect the SIG pin of Grove - Mini Fan to P26 on LinkIt smart 7688. And don’t forget to insert the VCC and GND pin to the right position on breakout for 7688 .
Note that only P26-GPIO18-PWM0, P27-GPIO19-PWM1, P8-GPIO20-PWM2, P9-GPIO21-PWM3 supports PWM on LinkIt smart 7688. And we have used the P26-GPIO18-PWM0 just now. Of course you can try the others.
To control the PWM pattern, several parameters are required, the first is period. This defines the carrier frequency of the modulation. It’s controlled by period, period_ms and period_us APIs. And then is duty cycle. Duty cycle is controlled by write API with a value range between 0.0 to 1.0, where 0.0 is 0% of duty cycle and 1.0 is 100% of duty cycle. We can control the speed of the Grove - Mini Fan by changing the duty cycle.
The following code shows how to make the Grove -Mini Fan works per five seconds with 20% duty cycle.
import mraa import time pin = mraa.Pwm(18) pin.period_ms(2) pin.enable(True) while True: pin.write(0.2) time.sleep(5) pin.write(0) time.sleep(5)
Paste the code above into a new file and save it as pwmfan.py. Then run it :
Then you will see the mini fan turn on or off per 5 seconds. If you don’t, please check the connection and make sure you code is right.
It seems easy and convenient to drive a motor with Mraa PWM. So why not try to make a little car with LinkIt smart 7688? I am sure you will success! And don’t forget to post your recipe on seeed.cc!