Page 1 of 1

Controlling Motor on DFRobot Quad Motor Shield with pyboard

Posted: Sun Mar 24, 2019 2:33 am
by kshape8
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)