{ "info": { "author": "Morten Kals", "author_email": "morten@kals.no", "bugtrack_url": null, "classifiers": [], "description": "# Arduino-Python3 Command API\n\nThis API is forked from the original [Python Arduino Command API](https://github.com/thearn/Python-Arduino-Command-API) to add support for Python 3.\n\nThe Arduino-Python3 Command API is a lightweight Python library for\ncommunicating with [Arduino microcontroller boards](http://www.arduino.cc/) from a connected computer using\nstandard serial IO, either over a physical wire\nor wirelessly. It is written using a custom protocol, similar to [Firmata](http://firmata.org/wiki/Main_Page).\n\nThis allows a user to quickly prototype programs for Arduino using Python code, or to\nsimply read/control/troubleshoot/experiment\nwith hardware connected to an Arduino board without ever having to recompile and reload sketches to the board itself.\n\nMethod names within the Arduino-Python3 Command API are designed to be as close\nas possible to their Arduino programming language counterparts\n\n## Simple usage example (LED blink)\n```python\n#!/usr/bin/env python\n\"\"\"\n Blinks an LED on digital pin 13\n in 1 second intervals\n\"\"\"\n\nfrom Arduino import Arduino\nimport time\n\nboard = Arduino() # plugged in via USB, serial com at rate 115200\nboard.pinMode(13, \"OUTPUT\")\n\nwhile True:\n board.digitalWrite(13, \"LOW\")\n time.sleep(1)\n board.digitalWrite(13, \"HIGH\")\n time.sleep(1)\n```\n\n## Requirements:\n- [Python](http://python.org/) 3.7 tested on Windows and macOS.\n- [pyserial](http://pyserial.sourceforge.net/) 2.6 or higher\n- Any [Arduino compatible microcontroller](https://www.sparkfun.com/categories/242) with at least 14KB of flash memory\n\n## Installation:\nEither run `pip install arduino-python3` from a command line, or run `python setup.py\nbuild install` from the source directory to install this library.\n\n## Setup:\n1. Verify that your Arduino board communicates at the baud rate specified in the\n`setup()` function (line 407) in `prototype.ino`. Change it there if necessary.\n2. Load the `prototype.ino` sketch onto your Arduino board, using the Arduino IDE.\n3. Set up some kind of serial I/O communication between the Arduino board and your computer (via physical USB cable,\nBluetooth, xbee, etc. + associated drivers)\n4. Add `from Arduino import Arduino` into your python script to communicate with your Arduino\n\nFor a collection of examples, see `examples.py`. This file contains methods which replicate\nthe functionality of many Arduino demo sketches.\n\n## Testing:\nThe `tests` directory contains some basic tests for the library. Extensive code coverage is a bit difficult to expect for every release, since a positive test involves actually\nconnecting and issuing commands to a live Arduino, hosting any hardware\nrequired to test a particular function. But a core of basic communication tests\nshould at least be maintained here and used before merging into the `master` branch.\n\nAfter installation, the interactive tests can be run from the source directory:\n```bash\n$ python tests/test_main.py\n```\n\nAutomated tests can be run from the source directory with:\n```bash\n$ python tests/test_arduino.py\n```\n\n## Classes\n- `Arduino(baud)` - Set up communication with currently connected and powered\nArduino.\n\n```python\nboard = Arduino(\"115200\") #Example\n```\n\nThe device name / COM port of the connected Arduino will be auto-detected.\nIf there are more than one Arduino boards connected,\nthe desired COM port can be also be passed as an optional argument:\n\n```python\nboard = Arduino(\"115200\", port=\"COM3\") #Windows example\n```\n```python\nboard = Arduino(\"115200\", port=\"/dev/tty.usbmodemfa141\") #OSX example\n```\n\nA time-out for reading from the Arduino can also be specified as an optional\nargument:\n\n```python\nboard = Arduino(\"115200\", timeout=2) #Serial reading functions will\n#wait for no more than 2 seconds\n```\n\n## Methods\n\n**Digital I/O**\n\n- `Arduino.digitalWrite(pin_number, state)` turn digital pin on/off\n- `Arduino.digitalRead(pin_number)` read state of a digital pin\n\n```python\n#Digital read / write example\nboard.digitalWrite(13, \"HIGH\") #Set digital pin 13 voltage\nstate_1 = board.digitalRead(13) #Will return integer 1\nboard.digitalWrite(13, \"LOW\") #Set digital pin 13 voltage\nstate_2 = board.digitalRead(13) #Will return integer 0\n```\n\n- `Arduino.pinMode(pin_number, io_mode)` set pin I/O mode\n- `Arduino.pulseIn(pin_number, state)` measures a pulse\n- `Arduino.pulseIn_set(pin_number, state)` measures a pulse, with preconditioning\n\n```python\n#Digital mode / pulse example\nboard.pinMode(7, \"INPUT\") #Set digital pin 7 mode to INPUT\nduration = board.pulseIn(7, \"HIGH\") #Return pulse width measurement on pin 7\n```\n\n**Analog I/O**\n\n- `Arduino.analogRead(pin_number)` returns the analog value\n- `Arduino.analogWrite(pin_number, value)` sets the analog value\n\n```python\n#Analog I/O examples\nval=board.analogRead(5) #Read value on analog pin 5 (integer 0 to 1023)\nval = val / 4 # scale to 0 - 255\nboard.analogWrite(11) #Set analog value (PWM) based on analog measurement\n```\n\n**Shift Register**\n\n- `Arduino.shiftIn(dataPin, clockPin, bitOrder)` shift a byte in and returns it\n- `Arduino.shiftOut(dataPin, clockPin, bitOrder, value)` shift the given byte out\n\n`bitOrder` should be either `\"MSBFIRST\"` or `\"LSBFIRST\"`\n\n**Servo Library Functionality**\nSupport is included for up to 8 servos.\n\n- `Arduino.Servos.attach(pin, min=544, max=2400)` Create servo instance. Only 8 servos can be used at one time.\n- `Arduino.Servos.read(pin)` Returns the angle of the servo attached to the specified pin\n- `Arduino.Servos.write(pin, angle)` Move an attached servo on a pin to a specified angle\n- `Arduino.Servos.writeMicroseconds(pin, uS)` Write a value in microseconds to the servo on a specified pin\n- `Arduino.Servos.detach(pin)` Detaches the servo on the specified pin\n\n```python\n#Servo example\nboard.Servos.attach(9) #declare servo on pin 9\nboard.Servos.write(9, 0) #move servo on pin 9 to 0 degrees\nprint board.Servos.read(9) # should be 0\nboard.Servos.detach(9) #free pin 9\n```\n\n**Software Serial Functionality**\n\n- `Arduino.SoftwareSerial.begin(ss_rxPin, ss_txPin, ss_device_baud)` initialize software serial device on\nspecified pins.\nOnly one software serial device can be used at a time. Existing software serial instance will\nbe overwritten by calling this method, both in Python and on the Arduino board.\n- `Arduino.SoftwareSerial.write(data)` send data using the Arduino 'write' function to the existing software\nserial connection.\n- `Arduino.SoftwareSerial.read()` returns one byte from the existing software serial connection\n\n```python\n#Software serial example\nboard.SoftwareSerial.begin(0, 7, \"19200\") # Start software serial for transmit only (tx on pin 7)\nboard.SoftwareSerial.write(\" test \") #Send some data\nresponse_char = board.SoftwareSerial.read() #read response character\n```\n\n**EEPROM**\n\n- `Arduino.EEPROM.read(address)` reads a byte from the EEPROM\n- `Arduino.EEPROM.write(address, value)` writes a byte to the EEPROM\n- `Arduino.EEPROM.size()` returns size of the EEPROM\n\n```python\n#EEPROM read and write examples\nlocation = 42\nvalue = 10 # 0-255(byte)\n\nboard.EEPROM.write(location, 10)\nprint(board.EEPROM.read(location))\nprint('EEPROM size {size}'.format(size=board.EEPROM.size()))\n```\n\n\n**Misc**\n\n- `Arduino.close()` closes serial connection to the Arduino.\n\n## To-do list:\n- Expand software serial functionality (`print()` and `println()`)\n- Add simple reset functionality that zeros out all pin values\n- Add I2C / TWI function support (Arduino `Wire.h` commands)\n- Include a wizard which generates 'prototype.ino' with selected serial baud rate and Arduino function support\n(to help reduce memory requirements).\n- Multi-serial support for Arduino mega (`Serial1.read()`, etc)\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/mkals/Arduino-Python3-Command-API", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "arduino-python3", "package_url": "https://pypi.org/project/arduino-python3/", "platform": "", "project_url": "https://pypi.org/project/arduino-python3/", "project_urls": { "Homepage": "https://github.com/mkals/Arduino-Python3-Command-API" }, "release_url": "https://pypi.org/project/arduino-python3/0.6/", "requires_dist": [ "pyserial" ], "requires_python": "", "summary": "A light-weight Python library that provides a serial bridge for communicating with Arduino microcontroller boards. Extended to work with Python 3", "version": "0.6" }, "last_serial": 5241726, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "dd2adb6d80b27a59bcc588f9b537460d", "sha256": "01e11c9e033f19acbdf4f611a817dec7a9cfd2af1f8db073c9f176976b756d78" }, "downloads": -1, "filename": "arduino_python3-0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "dd2adb6d80b27a59bcc588f9b537460d", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11570, "upload_time": "2019-04-09T21:46:29", "url": "https://files.pythonhosted.org/packages/21/ce/0b728e608eba1e2d6180801d61529bd6ddc6bb25aa73e46136b927f1212d/arduino_python3-0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "896bf31b4cfe3241b41cacf465b04580", "sha256": "30406bf6eb0ccecb14b63b7c5093d885c74d62d4a19c4e766fc66f3f99043018" }, "downloads": -1, "filename": "arduino-python3-0.1.tar.gz", "has_sig": false, "md5_digest": "896bf31b4cfe3241b41cacf465b04580", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8856, "upload_time": "2019-04-09T21:46:31", "url": "https://files.pythonhosted.org/packages/a7/0d/14533d3970ea26c805ea5b044516418280a923cc34023040fefb978bc1e8/arduino-python3-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "c0ced29f1ea24c7310e4dbcc27ce17cb", "sha256": "adc6bd9dbe39533f43fdae17fc952f3089b599f1d3c59d7956d31043894b0930" }, "downloads": -1, "filename": "arduino_python3-0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "c0ced29f1ea24c7310e4dbcc27ce17cb", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11590, "upload_time": "2019-04-09T23:49:09", "url": "https://files.pythonhosted.org/packages/f3/f0/212fbf5dfe954e13745e8a144bfc427ed8be7b5e99e03fd472c4c6eda0c3/arduino_python3-0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "39c29b424d173956570af77987b1c37e", "sha256": "d5e9a27f5e5d62adc46ed72b4730ebc442fc3c6a0efb7a4b4621c9884e93bba6" }, "downloads": -1, "filename": "arduino-python3-0.2.tar.gz", "has_sig": false, "md5_digest": "39c29b424d173956570af77987b1c37e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8871, "upload_time": "2019-04-09T23:49:11", "url": "https://files.pythonhosted.org/packages/77/2f/dd20e7acd4ec3cecb70a3235e2e7b497f43b5c32a1c542731577cab3a118/arduino-python3-0.2.tar.gz" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "8f3a93a92cf5677cc9decb2cb23c3442", "sha256": "ca30d74f36f51635b8171412003ba9357e20203d9cc6935d6da2f877038550ee" }, "downloads": -1, "filename": "arduino_python3-0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "8f3a93a92cf5677cc9decb2cb23c3442", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 12460, "upload_time": "2019-04-21T05:42:57", "url": "https://files.pythonhosted.org/packages/10/9a/1189c6de54dead8b6a957bcd9965e2adb55567f6d2da8967f460fbd07005/arduino_python3-0.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "748b2c346fc4622bd9f2087363488298", "sha256": "350e586edee0ed909b0df8f67af6f090cfb2ce742973129ab8393b1dbd89659f" }, "downloads": -1, "filename": "arduino-python3-0.3.tar.gz", "has_sig": false, "md5_digest": "748b2c346fc4622bd9f2087363488298", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9753, "upload_time": "2019-04-21T05:43:01", "url": "https://files.pythonhosted.org/packages/36/84/9e805592fda555350b15d453f3e055d0b9eee787f0de68f0b5f45aca2bac/arduino-python3-0.3.tar.gz" } ], "0.4": [ { "comment_text": "", "digests": { "md5": "32c7a6ff4ad5fb04215a47512bc1dbbb", "sha256": "e8d3b1e0700e49823b698231bed44b503695d42f10ee8de444a85d6123a09a87" }, "downloads": -1, "filename": "arduino_python3-0.4-py3-none-any.whl", "has_sig": false, "md5_digest": "32c7a6ff4ad5fb04215a47512bc1dbbb", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 12694, "upload_time": "2019-04-21T23:06:01", "url": "https://files.pythonhosted.org/packages/43/5c/00ae204529022588734e40cd9505f9d1aef5c60cda8eeede650d4ae0fd0a/arduino_python3-0.4-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "bbbe9885d0b8c11e65cbf1b425c4368c", "sha256": "5466a88e3bcee36dd2c51f2bc9031c9a05b0c9c1afa7f40f788de03c7887d994" }, "downloads": -1, "filename": "arduino-python3-0.4.tar.gz", "has_sig": false, "md5_digest": "bbbe9885d0b8c11e65cbf1b425c4368c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9969, "upload_time": "2019-04-21T23:06:04", "url": "https://files.pythonhosted.org/packages/b7/98/72d01ec40db34236103e749b9aa20e91e4045389ae56c638b0787fdc203b/arduino-python3-0.4.tar.gz" } ], "0.4.1": [ { "comment_text": "", "digests": { "md5": "0983dc476164ac6c65d8a59b12eb142a", "sha256": "297bf5d7a05e105813ffbeb97539ba84bc96a1499202f00852dc5085201d8858" }, "downloads": -1, "filename": "arduino_python3-0.4.1-py3-none-any.whl", "has_sig": false, "md5_digest": "0983dc476164ac6c65d8a59b12eb142a", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 12811, "upload_time": "2019-04-29T18:02:26", "url": "https://files.pythonhosted.org/packages/e7/b2/37b62e4158eb49f404be5594e75572d005b3450e7ceb1479d58755f34d78/arduino_python3-0.4.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "65d9c446943803e4e0417e876d3340ae", "sha256": "5f95e23cc8257cefc88e65ec87b820de61fbe4048e5f9051c85e14ee322312d4" }, "downloads": -1, "filename": "arduino-python3-0.4.1.tar.gz", "has_sig": false, "md5_digest": "65d9c446943803e4e0417e876d3340ae", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10055, "upload_time": "2019-04-29T18:02:31", "url": "https://files.pythonhosted.org/packages/d3/65/f877bec5e7338cb806cdc0363bc9a4fe4be28fb4adf207b264de39b6285b/arduino-python3-0.4.1.tar.gz" } ], "0.5": [ { "comment_text": "", "digests": { "md5": "bb42bbed6187de8d2651b5b7c9083a45", "sha256": "44c4e3be23924f5bed51b4366491073271ae3cf08c39e3e01bbc265285fdc67a" }, "downloads": -1, "filename": "arduino_python3-0.5-py3-none-any.whl", "has_sig": false, "md5_digest": "bb42bbed6187de8d2651b5b7c9083a45", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 13512, "upload_time": "2019-05-02T23:28:55", "url": "https://files.pythonhosted.org/packages/7a/e9/cff38661fa980198e49b95e110d1825ccf112be7084f41b716be9557131a/arduino_python3-0.5-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "468a9bcc6ce4e3d0a9c9b9f49b4187f6", "sha256": "797ac29690eb4501d924b8ec1d293ff16b2c22d2fdc5941d09efbe56dcf3877a" }, "downloads": -1, "filename": "arduino-python3-0.5.tar.gz", "has_sig": false, "md5_digest": "468a9bcc6ce4e3d0a9c9b9f49b4187f6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10730, "upload_time": "2019-05-02T23:28:57", "url": "https://files.pythonhosted.org/packages/7d/8d/6683a46f74d8f0132406c466aa1d9e0b1b965b65384540919d445e16ebf1/arduino-python3-0.5.tar.gz" } ], "0.6": [ { "comment_text": "", "digests": { "md5": "01430e0aa6e3ef1a68c109799d2be88b", "sha256": "dc99d082a474d1407b5428923e62db0fe4ee0b503db6555fedfe9080bec4edb6" }, "downloads": -1, "filename": "arduino_python3-0.6-py3-none-any.whl", "has_sig": false, "md5_digest": "01430e0aa6e3ef1a68c109799d2be88b", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11915, "upload_time": "2019-05-08T07:19:01", "url": "https://files.pythonhosted.org/packages/3a/f7/c9d1506b76f82178e71f6c6bbb795b6b2f573d1b7285e1e0f6eb3e240e46/arduino_python3-0.6-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "fbf567faf00df267be655cbf44a2a957", "sha256": "765e96e66cdab9382995d1ec10a6381c929478d32936ae31c436e53dcd9a9b8c" }, "downloads": -1, "filename": "arduino-python3-0.6.tar.gz", "has_sig": false, "md5_digest": "fbf567faf00df267be655cbf44a2a957", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9147, "upload_time": "2019-05-08T07:19:04", "url": "https://files.pythonhosted.org/packages/cb/c1/6d7bbceb45315aa78f9fa75a60ee14a796eee2b1c2170b21c31a50fe208b/arduino-python3-0.6.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "01430e0aa6e3ef1a68c109799d2be88b", "sha256": "dc99d082a474d1407b5428923e62db0fe4ee0b503db6555fedfe9080bec4edb6" }, "downloads": -1, "filename": "arduino_python3-0.6-py3-none-any.whl", "has_sig": false, "md5_digest": "01430e0aa6e3ef1a68c109799d2be88b", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11915, "upload_time": "2019-05-08T07:19:01", "url": "https://files.pythonhosted.org/packages/3a/f7/c9d1506b76f82178e71f6c6bbb795b6b2f573d1b7285e1e0f6eb3e240e46/arduino_python3-0.6-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "fbf567faf00df267be655cbf44a2a957", "sha256": "765e96e66cdab9382995d1ec10a6381c929478d32936ae31c436e53dcd9a9b8c" }, "downloads": -1, "filename": "arduino-python3-0.6.tar.gz", "has_sig": false, "md5_digest": "fbf567faf00df267be655cbf44a2a957", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9147, "upload_time": "2019-05-08T07:19:04", "url": "https://files.pythonhosted.org/packages/cb/c1/6d7bbceb45315aa78f9fa75a60ee14a796eee2b1c2170b21c31a50fe208b/arduino-python3-0.6.tar.gz" } ] }