Controlling Motor on DFRobot Quad Motor Shield with pyboard

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
kshape8
Posts: 1
Joined: Sun Mar 24, 2019 2:26 am

Controlling Motor on DFRobot Quad Motor Shield with pyboard

Post by kshape8 » Sun Mar 24, 2019 2:33 am

Hey everyone,

I am not very fluent with coding and am trying to build a robot for an engineering class. I am trying to control a few motors with my DFRobot Quad Motor shield and it is not recognizing my code. I didnt really want to use a PWM method but honestly just don't mind if necessary. I was wondering if someone could show a small example of how they would import and call the motor to drive. Below I will attach my current code and the motor shield overview.

Thanks guys

https://www.dfrobot.com/wiki/index.php/ ... KU:DRI0039


code:
i2c = machine.I2C(scl=machine.Pin('Y9'), sda=machine.Pin('Y10'))
motors = motor.DCMotors(i2c)
MOTOR1 = 3
MOTOR2 = 4
#Initiate Communication from Sonar sensor
sensor_front = adafruit_hcsr04.HCSR04(trigger_pin=board.Pin('X3'), echo_pin=board.Pin('X4'))
sensor_back = adafruit_hcsr04.HCSR04(trigger_pin=board.Pin('X6'), echo_pin=board.Pin('X7'))
#Create minimum distance For Ultrasonic sensor
min_distance = sensor.distance(70)
button = pyb.switch()
def autonomy():
#no_problem = True
while (True):
if (button()):
dist_front = sensor1.distance(15)
dist_back = sensor2.distance(15)
if dist_front > min_distance:
print('Nothing can stop me!')
motors.speed(MOTOR1, 1500)
motors.speed(MOTOR2,-1500)

Post Reply