EasyManuals Logo

Freenove Ultimate Starter Kit User Manual

Freenove Ultimate Starter Kit
286 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #151 background imageLoading...
Page #151 background image
151
Chapter 13 Motor & Driver
www.freenove.com
support@freenove.com
64
65
66
67
68
69
p rint ('Program is starting ... ')
setup()
try:
loop()
e xcept KeyboardInterrupt:
destroy()
We have been familiar with reading ADC value. So, let’s learn directly subfunction def motor(ADC): first,
compare ADC value with 128 (value corresponding to midpoint). When the current ADC value is higher,
motoRPin1 outputs high level and motoRPin2 output low level to control motor to run with forward rotation
direction. When the current ADC value is lower, motoRPin1 outputs low level and motoRPin2 outputs high
level to control run with reversed direction. When the ADC value is equal to 128, make motoRPin1 and
motoRPin2 output low level, then the motor stops. And then determine PWM duty cycle according to the
difference between ADC value and 128. Because the absolute difference value stays within 0-128. We need
to use the map () subfunction mapping the difference value to range of 0-100. Finally print out the duty cycle.
def motor(ADC):
value = ADC - 128
if (value > 0):
GPIO.output(motoRPin1,GPIO.HIGH)
GPIO.output(motoRPin2,GPIO.LOW)
print ('Turn Forward...')
e lif (value < 0):
GPIO.output(motoRPin1,GPIO.LOW)
GPIO.output(motoRPin2,GPIO.HIGH)
print ('Turn Backward...')
e lse :
GPIO.output(motoRPin1,GPIO.LOW)
GPIO.output(motoRPin2,GPIO.LOW)
print ('Motor Stop...')
p. start(mapNUM(abs(value),0,128,0,100))
p rint ('The PWM duty cycle is %d%%\n'%(abs(value)*100/127)) #print PMW duty cycle.

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Freenove Ultimate Starter Kit and is the answer not in the manual?

Freenove Ultimate Starter Kit Specifications

General IconGeneral
BrandFreenove
ModelUltimate Starter Kit
CategorySingle board computers
LanguageEnglish