Raspberry pi Megapi, not working


#1

Hi, I’m trying to control to control a mega pi through a raspberry pi via python.

I’m trying to activate the encoder motors from the raspberry pi so I can setup a websocket server where it listens to and then use that as a control panel, but the the motors never activate.

I have already updated the firmware, it works via the bluetooth from my phone.

Its connected via the included jumper thingy (the black rectangle that you put on the raspberry pi pins and into the bottom of the mega pi), but i have also tried it via a usb cable with the same results

In the rpi i have this python script atm
i run it via sudo python3 filename.py
non sudo has the same results

from megapi import *

def onForwardFinish(slot):
	sleep(0.4);
	print("test2")
	bot.encoderMotorMove(slot,100,-1000,onBackwardFinish);

def onBackwardFinish(slot):
	sleep(0.4);
	print("slot")
	bot.encoderMotorMove(slot,100,1000,onForwardFinish);

if __name__ == '__main__':
	bot = MegaPi()
	bot.start()
	print("test")
	bot.encoderMotorRun(3,0);
	sleep(1);
	onForwardFinish(3);
	while 1:
		continue;

and it outputs this

[GCC 8.3.0]
init MegaPi
<megapi_python3.mSerial object at 0x76128db0>
test
test2


#2

If you are having trouble using these libraries and packages I suggest to write your own “easy” code.
What I did was look at example sketches from makeblock to control the motors and set-up a serial connection through which the bot will receive it’s commands.
In Python I use Pyserial to establish a serial connection to the bot.

I will post my code in the next couple of days on Github.

Let me know if you need help or if you succeeded. If you do need help tell me something more about your project and your ultimate goal. Often there are many ways to Rome…


#3

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