Megapi python raspberry pi 3B Problem,Please Help~


#1

I use megpai, connnect whith raspberry pi 3B, the Wiring like this:

but when I run the python example code:

encoderMotorMove.py
from megapi import *

def onForwardFinish(slot):
sleep(0.4);
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()
bot.encoderMotorRun(1,0);
sleep(1);
onForwardFinish(1);
while 1:
continue;

Then I got the error:
init MegaPi
<megapi.mSerial instance at 0x76748b70>
[Errno 25] Inappropriate ioctl for device
Error in sys.excepthook:
Traceback (most recent call last):
File “/usr/local/lib/python2.7/dist-packages/megapi.py”, line 89, in excepthook
self.close()
File “/usr/local/lib/python2.7/dist-packages/megapi.py”, line 92, in close
self.device.close()
File “/usr/local/lib/python2.7/dist-packages/megapi.py”, line 51, in close
self.ser.close()
File “/usr/lib/python2.7/dist-packages/serial/serialposix.py”, line 423, in close
os.close(self.fd)
OSError: [Errno 9] Bad file descriptor

Original exception was:
Traceback (most recent call last):
File “encoderMotorMove.py”, line 15, in
bot.encoderMotorRun(1,0);
File “/usr/local/lib/python2.7/dist-packages/megapi.py”, line 209, in encoderMotorRun
self.__writePackage(bytearray([0xff,0x55,0x8,0,0x2,deviceId,0,slot,1]+self.short2bytes(speed)))
File “/usr/local/lib/python2.7/dist-packages/megapi.py”, line 116, in __writePackage
self.device.writePackage(pack)
File “/usr/local/lib/python2.7/dist-packages/megapi.py”, line 38, in writePackage
self.ser.write(package)
File “/usr/lib/python2.7/dist-packages/serial/serialposix.py”, line 489, in write
raise SerialException(‘write failed: %s’ % (v,))
serial.serialutil.SerialException: write failed: [Errno 9] Bad file descriptor

Thank you!


#2

Not entirely sure what’s going on, but the bad file descriptor usually indicates that a serial port was not opened correctly.


#3

I am getting the below error please help

I Have IC2 and SPI enabled but Serial disabled. If I enable serial raspberry won’t boot

pi@raspberrypi:~ $ sudo python ./stepperMove.py
init MegaPi
<megapi.mSerial instance at 0x766e0b98>
[Errno 25] Inappropriate ioctl for device


#4

Hmm, I read about a similar issue in this thread that seemed to have a solution. Not sure if it will help you, but we can keep looking. :slight_smile:


#5

See my post here.

You need to alter your boot/config.txt using 1 of 2 ways;

1.Enable uart & set the frequency so you can use the default dev/ttys0

core_freq=250
enable_uart=1
*note: call bot.start(’/dev/ttyS0’)

2.Disabled bluetooth, so the original port can be used for serial communication

dtoverlay=pi3-disable-bt
*note: call bot.start() as normal


#6

Hello I need help with the installation of the Raspberry pi with megapi.
I have a Makeblock Ultimate V2.0
On the robot is the current firmware. About mBlock and Android App Does the robot work.
I installed the megapi on the Raspberry pi.
On the Raspberry pi I have the current raspbian version installed and as described Serial = Disabled and set in the config dtoverlay = pi3-disable-bt.
I installed sudo pip install megapi.
When I run the script motorRun.py I get

Init MegaPi
Megapi.mSerial instance at 0x76755b20
[Errno 5] Input / qutput error

can someone help me


#7

I’m getting the same error as roboterpi @tec_support .


Can't control Megapi via raspberry pi and python
#8

Hi mizzi,

It looks like the raspberry serial configuration is incorrect.The serial part of the raspberry has relatively large correlation with the os version of the raspberry Pi. Different version raspberry os has different configuration.This has little relationship with MegaPi, you may need locate the reason by yourself.

Here we have an example instruction to guide the serial configuration for the 2016-5-10 version raspberry, you may use this version raspberry and refer to it have a try.


#9