Maqueenplus

Questions and discussion about running MicroPython on a micro:bit board.
Target audience: MicroPython users with a micro:bit.
Post Reply
Jackpo
Posts: 4
Joined: Thu Dec 10, 2020 11:06 am

Maqueenplus

Post by Jackpo » Sat Dec 12, 2020 1:25 pm

Hallo.
How can i program de robot Maqueenplus. I can not find a schematic from this bot so i don't have pin-numbers how to program the motors.
Thanks.
Jack.

lujo
Posts: 24
Joined: Sat May 11, 2019 2:30 pm

Re: Maqueenplus

Post by lujo » Sun Dec 13, 2020 11:39 pm

Hi,

Check out: https://www.dfrobot.com/forum/viewtopic ... 176#p42615

That did not help me: downloads mu-editor with maqueen library distributed
as MS-Windows installer file. No MS-Windows here.

So, figured it out by sending bytes to i2c addr, see what happens.

Here is my line-following program for the mu-editor.

Code: Select all

$ cat maqueen_line_following.py 

from microbit import i2c, display, button_a, button_b, sleep
from microbit import pin13 as ir_left_led, pin14 as ir_right_led
from microbit import accelerometer
from micropython import const

i2c.init()
i2c_addr = const(16)

speed = const(50)

def drive():
  i2c.write(i2c_addr, bytes((0,0,speed)))
  i2c.write(i2c_addr, bytes((2,0,speed)))

def turn_right():
  i2c.write(i2c_addr, bytes((0,0,speed*2)))
  i2c.write(i2c_addr, bytes((2,0,0)))

def turn_left():
  i2c.write(i2c_addr, bytes((0,0,0)))
  i2c.write(i2c_addr, bytes((2,0,speed*2)))

def stop():
  i2c.write(i2c_addr, bytes((0,0,0)))
  i2c.write(i2c_addr, bytes((2,0,0)))

def run():
  p = 0
  while True:
    if accelerometer.is_gesture('face up'):
      stop()
    else:
      i = ir_left_led.read_digital() + 2 * ir_right_led.read_digital()
      if i == 0:
        drive()
      elif i == 1:
        turn_right()
        p = i
      elif i == 2:
        turn_left()
        p = i
      else:
        if p == 1:
          turn_right()
        if p == 2:
          turn_left()

run()
lujo

Jackpo
Posts: 4
Joined: Thu Dec 10, 2020 11:06 am

Re: Maqueenplus

Post by Jackpo » Mon Dec 14, 2020 10:39 am

Hallo Iujo

Thanks for answer, but the line: Check out: https://www.dfrobot.com/forum/viewtopic ... 176#p42615
gives: can not find!
What is wrong?
Thanks.
Jack.

lujo
Posts: 24
Joined: Sat May 11, 2019 2:30 pm

Re: Maqueenplus

Post by lujo » Mon Dec 14, 2020 12:27 pm

Hi,

Try this: go to https://www.dfrobot.com/forum/viewforum.php?f=7 (the Products
forum) and click Robotics. Search for micropython, read the post by nana.wang.

lujo

Jackpo
Posts: 4
Joined: Thu Dec 10, 2020 11:06 am

Re: Maqueenplus

Post by Jackpo » Wed Dec 16, 2020 1:26 pm

Hallo Lujo'

Sorry, but the linefollower program i tried but does not not work.
Jack.

kgarnier
Posts: 1
Joined: Mon Feb 21, 2022 7:55 pm

Re: Maqueenplus

Post by kgarnier » Mon Feb 21, 2022 8:05 pm

Hi lujo:

This code is very helpful, but I am wondering if you could explain something. In the drive, turn_right, and turn_left functions, what are the three numbers you are sending to the bytes in the two i2c.write statements? I can kind of guess, but not sure of the middle one. I can guess that the first statement is for the right motor and the second is for the left

First argument:
0 is right motor, 2 is left

Second argument:
Always 0, no not sure what this is for

Third argument:
How fast to turn the motor?
lujo wrote:
Sun Dec 13, 2020 11:39 pm

Code: Select all

def drive():
  i2c.write(i2c_addr, bytes((0,0,speed)))
  i2c.write(i2c_addr, bytes((2,0,speed)))

def turn_right():
  i2c.write(i2c_addr, bytes((0,0,speed*2)))
  i2c.write(i2c_addr, bytes((2,0,0)))

def turn_left():
  i2c.write(i2c_addr, bytes((0,0,0)))
  i2c.write(i2c_addr, bytes((2,0,speed*2)))

def stop():
  i2c.write(i2c_addr, bytes((0,0,0)))
  i2c.write(i2c_addr, bytes((2,0,0)))

Thanks for any help!

lujo
Posts: 24
Joined: Sat May 11, 2019 2:30 pm

Re: Maqueenplus

Post by lujo » Tue Feb 22, 2022 8:25 am

Hi,

This was for the "old" Maqueen, I don't have a Maqueen PLUS.

At the time DFRobot did not support MicroPython for the Maqueen.
Had to figure this out myself sending i2c commands en observing what happened.

From an earlier version of the code:

Code: Select all

def move(motor = 0, direction = 0, speed = 10):
  buf = bytearray(3)
  buf[0] = motor         # 0 = left, 2 = right
  buf[1] = direction     # 0 = CW, 1 = CCW
  buf[2] = speed         # 0 - 255
  i2c.write(i2c_addr, buf)
lujo

Post Reply