Mbot Mega from RPi


#1

I have a mbot Mega here that I have connected to a RPi. I would like to have computer vision running on the RPi then the RPi can control the mecan wheels.

I have the RPi setup correct;y and have it connecting MegaPi and can get 2 of the 4 wheels to turn. Each motor driver has 2 DC motors connected to the green ports below the motor drivers. It seems that it will only run the first motor of each slot and not the second motor.

Here’s the code that I tested

from megapi import *
import time

bot = MegaPi()
bot.start()

bot.motorRun(1,50)
bot.motorRun(2,50)
bot.motorRun(3,50)
bot.motorRun(4,50)

time.sleep(3)

bot.motorRun(1,0)
bot.motorRun(2,0)
bot.motorRun(3,0)
bot.motorRun(4,0)

bot.close()


#2

Hello,

The Library used in your code is out of date, which cannot distinguish motor 1&2 in one port.
To realize the function, you may need to update the Python3 and install Makeblock Library, details please refer to: https://support.makeblock.com/hc/en-us/articles/1500012868722-Programming-mBot-Mega-with-Raspberry-Pi-in-Python

Here is the demo for your reference: https://gist.github.com/xeecos/5fa6cb5876a8c9449562d8026942fff1


#3

Thanks for answering my question.

I am not able to execute your code without error.

The RPi serial port is correctly setup.

I did a “sudo pip3 install makeblock” at the command line as in your code, I had previously done a “sudo pip install megapi” as in the instructions on the webpage

When I tried to execute your code I got this error when it tried to execute motor1.run(50)

Traceback (most recent call last):
File “play.py”, line 8, in
motor1.run(50)
File “/home/pi/.local/lib/python3.7/site-packages/makeblock/modules/rj25/modules.py”, line 177, in run
self.call(self._pack)
File “/home/pi/.local/lib/python3.7/site-packages/makeblock/modules/rj25/modules.py”, line 29, in call
self._board.call(pack)
File “/home/pi/.local/lib/python3.7/site-packages/makeblock/boards/base/init.py”, line 68, in call
self._dev.send(pack.to_buffer())
AttributeError: ‘NoneType’ object has no attribute ‘send’


#4

Hello,

Can we have your “play.py” file to check what happened?
Thanks!


#5

It is just a copy of your program https://www.dropbox.com/s/aop9pf0l2ynsvjc/play.py?dl=0


#6

Hi,
Sorry for late response.
The program is normal. but we found similar error warning while we plug out the USB cable between RPi & MegaPi, you can enter below links for details.

USB connection: https://download.makeblock.com/USB%20Connection.png
Normal run:https://download.makeblock.com/normal.mp4

Please kindly check if the USB cable connection is stable.


#7

Ok if I connect via USB then it works correctly.

The USB lead is too big to fit on the robot so I need to be able to use RPi GPIO pins. How can I make it work without USB lead only using GPIO pins??

Here’s my robot


#8

Hello,

Sorry but we didn’t consider GPIO pins before, we will forward your idea to our product develop team to raise their attention.


#9

The link you posted above to the official website https://support.makeblock.com/hc/en-us/articles/1500012868722-Programming-mBot-Mega-with-Raspberry-Pi-in-Python shows connection by GPIO pins .

Are you saying it is not possible to do what is advertised it can do??

see these pictures from the official website


mega-Raspberry%20Pi-08


#10

Hello,

Sorry for the confusion.
Here follows instruction with RPi 3B+:
On your Raspberry Pi, disable the login prompt from Desktop > Menu > Preferences > Raspberry Pi Configuration.

mega-Raspberry_Pi-02.png

If you are using raspberry 3 B+, since the Bluetooth function takes up the ttyAMA0 port, you have two ways to solve this problem.
a. Disable the pi3 bluetooth and restore UART0/ttyAMA0 over GPIOs 14&15

b. Switch pi3 blutooth function to use the mini-UART(ttyS0) and restore UART0/ttyAMA0 over GPIOs 14&15.

Here, I disable the pi3 bluetooth as an example
a. Search for pi3-disable-bt in file /boot/overlays/README, it will show you how to disable the bluetooth; if you want switch the bluetooth to mini-UART(ttyS0), you can search for pi3-miniuart-bt.

mega-Raspberry_Pi-03.jpg

b. Modify the file /boot/config.txt. At the end of the file, add the following content.

#Enable uart

enable_uart=1

dtoverlay=pi3-disable-bt
mega-Raspberry_Pi-04.jpg

c. Reboot Raspberry Pi

d. Open the Terminal and input the following command:

sudo systemctl disable hciuart
e. Now you can use ttyAMA0 as UART over GPIOs 14&15


#11

I have already done all that before I started this thread. I have a RPi4 and the UART is setup correctly as when I use the old module "from megapi import *"the RPi will communicate with the megapi but only 2 of the 4 wheels will turn see my original post at the top of this thread. It is only the new module “from makeblock import MegaPi,SerialPort” that it causes an error. There is a bug in the new module.


#12

Hello Shane,

You can try megapi = MegaPi.connect(SerialPort.connect("/dev/ttyXXXX")) to select exact port for connection.
It’s test to be available, refer to https://download.makeblock.com/GPIO%20connection.mp4


#13

Sorry for the late return but I have been very busy with my professional work.

I tried using your new code and everything worked correctly.

Thank you :slight_smile:


#14

Hello Shane,

We’re glad that the problem has been solved!
Feel free to let us know if there’s any other inquires, you can also contact service@makeblock.com directly.


#15

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.