|
| 1 | +# Python Arduino Prototyping API v2 |
| 2 | + |
| 3 | +This is a project based on the original [Python Arduino Prototyping API](https://github.com/HashNuke/Python-Arduino-Prototyping-API). |
| 4 | +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. |
| 5 | +The old project had wierd things going on to handle the communication, where I rely on parseInt() to do the work for me. |
| 6 | +There were also problems with analogWrite(), which is working in this version. |
| 7 | + |
| 8 | +Major changes: |
| 9 | +- .pde is completely redone |
| 10 | +- Small changes in the arduino.py file |
| 11 | +- Added examples |
| 12 | + |
| 13 | +Here follows the original README: |
| 14 | + |
| 15 | +> © 2009-2010 Akash Manohar J <akash@akash.im> |
| 16 | +> under the MIT License |
| 17 | +
|
| 18 | +The Python Arduino Prototyping API helps you to quickly prototype Arduino programs, |
| 19 | +without having to repeatedly load the program to the Arduino board. |
| 20 | + |
| 21 | +#### Setup: |
| 22 | + |
| 23 | +1. Load prototype.pde onto your Arduino dev board. |
| 24 | +2. Import the arduino lib in your python script. |
| 25 | + |
| 26 | + |
| 27 | +## Methods |
| 28 | + |
| 29 | +*Arduino.output(list_of_output_pins)* - set the output pins |
| 30 | + |
| 31 | +**Digital I/O** |
| 32 | + |
| 33 | +1. *Arduino.setHigh(pin_number)* |
| 34 | +2. *Arduino.setLow(pin_number)* |
| 35 | +3. *Arduino.getState(pin_number)* |
| 36 | +4. *Arduino.getState()* - returns true if pin state is high, else it returns false. |
| 37 | + |
| 38 | +**Analog I/O** |
| 39 | + |
| 40 | +1. *Arduino.analogRead(pin_number)* - returns the analog value |
| 41 | +2. *Arduino.analogWrite(pin_number, value)* - sets the analog value |
| 42 | + |
| 43 | +**Misc** |
| 44 | + |
| 45 | +1.) *Arduino.turnOff()* - sets all the pins to low state |
| 46 | + |
| 47 | +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. |
| 48 | + |
| 49 | +## Usage example |
| 50 | + |
| 51 | + from arduino import Arduino |
| 52 | + import time |
| 53 | + |
| 54 | + b = Arduino('/dev/ttyUSB0') |
| 55 | + pin = 9 |
| 56 | + |
| 57 | + #declare output pins as a list/tuple |
| 58 | + b.output([pin]) |
| 59 | + |
| 60 | + for xrange(10): |
| 61 | + b.setHigh(pin) |
| 62 | + time.sleep(1) |
| 63 | + print b.getState(pin) |
| 64 | + b.setLow(pin) |
| 65 | + print b.getState(pin) |
| 66 | + time.sleep(1) |
| 67 | + |
| 68 | + b.close() |
0 commit comments