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 #149 background imageLoading...
Page #149 background image
149
Chapter 13 Motor & Driver
www.freenove.com
support@freenove.com
Python Code 13.1.1 Motor
First observe the project result, and then analyze the code.
1. Use cd command to enter 13.1.1_Motor directory of Python code.
cd ~/Freenove_Ultimate_Starter_Kit_for_Raspberry_Pi/Code/Python_Code/13.1.1_Motor
2. Use python command to execute python code Motor.py”.
python Motor.py
After the program is executed, shift the potentiometer, then the rotation speed and direction of the motor
will change with it. And when the potentiometer is turned to midpoint position, the motor stops running.
When away from the middle position, the motor speed will increase. When to both ends, motor speed reach
to maximum. When the potentiometer is turned to different side of the middle position, the motor will run
with different direction. Meanwhile, the terminal will print out ADC value of the potentiometer, the motor
direction and the PWM duty cycle used to control motor speed.
The following is the code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
im port RPi. GPIO as GPIO
im port smbus
im port time
address = 0x48
bus=smbus.SMBus(1)
cmd=0x40
# define the pin connected to L293D
motoRPin1 = 13
motoRPin2 = 11
enablePin = 15
def analogRead(chn):
value = bus.read_byte_data(address,cmd+chn)
r eturn value
def analogWrite(value):
bus. write_byte_data(address,cmd,value)

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