pizg 发表于 2013-2-1 11:39:18

用 Python 寫 Arduino sketches

我最近發現也可以使用 Python 程式語言搭配眾多的 Python IDE 來控制 Arduino,
熟悉 Python 的人都知道它的好處,
其中 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

程式碼:

#inoBlink.py
import pyfirmata

PIN = 13 # Pin 13 is used
DELAY = 1 # A 1 seconds delay

# Adjust that the port match your system, see samples below:
# On Linux: /dev/tty.usbserial-A6008rIF, /dev/ttyACM0,
# On Windows: \\.\COM1, \\.\COM2
PORT = '\\.\COM3'

# Creates a new board
board = pyfirmata.Arduino(PORT)

# Loop for blinking the led
while True:
    board.digital.write(1) # Set the LED pin to 1 (HIGH)
    board.pass_time(DELAY)
    board.digital.write(0) # Set the LED pin to 0 (LOW)
    board.pass_time(DELAY)

peanut 发表于 2013-2-1 14:10:24

看起来不错。有空了研究一下

estar 发表于 2013-2-4 09:36:05

这样的话,arduino还能脱离电脑独立运行吗?

pizg 发表于 2013-2-21 12:35:22

estar 发表于 2013-2-4 09:36 static/image/common/back.gif
这样的话,arduino还能脱离电脑独立运行吗?

Arduino當然可以不必脫離電腦而運行.
不同的用途有不同的做法,
為何一定要跟電腦劃清界線?

hick 发表于 2013-8-18 01:42:22

强烈支持! 个人觉得利用 python 处理传统计算机和网络的数据,然后发送指令到 arduino 是很有应用空间的


hick 发表于 2013-8-18 01:48:09

pizg 发表于 2013-2-21 12:35 static/image/common/back.gif
Arduino當然可以不必脫離電腦而運行.
不同的用途有不同的做法,
為何一定要跟電腦劃清界線?

新手请教下 pizg 同学:python 这种方式跟 arduino IDE 的方式有是不是有什么不同?

我现在理解起来 arduino IDE 必须上传程序到板子上; python 这种操作方式算怎么个回事?理解你说的,也是用 firmata 这种方式上传到板子上?
页: [1]
查看完整版本: 用 Python 寫 Arduino sketches