1 Star 0 Fork 0

大魔王 / Python-Arduino-Proto-API-v2

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Python Arduino Prototyping API v2

This is a project based on the original Python Arduino Prototyping API. I started a fork and after a while the whole thing was getting too different to make a pull request so I just put it here. The old project had wierd things going on to handle the communication, where I rely on parseInt() to do the work for me. There were also problems with analogWrite(), which is working in this version.

Major changes:

  • .pde is completely redone
  • Small changes in the arduino.py file
  • Added examples

Here follows the original README (with updated example):

© 2009-2010 Akash Manohar J akash@akash.im under the MIT License

The Python Arduino Prototyping API helps you to quickly prototype Arduino programs, without having to repeatedly load the program to the Arduino board.

Setup:

  1. Load prototype.pde onto your Arduino dev board.
  2. Import the arduino lib in your python script.

Methods

Arduino.output(list_of_output_pins) - set the output pins

Digital I/O

  1. Arduino.setHigh(pin_number)
  2. Arduino.setLow(pin_number)
  3. Arduino.getState(pin_number)
  4. Arduino.getState() - returns true if pin state is high, else it returns false.

Analog I/O

  1. Arduino.analogRead(pin_number) - returns the analog value
  2. Arduino.analogWrite(pin_number, value) - sets the analog value

Misc

1.) Arduino.turnOff() - sets all the pins to low state

2.) Arduino.close() - closes serial connection. Using this makes sure that you won't have to disconnect & reconnect the Arduino again to recover the serial port.

Usage example

from arduino import Arduino
import time

b = Arduino('/dev/ttyUSB0')
pin = 9

#declare output pins as a list/tuple
b.output([pin])

for xrange(10):
    b.setHigh(pin)
    time.sleep(1)
    print b.getState(pin)
    b.setLow(pin)
    print b.getState(pin)
    time.sleep(1)

b.close()
Copyright (c) 2009-2010 Akash Manohar J <akash@akash.im> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

A Python-Arduino-Prototyping-API fork gone wild 展开 收起
Python
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Python
1
https://gitee.com/kingsjl/Python-Arduino-Proto-API-v2.git
git@gitee.com:kingsjl/Python-Arduino-Proto-API-v2.git
kingsjl
Python-Arduino-Proto-API-v2
Python-Arduino-Proto-API-v2
master

搜索帮助