Metadata-Version: 2.1
Name: pymata-express
Version: 1.14
Summary: A Python Protocol Abstraction Library For Arduino Firmata using Python asyncio
Home-page: https://mryslab.github.io/pymata-express/
Author: Alan Yorinks
Author-email: MisterYsLab@gmail.com
License: GNU Affero General Public License v3 or later (AGPLv3+)
Download-URL: https://github.com/MrYsLab/pymata-express
Description: # pymata-express
        
        
        ### A high performance, Python asyncio client for the Arduino Firmata Protocol.
        Pymata-Express is a Firmata client that, like its conventional Python sibling,
         [pymata4,](https://mryslab.github.io/pymata4/)
         allows you to control an Arduino using the high-performance FirmataExpress sketch.
        
        ### It supports both an enhanced version of StandardaFirmata 2.5.8, called FirmataExpress, as well as StandardFirmata and StandardFimataWiFi. 
        * **[FirmataExpress](https://github.com/MrYsLab/FirmataExpress) adds support for:**
             * **HC-SR04 Ultrasonic Distance Sensors using a single pin.**
             * **DHT Humidity/Temperature Sensors.** 
             * **Stepper Motors.** 
             * **Piezo Tone Generation.**
             * **Baud rate of 115200**
        
        ##Major features
        
        * **Fully documented <a href="https://htmlpreview.github.com/?https://github.com/MrYsLab/pymata-express/blob/master/html/pymata_express/index.html" target="_blank">intuitive API</a>**
        
        
        * **Python 3.7+ compatible.**
        
        * **Set the pin mode and go!**
        
        * **Data change events may be associated with a callback function or each pin can be polled for its last event change.**
        
            * **Each data change event is time stamped and logged.**
        
        * **[User's Guide](https://mryslab.github.io/pymata-express/), Including Examples.**
        
        * **Implements 100% of the StandardFirmata Protocol (StandardFirmata 2.5.8).**
        
        * **Advanced auto-detection of Arduino devices (when using FirmataExpress).**
        
        Here is an example that monitors for data changes on a digital input pin. 
        
        
        ```python
        import asyncio
        import time
        import sys
        from pymata_express import pymata_express
        
        """
        Setup a pin for digital input and monitor its changes
        using a callback.
        """
        
        # Setup a pin for analog input and monitor its changes
        DIGITAL_PIN = 12  # arduino pin number
        IDLE_TIME = .001  # number of seconds for idle loop to sleep
        
        # Callback data indices
        # Callback data indices
        CB_PIN_MODE = 0
        CB_PIN = 1
        CB_VALUE = 2
        CB_TIME = 3
        
        
        async def the_callback(data):
            """
            A callback function to report data changes.
            This will print the pin number, its reported value and
            the date and time when the change occurred
        
            :param data: [pin, current reported value, pin_mode, timestamp]
            """
            date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(data[CB_TIME]))
            print(f'Pin: {data[CB_PIN]} Value: {data[CB_VALUE]} Time Stamp: {date}')
        
        
        async def digital_in(my_board, pin):
            """
             This function establishes the pin as a
             digital input. Any changes on this pin will
             be reported through the call back function.
        
             :param my_board: a pymata_express instance
             :param pin: Arduino pin number
             """
        
            # set the pin mode
            await my_board.set_pin_mode_digital_input(pin, callback=the_callback)
        
            while True:
                try:
                    await asyncio.sleep(IDLE_TIME)
                except KeyboardInterrupt:
                    await board.shutdown()
                    sys.exit(0)
        
        # get the event loop
        loop = asyncio.get_event_loop()
        
        # instantiate pymata_express
        board = pymata_express.PymataExpress()
        
        try:
            # start the main function
            loop.run_until_complete(digital_in(board, 12))
        except (KeyboardInterrupt, RuntimeError) as e:
            loop.run_until_complete(board.shutdown())
            sys.exit(0)
        
        ```
        
        Sample console output as input change events occur:
        ```bash
        Pin: 12 Value: 0 Time Stamp: 2020-03-10 13:26:22
        Pin: 12 Value: 1 Time Stamp: 2020-03-10 13:26:27
        ```
Keywords: Firmata,Arduino,Protocol,Python,asyncio
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Other Environment
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Education
Classifier: License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Utilities
Classifier: Topic :: Education
Classifier: Topic :: Home Automation
Description-Content-Type: text/markdown
