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!