How to import Motor on Micropython into a DFRobot Quad Motor ShieldHow to merge two dictionaries in a single expression?How do I check if a list is empty?How do I check whether a file exists without exceptions?How can I safely create a nested directory?How to get the current time in PythonHow can I make a time delay in Python?How do I sort a dictionary by value?How to make a chain of function decorators?How to make a flat list out of list of listsHow do I list all files of a directory?
Popcorn is the only acceptable snack to consume while watching a movie
Is there a simple example that empirical evidence is misleading?
Count rotary dial pulses in a phone number (including letters)
Does a transgender male convert require a Hatafas Dam Bris?
My players want to grind XP but we're using milestone advancement
A steel cutting sword?
Count Even Digits In Number
Who is in charge of Wakanda?
Which European Languages are not Indo-European?
Is "cool" appropriate or offensive to use in IMs?
Do I need full recovery mode when I have multiple daily backup?
Can my floppy disk still work without a shutter spring?
What does $!# mean in Shell scripting?
Is it legal to meet with potential future employers in the UK, whilst visiting from the USA
Open office space - complaints for noise - how to respond
I know that there is a preselected candidate for a position to be filled at my department. What should I do?
How to deal with a colleague who is being aggressive?
Why were helmets and other body armour not commonplace in the 1800s?
Is the Unsullied name meant to be ironic? How did it come to be?
Find the three digit Prime number P from the given unusual relationships
Why does the hash of infinity have the digits of π?
Can I summon an otherworldly creature with the Gate spell without knowing its true name?
Compaq Portable vs IBM 5155 Portable PC
Can I tell a prospective employee that everyone in the team is leaving?
How to import Motor on Micropython into a DFRobot Quad Motor Shield
How to merge two dictionaries in a single expression?How do I check if a list is empty?How do I check whether a file exists without exceptions?How can I safely create a nested directory?How to get the current time in PythonHow can I make a time delay in Python?How do I sort a dictionary by value?How to make a chain of function decorators?How to make a flat list out of list of listsHow do I list all files of a directory?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am attempting to import two motors onto my pyboard in micropython that are connected to my DFRobot DC Quad Motor Shield. Example code from them is written in Arduino and I cannot translate. Attached is my previous code that did not work and the motor shield over view with its speeds and connections.
Any help is appreciated!
Code Previously Written
Board Overview
Here is what I have
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)
Here is the arduino code
/*!
* @file QuadMotorDriverShield.ino
* @brief QuadMotorDriverShield.ino Motor control program
*
* Every 2 seconds to control motor positive inversion
*
* @author linfeng(490289303@qq.com)
* @version V1.0
* @date 2016-4-5
*/
const int E1 = 3; ///<Motor1 Speed
const int E2 = 11;///<Motor2 Speed
const int E3 = 5; ///<Motor3 Speed
const int E4 = 6; ///<Motor4 Speed
const int M1 = 4; ///<Motor1 Direction
const int M2 = 12;///<Motor2 Direction
const int M3 = 8; ///<Motor3 Direction
const int M4 = 7; ///<Motor4 Direction
void M1_advance(char Speed) ///<Motor1 Advance
digitalWrite(M1,LOW);
analogWrite(E1,Speed);
void M2_advance(char Speed) ///<Motor2 Advance
digitalWrite(M2,HIGH);
analogWrite(E2,Speed);
void M3_advance(char Speed) ///<Motor3 Advance
digitalWrite(M3,LOW);
analogWrite(E3,Speed);
void M4_advance(char Speed) ///<Motor4 Advance
digitalWrite(M4,HIGH);
analogWrite(E4,Speed);
void M1_back(char Speed) ///<Motor1 Back off
digitalWrite(M1,HIGH);
analogWrite(E1,Speed);
void M2_back(char Speed) ///<Motor2 Back off
digitalWrite(M2,LOW);
analogWrite(E2,Speed);
void M3_back(char Speed) ///<Motor3 Back off
digitalWrite(M3,HIGH);
analogWrite(E3,Speed);
void M4_back(char Speed) ///<Motor4 Back off
digitalWrite(M4,LOW);
analogWrite(E4,Speed);
void setup()
for(int i=3;i<9;i++)
pinMode(i,OUTPUT);
for(int i=11;i<13;i++)
pinMode(i,OUTPUT);
void loop()
M1_advance(100);
M2_advance(100);
M3_advance(100);
M4_advance(100);
delay(2000); ///<Delay 2S
M1_back(100);
M2_back(100);
M3_back(100);
M4_back(100);
delay(2000); ///<Delay 2S
python robotics micropython
|
show 8 more comments
I am attempting to import two motors onto my pyboard in micropython that are connected to my DFRobot DC Quad Motor Shield. Example code from them is written in Arduino and I cannot translate. Attached is my previous code that did not work and the motor shield over view with its speeds and connections.
Any help is appreciated!
Code Previously Written
Board Overview
Here is what I have
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)
Here is the arduino code
/*!
* @file QuadMotorDriverShield.ino
* @brief QuadMotorDriverShield.ino Motor control program
*
* Every 2 seconds to control motor positive inversion
*
* @author linfeng(490289303@qq.com)
* @version V1.0
* @date 2016-4-5
*/
const int E1 = 3; ///<Motor1 Speed
const int E2 = 11;///<Motor2 Speed
const int E3 = 5; ///<Motor3 Speed
const int E4 = 6; ///<Motor4 Speed
const int M1 = 4; ///<Motor1 Direction
const int M2 = 12;///<Motor2 Direction
const int M3 = 8; ///<Motor3 Direction
const int M4 = 7; ///<Motor4 Direction
void M1_advance(char Speed) ///<Motor1 Advance
digitalWrite(M1,LOW);
analogWrite(E1,Speed);
void M2_advance(char Speed) ///<Motor2 Advance
digitalWrite(M2,HIGH);
analogWrite(E2,Speed);
void M3_advance(char Speed) ///<Motor3 Advance
digitalWrite(M3,LOW);
analogWrite(E3,Speed);
void M4_advance(char Speed) ///<Motor4 Advance
digitalWrite(M4,HIGH);
analogWrite(E4,Speed);
void M1_back(char Speed) ///<Motor1 Back off
digitalWrite(M1,HIGH);
analogWrite(E1,Speed);
void M2_back(char Speed) ///<Motor2 Back off
digitalWrite(M2,LOW);
analogWrite(E2,Speed);
void M3_back(char Speed) ///<Motor3 Back off
digitalWrite(M3,HIGH);
analogWrite(E3,Speed);
void M4_back(char Speed) ///<Motor4 Back off
digitalWrite(M4,LOW);
analogWrite(E4,Speed);
void setup()
for(int i=3;i<9;i++)
pinMode(i,OUTPUT);
for(int i=11;i<13;i++)
pinMode(i,OUTPUT);
void loop()
M1_advance(100);
M2_advance(100);
M3_advance(100);
M4_advance(100);
delay(2000); ///<Delay 2S
M1_back(100);
M2_back(100);
M3_back(100);
M4_back(100);
delay(2000); ///<Delay 2S
python robotics micropython
Can you post the arduino code? If you get closed. Repost on forum.micropython.org/index.php
– rhubarbdog
Mar 24 at 4:00
Can you repost your code. It has to all be indented an extra 4 spaces for the stackoverflow to make it into a code block
– rhubarbdog
Mar 24 at 7:36
@rhubarbdog There, sorry for such a late response.
– Kyle Everett Shapen
Mar 24 at 23:02
What is your question?
– nekomatic
Mar 25 at 10:53
@Kyle Everett Shapen i looked at the arduino code. The device is not i2c it works by.write_digital()to a pin to engage that motor followed by.write_analog()to another pin to control the speed. Do you have a pdf for this device? Post a link to it. I think i know how to wire it up and get mooving.
– rhubarbdog
Mar 26 at 9:25
|
show 8 more comments
I am attempting to import two motors onto my pyboard in micropython that are connected to my DFRobot DC Quad Motor Shield. Example code from them is written in Arduino and I cannot translate. Attached is my previous code that did not work and the motor shield over view with its speeds and connections.
Any help is appreciated!
Code Previously Written
Board Overview
Here is what I have
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)
Here is the arduino code
/*!
* @file QuadMotorDriverShield.ino
* @brief QuadMotorDriverShield.ino Motor control program
*
* Every 2 seconds to control motor positive inversion
*
* @author linfeng(490289303@qq.com)
* @version V1.0
* @date 2016-4-5
*/
const int E1 = 3; ///<Motor1 Speed
const int E2 = 11;///<Motor2 Speed
const int E3 = 5; ///<Motor3 Speed
const int E4 = 6; ///<Motor4 Speed
const int M1 = 4; ///<Motor1 Direction
const int M2 = 12;///<Motor2 Direction
const int M3 = 8; ///<Motor3 Direction
const int M4 = 7; ///<Motor4 Direction
void M1_advance(char Speed) ///<Motor1 Advance
digitalWrite(M1,LOW);
analogWrite(E1,Speed);
void M2_advance(char Speed) ///<Motor2 Advance
digitalWrite(M2,HIGH);
analogWrite(E2,Speed);
void M3_advance(char Speed) ///<Motor3 Advance
digitalWrite(M3,LOW);
analogWrite(E3,Speed);
void M4_advance(char Speed) ///<Motor4 Advance
digitalWrite(M4,HIGH);
analogWrite(E4,Speed);
void M1_back(char Speed) ///<Motor1 Back off
digitalWrite(M1,HIGH);
analogWrite(E1,Speed);
void M2_back(char Speed) ///<Motor2 Back off
digitalWrite(M2,LOW);
analogWrite(E2,Speed);
void M3_back(char Speed) ///<Motor3 Back off
digitalWrite(M3,HIGH);
analogWrite(E3,Speed);
void M4_back(char Speed) ///<Motor4 Back off
digitalWrite(M4,LOW);
analogWrite(E4,Speed);
void setup()
for(int i=3;i<9;i++)
pinMode(i,OUTPUT);
for(int i=11;i<13;i++)
pinMode(i,OUTPUT);
void loop()
M1_advance(100);
M2_advance(100);
M3_advance(100);
M4_advance(100);
delay(2000); ///<Delay 2S
M1_back(100);
M2_back(100);
M3_back(100);
M4_back(100);
delay(2000); ///<Delay 2S
python robotics micropython
I am attempting to import two motors onto my pyboard in micropython that are connected to my DFRobot DC Quad Motor Shield. Example code from them is written in Arduino and I cannot translate. Attached is my previous code that did not work and the motor shield over view with its speeds and connections.
Any help is appreciated!
Code Previously Written
Board Overview
Here is what I have
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)
Here is the arduino code
/*!
* @file QuadMotorDriverShield.ino
* @brief QuadMotorDriverShield.ino Motor control program
*
* Every 2 seconds to control motor positive inversion
*
* @author linfeng(490289303@qq.com)
* @version V1.0
* @date 2016-4-5
*/
const int E1 = 3; ///<Motor1 Speed
const int E2 = 11;///<Motor2 Speed
const int E3 = 5; ///<Motor3 Speed
const int E4 = 6; ///<Motor4 Speed
const int M1 = 4; ///<Motor1 Direction
const int M2 = 12;///<Motor2 Direction
const int M3 = 8; ///<Motor3 Direction
const int M4 = 7; ///<Motor4 Direction
void M1_advance(char Speed) ///<Motor1 Advance
digitalWrite(M1,LOW);
analogWrite(E1,Speed);
void M2_advance(char Speed) ///<Motor2 Advance
digitalWrite(M2,HIGH);
analogWrite(E2,Speed);
void M3_advance(char Speed) ///<Motor3 Advance
digitalWrite(M3,LOW);
analogWrite(E3,Speed);
void M4_advance(char Speed) ///<Motor4 Advance
digitalWrite(M4,HIGH);
analogWrite(E4,Speed);
void M1_back(char Speed) ///<Motor1 Back off
digitalWrite(M1,HIGH);
analogWrite(E1,Speed);
void M2_back(char Speed) ///<Motor2 Back off
digitalWrite(M2,LOW);
analogWrite(E2,Speed);
void M3_back(char Speed) ///<Motor3 Back off
digitalWrite(M3,HIGH);
analogWrite(E3,Speed);
void M4_back(char Speed) ///<Motor4 Back off
digitalWrite(M4,LOW);
analogWrite(E4,Speed);
void setup()
for(int i=3;i<9;i++)
pinMode(i,OUTPUT);
for(int i=11;i<13;i++)
pinMode(i,OUTPUT);
void loop()
M1_advance(100);
M2_advance(100);
M3_advance(100);
M4_advance(100);
delay(2000); ///<Delay 2S
M1_back(100);
M2_back(100);
M3_back(100);
M4_back(100);
delay(2000); ///<Delay 2S
python robotics micropython
python robotics micropython
edited Mar 24 at 23:01
Kyle Everett Shapen
asked Mar 24 at 2:18
Kyle Everett ShapenKyle Everett Shapen
43
43
Can you post the arduino code? If you get closed. Repost on forum.micropython.org/index.php
– rhubarbdog
Mar 24 at 4:00
Can you repost your code. It has to all be indented an extra 4 spaces for the stackoverflow to make it into a code block
– rhubarbdog
Mar 24 at 7:36
@rhubarbdog There, sorry for such a late response.
– Kyle Everett Shapen
Mar 24 at 23:02
What is your question?
– nekomatic
Mar 25 at 10:53
@Kyle Everett Shapen i looked at the arduino code. The device is not i2c it works by.write_digital()to a pin to engage that motor followed by.write_analog()to another pin to control the speed. Do you have a pdf for this device? Post a link to it. I think i know how to wire it up and get mooving.
– rhubarbdog
Mar 26 at 9:25
|
show 8 more comments
Can you post the arduino code? If you get closed. Repost on forum.micropython.org/index.php
– rhubarbdog
Mar 24 at 4:00
Can you repost your code. It has to all be indented an extra 4 spaces for the stackoverflow to make it into a code block
– rhubarbdog
Mar 24 at 7:36
@rhubarbdog There, sorry for such a late response.
– Kyle Everett Shapen
Mar 24 at 23:02
What is your question?
– nekomatic
Mar 25 at 10:53
@Kyle Everett Shapen i looked at the arduino code. The device is not i2c it works by.write_digital()to a pin to engage that motor followed by.write_analog()to another pin to control the speed. Do you have a pdf for this device? Post a link to it. I think i know how to wire it up and get mooving.
– rhubarbdog
Mar 26 at 9:25
Can you post the arduino code? If you get closed. Repost on forum.micropython.org/index.php
– rhubarbdog
Mar 24 at 4:00
Can you post the arduino code? If you get closed. Repost on forum.micropython.org/index.php
– rhubarbdog
Mar 24 at 4:00
Can you repost your code. It has to all be indented an extra 4 spaces for the stackoverflow to make it into a code block
– rhubarbdog
Mar 24 at 7:36
Can you repost your code. It has to all be indented an extra 4 spaces for the stackoverflow to make it into a code block
– rhubarbdog
Mar 24 at 7:36
@rhubarbdog There, sorry for such a late response.
– Kyle Everett Shapen
Mar 24 at 23:02
@rhubarbdog There, sorry for such a late response.
– Kyle Everett Shapen
Mar 24 at 23:02
What is your question?
– nekomatic
Mar 25 at 10:53
What is your question?
– nekomatic
Mar 25 at 10:53
@Kyle Everett Shapen i looked at the arduino code. The device is not i2c it works by
.write_digital() to a pin to engage that motor followed by .write_analog() to another pin to control the speed. Do you have a pdf for this device? Post a link to it. I think i know how to wire it up and get mooving.– rhubarbdog
Mar 26 at 9:25
@Kyle Everett Shapen i looked at the arduino code. The device is not i2c it works by
.write_digital() to a pin to engage that motor followed by .write_analog() to another pin to control the speed. Do you have a pdf for this device? Post a link to it. I think i know how to wire it up and get mooving.– rhubarbdog
Mar 26 at 9:25
|
show 8 more comments
1 Answer
1
active
oldest
votes
Here's attempt one. Consider using fuses until we're certain this is how to connect a DFRobot Motor HAT to a pyboard.
The connection point on the motor hat is the green digital bus.
import pyb
# don't use timers 2,3,5,6
'''
connect:
pyboard Motor Hat
X1 4
X3 3
GND GND
'''
FREQ = 50
backward = pyb.Pin('X1' ,pyb.Pin.OUT_PP)
speed = pyb.Timer(9, freq=FREQ).channel(1, pyb.Timer.PWM,
pin = pyb.Pin('X3'))
while True:
backward.high()
for percent in range(100):
speed.pulse_width_percent(percent + 1)
pyb.delay(10)
speed.pulse_width_percent(0)
backward.low()
for percent in range(100):
speed.pulse_width_percent(percent + 1)
pyb.delay(10)
speed.pulse_width_percent(0)
I've guessed FREQ to be 50Hz it's that for many servos and i'm guessing arduino uses this as a default value for PWM (pulse width modulation).
Connect a motor to connector M1 and a battery to the motor hat's power socket. Don't connect to v+ on the pyboard. Power your pyboard with it's own power source. You motor hat probably creates a lot of electrical noise.
The motor should go backwards speeding up then suddenly stopping before going forwards getting faster then suddenly stop.
good luck
@Kyle Everett Shapen i noticed you were also using an HCSR04 ultrasonic distance measurement. Here's a link to some pyboard code for this github.com/rhubarbdog/pyboard-hcsr04.
– rhubarbdog
Mar 29 at 0:47
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55320175%2fhow-to-import-motor-on-micropython-into-a-dfrobot-quad-motor-shield%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Here's attempt one. Consider using fuses until we're certain this is how to connect a DFRobot Motor HAT to a pyboard.
The connection point on the motor hat is the green digital bus.
import pyb
# don't use timers 2,3,5,6
'''
connect:
pyboard Motor Hat
X1 4
X3 3
GND GND
'''
FREQ = 50
backward = pyb.Pin('X1' ,pyb.Pin.OUT_PP)
speed = pyb.Timer(9, freq=FREQ).channel(1, pyb.Timer.PWM,
pin = pyb.Pin('X3'))
while True:
backward.high()
for percent in range(100):
speed.pulse_width_percent(percent + 1)
pyb.delay(10)
speed.pulse_width_percent(0)
backward.low()
for percent in range(100):
speed.pulse_width_percent(percent + 1)
pyb.delay(10)
speed.pulse_width_percent(0)
I've guessed FREQ to be 50Hz it's that for many servos and i'm guessing arduino uses this as a default value for PWM (pulse width modulation).
Connect a motor to connector M1 and a battery to the motor hat's power socket. Don't connect to v+ on the pyboard. Power your pyboard with it's own power source. You motor hat probably creates a lot of electrical noise.
The motor should go backwards speeding up then suddenly stopping before going forwards getting faster then suddenly stop.
good luck
@Kyle Everett Shapen i noticed you were also using an HCSR04 ultrasonic distance measurement. Here's a link to some pyboard code for this github.com/rhubarbdog/pyboard-hcsr04.
– rhubarbdog
Mar 29 at 0:47
add a comment |
Here's attempt one. Consider using fuses until we're certain this is how to connect a DFRobot Motor HAT to a pyboard.
The connection point on the motor hat is the green digital bus.
import pyb
# don't use timers 2,3,5,6
'''
connect:
pyboard Motor Hat
X1 4
X3 3
GND GND
'''
FREQ = 50
backward = pyb.Pin('X1' ,pyb.Pin.OUT_PP)
speed = pyb.Timer(9, freq=FREQ).channel(1, pyb.Timer.PWM,
pin = pyb.Pin('X3'))
while True:
backward.high()
for percent in range(100):
speed.pulse_width_percent(percent + 1)
pyb.delay(10)
speed.pulse_width_percent(0)
backward.low()
for percent in range(100):
speed.pulse_width_percent(percent + 1)
pyb.delay(10)
speed.pulse_width_percent(0)
I've guessed FREQ to be 50Hz it's that for many servos and i'm guessing arduino uses this as a default value for PWM (pulse width modulation).
Connect a motor to connector M1 and a battery to the motor hat's power socket. Don't connect to v+ on the pyboard. Power your pyboard with it's own power source. You motor hat probably creates a lot of electrical noise.
The motor should go backwards speeding up then suddenly stopping before going forwards getting faster then suddenly stop.
good luck
@Kyle Everett Shapen i noticed you were also using an HCSR04 ultrasonic distance measurement. Here's a link to some pyboard code for this github.com/rhubarbdog/pyboard-hcsr04.
– rhubarbdog
Mar 29 at 0:47
add a comment |
Here's attempt one. Consider using fuses until we're certain this is how to connect a DFRobot Motor HAT to a pyboard.
The connection point on the motor hat is the green digital bus.
import pyb
# don't use timers 2,3,5,6
'''
connect:
pyboard Motor Hat
X1 4
X3 3
GND GND
'''
FREQ = 50
backward = pyb.Pin('X1' ,pyb.Pin.OUT_PP)
speed = pyb.Timer(9, freq=FREQ).channel(1, pyb.Timer.PWM,
pin = pyb.Pin('X3'))
while True:
backward.high()
for percent in range(100):
speed.pulse_width_percent(percent + 1)
pyb.delay(10)
speed.pulse_width_percent(0)
backward.low()
for percent in range(100):
speed.pulse_width_percent(percent + 1)
pyb.delay(10)
speed.pulse_width_percent(0)
I've guessed FREQ to be 50Hz it's that for many servos and i'm guessing arduino uses this as a default value for PWM (pulse width modulation).
Connect a motor to connector M1 and a battery to the motor hat's power socket. Don't connect to v+ on the pyboard. Power your pyboard with it's own power source. You motor hat probably creates a lot of electrical noise.
The motor should go backwards speeding up then suddenly stopping before going forwards getting faster then suddenly stop.
good luck
Here's attempt one. Consider using fuses until we're certain this is how to connect a DFRobot Motor HAT to a pyboard.
The connection point on the motor hat is the green digital bus.
import pyb
# don't use timers 2,3,5,6
'''
connect:
pyboard Motor Hat
X1 4
X3 3
GND GND
'''
FREQ = 50
backward = pyb.Pin('X1' ,pyb.Pin.OUT_PP)
speed = pyb.Timer(9, freq=FREQ).channel(1, pyb.Timer.PWM,
pin = pyb.Pin('X3'))
while True:
backward.high()
for percent in range(100):
speed.pulse_width_percent(percent + 1)
pyb.delay(10)
speed.pulse_width_percent(0)
backward.low()
for percent in range(100):
speed.pulse_width_percent(percent + 1)
pyb.delay(10)
speed.pulse_width_percent(0)
I've guessed FREQ to be 50Hz it's that for many servos and i'm guessing arduino uses this as a default value for PWM (pulse width modulation).
Connect a motor to connector M1 and a battery to the motor hat's power socket. Don't connect to v+ on the pyboard. Power your pyboard with it's own power source. You motor hat probably creates a lot of electrical noise.
The motor should go backwards speeding up then suddenly stopping before going forwards getting faster then suddenly stop.
good luck
answered Mar 26 at 21:34
rhubarbdogrhubarbdog
37419
37419
@Kyle Everett Shapen i noticed you were also using an HCSR04 ultrasonic distance measurement. Here's a link to some pyboard code for this github.com/rhubarbdog/pyboard-hcsr04.
– rhubarbdog
Mar 29 at 0:47
add a comment |
@Kyle Everett Shapen i noticed you were also using an HCSR04 ultrasonic distance measurement. Here's a link to some pyboard code for this github.com/rhubarbdog/pyboard-hcsr04.
– rhubarbdog
Mar 29 at 0:47
@Kyle Everett Shapen i noticed you were also using an HCSR04 ultrasonic distance measurement. Here's a link to some pyboard code for this github.com/rhubarbdog/pyboard-hcsr04.
– rhubarbdog
Mar 29 at 0:47
@Kyle Everett Shapen i noticed you were also using an HCSR04 ultrasonic distance measurement. Here's a link to some pyboard code for this github.com/rhubarbdog/pyboard-hcsr04.
– rhubarbdog
Mar 29 at 0:47
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55320175%2fhow-to-import-motor-on-micropython-into-a-dfrobot-quad-motor-shield%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you post the arduino code? If you get closed. Repost on forum.micropython.org/index.php
– rhubarbdog
Mar 24 at 4:00
Can you repost your code. It has to all be indented an extra 4 spaces for the stackoverflow to make it into a code block
– rhubarbdog
Mar 24 at 7:36
@rhubarbdog There, sorry for such a late response.
– Kyle Everett Shapen
Mar 24 at 23:02
What is your question?
– nekomatic
Mar 25 at 10:53
@Kyle Everett Shapen i looked at the arduino code. The device is not i2c it works by
.write_digital()to a pin to engage that motor followed by.write_analog()to another pin to control the speed. Do you have a pdf for this device? Post a link to it. I think i know how to wire it up and get mooving.– rhubarbdog
Mar 26 at 9:25