├── .gitattributes ├── .gitignore ├── README.md ├── examples ├── analog_input_with_time_stamps.py ├── analog_input_with_time_stamps_oo.py ├── dht.py ├── digital_input.py ├── digital_input_debounce.py ├── digital_input_pullup.py ├── digital_input_with_keep_alive.py ├── digital_output.py ├── digital_pin_output.py ├── disable_enable_analog_reporting.py ├── disable_enable_digital_reporting.py ├── hc-sr04_distance_sensor.py ├── i2c_adxl345_accelerometer.py ├── i2c_liquidcrystaldisplay.py ├── keep_alive.py ├── play_tone.py ├── pwm_analog_output.py ├── retrieve_analog_map.py ├── retrieve_capability_report.py ├── retrieve_firmware_version.py ├── retrieve_pin_state.py ├── retrieve_protocol_version.py ├── retrieve_pymata_version.py ├── servo.py ├── stepper.py ├── stress_test.py └── wifi_blink.py ├── html └── pymata4 │ ├── index.html │ ├── index_ORIG.html │ ├── pin_data.html │ └── private_constants.html ├── license.txt ├── pymata4 ├── __init__.py ├── pin_data.py ├── private_constants.py └── pymata4.py ├── pypi_desc.md └── setup.py /.gitattributes: -------------------------------------------------------------------------------- 1 | *.html linguist-language=Python -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Python template 3 | # Byte-compiled / optimized / DLL files 4 | __pycache__/ 5 | *.py[cod] 6 | *$py.class 7 | 8 | # C extensions 9 | *.so 10 | 11 | # Distribution / packaging 12 | .Python 13 | build/ 14 | develop-eggs/ 15 | dist/ 16 | downloads/ 17 | eggs/ 18 | .eggs/ 19 | html/ 20 | lib/ 21 | lib64/ 22 | parts/ 23 | sdist/ 24 | var/ 25 | wheels/ 26 | pip-wheel-metadata/ 27 | share/python-wheels/ 28 | *.egg-info/ 29 | .installed.cfg 30 | *.egg 31 | MANIFEST 32 | 33 | # PyInstaller 34 | # Usually these files are written by a python script from a template 35 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 36 | *.manifest 37 | *.spec 38 | 39 | # Installer logs 40 | pip-log.txt 41 | pip-delete-this-directory.txt 42 | 43 | # Unit test / coverage reports 44 | htmlcov/ 45 | .tox/ 46 | .nox/ 47 | .coverage 48 | .coverage.* 49 | .cache 50 | nosetests.xml 51 | coverage.xml 52 | *.cover 53 | *.py,cover 54 | .hypothesis/ 55 | .pytest_cache/ 56 | 57 | # Translations 58 | *.mo 59 | *.pot 60 | 61 | # Django stuff: 62 | *.log 63 | local_settings.py 64 | db.sqlite3 65 | db.sqlite3-journal 66 | 67 | # Flask stuff: 68 | instance/ 69 | .webassets-cache 70 | 71 | # Scrapy stuff: 72 | .scrapy 73 | 74 | # Sphinx documentation 75 | docs/_build/ 76 | 77 | # PyBuilder 78 | target/ 79 | 80 | # Jupyter Notebook 81 | .ipynb_checkpoints 82 | 83 | # IPython 84 | profile_default/ 85 | ipython_config.py 86 | 87 | # pyenv 88 | .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 98 | __pypackages__/ 99 | 100 | # Celery stuff 101 | celerybeat-schedule 102 | celerybeat.pid 103 | 104 | # SageMath parsed files 105 | *.sage.py 106 | 107 | # Environments 108 | .env 109 | .venv 110 | env/ 111 | venv/ 112 | ENV/ 113 | env.bak/ 114 | venv.bak/ 115 | 116 | # Spyder project settings 117 | .spyderproject 118 | .spyproject 119 | 120 | # Rope project settings 121 | .ropeproject 122 | 123 | # mkdocs documentation 124 | /site 125 | 126 | # mypy 127 | .mypy_cache/ 128 | .dmypy.json 129 | dmypy.json 130 | 131 | # Pyre type checker 132 | .pyre/ 133 | 134 | !/html/ 135 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # pymata4 2 | 3 | ## Please note that the pymata4 feature set is now frozen and the project has been placed in maintenance mode. 4 | 5 | ## Please consider using [Telemetrix](https://mryslab.github.io/telemetrix/) instead. 6 | 7 | 8 | 9 | 10 | 11 | 12 | ### A high performance, Python client for the Arduino Firmata Protocol. 13 | Pymata4 is a Firmata client that, like its asyncio sibling, 14 | [pymata-express,](https://mryslab.github.io/pymata-express/) 15 | allows you to control an Arduino using the high-performance FirmataExpress sketch. 16 | It uses a conventional Python API for those that do not need or wish to use the asyncio programming paradigm of pymata-express. 17 | 18 | ### A [User's Guide is available,](https://mryslab.github.io/pymata4/) containing an annotated API as well as links to working examples. 19 | 20 | ### It supports both an enhanced version of StandardaFirmata 2.5.8, called FirmataExpress, as well as StandardFirmata and StandardFimataWiFi. 21 | * **[FirmataExpress](https://github.com/MrYsLab/FirmataExpress) adds support for:** 22 | * **HC-SR04 Ultrasonic Distance Sensors.** 23 | * **DHT Humidity/Temperature Sensors.** 24 | * **Stepper Motors.** 25 | * **Piezo Tone Generation.** 26 | * **Baud rate of 115200** 27 | 28 | ## Special Note For FirmataExpress Users: 29 | ### pymata4 now verifies the version of FirmataExpress in use. You may need to upgrade to the latest version of FirmataExpress using the Arduino IDE Library management tool. 30 | 31 | 32 |

Major features

33 | 34 | * **Fully documented intuitive API** 35 | 36 | 37 | * **Python 3.7+ compatible.** 38 | 39 | * **Set the pin mode and go!** 40 | 41 | * **Data change events may be associated with a callback function, or each pin can be polled for its last event change.** 42 | 43 | * **Each data change event is time-stamped and logged.** 44 | 45 | * **[User's Guide](https://mryslab.github.io/pymata4/), Including Examples.** 46 | 47 | * **Implements 100% of the StandardFirmata Protocol (StandardFirmata 2.5.8).** 48 | 49 | * **Advanced auto-detection of Arduino devices (when using FirmataExpress).** 50 | 51 | Here is an example that monitors data changes on a digital input pin. It demonstrates both callback and 52 | polling techniques 53 | 54 | ```python 55 | import time 56 | import sys 57 | from pymata4 import pymata4 58 | 59 | """ 60 | Setup a pin for digital input and monitor its changes 61 | Both polling and callback are being used in this example. 62 | """ 63 | 64 | # Setup a pin for analog input and monitor its changes 65 | DIGITAL_PIN = 12 # arduino pin number 66 | POLL_TIME = 5 # number of seconds between polls 67 | 68 | # Callback data indices 69 | # Callback data indices 70 | CB_PIN_MODE = 0 71 | CB_PIN = 1 72 | CB_VALUE = 2 73 | CB_TIME = 3 74 | 75 | 76 | def the_callback(data): 77 | """ 78 | A callback function to report data changes. 79 | This will print the pin number, its reported value and 80 | the date and time when the change occurred 81 | 82 | :param data: [pin, current reported value, pin_mode, timestamp] 83 | """ 84 | date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(data[CB_TIME])) 85 | print(f'Pin: {data[CB_PIN]} Value: {data[CB_VALUE]} Time Stamp: {date}') 86 | 87 | 88 | def digital_in(my_board, pin): 89 | """ 90 | This function establishes the pin as a 91 | digital input. Any changes on this pin will 92 | be reported through the call back function. 93 | 94 | :param my_board: a pymata_express instance 95 | :param pin: Arduino pin number 96 | """ 97 | 98 | # set the pin mode 99 | my_board.set_pin_mode_digital_input(pin, callback=the_callback) 100 | 101 | while True: 102 | try: 103 | # Do a read of the last value reported every 5 seconds and print it 104 | # digital_read returns A tuple of last value change and the time that it occurred 105 | value, time_stamp = my_board.digital_read(pin) 106 | date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time_stamp)) 107 | # value 108 | print(f'Polling - last value: {value} received on {date} ') 109 | time.sleep(POLL_TIME) 110 | except KeyboardInterrupt: 111 | board.shutdown() 112 | sys.exit(0) 113 | 114 | board = pymata4.Pymata4() 115 | 116 | try: 117 | digital_in(board, DIGITAL_PIN) 118 | except KeyboardInterrupt: 119 | board.shutdown() 120 | sys.exit(0) 121 | 122 | ``` 123 | 124 | And here is the console output: 125 | ```bash 126 | pymata4: Version 1.00 127 | 128 | Copyright (c) 2020 Alan Yorinks All Rights Reserved. 129 | 130 | Opening all potential serial ports... 131 | /dev/ttyACM0 132 | 133 | Waiting 4 seconds(arduino_wait) for Arduino devices to reset... 134 | 135 | Searching for an Arduino configured with an arduino_instance = 1 136 | Arduino compatible device found and connected to /dev/ttyACM0 137 | 138 | Retrieving Arduino Firmware ID... 139 | Arduino Firmware ID: 2.5 FirmataExpress.ino 140 | 141 | Retrieving analog map... 142 | Auto-discovery complete. Found 20 Digital Pins and 6 Analog Pins 143 | 144 | 145 | Polling - last change: 0 change received on 1969-12-31 19:00:00 146 | Pin: 12 Value: 0 Time Stamp: 2020-03-07 08:52:10 147 | Pin: 12 Value: 1 Time Stamp: 2020-03-07 08:52:12 148 | Polling - last value: 1 received on 2020-03-07 08:52:12 149 | ``` 150 | 151 | 152 | This project was developed with [Pycharm](https://www.jetbrains.com/pycharm/?from=pymata4) ![logo](https://github.com/MrYsLab/python_banyan/blob/master/images/icon_PyCharm.png) 153 | -------------------------------------------------------------------------------- /examples/analog_input_with_time_stamps.py: -------------------------------------------------------------------------------- 1 | """ 2 | Copyright (c) 2020 Alan Yorinks All rights reserved. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE 6 | Version 3 as published by the Free Software Foundation; either 7 | or (at your option) any later version. 8 | This library is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | General Public License for more details. 12 | 13 | You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE 14 | along with this library; if not, write to the Free Software 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | """ 17 | 18 | import sys 19 | import time 20 | from pymata4 import pymata4 21 | 22 | """ 23 | This file demonstrates analog input using both callbacks and 24 | polling. Time stamps are provided in both "cooked" and raw form 25 | """ 26 | 27 | # Setup a pin for analog input and monitor its changes 28 | ANALOG_PIN = 2 # arduino pin number 29 | POLL_TIME = 5 # number of seconds between polls 30 | 31 | # Callback data indices 32 | CB_PIN_MODE = 0 33 | CB_PIN = 1 34 | CB_VALUE = 2 35 | CB_TIME = 3 36 | 37 | 38 | # 39 | 40 | def the_callback(data): 41 | """ 42 | A callback function to report data changes. 43 | 44 | :param data: [pin_mode, pin, current_reported_value, timestamp] 45 | """ 46 | 47 | formatted_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(data[CB_TIME])) 48 | print(f'Analog Call Input Callback: pin={data[CB_PIN]}, ' 49 | f'Value={data[CB_VALUE]} Time={formatted_time} ' 50 | f'(Raw Time={data[CB_TIME]})') 51 | 52 | 53 | def analog_in(my_board, pin): 54 | """ 55 | This function establishes the pin as an 56 | analog input. Any changes on this pin will 57 | be reported through the call back function. 58 | 59 | Every 5 seconds the last value and time stamp is polled 60 | and printed. 61 | 62 | Also, the differential parameter is being used. 63 | The callback will only be called when there is 64 | difference of 5 or more between the current and 65 | last value reported. 66 | 67 | :param my_board: a pymata4 instance 68 | 69 | :param pin: Arduino pin number 70 | """ 71 | my_board.set_pin_mode_analog_input(pin, callback=the_callback, differential=5) 72 | # run forever waiting for input changes 73 | try: 74 | while True: 75 | time.sleep(POLL_TIME) 76 | # retrieve both the value and time stamp with each poll 77 | value, time_stamp = board.analog_read(pin) 78 | # format the time stamp 79 | formatted_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time_stamp)) 80 | print( 81 | f'Reading latest analog input data for pin {pin} = {value} change received on {formatted_time} ' 82 | f'(raw_time: {time_stamp})') 83 | except KeyboardInterrupt: 84 | my_board.shutdown() 85 | sys.exit(0) 86 | 87 | 88 | # instantiate pymata4 89 | board = pymata4.Pymata4() 90 | 91 | analog_in(board, ANALOG_PIN) 92 | -------------------------------------------------------------------------------- /examples/analog_input_with_time_stamps_oo.py: -------------------------------------------------------------------------------- 1 | """ 2 | Copyright (c) 2020 Alan Yorinks All rights reserved. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE 6 | Version 3 as published by the Free Software Foundation; either 7 | or (at your option) any later version. 8 | This library is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | General Public License for more details. 12 | 13 | You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE 14 | along with this library; if not, write to the Free Software 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | """ 17 | import argparse 18 | import sys 19 | import time 20 | from pymata4 import pymata4 21 | 22 | """ 23 | This file demonstrates analog input using both callbacks and 24 | polling. Time stamps are provided in both "cooked" and raw form. 25 | 26 | This is an object oriented example of the the analog_input_with_time_stamps 27 | example using argparse to allow command line entry of the pin, poll-time and 28 | differential values. 29 | """ 30 | 31 | 32 | class MonitorAnalogPin: 33 | 34 | def __init__(self, analog_pin=2, poll_time=5, differential=5): 35 | """ 36 | 37 | :param analog_pin: arduino analog input pin number 38 | 39 | :param poll_time: polling interval in seconds 40 | 41 | :param differential: difference between current value and 42 | previous value to consider the change 43 | in value a change event 44 | """ 45 | self.analog_pin = analog_pin 46 | self.poll_time = poll_time 47 | self.differential = differential 48 | 49 | # Callback data indices 50 | self.CB_PIN_MODE = 0 # pin mode (see pin modes in private_constants.py) 51 | self.CB_PIN = 1 # pin number 52 | self.CB_VALUE = 2 # reported value 53 | self.CB_TIME = 3 # raw time stamp 54 | 55 | # instantiate pymata4 56 | self.board = pymata4.Pymata4() 57 | 58 | # set the pin mode for analog input 59 | self.board.set_pin_mode_analog_input(self.analog_pin, self.the_callback, self.differential) 60 | 61 | # start polling 62 | self.keep_polling() 63 | 64 | def keep_polling(self): 65 | """ 66 | A forever loop. 67 | Poll the selected pin at the specified poll interval and print out 68 | the last value received. 69 | """ 70 | try: 71 | while True: 72 | time.sleep(self.poll_time) 73 | # retrieve both the value and time stamp with each poll 74 | value, time_stamp = self.board.analog_read(self.analog_pin) 75 | # format the time stamp 76 | formatted_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time_stamp)) 77 | print( 78 | f'Reading latest analog input data for pin {self.analog_pin} = {value} ' 79 | f'change received on {formatted_time} ' 80 | f'(raw_time: {time_stamp})') 81 | except KeyboardInterrupt: 82 | self.board.shutdown() 83 | sys.exit(0) 84 | 85 | def the_callback(self, data): 86 | """ 87 | A callback function to report data changes. 88 | 89 | :param data: [pin_mode, pin, current_reported_value, timestamp] 90 | 91 | """ 92 | formatted_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(data[self.CB_TIME])) 93 | print(f'Analog Call Input Callback: pin={data[self.CB_PIN]}, ' 94 | f'Value={data[self.CB_VALUE]} Time={formatted_time} ' 95 | f'(Raw Time={data[self.CB_TIME]})') 96 | 97 | 98 | def monitor_analog_pin(): 99 | # noinspection PyShadowingNames 100 | 101 | parser = argparse.ArgumentParser() 102 | parser.add_argument("-d", dest="differential", default=5, 103 | help="Set reporting differential - default = 5") 104 | parser.add_argument("-p", dest="analog_pin", default=2, 105 | help="Arduino analog pin number - default = 2") 106 | parser.add_argument("-t", dest="poll_time", default=5, 107 | help="Poll Time In Seconds - default = 5") 108 | 109 | args = parser.parse_args() 110 | 111 | MonitorAnalogPin(analog_pin=int(args.analog_pin), 112 | differential=int(args.differential), 113 | poll_time=int(args.poll_time)) 114 | 115 | 116 | if __name__ == '__main__': 117 | monitor_analog_pin() 118 | -------------------------------------------------------------------------------- /examples/dht.py: -------------------------------------------------------------------------------- 1 | """ 2 | Copyright (c) 2020 Alan Yorinks All rights reserved. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE 6 | Version 3 as published by the Free Software Foundation; either 7 | or (at your option) any later version. 8 | This library is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | General Public License for more details. 12 | 13 | You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE 14 | along with this library; if not, write to the Free Software 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | """ 17 | 18 | import time 19 | import sys 20 | from pymata4 import pymata4 21 | 22 | """ 23 | Setup a pin for dht mode 24 | One pin is set for a dht22 and another for dht11 25 | Both polling and callback are being used in this example. 26 | """ 27 | 28 | # 29 | POLL_TIME = 5 # number of seconds between polls 30 | 31 | # Callback data indices 32 | CB_PIN_MODE = 0 33 | CB_PIN = 1 34 | CB_VALUE = 2 35 | CB_TIME = 3 36 | 37 | 38 | def the_callback(data): 39 | """ 40 | A callback function to report data changes. 41 | This will print the pin number, its reported value and 42 | the date and time when the change occurred 43 | 44 | :param data: [report_type, pin, dht_type, error_value, 45 | humidity, temperature, timestamp] 46 | """ 47 | 48 | if not data[3]: 49 | tlist = time.localtime(data[6]) 50 | ftime = f'{tlist.tm_year}-{tlist.tm_mon:02}-{tlist.tm_mday:02} ' \ 51 | f'{tlist.tm_hour:02}:{tlist.tm_min:0}:{tlist.tm_sec:02}' 52 | 53 | print(f'Pin: {data[1]} DHT Type: {data[2]} Humidity:{data[4]}, ' 54 | f'Temperature: {data[5]} Timestamp: {ftime}') 55 | 56 | 57 | def dht(my_board, callback=None): 58 | """ 59 | This function establishes the pin as a 60 | digital input. Any changes on this pin will 61 | be reported through the call back function. 62 | 63 | :param my_board: a pymata4 instance 64 | :param callback: callback funtion 65 | """ 66 | 67 | # set the pin mode - for pin 6 differential is set explicitly 68 | my_board.set_pin_mode_dht(4, sensor_type=11, differential=.05, callback=callback) 69 | # my_board.set_pin_mode_dht(9, sensor_type=22, differential=.05, callback=callback) 70 | 71 | # my_board.set_pin_mode_dht(10, sensor_type=22, differential=.05, callback=callback) 72 | # my_board.set_pin_mode_dht(11, sensor_type=11, differential=.05, callback=callback) 73 | 74 | # a flag to change the differential value after the first 5 seconds 75 | changed = False 76 | while True: 77 | try: 78 | time.sleep(POLL_TIME) 79 | 80 | # poll the first dht 81 | value = board.dht_read(4) 82 | 83 | # format the time string and then print the data 84 | tlist = time.localtime(value[2]) 85 | ftime = f'{tlist.tm_year}-{tlist.tm_mon:02}-{tlist.tm_mday:02} ' \ 86 | f'{tlist.tm_hour:02}:{tlist.tm_min:0}:{tlist.tm_sec:02}' 87 | print(f'poll pin 8: humidity={value[0]} temp={value[1]} ' 88 | f'time of last report: {ftime}') 89 | 90 | # poll the second DHT and print the values 91 | value = board.dht_read(9) 92 | tlist = time.localtime(value[2]) 93 | ftime = f'{tlist.tm_year}-{tlist.tm_mon:02}-{tlist.tm_mday:02} ' \ 94 | f'{tlist.tm_hour:02}:{tlist.tm_min:0}:{tlist.tm_sec:02}' 95 | print(f'poll pin 9: humidity={value[0]} temp={value[1]} ' 96 | f'time of last report: {ftime}') 97 | 98 | # poll the third dht 99 | 100 | # value = board.dht_read(10) 101 | 102 | # format the time string and then print the data 103 | # tlist = time.localtime(value[2]) 104 | # ftime = f'{tlist.tm_year}-{tlist.tm_mon:02}-{tlist.tm_mday:02} ' \ 105 | # f'{tlist.tm_hour:02}:{tlist.tm_min:0}:{tlist.tm_sec:02}' 106 | # print(f'poll pin 10: humidity={value[0]} temp={value[1]} ' 107 | # f'time of last report: {ftime}') 108 | 109 | # poll the fourth DHT 110 | # value = board.dht_read(11) 111 | # tlist = time.localtime(value[2]) 112 | # ftime = f'{tlist.tm_year}-{tlist.tm_mon:02}-{tlist.tm_mday:02} ' \ 113 | # f'{tlist.tm_hour:02}:{tlist.tm_min:0}:{tlist.tm_sec:02}' 114 | # print(f'poll pin 11: humidity={value[0]} temp={value[1]} ' 115 | # f'time of last report: {ftime}') 116 | # if not changed: 117 | # explicitly change the differential values 118 | 119 | # my_board.set_pin_mode_dht(8, sensor_type=11, differential=2.0, 120 | # callback=callback) 121 | # my_board.set_pin_mode_dht(9, sensor_type=22, differential=20.0, 122 | # callback=callback) 123 | # my_board.set_pin_mode_dht(10, sensor_type=22, differential=20.0, 124 | # callback=callback) 125 | # my_board.set_pin_mode_dht(11, sensor_type=11, differential=2.0, 126 | # callback=callback) 127 | # changed = True 128 | except KeyboardInterrupt: 129 | board.shutdown() 130 | sys.exit(0) 131 | 132 | 133 | board = pymata4.Pymata4() 134 | 135 | try: 136 | dht(board, the_callback) 137 | except KeyboardInterrupt: 138 | board.shutdown() 139 | sys.exit(0) 140 | -------------------------------------------------------------------------------- /examples/digital_input.py: -------------------------------------------------------------------------------- 1 | """ 2 | Copyright (c) 2020 Alan Yorinks All rights reserved. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE 6 | Version 3 as published by the Free Software Foundation; either 7 | or (at your option) any later version. 8 | This library is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | General Public License for more details. 12 | 13 | You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE 14 | along with this library; if not, write to the Free Software 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | """ 17 | 18 | import time 19 | import sys 20 | from pymata4 import pymata4 21 | 22 | """ 23 | Setup a pin for digital input and monitor its changes 24 | Both polling and callback are being used in this example. 25 | """ 26 | 27 | # Setup a pin for analog input and monitor its changes 28 | DIGITAL_PIN = 12 # arduino pin number 29 | POLL_TIME = 5 # number of seconds between polls 30 | 31 | # Callback data indices 32 | # Callback data indices 33 | CB_PIN_MODE = 0 34 | CB_PIN = 1 35 | CB_VALUE = 2 36 | CB_TIME = 3 37 | 38 | 39 | def the_callback(data): 40 | """ 41 | A callback function to report data changes. 42 | This will print the pin number, its reported value and 43 | the date and time when the change occurred 44 | 45 | :param data: [pin, current reported value, pin_mode, timestamp] 46 | """ 47 | date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(data[CB_TIME])) 48 | print(f'Pin: {data[CB_PIN]} Value: {data[CB_VALUE]} Time Stamp: {date}') 49 | 50 | 51 | def digital_in(my_board, pin): 52 | """ 53 | This function establishes the pin as a 54 | digital input. Any changes on this pin will 55 | be reported through the call back function. 56 | 57 | :param my_board: a pymata4 instance 58 | :param pin: Arduino pin number 59 | """ 60 | 61 | # set the pin mode 62 | my_board.set_pin_mode_digital_input(pin, callback=the_callback) 63 | 64 | while True: 65 | try: 66 | # Do a read of the last value reported every 5 seconds and print it 67 | # digital_read returns A tuple of last value change and the time that it occurred 68 | value, time_stamp = my_board.digital_read(pin) 69 | date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time_stamp)) 70 | # value 71 | print(f'Polling - last value: {value} received on {date} ') 72 | time.sleep(POLL_TIME) 73 | except KeyboardInterrupt: 74 | board.shutdown() 75 | sys.exit(0) 76 | 77 | board = pymata4.Pymata4() 78 | 79 | try: 80 | digital_in(board, DIGITAL_PIN) 81 | except KeyboardInterrupt: 82 | board.shutdown() 83 | sys.exit(0) 84 | -------------------------------------------------------------------------------- /examples/digital_input_debounce.py: -------------------------------------------------------------------------------- 1 | """ 2 | Copyright (c) 2020 Alan Yorinks All rights reserved. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE 6 | Version 3 as published by the Free Software Foundation; either 7 | or (at your option) any later version. 8 | This library is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | General Public License for more details. 12 | 13 | You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE 14 | along with this library; if not, write to the Free Software 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | """ 17 | 18 | import sys 19 | import time 20 | from pymata4 import pymata4 21 | 22 | """ 23 | Setup a pin for digital input and monitor its changes 24 | Both polling and callback are being used in this example. 25 | This demonstrates one possible way to debounce a switch. 26 | """ 27 | 28 | # A global to hold the time of the last change detected. 29 | # Used to debounce a switch 30 | previous_change_time = 0 31 | 32 | # differential in time to suppress switch bounces 33 | # adjust this to your device "bounciness" 34 | debounce_time = 600 35 | 36 | # Setup a pin for analog input and monitor its changes 37 | DIGITAL_PIN = 12 # arduino pin number 38 | POLL_TIME = 5 # number of seconds between polls 39 | 40 | # Callback data indices 41 | # Callback data indices 42 | CB_PIN_MODE = 0 43 | CB_PIN = 1 44 | CB_VALUE = 2 45 | CB_TIME = 3 46 | 47 | 48 | def the_callback(data): 49 | """ 50 | A callback function to report data changes. 51 | This will print the pin number, its reported value and 52 | the date and time when the change occurred 53 | 54 | :param data: [pin, current reported value, pin_mode, timestamp] 55 | """ 56 | 57 | global debounce_time, previous_change_time 58 | # see if we waited long enough for debounce 59 | # get the reported change time 60 | ts_milliseconds = int(round(data[CB_TIME] * 1000)) 61 | 62 | if ts_milliseconds - previous_change_time > debounce_time: 63 | date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(data[CB_TIME])) 64 | print(f'Pin: {data[CB_PIN]} Value: {data[CB_VALUE]} Time Stamp: {date}') 65 | previous_change_time = ts_milliseconds 66 | 67 | 68 | def digital_in(my_board, pin): 69 | """ 70 | This function establishes the pin as a 71 | digital input. Any changes on this pin will 72 | be reported through the call back function. 73 | 74 | :param my_board: a pymata4 instance 75 | :param pin: Arduino pin number 76 | """ 77 | 78 | # set the pin mode 79 | my_board.set_pin_mode_digital_input(pin, callback=the_callback) 80 | 81 | while True: 82 | # Do a read of the last value reported every 5 seconds and print it 83 | # digital_read returns A tuple of last value change and the time that it occurred 84 | value, time_stamp = my_board.digital_read(pin) 85 | date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time_stamp)) 86 | print(f'Polling - last change: {value} change received on {date} ') 87 | time.sleep(POLL_TIME) 88 | 89 | 90 | board = pymata4.Pymata4() 91 | 92 | try: 93 | digital_in(board, DIGITAL_PIN) 94 | except KeyboardInterrupt: 95 | board.shutdown() 96 | sys.exit(0) 97 | -------------------------------------------------------------------------------- /examples/digital_input_pullup.py: -------------------------------------------------------------------------------- 1 | """ 2 | Copyright (c) 2020 Alan Yorinks All rights reserved. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE 6 | Version 3 as published by the Free Software Foundation; either 7 | or (at your option) any later version. 8 | This library is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | General Public License for more details. 12 | 13 | You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE 14 | along with this library; if not, write to the Free Software 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | """ 17 | 18 | 19 | import sys 20 | import time 21 | 22 | from pymata4 import pymata4 23 | 24 | """ 25 | Setup a digital pin for input pullup and monitor its changes. 26 | """ 27 | 28 | # some globals 29 | DIGITAL_PIN = 12 # arduino pin number 30 | KILL_TIME = 5 # sleep time to keep forever loop open 31 | 32 | # Callback data indices 33 | # Callback data indices 34 | CB_PIN_MODE = 0 35 | CB_PIN = 1 36 | CB_VALUE = 2 37 | CB_TIME = 3 38 | 39 | 40 | # Setup a pin for digital pin input and monitor its changes 41 | 42 | def the_callback(data): 43 | """ 44 | A callback function to report data changes. 45 | This will print the pin number, its reported value and 46 | the date and time when the change occurred 47 | 48 | :param data: [pin, current reported value, pin_mode, timestamp] 49 | """ 50 | date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(data[CB_TIME])) 51 | print(f'Pin: {data[CB_PIN]} Value: {data[CB_VALUE]} Time Stamp: {date}') 52 | 53 | 54 | def digital_in_pullup(my_board, pin): 55 | """ 56 | This function establishes the pin as a 57 | digital input. Any changes on this pin will 58 | be reported through the call back function. 59 | 60 | :param my_board: a pymata4 instance 61 | :param pin: Arduino pin number 62 | """ 63 | 64 | # start monitoring the pin by setting its mode 65 | my_board.set_pin_mode_digital_input_pullup(pin, callback=the_callback) 66 | 67 | # get pin changes forever 68 | while True: 69 | try: 70 | time.sleep(KILL_TIME) 71 | except KeyboardInterrupt: 72 | board.shutdown() 73 | sys.exit(0) 74 | 75 | 76 | board = pymata4.Pymata4() 77 | try: 78 | digital_in_pullup(board, DIGITAL_PIN) 79 | board.shutdown() 80 | except KeyboardInterrupt: 81 | board.shutdown() 82 | sys.exit(0) 83 | -------------------------------------------------------------------------------- /examples/digital_input_with_keep_alive.py: -------------------------------------------------------------------------------- 1 | """ 2 | Copyright (c) 2020 Alan Yorinks All rights reserved. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE 6 | Version 3 as published by the Free Software Foundation; either 7 | or (at your option) any later version. 8 | This library is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | General Public License for more details. 12 | 13 | You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE 14 | along with this library; if not, write to the Free Software 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | """ 17 | 18 | import time 19 | import sys 20 | from pymata4 import pymata4 21 | 22 | """ 23 | Setup a pin for digital input and monitor its changes 24 | Both polling and callback are being used in this example. 25 | Keepalives are enabled. 26 | """ 27 | 28 | # Setup a pin for analog input and monitor its changes 29 | DIGITAL_PIN = 12 # arduino pin number 30 | POLL_TIME = 5 # number of seconds between polls 31 | 32 | # Callback data indices 33 | # Callback data indices 34 | CB_PIN_MODE = 0 35 | CB_PIN = 1 36 | CB_VALUE = 2 37 | CB_TIME = 3 38 | 39 | def the_callback(data): 40 | """ 41 | A callback function to report data changes. 42 | This will print the pin number, its reported value and 43 | the date and time when the change occurred 44 | 45 | :param data: [pin, current reported value, pin_mode, timestamp] 46 | """ 47 | date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(data[3])) 48 | print(f'Pin: {data[0]} Value: {data[1]} Time Stamp: {date}') 49 | 50 | date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(data[CB_TIME])) 51 | print(f'Pin: {data[CB_PIN]} Value: {data[CB_VALUE]} Time Stamp: {date}') 52 | 53 | 54 | def digital_in(my_board, pin): 55 | """ 56 | This function establishes the pin as a 57 | digital input. Any changes on this pin will 58 | be reported through the call back function. 59 | 60 | :param my_board: a pymata4 instance 61 | :param pin: Arduino pin number 62 | """ 63 | # enable keep alives 64 | my_board.keep_alive() 65 | # set the pin mode 66 | my_board.set_pin_mode_digital_input(pin, callback=the_callback) 67 | 68 | while True: 69 | try: 70 | # Do a read of the last value reported every 5 seconds and print it 71 | # digital_read returns A tuple of last value change and the time that it occurred 72 | value, time_stamp = my_board.digital_read(pin) 73 | date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time_stamp)) 74 | # value 75 | print(f'Polling - last change: {value} change received on {date} ') 76 | time.sleep(POLL_TIME) 77 | except KeyboardInterrupt: 78 | board.shutdown() 79 | sys.exit(0) 80 | 81 | board = pymata4.Pymata4() 82 | 83 | try: 84 | digital_in(board, DIGITAL_PIN) 85 | except KeyboardInterrupt: 86 | board.shutdown() 87 | sys.exit(0) 88 | -------------------------------------------------------------------------------- /examples/digital_output.py: -------------------------------------------------------------------------------- 1 | """ 2 | Copyright (c) 2020 Alan Yorinks All rights reserved. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE 6 | Version 3 as published by the Free Software Foundation; either 7 | or (at your option) any later version. 8 | This library is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | General Public License for more details. 12 | 13 | You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE 14 | along with this library; if not, write to the Free Software 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | """ 17 | import sys 18 | import time 19 | 20 | from pymata4 import pymata4 21 | 22 | """ 23 | Setup a pin for digital output and output a signal 24 | and toggle the pin. Do this 4 times. 25 | """ 26 | 27 | # some globals 28 | DIGITAL_PIN = 6 # arduino pin number 29 | 30 | 31 | def blink(my_board, pin): 32 | """ 33 | This function will to toggle a digital pin. 34 | 35 | :param my_board: an PymataExpress instance 36 | :param pin: pin to be controlled 37 | """ 38 | 39 | # set the pin mode 40 | my_board.set_pin_mode_digital_output(pin) 41 | 42 | # toggle the pin 4 times and exit 43 | for x in range(4): 44 | print('ON') 45 | my_board.digital_write(pin, 1) 46 | time.sleep(1) 47 | print('OFF') 48 | my_board.digital_write(pin, 0) 49 | time.sleep(1) 50 | 51 | my_board.shutdown() 52 | 53 | 54 | board = pymata4.Pymata4() 55 | try: 56 | blink(board, DIGITAL_PIN) 57 | except KeyboardInterrupt: 58 | board.shutdown() 59 | sys.exit(0) 60 | -------------------------------------------------------------------------------- /examples/digital_pin_output.py: -------------------------------------------------------------------------------- 1 | """ 2 | Copyright (c) 2020 Alan Yorinks All rights reserved. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE 6 | Version 3 as published by the Free Software Foundation; either 7 | or (at your option) any later version. 8 | This library is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | General Public License for more details. 12 | 13 | You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE 14 | along with this library; if not, write to the Free Software 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | """ 17 | 18 | import sys 19 | import time 20 | from pymata4 import pymata4 21 | 22 | """ 23 | Setup a pin for digital output and output 24 | and toggle the pin using the digital_pin_output as opposed to digital_output 25 | pin mode. 26 | """ 27 | 28 | 29 | def blink(my_board, pin): 30 | """ 31 | This function will to toggle a digital pin. 32 | 33 | :param my_board: an PymataExpress instance 34 | :param pin: pin to be controlled 35 | """ 36 | 37 | # set the pin mode 38 | my_board.set_pin_mode_digital_output(pin) 39 | 40 | # toggle the pin 4 times and exit 41 | for x in range(4): 42 | print('ON') 43 | my_board.digital_pin_write(pin, 1) 44 | time.sleep(1) 45 | print('OFF') 46 | my_board.digital_pin_write(pin, 0) 47 | time.sleep(1) 48 | 49 | board = pymata4.Pymata4() 50 | try: 51 | blink(board, 9) 52 | board.shutdown() 53 | except KeyboardInterrupt: 54 | board.shutdown() 55 | sys.exit(0) 56 | -------------------------------------------------------------------------------- /examples/disable_enable_analog_reporting.py: -------------------------------------------------------------------------------- 1 | """ 2 | Copyright (c) 2020 Alan Yorinks All rights reserved. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE 6 | Version 3 as published by the Free Software Foundation; either 7 | or (at your option) any later version. 8 | This library is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | General Public License for more details. 12 | 13 | You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE 14 | along with this library; if not, write to the Free Software 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | """ 17 | 18 | import time 19 | import sys 20 | from pymata4 import pymata4 21 | 22 | """ 23 | Test disable and enable analog reporting 24 | """ 25 | 26 | # Setup a pin for analog input and monitor its changes 27 | ANALOG_PIN = 2 # arduino pin number 28 | 29 | 30 | def the_callback(data): 31 | """ 32 | A callback function to report raw data changes. 33 | 34 | :param data: [pin, current reported value, pin_mode, timestamp] 35 | """ 36 | 37 | print(data) 38 | 39 | 40 | def analog_reporting(my_board, pin): 41 | """ 42 | This function will enable the analog input pin. 43 | It then allows you to manipulate the pin for 5 44 | seconds before disabling reporting. 45 | 46 | Next it waits another 5 seconds with reporting disabled 47 | allowing you to manipulate the pin to verify that 48 | callbacks are not generated 49 | 50 | :param my_board: a pymata4 instance 51 | :param pin: Arduino pin number 52 | """ 53 | 54 | # set the pin mode 55 | try: 56 | my_board.set_pin_mode_analog_input(pin, callback=the_callback) 57 | 58 | # start a 5 second period for you to manipulate the 5 59 | print('You have 5 seconds to manipulate the pin input.') 60 | 61 | time.sleep(5) 62 | value, time_stamp = my_board.analog_read(pin) 63 | print(f'Print polling the pin: value = {value} ') 64 | 65 | my_board.disable_analog_reporting(pin) 66 | 67 | print('Reporting is disabled. You have another 5 seconds ' 68 | 'to manipulate the pin to see that reporting has ceased') 69 | value, time_stamp = my_board.analog_read(pin) 70 | time.sleep(5) 71 | 72 | print(f'Print polling the pin: value = {value} ') 73 | 74 | my_board.enable_analog_reporting(pin, callback=the_callback) 75 | 76 | print('Reporting is now re-enabled. You have 5 seconds to ' 77 | 'manipulate the pin until the program exits') 78 | 79 | time.sleep(5) 80 | value, time_stamp = my_board.analog_read(pin) 81 | print(f'Print polling the pin: value = {value} ') 82 | my_board.shutdown() 83 | sys.exit(0) 84 | 85 | except KeyboardInterrupt: 86 | my_board.shutdown() 87 | sys.exit(0) 88 | 89 | 90 | board = pymata4.Pymata4() 91 | 92 | try: 93 | analog_reporting(board, ANALOG_PIN) 94 | except KeyboardInterrupt: 95 | board.shutdown() 96 | sys.exit(0) 97 | -------------------------------------------------------------------------------- /examples/disable_enable_digital_reporting.py: -------------------------------------------------------------------------------- 1 | """ 2 | Copyright (c) 2020 Alan Yorinks All rights reserved. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE 6 | Version 3 as published by the Free Software Foundation; either 7 | or (at your option) any later version. 8 | This library is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | General Public License for more details. 12 | 13 | You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE 14 | along with this library; if not, write to the Free Software 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | """ 17 | 18 | import time 19 | import sys 20 | from pymata4 import pymata4 21 | 22 | """ 23 | Test disable and enable digital reporting 24 | """ 25 | 26 | # Setup a pin for analog input and monitor its changes 27 | DIGITAL_PIN = 12 # arduino pin number 28 | 29 | 30 | def the_callback(data): 31 | """ 32 | A callback function to report raw data changes. 33 | 34 | :param data: [pin, current reported value, pin_mode, timestamp] 35 | """ 36 | 37 | print(data) 38 | 39 | 40 | def digital_reporting(my_board, pin): 41 | """ 42 | This function will enable the digital input pin. 43 | It then allows you to manipulate the pin for 5 44 | seconds before disabling reporting. 45 | 46 | Next it waits another 5 seconds with reporting disabled 47 | allowing you to manipulate the pin to verify that 48 | callbacks are not generated 49 | 50 | :param my_board: a pymata4 instance 51 | :param pin: Arduino pin number 52 | """ 53 | 54 | # set the pin mode 55 | try: 56 | my_board.set_pin_mode_digital_input(pin, callback=the_callback) 57 | 58 | # start a 5 second period for you to manipulate the 5 59 | print('You have 5 seconds to manipulate the pin input.') 60 | 61 | time.sleep(5) 62 | value, time_stamp = my_board.digital_read(pin) 63 | print(f'Print polling the pin: value = {value} ') 64 | 65 | my_board.disable_digital_reporting(pin) 66 | 67 | print('Reporting is disabled. You have another 5 seconds ' 68 | 'to manipulate the pin to see that reporting has ceased') 69 | value, time_stamp = my_board.digital_read(pin) 70 | time.sleep(5) 71 | 72 | print(f'Print polling the pin: value = {value} ') 73 | 74 | my_board.enable_digital_reporting(pin) 75 | 76 | print('Reporting is now re-enabled. You have 5 seconds to ' 77 | 'manipulate the pin until the program exits') 78 | 79 | time.sleep(5) 80 | value, time_stamp = my_board.digital_read(pin) 81 | print(f'Print polling the pin: value = {value} ') 82 | my_board.shutdown() 83 | sys.exit(0) 84 | 85 | except KeyboardInterrupt: 86 | my_board.shutdown() 87 | sys.exit(0) 88 | 89 | 90 | board = pymata4.Pymata4() 91 | 92 | try: 93 | digital_reporting(board, DIGITAL_PIN) 94 | except KeyboardInterrupt: 95 | board.shutdown() 96 | sys.exit(0) 97 | -------------------------------------------------------------------------------- /examples/hc-sr04_distance_sensor.py: -------------------------------------------------------------------------------- 1 | """ 2 | Copyright (c) 2020 Alan Yorinks All rights reserved. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE 6 | Version 3 as published by the Free Software Foundation; either 7 | or (at your option) any later version. 8 | This library is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | General Public License for more details. 12 | 13 | You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE 14 | along with this library; if not, write to the Free Software 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | """ 17 | 18 | import sys 19 | import time 20 | from pymata4 import pymata4 21 | 22 | """ 23 | This program continuously monitors an HC-SR04 Ultrasonic Sensor 24 | It reports changes to the distance sensed. 25 | """ 26 | # indices into callback data 27 | DISTANCE_CM = 2 28 | TRIGGER_PIN = 12 29 | ECHO_PIN = 13 30 | 31 | 32 | # A callback function to display the distance 33 | def the_callback(data): 34 | """ 35 | The callback function to display the change in distance 36 | :param data: [pin_type=12, trigger pin number, distance, timestamp] 37 | """ 38 | print(f'Distance in cm: {data[DISTANCE_CM]}') 39 | 40 | 41 | def sonar(my_board, trigger_pin, echo_pin, callback): 42 | """ 43 | Set the pin mode for a sonar device. Results will appear via the 44 | callback. 45 | 46 | :param my_board: an pymata express instance 47 | :param trigger_pin: Arduino pin number 48 | :param echo_pin: Arduino pin number 49 | :param callback: The callback function 50 | """ 51 | 52 | # set the pin mode for the trigger and echo pins 53 | my_board.set_pin_mode_sonar(trigger_pin, echo_pin, callback) 54 | # wait forever 55 | while True: 56 | try: 57 | time.sleep(.01) 58 | print(f'data read: {my_board.sonar_read(TRIGGER_PIN)}') 59 | except KeyboardInterrupt: 60 | my_board.shutdown() 61 | sys.exit(0) 62 | 63 | 64 | board = pymata4.Pymata4() 65 | try: 66 | sonar(board, TRIGGER_PIN, ECHO_PIN, the_callback) 67 | board.shutdown() 68 | except (KeyboardInterrupt, RuntimeError): 69 | board.shutdown() 70 | sys.exit(0) 71 | -------------------------------------------------------------------------------- /examples/i2c_adxl345_accelerometer.py: -------------------------------------------------------------------------------- 1 | """ 2 | Copyright (c) 2020 Alan Yorinks All rights reserved. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE 6 | Version 3 as published by the Free Software Foundation; either 7 | or (at your option) any later version. 8 | This library is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | General Public License for more details. 12 | 13 | You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE 14 | along with this library; if not, write to the Free Software 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | """ 17 | 18 | import sys 19 | import time 20 | from pymata4 import pymata4 21 | 22 | """ 23 | This example sets up and control an ADXL345 i2c accelerometer. 24 | It will continuously print data the raw xyz data from the device. 25 | """ 26 | 27 | 28 | # the call back function to print the adxl345 data 29 | def the_callback(data): 30 | """ 31 | 32 | :param data: [pin_type, Device address, device read register, x data pair, y data pair, z data pair] 33 | :return: 34 | """ 35 | print(data) 36 | 37 | 38 | def adxl345(my_board): 39 | # setup adxl345 40 | # device address = 83 41 | my_board.set_pin_mode_i2c() 42 | 43 | # set up power and control register 44 | my_board.i2c_write(83, [45, 0]) 45 | time.sleep(.1) 46 | my_board.i2c_write(83, [45, 8]) 47 | time.sleep(.1) 48 | 49 | # set up the data format register 50 | my_board.i2c_write(83, [49, 8]) 51 | time.sleep(.1) 52 | my_board.i2c_write(83, [49, 3]) 53 | time.sleep(1) 54 | 55 | read_count = 20 56 | while True: 57 | # read 6 bytes from the data register 58 | my_board.i2c_read(83, 50, 6, the_callback) 59 | try: 60 | time.sleep(.2) 61 | read_count -= 1 62 | if not read_count: 63 | print(f'reading: {my_board.i2c_read_saved_data(83)}') 64 | read_count = 20 65 | except KeyboardInterrupt: 66 | my_board.shutdown() 67 | sys.exit(0) 68 | 69 | 70 | board = pymata4.Pymata4() 71 | try: 72 | adxl345(board) 73 | except KeyboardInterrupt: 74 | board.shutdown() 75 | sys.exit(0) 76 | -------------------------------------------------------------------------------- /examples/i2c_liquidcrystaldisplay.py: -------------------------------------------------------------------------------- 1 | from time import sleep 2 | from pymata4 import pymata4 3 | from typing import ( 4 | AnyStr 5 | ) 6 | 7 | 8 | class LiquidCrystal_I2C: 9 | LCD_CLEARDISPLAY = 0x01 10 | LCD_RETURNHOME = 0x02 11 | LCD_ENTRYMODESET = 0x04 12 | LCD_DISPLAYCONTROL = 0x08 13 | LCD_CURSORSHIFT = 0x10 14 | LCD_FUNCTIONSET = 0x20 15 | LCD_SETCGRAMADDR = 0x40 16 | LCD_SETDDRAMADDR = 0x80 17 | 18 | LCD_ENTRYRIGHT = 0x00 19 | LCD_ENTRYLEFT = 0x02 20 | LCD_ENTRYSHIFTINCREMENT = 0x01 21 | LCD_ENTRYSHIFTDECREMENT = 0x00 22 | 23 | LCD_DISPLAYON = 0x04 24 | LCD_DISPLAYOFF = 0x00 25 | LCD_CURSORON = 0x02 26 | LCD_CURSOROFF = 0x00 27 | LCD_BLINKON = 0x01 28 | LCD_BLINKOFF = 0x00 29 | 30 | LCD_DISPLAYMOVE = 0x08 31 | LCD_CURSORMOVE = 0x00 32 | LCD_MOVERIGHT = 0x04 33 | LCD_MOVELEFT = 0x00 34 | 35 | LCD_8BITMODE = 0x10 36 | LCD_4BITMODE = 0x00 37 | LCD_2LINE = 0x08 38 | LCD_1LINE = 0x00 39 | LCD_5x10DOTS = 0x04 40 | LCD_5x8DOTS = 0x00 41 | 42 | LCD_BACKLIGHT = 0x08 43 | LCD_NOBACKLIGHT = 0x00 44 | 45 | ENABLE_BIT = 0B00000100 # Enable bit 46 | READ_WRITE_BIT = 0B00000010 # Read/Write bit 47 | REGISTER_SELECT_BIT = 0B00000001 # Register select bit 48 | 49 | _backlight_value: int = LCD_NOBACKLIGHT 50 | _display_function: int = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS 51 | _numlines: int = None 52 | _display_control: int = None 53 | _display_mode: int = None 54 | _oled: bool = True 55 | 56 | def write(self, value: int): 57 | self.send(value, self.REGISTER_SELECT_BIT) 58 | 59 | def __init__(self, address: int, column: int, row: int, board: pymata4.Pymata4, dotsize: int = 1) -> None: 60 | self.address: int = address 61 | self.column: int = column 62 | self.row: int = row 63 | if not isinstance(board, pymata4.Pymata4): 64 | raise AttributeError("argument board not from pymata4.Pymata4") 65 | else: 66 | self.board: pymata4.Pymata4 = board 67 | 68 | self.begin(self.column, self.row, dotsize=dotsize) 69 | 70 | def begin(self, column: int, lines: int, dotsize: int = LCD_5x8DOTS) -> None: 71 | self.board.set_pin_mode_i2c() 72 | 73 | if lines >= 1: 74 | self._display_function = self._display_function | self.LCD_2LINE 75 | 76 | self._numlines = lines 77 | 78 | if dotsize != 0 and lines == 1: 79 | self._display_function = self._display_function | self.LCD_5x10DOTS 80 | 81 | sleep(0.05) 82 | 83 | self.expander_write(self._backlight_value) 84 | sleep(1) 85 | 86 | self.write_4_bits(0x03 << 0x4) 87 | sleep(0.0045) 88 | 89 | self.write_4_bits(0x03 << 0x4) 90 | sleep(0.0045) 91 | 92 | self.write_4_bits(0x03 << 0x4) 93 | sleep(0.00015) 94 | 95 | self.write_4_bits(0x02 << 0x4) 96 | 97 | self.command(self.LCD_FUNCTIONSET | self._display_function) 98 | 99 | self._display_control = self.LCD_DISPLAYON | self.LCD_CURSOROFF | self.LCD_BLINKOFF 100 | self.enable_display() 101 | 102 | self.clear() 103 | 104 | self._display_mode = self.LCD_ENTRYLEFT | self.LCD_ENTRYSHIFTDECREMENT 105 | self.command(self.LCD_ENTRYMODESET | self._display_mode) 106 | 107 | self.home() 108 | 109 | def clear(self): 110 | self.command(self.LCD_CLEARDISPLAY) 111 | sleep(0.002) 112 | if self._oled: 113 | self.set_cursor(0, 0) 114 | 115 | def home(self) -> None: 116 | self.command(self.LCD_RETURNHOME) 117 | sleep(0.002) 118 | 119 | def set_cursor(self, column: int, row: int) -> None: 120 | row_offsets = [0x00, 0x40, 0x14, 0x54] 121 | if row > self._numlines: 122 | row = self._numlines - 1 123 | self.command(self.LCD_SETDDRAMADDR | (column + row_offsets[row])) 124 | 125 | def disable_display(self) -> None: 126 | self._display_control = self._display_control & ~self.LCD_DISPLAYON 127 | self.command(self.LCD_DISPLAYON | self._display_control) 128 | 129 | def enable_display(self) -> None: 130 | self._display_control = self._display_control | self.LCD_DISPLAYON 131 | self.command(self.LCD_DISPLAYCONTROL | self._display_control) 132 | 133 | def disable_cursor(self) -> None: 134 | self._display_control = self._display_control & ~self.LCD_CURSORON 135 | self.command(self.LCD_DISPLAYCONTROL | self._display_control) 136 | 137 | def enable_cursor(self) -> None: 138 | self._display_control = self._display_control | self.LCD_CURSORON 139 | self.command(self.LCD_DISPLAYCONTROL | self._display_control) 140 | 141 | def disable_blink(self) -> None: 142 | self._display_control = self._display_control & ~self.LCD_BLINKON 143 | self.command(self.LCD_DISPLAYCONTROL | self._display_control) 144 | 145 | def enable_blink(self) -> None: 146 | self._display_control = self._display_control | self.LCD_BLINKON 147 | self.command(self.LCD_DISPLAYCONTROL | self._display_control) 148 | 149 | def scroll_display_left(self) -> None: 150 | self.command(self.LCD_CURSORSHIFT | self.LCD_DISPLAYMOVE | self.LCD_MOVELEFT) 151 | 152 | def scroll_display_right(self) -> None: 153 | self.command(self.LCD_CURSORSHIFT | self.LCD_DISPLAYMOVE | self.LCD_MOVERIGHT) 154 | 155 | def left_to_right(self) -> None: 156 | self._display_mode = self._display_mode | self.LCD_ENTRYLEFT 157 | self.command(self.LCD_ENTRYMODESET | self._display_mode) 158 | 159 | def right_to_left(self) -> None: 160 | self._display_mode = self._display_mode & ~self.LCD_ENTRYLEFT 161 | self.command(self.LCD_ENTRYMODESET | self._display_mode) 162 | 163 | def enable_auto_scroll(self) -> None: 164 | self._display_mode = self._display_mode | self.LCD_ENTRYSHIFTINCREMENT 165 | self.command(self.LCD_ENTRYMODESET | self._display_mode) 166 | 167 | def disable_auto_scroll(self) -> None: 168 | self._display_mode = self._display_mode & ~self.LCD_ENTRYSHIFTINCREMENT 169 | self.command(self.LCD_ENTRYMODESET | self._display_mode) 170 | 171 | def disable_backlight(self) -> None: 172 | self._backlight_value = self.LCD_NOBACKLIGHT 173 | self.expander_write(0) 174 | 175 | def enable_backlight(self) -> None: 176 | self._backlight_value = self.LCD_BACKLIGHT 177 | self.expander_write(0) 178 | 179 | def command(self, value) -> None: 180 | self.send(value, 0) 181 | 182 | def send(self, value: int, mode: int) -> None: 183 | high_nibble: int = value & 0xf0 184 | low_nibble: int = (value << 4) & 0xf0 185 | self.write_4_bits(high_nibble | mode) 186 | self.write_4_bits(low_nibble | mode) 187 | 188 | def write_4_bits(self, value: int) -> None: 189 | self.expander_write(value) 190 | self.pulse_enable(value) 191 | 192 | def expander_write(self, data: int) -> None: 193 | self.board.i2c_write(self.address, [data, self._backlight_value]) 194 | 195 | def pulse_enable(self, data: int) -> None: 196 | self.expander_write(data | self.ENABLE_BIT) 197 | sleep(0.000001) 198 | 199 | self.expander_write(data & ~self.ENABLE_BIT) 200 | sleep(0.00005) 201 | 202 | def print(self, string: AnyStr) -> None: 203 | for character in string: 204 | self.write(ord(character)) 205 | sleep(0.000001) 206 | else: 207 | sleep(0.00005) 208 | 209 | 210 | Board = pymata4.Pymata4("/dev/ttyACM0") 211 | LCD = LiquidCrystal_I2C(0x27, 0, 1, Board) 212 | LCD.enable_backlight() 213 | LCD.print("Hello, Worlds!") -------------------------------------------------------------------------------- /examples/keep_alive.py: -------------------------------------------------------------------------------- 1 | """ 2 | Copyright (c) 2020 Alan Yorinks All rights reserved. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE 6 | Version 3 as published by the Free Software Foundation; either 7 | or (at your option) any later version. 8 | This library is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | General Public License for more details. 12 | 13 | You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE 14 | along with this library; if not, write to the Free Software 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | """ 17 | 18 | import time 19 | import sys 20 | from pymata4 import pymata4 21 | 22 | """ 23 | Demonstrate the keep-alive functionality 24 | of FirmataExpress. 25 | NOTE: This only works with ATmega328P processors, such 26 | as used by the Arduino Uno. 27 | """ 28 | 29 | 30 | def keep_alive_test(pin_number): 31 | """ 32 | This program will set a digital output pin to high. 33 | It is assumed that an LED is connected to this pin. 34 | After 2 seconds the program exits, and in approximately 35 | one second the LED should extinguish. 36 | 37 | If keep_alive is working, the LED should extinguish. 38 | 39 | :param pin_number: A pin with an LED connected to it 40 | """ 41 | 42 | board = pymata4.Pymata4() 43 | 44 | # set the as a digital output 45 | board.set_pin_mode_digital_output(pin_number) 46 | 47 | # set the pin high 48 | board.digital_write(pin_number, 1) 49 | 50 | # turn on keep_alives 51 | board.keep_alive() 52 | 53 | print('Sleeping for 2 seconds...') 54 | time.sleep(2) 55 | print('Exiting. In about 1 second, the LED should extinguish.') 56 | sys.exit(0) 57 | 58 | 59 | keep_alive_test(6) 60 | -------------------------------------------------------------------------------- /examples/play_tone.py: -------------------------------------------------------------------------------- 1 | """ 2 | Copyright (c) 2020 Alan Yorinks All rights reserved. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE 6 | Version 3 as published by the Free Software Foundation; either 7 | or (at your option) any later version. 8 | This library is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | General Public License for more details. 12 | 13 | You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE 14 | along with this library; if not, write to the Free Software 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | """ 17 | 18 | import sys 19 | import time 20 | from pymata4 import pymata4 21 | 22 | """ 23 | This is a demonstration of the tone methods 24 | """ 25 | 26 | # instantiate pymata4 27 | board = pymata4.Pymata4() 28 | TONE_PIN=3 29 | try: 30 | # set a pin's mode for tone operations 31 | board.set_pin_mode_tone(TONE_PIN) 32 | 33 | # specify pin, frequency and duration and play tone 34 | board.play_tone(TONE_PIN, 1000, 500) 35 | time.sleep(2) 36 | 37 | # specify pin and frequency and play continuously 38 | board.play_tone_continuously(TONE_PIN, 2000) 39 | time.sleep(2) 40 | 41 | # specify pin to turn pin off 42 | board.play_tone_off(TONE_PIN) 43 | 44 | # clean up 45 | board.shutdown() 46 | except KeyboardInterrupt: 47 | board.shutdown() 48 | sys.exit(0) 49 | -------------------------------------------------------------------------------- /examples/pwm_analog_output.py: -------------------------------------------------------------------------------- 1 | """ 2 | Copyright (c) 2020 Alan Yorinks All rights reserved. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE 6 | Version 3 as published by the Free Software Foundation; either 7 | or (at your option) any later version. 8 | This library is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | General Public License for more details. 12 | 13 | You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE 14 | along with this library; if not, write to the Free Software 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | """ 17 | 18 | import sys 19 | import time 20 | 21 | from pymata4 import pymata4 22 | 23 | """ 24 | Setup a pin for PWM (aka analog) output and output 25 | some different values. 26 | """ 27 | 28 | 29 | def set_intensity(my_board, pin): 30 | """ 31 | This function will set an LED and set it to 32 | several PWM intensities. 33 | 34 | :param my_board: an PymataExpress instance 35 | :param pin: pin to be controlled 36 | """ 37 | 38 | # set the pin mode 39 | print('pwm_analog_output example') 40 | my_board.set_pin_mode_pwm_output(pin) 41 | 42 | # set the intensities with analog_write 43 | print('Maximum Intensity') 44 | my_board.pwm_write(pin, 255) 45 | time.sleep(.5) 46 | print('Mid Range Intensity') 47 | my_board.pwm_write(pin, 128) 48 | time.sleep(.5) 49 | print('Off') 50 | my_board.pwm_write(pin, 0) 51 | 52 | 53 | board = pymata4.Pymata4() 54 | set_intensity(board, 9) 55 | 56 | # here we clean up after the program completes. 57 | board.shutdown() 58 | sys.exit(0) 59 | -------------------------------------------------------------------------------- /examples/retrieve_analog_map.py: -------------------------------------------------------------------------------- 1 | """ 2 | Copyright (c) 2020 Alan Yorinks All rights reserved. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE 6 | Version 3 as published by the Free Software Foundation; either 7 | or (at your option) any later version. 8 | This library is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | General Public License for more details. 12 | 13 | You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE 14 | along with this library; if not, write to the Free Software 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | """ 17 | 18 | import sys 19 | 20 | from pymata4 import pymata4 21 | 22 | """ 23 | This example will retrieve the Firmata analog map and display 24 | the raw data. The pins are displayed in order. A value of 127 25 | indicates a digital only pin, and other values indicate the 26 | analog input pin number. 27 | """ 28 | 29 | 30 | # Retrieve and print the map 31 | 32 | def retrieve_analog_map(my_board): 33 | analog_map = my_board.get_analog_map() 34 | print(analog_map) 35 | 36 | 37 | board = pymata4.Pymata4() 38 | try: 39 | retrieve_analog_map(board) 40 | board.shutdown() 41 | except KeyboardInterrupt: 42 | board.shutdown() 43 | sys.exit(0) 44 | -------------------------------------------------------------------------------- /examples/retrieve_capability_report.py: -------------------------------------------------------------------------------- 1 | """ 2 | Copyright (c) 2020 Alan Yorinks All rights reserved. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE 6 | Version 3 as published by the Free Software Foundation; either 7 | or (at your option) any later version. 8 | This library is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | General Public License for more details. 12 | 13 | You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE 14 | along with this library; if not, write to the Free Software 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | """ 17 | 18 | import sys 19 | 20 | from pymata4 import pymata4 21 | 22 | """ 23 | This is a demo of retrieving a Firmata capability report and 24 | printing a formatted version of the report to the console 25 | """ 26 | 27 | 28 | def format_capability_report(data): 29 | """ 30 | This method prints a formatted capability report to the console. 31 | 32 | :param data: Capability report 33 | 34 | :returns: None 35 | """ 36 | 37 | pin_modes = {0: 'Digital_Input', 1: 'Digital_Output', 38 | 2: 'Analog_Input', 3: 'PWM', 4: 'Servo', 39 | 6: 'I2C', 8: 'Stepper', 40 | 11: 'Digital_Input_Pullup', 12: 'HC-SR04_Sonar', 13: 'Tone', 41 | 15: 'DHT'} 42 | x = 0 43 | pin = 0 44 | 45 | print('\nCapability Report') 46 | print('-----------------\n') 47 | while x < len(data): 48 | # get index of next end marker 49 | print('{} {}{}'.format('Pin', str(pin), ':')) 50 | while data[x] != 127: 51 | mode_str = "" 52 | pin_mode = pin_modes.get(data[x]) 53 | mode_str += str(pin_mode) 54 | x += 1 55 | bits = data[x] 56 | print('{:>5}{}{} {}'.format(' ', mode_str, ':', bits)) 57 | x += 1 58 | x += 1 59 | pin += 1 60 | 61 | 62 | def retrieve_capability_report(my_board): 63 | """ 64 | Retrieve the report. 65 | 66 | :param my_board: a pymata-express instance 67 | """ 68 | # get the report 69 | report = my_board.get_capability_report() 70 | 71 | # print a human readable version 72 | format_capability_report(report) 73 | 74 | 75 | # instantiate pymata4 76 | board = pymata4.Pymata4() 77 | 78 | try: 79 | # run the program 80 | retrieve_capability_report(board) 81 | 82 | # orderly shutdown 83 | board.shutdown() 84 | except KeyboardInterrupt: 85 | board.shutdown() 86 | sys.exit(0) 87 | -------------------------------------------------------------------------------- /examples/retrieve_firmware_version.py: -------------------------------------------------------------------------------- 1 | """ 2 | Copyright (c) 2020 Alan Yorinks All rights reserved. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE 6 | Version 3 as published by the Free Software Foundation; either 7 | or (at your option) any later version. 8 | This library is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | General Public License for more details. 12 | 13 | You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE 14 | along with this library; if not, write to the Free Software 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | """ 17 | 18 | import sys 19 | 20 | from pymata4 import pymata4 21 | 22 | """ 23 | This example retrieves the Firmata version, which consists 24 | of a version number and name of the file. 25 | """ 26 | 27 | 28 | def retrieve_firmware_version(my_board): 29 | """ 30 | 31 | :param my_board: pymata4 32 | :return: the firmware version 33 | """ 34 | print(my_board.get_firmware_version()) 35 | 36 | 37 | board = pymata4.Pymata4() 38 | try: 39 | retrieve_firmware_version(board) 40 | board.shutdown() 41 | except KeyboardInterrupt: 42 | board.shutdown() 43 | sys.exit(0) 44 | -------------------------------------------------------------------------------- /examples/retrieve_pin_state.py: -------------------------------------------------------------------------------- 1 | """ 2 | Copyright (c) 2020 Alan Yorinks All rights reserved. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE 6 | Version 3 as published by the Free Software Foundation; either 7 | or (at your option) any later version. 8 | This library is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | General Public License for more details. 12 | 13 | You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE 14 | along with this library; if not, write to the Free Software 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | """ 17 | 18 | import sys 19 | 20 | from pymata4 import pymata4 21 | 22 | 23 | # This example manipulates a PWM pin and retrieves its pin 24 | # state after each manipulation 25 | 26 | 27 | def retrieve_pin_state(my_board): 28 | """ 29 | Establish a pin as a PWM pin. Set its value 30 | to 127 and get the pin state. Then set the pin's 31 | value to zero and get the pin state again. 32 | 33 | :param my_board: pymata_aio instance 34 | :return: No values returned by results are printed to console 35 | """ 36 | my_board.set_pin_mode_pwm_output(9) 37 | my_board.pwm_write(9, 127) 38 | pin_state = my_board.get_pin_state(9) 39 | print(f'You should see [9, 3, 127] and have received: {pin_state}') 40 | my_board.pwm_write(9, 0) 41 | pin_state = my_board.get_pin_state(9) 42 | print(f'You should see [9, 3, 0] and have received: {pin_state}') 43 | 44 | 45 | board = pymata4.Pymata4() 46 | try: 47 | retrieve_pin_state(board) 48 | board.shutdown() 49 | except KeyboardInterrupt: 50 | board.shutdown() 51 | sys.exit(0) 52 | -------------------------------------------------------------------------------- /examples/retrieve_protocol_version.py: -------------------------------------------------------------------------------- 1 | """ 2 | Copyright (c) 2020 Alan Yorinks All rights reserved. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE 6 | Version 3 as published by the Free Software Foundation; either 7 | or (at your option) any later version. 8 | This library is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | General Public License for more details. 12 | 13 | You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE 14 | along with this library; if not, write to the Free Software 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | """ 17 | 18 | import sys 19 | 20 | from pymata4 import pymata4 21 | 22 | """ 23 | This example retrieves the Firmata sketch protocol number. 24 | """ 25 | 26 | 27 | def retrieve_protocol_version(my_board): 28 | """ 29 | Retrieve and print the protocol version 30 | 31 | :param my_board: pymata4 32 | """ 33 | 34 | print(f'Protocol Version: {my_board.get_protocol_version()}') 35 | 36 | 37 | board = pymata4.Pymata4() 38 | try: 39 | retrieve_protocol_version(board) 40 | board.shutdown() 41 | except KeyboardInterrupt: 42 | board.shutdown() 43 | sys.exit(0) 44 | -------------------------------------------------------------------------------- /examples/retrieve_pymata_version.py: -------------------------------------------------------------------------------- 1 | """ 2 | Copyright (c) 2020 Alan Yorinks All rights reserved. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE 6 | Version 3 as published by the Free Software Foundation; either 7 | or (at your option) any later version. 8 | This library is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | General Public License for more details. 12 | 13 | You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE 14 | along with this library; if not, write to the Free Software 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | """ 17 | 18 | import sys 19 | 20 | from pymata4 import pymata4 21 | 22 | """ 23 | This example retrieves the Pymata4 version, which consists 24 | of the major and minor version numbers. 25 | """ 26 | 27 | 28 | def retrieve_pymata_version(my_board): 29 | """ 30 | 31 | :param my_board: pymata4 32 | :return: the pymata version 33 | """ 34 | print(my_board.get_pymata_version()) 35 | 36 | 37 | board = pymata4.Pymata4() 38 | try: 39 | retrieve_pymata_version(board) 40 | board.shutdown() 41 | except KeyboardInterrupt: 42 | board.shutdown() 43 | sys.exit(0) 44 | -------------------------------------------------------------------------------- /examples/servo.py: -------------------------------------------------------------------------------- 1 | """ 2 | Copyright (c) 2020 Alan Yorinks All rights reserved. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE 6 | Version 3 as published by the Free Software Foundation; either 7 | or (at your option) any later version. 8 | This library is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | General Public License for more details. 12 | 13 | You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE 14 | along with this library; if not, write to the Free Software 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | """ 17 | 18 | import sys 19 | import time 20 | 21 | from pymata4 import pymata4 22 | 23 | """ 24 | This example will set a servo to 0, 90 and 180 degree 25 | positions. 26 | """ 27 | 28 | 29 | def servo(my_board, pin): 30 | """ 31 | Set a pin to servo mode and then adjust 32 | its position. 33 | 34 | :param my_board: pymata4 35 | :param pin: pin to be controlled 36 | """ 37 | 38 | # set the pin mode 39 | my_board.set_pin_mode_servo(pin) 40 | 41 | # set the servo to 0 degrees 42 | my_board.servo_write(pin, 0) 43 | time.sleep(1) 44 | # set the servo to 90 degrees 45 | my_board.servo_write(pin, 90) 46 | time.sleep(1) 47 | # set the servo to 180 degrees 48 | my_board.servo_write(pin, 180) 49 | 50 | 51 | board = pymata4.Pymata4() 52 | 53 | try: 54 | servo(board, 5) 55 | except KeyboardInterrupt: 56 | board.shutdown() 57 | sys.exit(0) 58 | -------------------------------------------------------------------------------- /examples/stepper.py: -------------------------------------------------------------------------------- 1 | """ 2 | Copyright (c) 2020 Alan Yorinks All rights reserved. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE 6 | Version 3 as published by the Free Software Foundation; either 7 | or (at your option) any later version. 8 | This library is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | General Public License for more details. 12 | 13 | You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE 14 | along with this library; if not, write to the Free Software 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | """ 17 | 18 | import sys 19 | import time 20 | from pymata4 import pymata4 21 | 22 | """ 23 | This example demonstrates running a stepper motor 24 | """ 25 | NUM_STEPS = 512 26 | ARDUINO_PINS = [8, 9, 10, 11] 27 | 28 | 29 | def stepper(my_board, steps_per_rev, pins): 30 | """ 31 | Set the motor control control pins to stepper mode. 32 | Rotate the motor. 33 | 34 | :param my_board: pymata4 35 | :param steps_per_rev: Number of steps per motor revolution 36 | :param pins: A list of the motor control pins 37 | """ 38 | 39 | my_board.set_pin_mode_stepper(steps_per_rev, pins) 40 | time.sleep(1) 41 | my_board.stepper_write(20, 500) 42 | 43 | 44 | board = pymata4.Pymata4() 45 | try: 46 | stepper(board, NUM_STEPS, ARDUINO_PINS) 47 | board.shutdown() 48 | except KeyboardInterrupt: 49 | board.shutdown() 50 | sys.exit(0) 51 | -------------------------------------------------------------------------------- /examples/stress_test.py: -------------------------------------------------------------------------------- 1 | """ 2 | Copyright (c) 2020 Alan Yorinks All rights reserved. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE 6 | Version 3 as published by the Free Software Foundation; either 7 | or (at your option) any later version. 8 | This library is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | General Public License for more details. 12 | 13 | You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE 14 | along with this library; if not, write to the Free Software 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | """ 17 | 18 | import sys 19 | import time 20 | 21 | from pymata4 import pymata4 22 | 23 | 24 | # This example tests multi-threading by 25 | # enabling many things at once 26 | 27 | def the_callback(data): 28 | print(data) 29 | 30 | 31 | def stress_test(my_board, loop_count): 32 | print(f'Iterating {loop_count} times.') 33 | 34 | my_board.set_pin_mode_digital_input(12, callback=the_callback) 35 | my_board.set_pin_mode_digital_input(13, callback=the_callback) 36 | my_board.set_pin_mode_analog_input(2, callback=the_callback, differential=5) 37 | my_board.set_pin_mode_pwm_output(9) 38 | my_board.set_pin_mode_digital_output(6) 39 | 40 | start_time = time.time() 41 | 42 | for x in range(loop_count): 43 | my_board.digital_pin_write(6, 1) 44 | my_board.pwm_write(9, 255) 45 | my_board.analog_read(2) 46 | time.sleep(.00001) 47 | my_board.digital_pin_write(6, 0) 48 | my_board.pwm_write(9, 0) 49 | my_board.digital_read(13) 50 | time.sleep(.00001) 51 | 52 | print(f'Execution time: {time.time() - start_time} seconds for {loop_count} iterations.') 53 | 54 | 55 | board = pymata4.Pymata4() 56 | try: 57 | stress_test(board, 10000) 58 | board.shutdown() 59 | except KeyboardInterrupt: 60 | board.shutdown() 61 | sys.exit(0) 62 | -------------------------------------------------------------------------------- /examples/wifi_blink.py: -------------------------------------------------------------------------------- 1 | """ 2 | Copyright (c) 2020 Alan Yorinks All rights reserved. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE 6 | Version 3 as published by the Free Software Foundation; either 7 | or (at your option) any later version. 8 | This library is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | General Public License for more details. 12 | 13 | You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE 14 | along with this library; if not, write to the Free Software 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | """ 17 | import sys 18 | import time 19 | 20 | from pymata4 import pymata4 21 | 22 | """ 23 | This program tests an ESP-8266 using StandardFirmataWiFi. 24 | It will toggle the on-board LED 4 times. 25 | 26 | Change the IP address and IP port to match that in the 27 | StandardFirmataWiFi config file. 28 | """ 29 | 30 | # some globals 31 | DIGITAL_PIN = 16 # arduino pin number 32 | IP_ADDRESS = "192.168.2.189" 33 | IP_PORT = 3030 34 | 35 | 36 | def blink(my_board, pin): 37 | """ 38 | This function will to toggle a digital pin. 39 | 40 | :param my_board: an PymataExpress instance 41 | :param pin: pin to be controlled 42 | """ 43 | 44 | # set the pin mode 45 | my_board.set_pin_mode_digital_output(pin) 46 | my_board.digital_write(pin, 1) 47 | 48 | # toggle the pin 4 times and exit 49 | for x in range(4): 50 | print('ON') 51 | my_board.digital_write(pin, 1) 52 | time.sleep(1) 53 | print('OFF') 54 | my_board.digital_write(pin, 0) 55 | time.sleep(1) 56 | 57 | my_board.shutdown() 58 | 59 | 60 | board = pymata4.Pymata4(ip_address=IP_ADDRESS, ip_port=IP_PORT) 61 | try: 62 | blink(board, DIGITAL_PIN) 63 | except KeyboardInterrupt: 64 | board.shutdown() 65 | sys.exit(0) 66 | -------------------------------------------------------------------------------- /html/pymata4/index_ORIG.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | pymata4 API documentation 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 |
19 |
20 |

Package pymata4

21 |
22 |
23 |
24 |
25 |

Sub-modules

26 |
27 |
pymata4.custompymata4
28 |
29 |
30 |
31 |
pymata4.pin_data
32 |
33 |

Copyright (c) 2015-2017 Alan Yorinks All rights reserved …

34 |
35 |
pymata4.private_constants
36 |
37 |

Copyright (c) 2015-2019 Alan Yorinks All rights reserved …

38 |
39 |
pymata4.pymata4
40 |
41 |

Copyright (c) 2020 Alan Yorinks All rights reserved …

42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 | 68 |
69 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /html/pymata4/pin_data.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | pymata4.pin_data API documentation 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 |
21 |
22 |

Module pymata4.pin_data

23 |
24 |
25 |

Copyright (c) 2015-2017 Alan Yorinks All rights reserved.

26 |

This program is free software; you can redistribute it and/or 27 | modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE 28 | Version 3 as published by the Free Software Foundation; either 29 | or (at your option) any later version. 30 | This library is distributed in the hope that it will be useful, 31 | but WITHOUT ANY WARRANTY; without even the implied warranty of 32 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 33 | See the GNU 34 | General Public License for more details.

35 |

You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE 36 | along with this library; if not, write to the Free Software 37 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 38 | 02110-1301 39 | USA

40 |
41 | 42 | Expand source code 43 | 44 |
"""
 45 |  Copyright (c) 2015-2017 Alan Yorinks All rights reserved.
 46 | 
 47 |  This program is free software; you can redistribute it and/or
 48 |  modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
 49 |  Version 3 as published by the Free Software Foundation; either
 50 |  or (at your option) any later version.
 51 |  This library is distributed in the hope that it will be useful,
 52 |  but WITHOUT ANY WARRANTY; without even the implied warranty of
 53 |  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 54 |  General Public License for more details.
 55 | 
 56 |  You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
 57 |  along with this library; if not, write to the Free Software
 58 |  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 59 | """
 60 | 
 61 | 
 62 | class PinData:
 63 |     """
 64 |     Each analog and digital input pin is described by an instance of
 65 |     this class. It contains both the last data value received and a potential
 66 |     callback reference. It may also contain a callback differential that if met
 67 |     will cause a callback to occur. The differential pertains to non-digital
 68 |     inputs.
 69 |     """
 70 | 
 71 |     def __init__(self, data_lock):
 72 |         self.data_lock = data_lock
 73 |         # current data value
 74 |         self._current_value = 0
 75 |         # time stamp of last change event
 76 |         self._event_time = 0
 77 |         # callback reference
 78 |         self._cb = None
 79 |         # analog differential
 80 |         self._differential = 1
 81 |         # digital pin was set as a pullup pin
 82 |         self._pull_up = False
 83 | 
 84 |     @property
 85 |     def current_value(self):
 86 |         with self.data_lock:
 87 |             return self._current_value
 88 | 
 89 |     @current_value.setter
 90 |     def current_value(self, value):
 91 |         with self.data_lock:
 92 |             self._current_value = value
 93 | 
 94 |     @property
 95 |     def event_time(self):
 96 |         with self.data_lock:
 97 |             return self._event_time
 98 | 
 99 |     @event_time.setter
100 |     def event_time(self, value):
101 |         with self.data_lock:
102 |             self._event_time = value
103 | 
104 |     @property
105 |     def cb(self):
106 |         with self.data_lock:
107 |             return self._cb
108 | 
109 |     @cb.setter
110 |     def cb(self, value):
111 |         with self.data_lock:
112 |             self._cb = value
113 | 
114 |     @property
115 |     def differential(self):
116 |         with self.data_lock:
117 |             return self._differential
118 | 
119 |     @differential.setter
120 |     def differential(self, value):
121 |         with self.data_lock:
122 |             self._differential = value
123 | 
124 |     @property
125 |     def pull_up(self):
126 |         with self.data_lock:
127 |             return self._pull_up
128 | 
129 |     @pull_up.setter
130 |     def pull_up(self, value):
131 |         with self.data_lock:
132 |             self._pull_up = value
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |

Classes

143 |
144 |
145 | class PinData 146 | (data_lock) 147 |
148 |
149 |

Each analog and digital input pin is described by an instance of 150 | this class. It contains both the last data value received and a potential 151 | callback reference. It may also contain a callback differential that if met 152 | will cause a callback to occur. The differential pertains to non-digital 153 | inputs.

154 |
155 | 156 | Expand source code 157 | 158 |
class PinData:
159 |     """
160 |     Each analog and digital input pin is described by an instance of
161 |     this class. It contains both the last data value received and a potential
162 |     callback reference. It may also contain a callback differential that if met
163 |     will cause a callback to occur. The differential pertains to non-digital
164 |     inputs.
165 |     """
166 | 
167 |     def __init__(self, data_lock):
168 |         self.data_lock = data_lock
169 |         # current data value
170 |         self._current_value = 0
171 |         # time stamp of last change event
172 |         self._event_time = 0
173 |         # callback reference
174 |         self._cb = None
175 |         # analog differential
176 |         self._differential = 1
177 |         # digital pin was set as a pullup pin
178 |         self._pull_up = False
179 | 
180 |     @property
181 |     def current_value(self):
182 |         with self.data_lock:
183 |             return self._current_value
184 | 
185 |     @current_value.setter
186 |     def current_value(self, value):
187 |         with self.data_lock:
188 |             self._current_value = value
189 | 
190 |     @property
191 |     def event_time(self):
192 |         with self.data_lock:
193 |             return self._event_time
194 | 
195 |     @event_time.setter
196 |     def event_time(self, value):
197 |         with self.data_lock:
198 |             self._event_time = value
199 | 
200 |     @property
201 |     def cb(self):
202 |         with self.data_lock:
203 |             return self._cb
204 | 
205 |     @cb.setter
206 |     def cb(self, value):
207 |         with self.data_lock:
208 |             self._cb = value
209 | 
210 |     @property
211 |     def differential(self):
212 |         with self.data_lock:
213 |             return self._differential
214 | 
215 |     @differential.setter
216 |     def differential(self, value):
217 |         with self.data_lock:
218 |             self._differential = value
219 | 
220 |     @property
221 |     def pull_up(self):
222 |         with self.data_lock:
223 |             return self._pull_up
224 | 
225 |     @pull_up.setter
226 |     def pull_up(self, value):
227 |         with self.data_lock:
228 |             self._pull_up = value
229 |
230 |

Instance variables

231 |
232 |
var cb
233 |
234 |
235 |
236 | 237 | Expand source code 238 | 239 |
@property
240 | def cb(self):
241 |     with self.data_lock:
242 |         return self._cb
243 |
244 |
245 |
var current_value
246 |
247 |
248 |
249 | 250 | Expand source code 251 | 252 |
@property
253 | def current_value(self):
254 |     with self.data_lock:
255 |         return self._current_value
256 |
257 |
258 |
var differential
259 |
260 |
261 |
262 | 263 | Expand source code 264 | 265 |
@property
266 | def differential(self):
267 |     with self.data_lock:
268 |         return self._differential
269 |
270 |
271 |
var event_time
272 |
273 |
274 |
275 | 276 | Expand source code 277 | 278 |
@property
279 | def event_time(self):
280 |     with self.data_lock:
281 |         return self._event_time
282 |
283 |
284 |
var pull_up
285 |
286 |
287 |
288 | 289 | Expand source code 290 | 291 |
@property
292 | def pull_up(self):
293 |     with self.data_lock:
294 |         return self._pull_up
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 | 329 |
330 | 333 | 334 | -------------------------------------------------------------------------------- /html/pymata4/private_constants.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | pymata4.private_constants API documentation 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 |
21 |
22 |

Module pymata4.private_constants

23 |
24 |
25 |

Copyright (c) 2015-2019 Alan Yorinks All rights reserved.

26 |

This program is free software; you can redistribute it and/or 27 | modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE 28 | Version 3 as published by the Free Software Foundation; either 29 | or (at your option) any later version. 30 | This library is distributed in the hope that it will be useful, 31 | but WITHOUT ANY WARRANTY; without even the implied warranty of 32 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 33 | See the GNU 34 | General Public License for more details.

35 |

You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE 36 | along with this library; if not, write to the Free Software 37 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 38 | 02110-1301 39 | USA

40 |
41 | 42 | Expand source code 43 | 44 |
"""
 45 |  Copyright (c) 2015-2019 Alan Yorinks All rights reserved.
 46 | 
 47 |  This program is free software; you can redistribute it and/or
 48 |  modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
 49 |  Version 3 as published by the Free Software Foundation; either
 50 |  or (at your option) any later version.
 51 |  This library is distributed in the hope that it will be useful,
 52 |  but WITHOUT ANY WARRANTY; without even the implied warranty of
 53 |  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 54 |  General Public License for more details.
 55 | 
 56 |  You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
 57 |  along with this library; if not, write to the Free Software
 58 |  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 59 | """
 60 | 
 61 | 
 62 | class PrivateConstants:
 63 |     """
 64 |     This class contains a set of constants for PyMata internal use .
 65 |     """
 66 |     # the following defines are from FirmataExpress.h
 67 |     # message command bytes (128-255/ 0x80- 0xFF)
 68 |     # from this client to firmata
 69 |     MSG_CMD_MIN = 0x80  # minimum value for a message from firmata
 70 |     REPORT_ANALOG = 0xC0  # enable analog input by pin #
 71 |     REPORT_DIGITAL = 0xD0  # enable digital input by port pair
 72 |     SET_PIN_MODE = 0xF4  # set a pin to INPUT/OUTPUT/PWM/etc
 73 |     SET_DIGITAL_PIN_VALUE = 0xF5  # set a single digital pin value instead of entire port
 74 |     START_SYSEX = 0xF0  # start a MIDI Sysex message
 75 |     END_SYSEX = 0xF7  # end a MIDI Sysex message
 76 |     SYSTEM_RESET = 0xFF  # reset from MIDI
 77 | 
 78 |     # messages from firmata
 79 |     DIGITAL_MESSAGE = 0x90  # send or receive data for a digital pin
 80 |     ANALOG_MESSAGE = 0xE0  # send or receive data for a PWM configured pin
 81 |     PWM_MESSAGE = 0xE0  # Firmata confusingly conflates analog input with PWM output
 82 |     REPORT_VERSION = 0xF9  # report protocol version
 83 | 
 84 |     # start of FirmataExpress defined SYSEX commands
 85 |     KEEP_ALIVE = 0x50  # keep alive message
 86 |     ARE_YOU_THERE = 0x51  # poll for boards existence
 87 |     I_AM_HERE = 0x52  # response to poll
 88 |     TONE_DATA = 0x5F  # play a tone at a specified frequency and duration
 89 |     SONAR_CONFIG = 0x62  # configure pins to control a sonar distance device
 90 |     SONAR_DATA = 0x63  # distance data returned
 91 |     # end of FirmataExpress defined SYSEX commands
 92 | 
 93 |     SERVO_CONFIG = 0x70  # set servo pin and max and min angles
 94 |     STRING_DATA = 0x71  # a string message with 14-bits per char
 95 |     STEPPER_DATA = 0x72  # Stepper motor command
 96 |     I2C_REQUEST = 0x76  # send an I2C read/write request
 97 |     I2C_REPLY = 0x77  # a reply to an I2C read request
 98 |     I2C_CONFIG = 0x78  # config I2C settings such as delay times and power pins
 99 |     REPORT_FIRMWARE = 0x79  # report name and version of the firmware
100 |     SAMPLING_INTERVAL = 0x7A  # modify the sampling interval
101 |     RESERVED_1 = 0x7B
102 | 
103 |     EXTENDED_PWM = 0x6F  # analog write (PWM, Servo, etc) to any pin
104 |     PIN_STATE_QUERY = 0x6D  # ask for a pin's current mode and value
105 |     PIN_STATE_RESPONSE = 0x6E  # reply with pin's current mode and value
106 |     CAPABILITY_QUERY = 0x6B  # ask for supported modes of all pins
107 |     CAPABILITY_RESPONSE = 0x6C  # reply with supported modes and resolution
108 |     ANALOG_MAPPING_QUERY = 0x69  # ask for mapping of analog to pin numbers
109 |     ANALOG_MAPPING_RESPONSE = 0x6A  # reply with analog mapping data
110 | 
111 |     # reserved values
112 |     SYSEX_NON_REALTIME = 0x7E  # MIDI Reserved for non-realtime messages
113 |     SYSEX_REALTIME = 0x7F  # MIDI Reserved for realtime messages
114 | 
115 |     # reserved for PyMata
116 |     PYMATA_EXPRESS_THREADED_VERSION = "1.11"
117 | 
118 |     # matching FirmataExpress Version Number
119 |     FIRMATA_EXPRESS_VERSION = "1.2"
120 | 
121 |     # each byte represents a digital port
122 |     #  and its value contains the current port settings
123 |     DIGITAL_OUTPUT_PORT_PINS = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
124 |                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
125 | 
126 |     # These values are the index into the data passed by _arduino and
127 |     # used to reassemble integer values
128 |     MSB = 2
129 |     LSB = 1
130 | 
131 |     # enable reporting for REPORT_ANALOG or REPORT_DIGITAL message
132 |     # sent to firmata
133 |     REPORTING_ENABLE = 1
134 |     # disable reporting for REPORT_ANALOG or REPORT_DIGITAL message
135 |     # sent to firmata
136 |     REPORTING_DISABLE = 0
137 | 
138 |     # Stepper Motor Sub-commands
139 |     STEPPER_CONFIGURE = 0  # configure a stepper motor for operation
140 |     STEPPER_STEP = 1  # command a motor to move at the provided speed
141 |     STEPPER_LIBRARY_VERSION = 2  # used to get stepper library version number
142 | 
143 |     # pin modes
144 |     INPUT = 0x00  # pin set as input
145 |     OUTPUT = 0x01  # pin set as output
146 |     ANALOG = 0x02  # analog pin in analogInput mode
147 |     PWM = 0x03  # digital pin in PWM output mode
148 |     SERVO = 0x04  # digital pin in Servo output mode
149 |     I2C = 0x06  # pin included in I2C setup
150 |     STEPPER = 0x08  # any pin in stepper mode
151 |     SERIAL = 0x0a
152 |     PULLUP = 0x0b  # Any pin in pullup mode
153 |     SONAR = 0x0c  # Any pin in SONAR mode
154 |     TONE = 0x0d  # Any pin in tone mode
155 |     PIXY = 0x0e  # reserved for pixy camera mode
156 |     DHT = 0x0f  # DHT sensor
157 | 
158 |     IGNORE = 0x7f
159 | 
160 |     # Tone commands
161 |     TONE_TONE = 0  # play a tone
162 |     TONE_NO_TONE = 1  # turn off tone
163 | 
164 |     # DHT command
165 |     DHT_CONFIG = 0x64  # dht config command
166 |     DHT_DATA = 0x65  # dht sensor command
167 |     ###
168 | 
169 |     # I2C command operation modes
170 |     I2C_WRITE = 0B00000000
171 |     I2C_READ = 0B00001000
172 |     I2C_READ_CONTINUOUSLY = 0B00010000
173 |     I2C_STOP_READING = 0B00011000
174 |     I2C_READ_WRITE_MODE_MASK = 0B00011000
175 |     I2C_10BIT_ADDRESS_MODE_MASK = 0B00100000
176 |     I2C_END_TX_MASK = 0B01000000
177 |     I2C_STOP_TX = 1
178 |     I2C_RESTART_TX = 0
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |

Classes

189 |
190 |
191 | class PrivateConstants 192 |
193 |
194 |

This class contains a set of constants for PyMata internal use .

195 |
196 | 197 | Expand source code 198 | 199 |
class PrivateConstants:
200 |     """
201 |     This class contains a set of constants for PyMata internal use .
202 |     """
203 |     # the following defines are from FirmataExpress.h
204 |     # message command bytes (128-255/ 0x80- 0xFF)
205 |     # from this client to firmata
206 |     MSG_CMD_MIN = 0x80  # minimum value for a message from firmata
207 |     REPORT_ANALOG = 0xC0  # enable analog input by pin #
208 |     REPORT_DIGITAL = 0xD0  # enable digital input by port pair
209 |     SET_PIN_MODE = 0xF4  # set a pin to INPUT/OUTPUT/PWM/etc
210 |     SET_DIGITAL_PIN_VALUE = 0xF5  # set a single digital pin value instead of entire port
211 |     START_SYSEX = 0xF0  # start a MIDI Sysex message
212 |     END_SYSEX = 0xF7  # end a MIDI Sysex message
213 |     SYSTEM_RESET = 0xFF  # reset from MIDI
214 | 
215 |     # messages from firmata
216 |     DIGITAL_MESSAGE = 0x90  # send or receive data for a digital pin
217 |     ANALOG_MESSAGE = 0xE0  # send or receive data for a PWM configured pin
218 |     PWM_MESSAGE = 0xE0  # Firmata confusingly conflates analog input with PWM output
219 |     REPORT_VERSION = 0xF9  # report protocol version
220 | 
221 |     # start of FirmataExpress defined SYSEX commands
222 |     KEEP_ALIVE = 0x50  # keep alive message
223 |     ARE_YOU_THERE = 0x51  # poll for boards existence
224 |     I_AM_HERE = 0x52  # response to poll
225 |     TONE_DATA = 0x5F  # play a tone at a specified frequency and duration
226 |     SONAR_CONFIG = 0x62  # configure pins to control a sonar distance device
227 |     SONAR_DATA = 0x63  # distance data returned
228 |     # end of FirmataExpress defined SYSEX commands
229 | 
230 |     SERVO_CONFIG = 0x70  # set servo pin and max and min angles
231 |     STRING_DATA = 0x71  # a string message with 14-bits per char
232 |     STEPPER_DATA = 0x72  # Stepper motor command
233 |     I2C_REQUEST = 0x76  # send an I2C read/write request
234 |     I2C_REPLY = 0x77  # a reply to an I2C read request
235 |     I2C_CONFIG = 0x78  # config I2C settings such as delay times and power pins
236 |     REPORT_FIRMWARE = 0x79  # report name and version of the firmware
237 |     SAMPLING_INTERVAL = 0x7A  # modify the sampling interval
238 |     RESERVED_1 = 0x7B
239 | 
240 |     EXTENDED_PWM = 0x6F  # analog write (PWM, Servo, etc) to any pin
241 |     PIN_STATE_QUERY = 0x6D  # ask for a pin's current mode and value
242 |     PIN_STATE_RESPONSE = 0x6E  # reply with pin's current mode and value
243 |     CAPABILITY_QUERY = 0x6B  # ask for supported modes of all pins
244 |     CAPABILITY_RESPONSE = 0x6C  # reply with supported modes and resolution
245 |     ANALOG_MAPPING_QUERY = 0x69  # ask for mapping of analog to pin numbers
246 |     ANALOG_MAPPING_RESPONSE = 0x6A  # reply with analog mapping data
247 | 
248 |     # reserved values
249 |     SYSEX_NON_REALTIME = 0x7E  # MIDI Reserved for non-realtime messages
250 |     SYSEX_REALTIME = 0x7F  # MIDI Reserved for realtime messages
251 | 
252 |     # reserved for PyMata
253 |     PYMATA_EXPRESS_THREADED_VERSION = "1.11"
254 | 
255 |     # matching FirmataExpress Version Number
256 |     FIRMATA_EXPRESS_VERSION = "1.2"
257 | 
258 |     # each byte represents a digital port
259 |     #  and its value contains the current port settings
260 |     DIGITAL_OUTPUT_PORT_PINS = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
261 |                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
262 | 
263 |     # These values are the index into the data passed by _arduino and
264 |     # used to reassemble integer values
265 |     MSB = 2
266 |     LSB = 1
267 | 
268 |     # enable reporting for REPORT_ANALOG or REPORT_DIGITAL message
269 |     # sent to firmata
270 |     REPORTING_ENABLE = 1
271 |     # disable reporting for REPORT_ANALOG or REPORT_DIGITAL message
272 |     # sent to firmata
273 |     REPORTING_DISABLE = 0
274 | 
275 |     # Stepper Motor Sub-commands
276 |     STEPPER_CONFIGURE = 0  # configure a stepper motor for operation
277 |     STEPPER_STEP = 1  # command a motor to move at the provided speed
278 |     STEPPER_LIBRARY_VERSION = 2  # used to get stepper library version number
279 | 
280 |     # pin modes
281 |     INPUT = 0x00  # pin set as input
282 |     OUTPUT = 0x01  # pin set as output
283 |     ANALOG = 0x02  # analog pin in analogInput mode
284 |     PWM = 0x03  # digital pin in PWM output mode
285 |     SERVO = 0x04  # digital pin in Servo output mode
286 |     I2C = 0x06  # pin included in I2C setup
287 |     STEPPER = 0x08  # any pin in stepper mode
288 |     SERIAL = 0x0a
289 |     PULLUP = 0x0b  # Any pin in pullup mode
290 |     SONAR = 0x0c  # Any pin in SONAR mode
291 |     TONE = 0x0d  # Any pin in tone mode
292 |     PIXY = 0x0e  # reserved for pixy camera mode
293 |     DHT = 0x0f  # DHT sensor
294 | 
295 |     IGNORE = 0x7f
296 | 
297 |     # Tone commands
298 |     TONE_TONE = 0  # play a tone
299 |     TONE_NO_TONE = 1  # turn off tone
300 | 
301 |     # DHT command
302 |     DHT_CONFIG = 0x64  # dht config command
303 |     DHT_DATA = 0x65  # dht sensor command
304 |     ###
305 | 
306 |     # I2C command operation modes
307 |     I2C_WRITE = 0B00000000
308 |     I2C_READ = 0B00001000
309 |     I2C_READ_CONTINUOUSLY = 0B00010000
310 |     I2C_STOP_READING = 0B00011000
311 |     I2C_READ_WRITE_MODE_MASK = 0B00011000
312 |     I2C_10BIT_ADDRESS_MODE_MASK = 0B00100000
313 |     I2C_END_TX_MASK = 0B01000000
314 |     I2C_STOP_TX = 1
315 |     I2C_RESTART_TX = 0
316 |
317 |

Class variables

318 |
319 |
var ANALOG
320 |
321 |
322 |
323 |
var ANALOG_MAPPING_QUERY
324 |
325 |
326 |
327 |
var ANALOG_MAPPING_RESPONSE
328 |
329 |
330 |
331 |
var ANALOG_MESSAGE
332 |
333 |
334 |
335 |
var ARE_YOU_THERE
336 |
337 |
338 |
339 |
var CAPABILITY_QUERY
340 |
341 |
342 |
343 |
var CAPABILITY_RESPONSE
344 |
345 |
346 |
347 |
var DHT
348 |
349 |
350 |
351 |
var DHT_CONFIG
352 |
353 |
354 |
355 |
var DHT_DATA
356 |
357 |
358 |
359 |
var DIGITAL_MESSAGE
360 |
361 |
362 |
363 |
var DIGITAL_OUTPUT_PORT_PINS
364 |
365 |
366 |
367 |
var END_SYSEX
368 |
369 |
370 |
371 |
var EXTENDED_PWM
372 |
373 |
374 |
375 |
var FIRMATA_EXPRESS_VERSION
376 |
377 |
378 |
379 |
var I2C
380 |
381 |
382 |
383 |
var I2C_10BIT_ADDRESS_MODE_MASK
384 |
385 |
386 |
387 |
var I2C_CONFIG
388 |
389 |
390 |
391 |
var I2C_END_TX_MASK
392 |
393 |
394 |
395 |
var I2C_READ
396 |
397 |
398 |
399 |
var I2C_READ_CONTINUOUSLY
400 |
401 |
402 |
403 |
var I2C_READ_WRITE_MODE_MASK
404 |
405 |
406 |
407 |
var I2C_REPLY
408 |
409 |
410 |
411 |
var I2C_REQUEST
412 |
413 |
414 |
415 |
var I2C_RESTART_TX
416 |
417 |
418 |
419 |
var I2C_STOP_READING
420 |
421 |
422 |
423 |
var I2C_STOP_TX
424 |
425 |
426 |
427 |
var I2C_WRITE
428 |
429 |
430 |
431 |
var IGNORE
432 |
433 |
434 |
435 |
var INPUT
436 |
437 |
438 |
439 |
var I_AM_HERE
440 |
441 |
442 |
443 |
var KEEP_ALIVE
444 |
445 |
446 |
447 |
var LSB
448 |
449 |
450 |
451 |
var MSB
452 |
453 |
454 |
455 |
var MSG_CMD_MIN
456 |
457 |
458 |
459 |
var OUTPUT
460 |
461 |
462 |
463 |
var PIN_STATE_QUERY
464 |
465 |
466 |
467 |
var PIN_STATE_RESPONSE
468 |
469 |
470 |
471 |
var PIXY
472 |
473 |
474 |
475 |
var PULLUP
476 |
477 |
478 |
479 |
var PWM
480 |
481 |
482 |
483 |
var PWM_MESSAGE
484 |
485 |
486 |
487 |
var PYMATA_EXPRESS_THREADED_VERSION
488 |
489 |
490 |
491 |
var REPORTING_DISABLE
492 |
493 |
494 |
495 |
var REPORTING_ENABLE
496 |
497 |
498 |
499 |
var REPORT_ANALOG
500 |
501 |
502 |
503 |
var REPORT_DIGITAL
504 |
505 |
506 |
507 |
var REPORT_FIRMWARE
508 |
509 |
510 |
511 |
var REPORT_VERSION
512 |
513 |
514 |
515 |
var RESERVED_1
516 |
517 |
518 |
519 |
var SAMPLING_INTERVAL
520 |
521 |
522 |
523 |
var SERIAL
524 |
525 |
526 |
527 |
var SERVO
528 |
529 |
530 |
531 |
var SERVO_CONFIG
532 |
533 |
534 |
535 |
var SET_DIGITAL_PIN_VALUE
536 |
537 |
538 |
539 |
var SET_PIN_MODE
540 |
541 |
542 |
543 |
var SONAR
544 |
545 |
546 |
547 |
var SONAR_CONFIG
548 |
549 |
550 |
551 |
var SONAR_DATA
552 |
553 |
554 |
555 |
var START_SYSEX
556 |
557 |
558 |
559 |
var STEPPER
560 |
561 |
562 |
563 |
var STEPPER_CONFIGURE
564 |
565 |
566 |
567 |
var STEPPER_DATA
568 |
569 |
570 |
571 |
var STEPPER_LIBRARY_VERSION
572 |
573 |
574 |
575 |
var STEPPER_STEP
576 |
577 |
578 |
579 |
var STRING_DATA
580 |
581 |
582 |
583 |
var SYSEX_NON_REALTIME
584 |
585 |
586 |
587 |
var SYSEX_REALTIME
588 |
589 |
590 |
591 |
var SYSTEM_RESET
592 |
593 |
594 |
595 |
var TONE
596 |
597 |
598 |
599 |
var TONE_DATA
600 |
601 |
602 |
603 |
var TONE_NO_TONE
604 |
605 |
606 |
607 |
var TONE_TONE
608 |
609 |
610 |
611 |
612 |
613 |
614 |
615 |
616 | 711 |
712 | 715 | 716 | -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published by 637 | the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . -------------------------------------------------------------------------------- /pymata4/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrYsLab/pymata4/1cbf02499024d36478ab7e90c3a2bc5d9bb17338/pymata4/__init__.py -------------------------------------------------------------------------------- /pymata4/pin_data.py: -------------------------------------------------------------------------------- 1 | """ 2 | Copyright (c) 2015-2017 Alan Yorinks All rights reserved. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE 6 | Version 3 as published by the Free Software Foundation; either 7 | or (at your option) any later version. 8 | This library is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | General Public License for more details. 12 | 13 | You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE 14 | along with this library; if not, write to the Free Software 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | """ 17 | 18 | 19 | class PinData: 20 | """ 21 | Each analog and digital input pin is described by an instance of 22 | this class. It contains both the last data value received and a potential 23 | callback reference. It may also contain a callback differential that if met 24 | will cause a callback to occur. The differential pertains to non-digital 25 | inputs. 26 | """ 27 | 28 | def __init__(self, data_lock): 29 | self.data_lock = data_lock 30 | # current data value 31 | self._current_value = 0 32 | # time stamp of last change event 33 | self._event_time = 0 34 | # callback reference 35 | self._cb = None 36 | # analog differential 37 | self._differential = 1 38 | # digital pin was set as a pullup pin 39 | self._pull_up = False 40 | 41 | @property 42 | def current_value(self): 43 | with self.data_lock: 44 | return self._current_value 45 | 46 | @current_value.setter 47 | def current_value(self, value): 48 | with self.data_lock: 49 | self._current_value = value 50 | 51 | @property 52 | def event_time(self): 53 | with self.data_lock: 54 | return self._event_time 55 | 56 | @event_time.setter 57 | def event_time(self, value): 58 | with self.data_lock: 59 | self._event_time = value 60 | 61 | @property 62 | def cb(self): 63 | with self.data_lock: 64 | return self._cb 65 | 66 | @cb.setter 67 | def cb(self, value): 68 | with self.data_lock: 69 | self._cb = value 70 | 71 | @property 72 | def differential(self): 73 | with self.data_lock: 74 | return self._differential 75 | 76 | @differential.setter 77 | def differential(self, value): 78 | with self.data_lock: 79 | self._differential = value 80 | 81 | @property 82 | def pull_up(self): 83 | with self.data_lock: 84 | return self._pull_up 85 | 86 | @pull_up.setter 87 | def pull_up(self, value): 88 | with self.data_lock: 89 | self._pull_up = value 90 | 91 | 92 | -------------------------------------------------------------------------------- /pymata4/private_constants.py: -------------------------------------------------------------------------------- 1 | """ 2 | Copyright (c) 2015-2019 Alan Yorinks All rights reserved. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE 6 | Version 3 as published by the Free Software Foundation; either 7 | or (at your option) any later version. 8 | This library is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | General Public License for more details. 12 | 13 | You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE 14 | along with this library; if not, write to the Free Software 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | """ 17 | 18 | 19 | class PrivateConstants: 20 | """ 21 | This class contains a set of constants for PyMata internal use . 22 | """ 23 | # the following defines are from FirmataExpress.h 24 | # message command bytes (128-255/ 0x80- 0xFF) 25 | # from this client to firmata 26 | MSG_CMD_MIN = 0x80 # minimum value for a message from firmata 27 | REPORT_ANALOG = 0xC0 # enable analog input by pin # 28 | REPORT_DIGITAL = 0xD0 # enable digital input by port pair 29 | SET_PIN_MODE = 0xF4 # set a pin to INPUT/OUTPUT/PWM/etc 30 | SET_DIGITAL_PIN_VALUE = 0xF5 # set a single digital pin value instead of entire port 31 | START_SYSEX = 0xF0 # start a MIDI Sysex message 32 | END_SYSEX = 0xF7 # end a MIDI Sysex message 33 | SYSTEM_RESET = 0xFF # reset from MIDI 34 | 35 | # messages from firmata 36 | DIGITAL_MESSAGE = 0x90 # send or receive data for a digital pin 37 | ANALOG_MESSAGE = 0xE0 # send or receive data for a PWM configured pin 38 | PWM_MESSAGE = 0xE0 # Firmata confusingly conflates analog input with PWM output 39 | REPORT_VERSION = 0xF9 # report protocol version 40 | 41 | # start of FirmataExpress defined SYSEX commands 42 | KEEP_ALIVE = 0x50 # keep alive message 43 | ARE_YOU_THERE = 0x51 # poll for boards existence 44 | I_AM_HERE = 0x52 # response to poll 45 | TONE_DATA = 0x5F # play a tone at a specified frequency and duration 46 | SONAR_CONFIG = 0x62 # configure pins to control a sonar distance device 47 | SONAR_DATA = 0x63 # distance data returned 48 | # end of FirmataExpress defined SYSEX commands 49 | 50 | SERVO_CONFIG = 0x70 # set servo pin and max and min angles 51 | STRING_DATA = 0x71 # a string message with 14-bits per char 52 | STEPPER_DATA = 0x72 # Stepper motor command 53 | I2C_REQUEST = 0x76 # send an I2C read/write request 54 | I2C_REPLY = 0x77 # a reply to an I2C read request 55 | I2C_CONFIG = 0x78 # config I2C settings such as delay times and power pins 56 | REPORT_FIRMWARE = 0x79 # report name and version of the firmware 57 | SAMPLING_INTERVAL = 0x7A # modify the sampling interval 58 | RESERVED_1 = 0x7B 59 | 60 | EXTENDED_PWM = 0x6F # analog write (PWM, Servo, etc) to any pin 61 | PIN_STATE_QUERY = 0x6D # ask for a pin's current mode and value 62 | PIN_STATE_RESPONSE = 0x6E # reply with pin's current mode and value 63 | CAPABILITY_QUERY = 0x6B # ask for supported modes of all pins 64 | CAPABILITY_RESPONSE = 0x6C # reply with supported modes and resolution 65 | ANALOG_MAPPING_QUERY = 0x69 # ask for mapping of analog to pin numbers 66 | ANALOG_MAPPING_RESPONSE = 0x6A # reply with analog mapping data 67 | 68 | # reserved values 69 | SYSEX_NON_REALTIME = 0x7E # MIDI Reserved for non-realtime messages 70 | SYSEX_REALTIME = 0x7F # MIDI Reserved for realtime messages 71 | 72 | # reserved for PyMata 73 | PYMATA_EXPRESS_THREADED_VERSION = "1.15" 74 | 75 | # matching FirmataExpress Version Number 76 | FIRMATA_EXPRESS_VERSION = "1.2" 77 | 78 | # each byte represents a digital port 79 | # and its value contains the current port settings 80 | DIGITAL_OUTPUT_PORT_PINS = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 81 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] 82 | 83 | # These values are the index into the data passed by _arduino and 84 | # used to reassemble integer values 85 | MSB = 2 86 | LSB = 1 87 | 88 | # enable reporting for REPORT_ANALOG or REPORT_DIGITAL message 89 | # sent to firmata 90 | REPORTING_ENABLE = 1 91 | # disable reporting for REPORT_ANALOG or REPORT_DIGITAL message 92 | # sent to firmata 93 | REPORTING_DISABLE = 0 94 | 95 | # Stepper Motor Sub-commands 96 | STEPPER_CONFIGURE = 0 # configure a stepper motor for operation 97 | STEPPER_STEP = 1 # command a motor to move at the provided speed 98 | STEPPER_LIBRARY_VERSION = 2 # used to get stepper library version number 99 | 100 | # pin modes 101 | INPUT = 0x00 # pin set as input 102 | OUTPUT = 0x01 # pin set as output 103 | ANALOG = 0x02 # analog pin in analogInput mode 104 | PWM = 0x03 # digital pin in PWM output mode 105 | SERVO = 0x04 # digital pin in Servo output mode 106 | I2C = 0x06 # pin included in I2C setup 107 | STEPPER = 0x08 # any pin in stepper mode 108 | SERIAL = 0x0a 109 | PULLUP = 0x0b # Any pin in pullup mode 110 | SONAR = 0x0c # Any pin in SONAR mode 111 | TONE = 0x0d # Any pin in tone mode 112 | PIXY = 0x0e # reserved for pixy camera mode 113 | DHT = 0x0f # DHT sensor 114 | 115 | IGNORE = 0x7f 116 | 117 | # Tone commands 118 | TONE_TONE = 0 # play a tone 119 | TONE_NO_TONE = 1 # turn off tone 120 | 121 | # DHT command 122 | DHT_CONFIG = 0x64 # dht config command 123 | DHT_DATA = 0x65 # dht sensor command 124 | ### 125 | 126 | # I2C command operation modes 127 | I2C_WRITE = 0B00000000 128 | I2C_READ = 0B00001000 129 | I2C_READ_CONTINUOUSLY = 0B00010000 130 | I2C_STOP_READING = 0B00011000 131 | I2C_READ_WRITE_MODE_MASK = 0B00011000 132 | I2C_10BIT_ADDRESS_MODE_MASK = 0B00100000 133 | I2C_END_TX_MASK = 0B01000000 134 | I2C_STOP_TX = 1 135 | I2C_RESTART_TX = 0 136 | -------------------------------------------------------------------------------- /pypi_desc.md: -------------------------------------------------------------------------------- 1 | # pymata4 2 | 3 | ### A high performance, non-blocking client for the Arduino Firmata Protocol. 4 | 5 | ### A high performance, Python client for the Arduino Firmata Protocol. 6 | Pymata4 is a Firmata client that, like its asyncio sibling, 7 | [pymata-express,](https://mryslab.github.io/pymata-express/) 8 | allows you to control an Arduino using the high-performance FirmataExpress sketch. 9 | It uses a conventional Python API for those that do not need or wish to use the asyncio programming paradigm of pymata-express. 10 | 11 | ### A [User's Guide is available,](https://mryslab.github.io/pymata4/) containing an annotated API as well as links to working examples. 12 | 13 | 14 | ### It supports both an enhanced version of StandardaFirmata 2.5.8, called FirmataExpress, as well as StandardFirmata and StandardFimataWiFi. 15 | * **[FirmataExpress](https://github.com/MrYsLab/FirmataExpress) adds support for:** 16 | * **HC-SR04 Ultrasonic Distance Sensors.** 17 | * **DHT Humidity/Temperature Sensors.** 18 | * **Stepper Motors.** 19 | * **Piezo Tone Generation.** 20 | * **Baud rate of 115200** 21 | 22 | ## Major features 23 | 24 | * **Fully documented intuitive API** 25 | 26 | 27 | * **Python 3.7+ compatible.** 28 | 29 | * **Set the pin mode and go!** 30 | 31 | * **Data change events may be associated with a callback function or each pin can be polled for its last event change.** 32 | 33 | * **Each data change event is time stamped and logged.** 34 | 35 | * **[User's Guide](https://mryslab.github.io/pymata4/), Including Examples.** 36 | 37 | * **Implements 100% of the StandardFirmata Protocol (StandardFirmata 2.5.8).** 38 | 39 | * **Advanced auto-detection of Arduino devices (when using FirmataExpress).** 40 | 41 | Here is an example that monitors for data changes on a digital input pin. It demonstrates both callback and 42 | polling techniques 43 | 44 | ```python 45 | import time 46 | import sys 47 | from pymata4 import pymata4 48 | 49 | """ 50 | Setup a pin for digital input and monitor its changes 51 | Both polling and callback are being used in this example. 52 | """ 53 | 54 | # Setup a pin for analog input and monitor its changes 55 | DIGITAL_PIN = 12 # arduino pin number 56 | POLL_TIME = 5 # number of seconds between polls 57 | 58 | # Callback data indices 59 | # Callback data indices 60 | CB_PIN_MODE = 0 61 | CB_PIN = 1 62 | CB_VALUE = 2 63 | CB_TIME = 3 64 | 65 | 66 | def the_callback(data): 67 | """ 68 | A callback function to report data changes. 69 | This will print the pin number, its reported value and 70 | the date and time when the change occurred 71 | 72 | :param data: [pin, current reported value, pin_mode, timestamp] 73 | """ 74 | date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(data[CB_TIME])) 75 | print(f'Pin: {data[CB_PIN]} Value: {data[CB_VALUE]} Time Stamp: {date}') 76 | 77 | 78 | def digital_in(my_board, pin): 79 | """ 80 | This function establishes the pin as a 81 | digital input. Any changes on this pin will 82 | be reported through the call back function. 83 | 84 | :param my_board: a pymata_express instance 85 | :param pin: Arduino pin number 86 | """ 87 | 88 | # set the pin mode 89 | my_board.set_pin_mode_digital_input(pin, callback=the_callback) 90 | 91 | while True: 92 | try: 93 | # Do a read of the last value reported every 5 seconds and print it 94 | # digital_read returns A tuple of last value change and the time that it occurred 95 | value, time_stamp = my_board.digital_read(pin) 96 | date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time_stamp)) 97 | # value 98 | print(f'Polling - last value: {value} received on {date} ') 99 | time.sleep(POLL_TIME) 100 | except KeyboardInterrupt: 101 | board.shutdown() 102 | sys.exit(0) 103 | 104 | board = pymata4.Pymata4() 105 | 106 | try: 107 | digital_in(board, DIGITAL_PIN) 108 | except KeyboardInterrupt: 109 | board.shutdown() 110 | sys.exit(0) 111 | 112 | 113 | ``` 114 | 115 | And here is the console output: 116 | ```python 117 | pymata4: Version 1.00 118 | 119 | Copyright (c) 2020 Alan Yorinks All Rights Reserved. 120 | 121 | Opening all potential serial ports... 122 | /dev/ttyACM0 123 | 124 | Waiting 4 seconds(arduino_wait) for Arduino devices to reset... 125 | 126 | Searching for an Arduino configured with an arduino_instance = 1 127 | Arduino compatible device found and connected to /dev/ttyACM0 128 | 129 | Retrieving Arduino Firmware ID... 130 | Arduino Firmware ID: 2.5 FirmataExpress.ino 131 | 132 | Retrieving analog map... 133 | Auto-discovery complete. Found 20 Digital Pins and 6 Analog Pins 134 | 135 | 136 | Polling - last change: 0 change received on 1969-12-31 19:00:00 137 | Pin: 12 Value: 0 Time Stamp: 2020-03-07 08:52:10 138 | Pin: 12 Value: 1 Time Stamp: 2020-03-07 08:52:12 139 | Polling - last value: 1 received on 2020-03-07 08:52:12 -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from setuptools import setup 4 | 5 | with open('README.md') as f: 6 | long_description = f.read() 7 | 8 | 9 | setup( 10 | name='pymata4', 11 | packages=['pymata4'], 12 | install_requires=['pyserial'], 13 | 14 | version='1.15', 15 | description="A Python Protocol Abstraction Library For Arduino Firmata", 16 | long_description=long_description, 17 | long_description_content_type='text/markdown', 18 | 19 | author='Alan Yorinks', 20 | author_email='MisterYsLab@gmail.com', 21 | url='https://github.com/MrYsLab/pymata4', 22 | download_url='https://github.com/MrYsLab/pymata4', 23 | keywords=['Firmata', 'Arduino', 'Protocol', 'Python'], 24 | classifiers=[ 25 | 'Development Status :: 5 - Production/Stable', 26 | 'Environment :: Other Environment', 27 | 'Intended Audience :: Developers', 28 | 'Intended Audience :: Education', 29 | 'License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)', 30 | 'Operating System :: OS Independent', 31 | 'Programming Language :: Python :: 3.7', 32 | 'Programming Language :: Python :: 3.8', 33 | 'Topic :: Software Development :: Libraries :: Python Modules' 34 | ], 35 | ) 36 | 37 | --------------------------------------------------------------------------------