乐高EV3机器人编程入门(持续更新...)

2016-3-11 Frank EV3

搭建环境


与PC通讯

  1. 通讯方式-Bluetooth,使用python+pySerial实现串口通信,osx安装pySerial
sudo pip install pySerial
'''
while True:
        with open('/dev/tty.EV3-SerialPort', 'w+', 0) as bt:
                incoming = bt.read()
                print incoming
'''
import serial
import time
EV3 = serial.Serial('/dev/tty.EV3-SerialPort')
print "Listening for EV3 Bluetooth messages, press CTRL C to quit."
try:
   while 1:
      n = EV3.inWaiting()
      if n <> 0:
         s = EV3.read(n)
         for n in s:
            print "%02X" % ord(n),
         print
      else:
         # No data is ready to be processed
         time.sleep(0.5)
except KeyboardInterrupt:
   pass
EV3.close()

发表评论 登录

Top