Robofun 機器人論壇

標題: 用 Python 寫 Arduino sketches [打印本頁]

作者: pizg    時間: 2013-2-1 11:26
標題: 用 Python 寫 Arduino sketches
本帖最後由 pizg 於 2013-2-1 16:35 編輯

我最近發現也可以使用 Python 程式語言搭配眾多的 Python IDE 來控制 Arduino,
熟悉 Python 的人都知道它的好處,
這兒有簡介可以瞧瞧 https://ep2013.europython.eu/media/conference/slides/python-e-arduino-una-storia-di-serpenti-e-re.pdf
其中 eMail Notifier 是一個不錯的例子 http://www.robofun.net/forum/viewthread.php?tid=7930&extra=page%3D1
其它的我就不多說了.

Python 和 Arduino 它們之間也是透過 Firmata 方式連繫的,
所以 Arduino 端必須要先 upload 「Standard Firmata」這支程式,
下列是一個能讓 pin 13 燈閃亮的範例.

相關資料:
Python http://www.python.org/
pyFirmata https://bitbucket.org/fab/pyfirmata/src/96116e877527?at=default

程式碼:

  1. #Blink.py
  2. import pyfirmata

  3. PIN = 13 # Pin 13 is used
  4. DELAY = 1 # A 1 seconds delay
  5. PORT = '\\.\COM3'
  6. board = pyfirmata.Arduino(PORT)

  7. while True:
  8.     board.digital[PIN].write(1) # Set the LED pin to 1 (HIGH)
  9.     board.pass_time(DELAY)
  10.     board.digital[PIN].write(0) # Set the LED pin to 0 (LOW)
  11.     board.pass_time(DELAY)
複製代碼


ps. 1.剛剛才發現對岸已有人用 Python 寫了一個 Arduino IDE, 真是牛人啊,
http://www.geek-workshop.com/forum.php?mod=viewthread&tid=2465
2.這個也是洋人用 Python 寫的Arduino IDE http://gnome.eu.org/index.php/Gnoduino#Source_Code




歡迎光臨 Robofun 機器人論壇 (https://robofun.net/forum/) Powered by Discuz! X3.2