diff --git a/.nojekyll b/.nojekyll new file mode 100644 index 0000000..e69de29 diff --git a/404.html b/404.html new file mode 100644 index 0000000..6ee4e5a --- /dev/null +++ b/404.html @@ -0,0 +1,985 @@ + + + +
+ + + + + + + + + + + + + +If you wish to report an issue with this library, please use +this link.
+For any of the servers, please use +this link.
+When filing an issue, please provide:
+For bugs, comments, or questions, please use the links above.
+
+
Copyright (C) 2023 Alan Yorinks. All Rights Reserved.
+ + + + + + +Pin modes must be set before interacting with a pin. All the methods listed +below have a consistent API across all API classes.
+
+
Copyright (C) 2023 Alan Yorinks. All Rights Reserved.
+ + + + + + +The following section contains a set of application templates for each of the four +servers. +The templates are based on the included examples.
+As you will see, your application needs to import the correct API +and instantiate the API class. +You then use the API method calls in writing your application.
+
+
Copyright (C) 2023 Alan Yorinks. All Rights Reserved.
+ + + + + + +Arduino IDE version 2.1.X is used to upload a server to the Minima or WIFI. It is also +used to modify server source code when configuration is necessary.
+To install a copy of the IDE, go to the Arduino Software Download page, and +select the version for your +operating system. Follow the installation instructions.
+ +You may need to add your login to the dialout group to upload to the Arduino.
+To do so, follow these instructions.
+
+Copyright (C) 2023 Alan Yorinks. All Rights Reserved.
A callback function must be registered when you set a pin to an input mode.
+The code below illustrates a typical callback function.
+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 mode, pin, current reported value,timestamp]
+ """
+ date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(data[CB_TIME]))
+ print(f'Report Type: {data[CB_PIN_MODE]} Pin: {data[CB_PIN]} '
+ f'Value: {data[CB_VALUE]} Time Stamp: {date}')
+
+And here, the callback is registered when the set_pin_mode is called:
+board.set_pin_mode_digital_input_pullup(12, the_callback)
+
+If you forget to register a callback, +a RunTime exception will be thrown.
+Traceback (most recent call last):
+ File "/home/afy/PycharmProjects/telemetrix-rpi-pico-w/ play/no_callback_registered.py", line 5, in <module>
+ board.set_pin_mode_digital_input(5)
+ File "/home/afy/PycharmProjects/telemetrix-rpi-pico-w/telemetrix_rpi_pico_w/telemetrix_rpi_pico_w.py", line 752, in set_pin_mode_digital_input
+ raise RuntimeError('A callback must be specified')
+RuntimeError: A callback must be specified
+
+A callback function or method must accept a single parameter. The client
+automatically fills in this parameter as a list
+when receiving an input data change notification.
+For "the_callback" above, this parameter is named data.
The list contents vary from input pin type to input pin type and +are described in detail for each set_pin_mode_XXX method in the +API documentation. +The first element in the list identifies the pin type, and the last element +is a timestamp of the data change occurrence. Other elements identify the GPIO pin, +the current data value, and additional relevant information.
+For example, the list may contain
+[DIGITAL_REPORT, pin_number, pin_value, raw_time_stamp]
+
+DIGITAL_REPORT = 2
+
+NOTE:
+**Telemetrix does not support polling or direct read methods for +inputs. Instead, the pin's associated callback is called as soon +as a data change is detected, allowing immediate response to data +changes and, generally, a more straightforward application design. +**
+Pin Mode | +Pin Mode Value | +
---|---|
Digital Input (including pullup and pulldown) | +2 | +
Analog Input (ADC) | +3 | +
I2C | +10 | +
SONAR Distance | +11 | +
DHT | +12 | +
To convert the raw timestamp field to a human-readable time, use time.localtime().
+date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(data[CB_TIME]))
+
+
+
Copyright (C) 2023 Alan Yorinks. All Rights Reserved.
+ + + + + + +Once the client and server software have been installed, +it would be an excellent time to try the examples.
+Examples are provided for all four of the servers.
+The naming convention used for the examples prefixes each example with three letters. +The first letter is for the board type:
+The second letter is for the transport type:
+The third is for the concurrency type:
+
+Copyright (C) 2023 Alan Yorinks. All Rights Reserved.
+
+
Telemetry is a system for collecting data on a remote device and then +automatically transmitting the collected data back to local receiving equipment for +processing.
+With Telemetrix, you can do things such as establish a GPIO pin as a PWM output pin and +set its value to run a DC motor, communicate with your favorite i2c device, +have the WIFI's LEDs scroll a message, or monitor temperature using a DHT temperature +device, and much more, +all within a Python application.
+Telemetrix is implemented using a client-server model. +A "fixed" server is uploaded to the Arduino.
+The server communicates with a Telemetrix Python client that sends commands to +the Arduino and receives data reports.
+Application debugging is simplified by using your favorite Python toolset.
+The Arduino UNO R4 Minima uses a USBSerial transport.
+For the Arduino UNO R4 WIFI, you can choose a WIFI, USBSerial or BLE transport. +There are servers for each of the transport types.
+Choose whichever one suits your needs.
+The transport type is specified for the UNO R4 WIFI when Telemetrix is instantiated.
+When you set a pin mode as an input type, a user-provided callback method is +registered to provide data change notifications. +Callbacks ensure that data changes +are processed as soon as possible and that no data change events are lost. +Each data change is time-stamped as it is received.
+You may implement the callback scheme as a single callback to +handle all data change events or multiple individual callbacks to handle +specific pins or input device types, giving you maximum flexibility.
+Data is reported automatically without polling for analog inputs, +digital inputs, DHT temperature sensors, and HC-SR04 distance sensors. +Once a pin mode is set, reporting begins immediately.
+Below is a Telemetrix example for the Arduino UNO R4 Mimima that monitors several +digital input pins. All the pins share a single callback.
+import sys
+import time
+
+from telemetrix_uno_r4.minima.telemetrix_uno_r4_minima import telemetrix_uno_r4_minima
+
+"""
+Monitor 4 digital input pins.
+"""
+
+
+# Callback data indices
+# When the callback function is called, the client fills in
+# the data parameter. Data is a list of values, and the following are
+# indexes into the list to retrieve report information
+
+CB_PIN_MODE = 0 # The mode of the reporting pin (input, output, PWM, etc.)
+CB_PIN = 1 # The GPIO pin number associated with this report
+CB_VALUE = 2 # The data value reported
+CB_TIME = 3 # A time stamp when the data change occurred
+
+
+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: [report type(i.e. analog, pwm, digital), pin number, current reported
+ value, timestamp]
+ """
+ date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(data[CB_TIME]))
+ print(f'Report Type: {data[CB_PIN_MODE]} Pin: {data[CB_PIN]} '
+ f'Value: {data[CB_VALUE]} Time Stamp: {date}')
+
+# instantiate TelemetrixUnoR4Minima
+board = telemetrix_uno_r4_minima.TelemetrixUnoR4Minima()
+
+# Set the pin mode for each pin.
+# A callback must be specified. A single callback is used for this example, but
+# separate callback could be used for each pin.
+board.set_pin_mode_digital_input(5, the_callback)
+board.set_pin_mode_digital_input(6, the_callback)
+board.set_pin_mode_digital_input(7, the_callback)
+board.set_pin_mode_digital_inputp(8, the_callback)
+
+try:
+ while True:
+ time.sleep(.0001)
+except KeyboardInterrupt:
+ board.shutdown()
+ sys.exit(0)
+
+And here is some sample output:
+telemetrix_uno_r4_minima: Version 1.00
+
+Copyright (c) 2023 Alan Yorinks All Rights Reserved.
+
+Opening all potential serial ports...
+ /dev/ttyACM0
+
+Waiting 1 seconds(arduino_wait) for Arduino devices to reset...
+Valid Arduino ID Found.
+Arduino compatible device found and connected to /dev/ttyACM0
+Reset Complete
+
+Retrieving Telemetrix4UnoR4Minima firmware ID...
+Telemetrix4UnoR4Minima firmware version: 1.0.0
+Enter Control-C to quit.
+
+Report Type: 2 Pin: 5 Value: 1 Time Stamp: 2023-07-14 13:34:52
+Report Type: 2 Pin: 6 Value: 1 Time Stamp: 2023-07-14 13:34:52
+Report Type: 2 Pin: 7 Value: 1 Time Stamp: 2023-07-14 13:34:52
+Report Type: 2 Pin: 8 Value: 1 Time Stamp: 2023-07-14 13:34:52
+Report Type: 2 Pin: 8 Value: 0 Time Stamp: 2023-07-14 13:35:21
+Report Type: 2 Pin: 8 Value: 1 Time Stamp: 2023-07-14 13:35:22
+Report Type: 2 Pin: 5 Value: 0 Time Stamp: 2023-07-14 13:35:29
+Report Type: 2 Pin: 5 Value: 1 Time Stamp: 2023-07-14 13:35:31
+Report Type: 2 Pin: 6 Value: 0 Time Stamp: 2023-07-14 13:35:33
+Report Type: 2 Pin: 8 Value: 1 Time Stamp: 2023-07-14 13:35:34
+
+
+
+Copyright (C) 2023 Alan Yorinks. All Rights Reserved.
+Last updated 7 August 2023
+ + + + + + +To install from PyPI, within your virtual environment type:
+pip install telemetrix-uno-r4
+
+To upgrade to a newer version from an existing installation, use the following command:
+pip install telemetrix-uno-r4 --upgrade
+
+
+The telemetrix-uno-r4 package contains four client APIs. You have the choice of using +an API employing a threaded concurrency model or an API using an asyncio concurrency +model. The asyncio API +names end +with _aio.
+NOTE: BLE is only supported by telemetrix_uno_r4_wifi_aio.
+telemetrix_uno_r4_minima
+telemetrix_uno_r4_minima_aio
+telemetrix_uno_r4_wifi
+telemetrix_uno_r4_wifi_aio
+
+
Copyright (C) 2023 Alan Yorinks. All Rights Reserved.
+ + + + + + +Telemetrix4UnoR4 uses the NewPing library for HC-SR04 Sonar distance sensor support. +You may see the following warning when compiling any of the servers. +This warning may be safely ignored.
+An issue was created but has not yet been addressed.
+WARNING: library NewPing claims to run on avr, megaavr, esp32 architecture(s)
+and may be incompatible with your current board which runs on
+renesas architecture(s).
+
+
+BLE support for Arduino UNO R4 boards is in a Beta state. Currently, it does not +support the Servo library. An issue has been generated against the ArduinoBLE library.
+Instructions to install the Beta version of ArduinoBLE may be found here.
+BLE is only supported using the asyncio API. The +threaded API does not support BLE.
+
+Copyright (C) 2023 Alan Yorinks. All Rights Reserved.
Version 3, 19 November 2007
+Copyright (C) 2007 Free Software Foundation, Inc. +https://fsf.org/
+Everyone is permitted to copy and distribute verbatim copies of this +license document, but changing it is not allowed.
+The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software.
+The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +our General Public Licenses are intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains +free software for all its users.
+When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things.
+Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software.
+A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public.
+The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version.
+An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing +under this license.
+The precise terms and conditions for copying, distribution and +modification follow.
+"This License" refers to version 3 of the GNU Affero General Public +License.
+"Copyright" also means copyright-like laws that apply to other kinds +of works, such as semiconductor masks.
+"The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations.
+To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of +an exact copy. The resulting work is called a "modified version" of +the earlier work or a work "based on" the earlier work.
+A "covered work" means either the unmodified Program or a work based +on the Program.
+To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well.
+To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user +through a computer network, with no transfer of a copy, is not +conveying.
+An interactive user interface displays "Appropriate Legal Notices" to +the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion.
+The "source code" for a work means the preferred form of the work for +making modifications to it. "Object code" means any non-source form of +a work.
+A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language.
+The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it.
+The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work.
+The Corresponding Source need not include anything that users can +regenerate automatically from other parts of the Corresponding Source.
+The Corresponding Source for a work in source code form is that same +work.
+All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law.
+You may make, run and propagate covered works that you do not convey, +without conditions so long as your license otherwise remains in force. +You may convey covered works to others for the sole purpose of having +them make modifications exclusively for you, or provide you with +facilities for running those works, provided that you comply with the +terms of this License in conveying all material for which you do not +control copyright. Those thus making or running the covered works for +you must do so exclusively on your behalf, under your direction and +control, on terms that prohibit them from making any copies of your +copyrighted material outside their relationship with you.
+Conveying under any other circumstances is permitted solely under the +conditions stated below. Sublicensing is not allowed; section 10 makes +it unnecessary.
+No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures.
+When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such +circumvention is effected by exercising rights under this License with +respect to the covered work, and you disclaim any intention to limit +operation or modification of the work as a means of enforcing, against +the work's users, your or third parties' legal rights to forbid +circumvention of technological measures.
+You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program.
+You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee.
+You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these +conditions:
+A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate.
+You may convey a covered work in object code form under the terms of +sections 4 and 5, provided that you also convey the machine-readable +Corresponding Source under the terms of this License, in one of these +ways:
+A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work.
+A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, +family, or household purposes, or (2) anything designed or sold for +incorporation into a dwelling. In determining whether a product is a +consumer product, doubtful cases shall be resolved in favor of +coverage. For a particular product received by a particular user, +"normally used" refers to a typical or common use of that class of +product, regardless of the status of the particular user or of the way +in which the particular user actually uses, or expects or is expected +to use, the product. A product is a consumer product regardless of +whether the product has substantial commercial, industrial or +non-consumer uses, unless such uses represent the only significant +mode of use of the product.
+"Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to +install and execute modified versions of a covered work in that User +Product from a modified version of its Corresponding Source. The +information must suffice to ensure that the continued functioning of +the modified object code is in no case prevented or interfered with +solely because modification has been made.
+If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM).
+The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or +updates for a work that has been modified or installed by the +recipient, or for the User Product in which it has been modified or +installed. Access to a network may be denied when the modification +itself materially and adversely affects the operation of the network +or violates the rules and protocols for communication across the +network.
+Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying.
+"Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions.
+When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission.
+Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders +of that material) supplement the terms of this License with terms:
+All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying.
+If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms.
+Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; the +above requirements apply either way.
+You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11).
+However, if you cease all violation of this License, then your license +from a particular copyright holder is reinstated (a) provisionally, +unless and until the copyright holder explicitly and finally +terminates your license, and (b) permanently, if the copyright holder +fails to notify you of the violation by some reasonable means prior to +60 days after the cessation.
+Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice.
+Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10.
+You are not required to accept this License in order to receive or run +a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so.
+Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License.
+An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts.
+You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it.
+A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version".
+A contributor's "essential patent claims" are all patent claims owned +or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License.
+Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version.
+In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party.
+If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid.
+If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it.
+A patent license is "discriminatory" if it does not include within the +scope of its coverage, prohibits the exercise of, or is conditioned on +the non-exercise of one or more of the rights that are specifically +granted under this License. You may not convey a covered work if you +are a party to an arrangement with a third party that is in the +business of distributing software, under which you make payment to the +third party based on the extent of your activity of conveying the +work, and under which the third party grants, to any of the parties +who would receive the covered work from you, a discriminatory patent +license (a) in connection with copies of the covered work conveyed by +you (or copies made from those copies), or (b) primarily for and in +connection with specific products or compilations that contain the +covered work, unless you entered into that arrangement, or that patent +license was granted, prior to 28 March 2007.
+Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law.
+If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under +this License and any other pertinent obligations, then as a +consequence you may not convey it at all. For example, if you agree to +terms that obligate you to collect a royalty for further conveying +from those to whom you convey the Program, the only way you could +satisfy both those terms and this License would be to refrain entirely +from conveying the Program.
+Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your +version supports such interaction) an opportunity to receive the +Corresponding Source of your version by providing access to the +Corresponding Source from a network server at no charge, through some +standard or customary means of facilitating copying of software. This +Corresponding Source shall include the Corresponding Source for any +work covered by version 3 of the GNU General Public License that is +incorporated pursuant to the following paragraph.
+Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the work with which it is combined will remain governed by version +3 of the GNU General Public License.
+The Free Software Foundation may publish revised and/or new versions +of the GNU Affero General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns.
+Each version is given a distinguishing version number. If the Program +specifies that a certain numbered version of the GNU Affero General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU Affero General Public License, you may choose any version ever +published by the Free Software Foundation.
+If the Program specifies that a proxy can decide which future versions +of the GNU Affero General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program.
+Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version.
+THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT +WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND +PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE +DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR +CORRECTION.
+IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR +CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES +ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT +NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR +LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM +TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER +PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee.
+END OF TERMS AND CONDITIONS
+If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these +terms.
+To do so, attach the following notices to the program. It is safest to +attach them to the start of each source file to most effectively state +the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found.
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper +mail.
+If your software can interact with users remotely through a computer +network, you should also make sure that it provides a way for users to +get its source. For example, if your program is a web application, its +interface could display a "Source" link that leads users to an archive +of the code. There are many ways you could offer source, and different +solutions will be better for different programs; see section 13 for +the specific requirements.
+You should also get your employer (if you work as a programmer) or +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. For more information on this, and how to apply and follow +the GNU AGPL, see https://www.gnu.org/licenses/.
+ + + + + + +Python 3.8 or greater is required before installing and using the telemetrix-uno-r4 +package.
+To check that you have the correct version of Python 3 installed, +open a command window and type:
+python3 -V
+
+For Windows, you may need to type:
+python -V
+
+Executing this command displays the current version of Python 3 installed.
+Python 3.11.4
+
+If you need to install Python 3, refer to python.org.
+
+
Copyright (C) 2023 Alan Yorinks. All Rights Reserved.
+ + + + + + +Telemetry is a system for collecting data on a remote device and then automatically transmitting the collected data back to local receiving equipment for processing.
With Telemetrix, you can do things such as establish a GPIO pin as a PWM output pin and set its value to run a DC motor, communicate with your favorite i2c device, have the WIFI's LEDs scroll a message, or monitor temperature using a DHT temperature device, and much more, all within a Python application.
"},{"location":"#telemetrix-client-server-model","title":"Telemetrix Client-Server Model","text":"Telemetrix is implemented using a client-server model. A \"fixed\" server is uploaded to the Arduino.
The server communicates with a Telemetrix Python client that sends commands to the Arduino and receives data reports.
Application debugging is simplified by using your favorite Python toolset.
"},{"location":"#telemetrix-client-server-transports","title":"Telemetrix Client-Server Transports","text":"The Arduino UNO R4 Minima uses a USBSerial transport.
For the Arduino UNO R4 WIFI, you can choose a WIFI, USBSerial or BLE transport. There are servers for each of the transport types.
"},{"location":"#both-threaded-and-asyncio-client-apis-are-available-for-each-board","title":"Both Threaded And ASYNCIO Client APIs Are Available For Each Board","text":"Choose whichever one suits your needs.
The transport type is specified for the UNO R4 WIFI when Telemetrix is instantiated.
"},{"location":"#data-is-reported-using-callback-methods","title":"Data Is Reported Using Callback Methods","text":"When you set a pin mode as an input type, a user-provided callback method is registered to provide data change notifications. Callbacks ensure that data changes are processed as soon as possible and that no data change events are lost. Each data change is time-stamped as it is received.
You may implement the callback scheme as a single callback to handle all data change events or multiple individual callbacks to handle specific pins or input device types, giving you maximum flexibility.
"},{"location":"#automatic-data-reporting","title":"Automatic Data Reporting","text":"Data is reported automatically without polling for analog inputs, digital inputs, DHT temperature sensors, and HC-SR04 distance sensors. Once a pin mode is set, reporting begins immediately.
"},{"location":"#summary-of-major-features","title":"Summary Of Major Features","text":"Below is a Telemetrix example for the Arduino UNO R4 Mimima that monitors several digital input pins. All the pins share a single callback.
import sys\nimport time\n\nfrom telemetrix_uno_r4.minima.telemetrix_uno_r4_minima import telemetrix_uno_r4_minima\n\n\"\"\"\nMonitor 4 digital input pins.\n\"\"\"\n\n\n# Callback data indices\n# When the callback function is called, the client fills in \n# the data parameter. Data is a list of values, and the following are \n# indexes into the list to retrieve report information\n\nCB_PIN_MODE = 0 # The mode of the reporting pin (input, output, PWM, etc.)\nCB_PIN = 1 # The GPIO pin number associated with this report\nCB_VALUE = 2 # The data value reported\nCB_TIME = 3 # A time stamp when the data change occurred\n\n\ndef the_callback(data):\n \"\"\"\n A callback function to report data changes.\n This will print the pin number, its reported value and\n the date and time when the change occurred\n :param data: [report type(i.e. analog, pwm, digital), pin number, current reported \n value, timestamp]\n \"\"\"\n date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(data[CB_TIME]))\n print(f'Report Type: {data[CB_PIN_MODE]} Pin: {data[CB_PIN]} '\n f'Value: {data[CB_VALUE]} Time Stamp: {date}')\n\n# instantiate TelemetrixUnoR4Minima\nboard = telemetrix_uno_r4_minima.TelemetrixUnoR4Minima()\n\n# Set the pin mode for each pin.\n# A callback must be specified. A single callback is used for this example, but\n# separate callback could be used for each pin.\nboard.set_pin_mode_digital_input(5, the_callback)\nboard.set_pin_mode_digital_input(6, the_callback)\nboard.set_pin_mode_digital_input(7, the_callback)\nboard.set_pin_mode_digital_inputp(8, the_callback)\n\ntry:\n while True:\n time.sleep(.0001)\nexcept KeyboardInterrupt:\n board.shutdown()\n sys.exit(0)\n
And here is some sample output:
telemetrix_uno_r4_minima: Version 1.00\n\nCopyright (c) 2023 Alan Yorinks All Rights Reserved.\n\nOpening all potential serial ports...\n /dev/ttyACM0\n\nWaiting 1 seconds(arduino_wait) for Arduino devices to reset...\nValid Arduino ID Found.\nArduino compatible device found and connected to /dev/ttyACM0\nReset Complete\n\nRetrieving Telemetrix4UnoR4Minima firmware ID...\nTelemetrix4UnoR4Minima firmware version: 1.0.0\nEnter Control-C to quit.\n\nReport Type: 2 Pin: 5 Value: 1 Time Stamp: 2023-07-14 13:34:52\nReport Type: 2 Pin: 6 Value: 1 Time Stamp: 2023-07-14 13:34:52\nReport Type: 2 Pin: 7 Value: 1 Time Stamp: 2023-07-14 13:34:52\nReport Type: 2 Pin: 8 Value: 1 Time Stamp: 2023-07-14 13:34:52\nReport Type: 2 Pin: 8 Value: 0 Time Stamp: 2023-07-14 13:35:21\nReport Type: 2 Pin: 8 Value: 1 Time Stamp: 2023-07-14 13:35:22\nReport Type: 2 Pin: 5 Value: 0 Time Stamp: 2023-07-14 13:35:29\nReport Type: 2 Pin: 5 Value: 1 Time Stamp: 2023-07-14 13:35:31\nReport Type: 2 Pin: 6 Value: 0 Time Stamp: 2023-07-14 13:35:33\nReport Type: 2 Pin: 8 Value: 1 Time Stamp: 2023-07-14 13:35:34\n\n\n
Copyright (C) 2023 Alan Yorinks. All Rights Reserved.
Last updated 7 August 2023
"},{"location":"about/","title":"REPORTING ISSUES","text":"If you wish to report an issue with this library, please use this link.
For any of the servers, please use this link.
When filing an issue, please provide:
For bugs, comments, or questions, please use the links above.
Copyright (C) 2023 Alan Yorinks. All Rights Reserved.
"},{"location":"about_the_apis/","title":"General Principles","text":""},{"location":"about_the_apis/#setting-pin-modes","title":"Setting Pin Modes","text":"Pin modes must be set before interacting with a pin. All the methods listed below have a consistent API across all API classes.
"},{"location":"about_the_apis/#input-pin-modes","title":"Input Pin Modes","text":""},{"location":"about_the_apis/#requiring-a-callback-to-be-specified","title":"Requiring A Callback To Be Specified","text":"Copyright (C) 2023 Alan Yorinks. All Rights Reserved.
"},{"location":"app_creation/","title":"Application Creation","text":""},{"location":"app_creation/#a-word-about-the-application-templates","title":"A Word About The Application Templates","text":"The following section contains a set of application templates for each of the four servers. The templates are based on the included examples.
As you will see, your application needs to import the correct API and instantiate the API class. You then use the API method calls in writing your application.
Copyright (C) 2023 Alan Yorinks. All Rights Reserved.
"},{"location":"arduino_ide/","title":"Install The Arduino IDE","text":""},{"location":"arduino_ide/#download-and-install-the-arduino-ide","title":"Download And Install The Arduino IDE","text":"Arduino IDE version 2.1.X is used to upload a server to the Minima or WIFI. It is also used to modify server source code when configuration is necessary.
To install a copy of the IDE, go to the Arduino Software Download page, and select the version for your operating system. Follow the installation instructions.
"},{"location":"arduino_ide/#a-note-for-linux-users","title":"A Note For Linux Users","text":"You may need to add your login to the dialout group to upload to the Arduino.
To do so, follow these instructions.
Copyright (C) 2023 Alan Yorinks. All Rights Reserved.
"},{"location":"callbacks/","title":"Callbacks","text":""},{"location":"callbacks/#registering-a-callback","title":"Registering A Callback","text":"A callback function must be registered when you set a pin to an input mode.
The code below illustrates a typical callback function.
def the_callback(data):\n \"\"\"\n A callback function to report data changes.\n This will print the pin number, its reported value and\n the date and time when the change occurred\n\n :param data: [pin mode, pin, current reported value,timestamp]\n \"\"\"\n date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(data[CB_TIME]))\n print(f'Report Type: {data[CB_PIN_MODE]} Pin: {data[CB_PIN]} '\n f'Value: {data[CB_VALUE]} Time Stamp: {date}')\n
And here, the callback is registered when the set_pin_mode is called:
board.set_pin_mode_digital_input_pullup(12, the_callback)\n
If you forget to register a callback, a RunTime exception will be thrown.
Traceback (most recent call last):\n File \"/home/afy/PycharmProjects/telemetrix-rpi-pico-w/ play/no_callback_registered.py\", line 5, in <module>\n board.set_pin_mode_digital_input(5)\n File \"/home/afy/PycharmProjects/telemetrix-rpi-pico-w/telemetrix_rpi_pico_w/telemetrix_rpi_pico_w.py\", line 752, in set_pin_mode_digital_input\n raise RuntimeError('A callback must be specified')\nRuntimeError: A callback must be specified\n
"},{"location":"callbacks/#callback-function-parameter","title":"Callback Function Parameter","text":"A callback function or method must accept a single parameter. The client automatically fills in this parameter as a list when receiving an input data change notification. For \"the_callback\" above, this parameter is named data.
The list contents vary from input pin type to input pin type and are described in detail for each set_pin_mode_XXX method in the API documentation. The first element in the list identifies the pin type, and the last element is a timestamp of the data change occurrence. Other elements identify the GPIO pin, the current data value, and additional relevant information.
For example, the list may contain
[DIGITAL_REPORT, pin_number, pin_value, raw_time_stamp]\n\nDIGITAL_REPORT = 2\n
NOTE:
**Telemetrix does not support polling or direct read methods for inputs. Instead, the pin's associated callback is called as soon as a data change is detected, allowing immediate response to data changes and, generally, a more straightforward application design. **
"},{"location":"callbacks/#pin-types","title":"Pin Types","text":"Pin Mode Pin Mode Value Digital Input (including pullup and pulldown) 2 Analog Input (ADC) 3 I2C 10 SONAR Distance 11 DHT 12"},{"location":"callbacks/#converting-the-raw-timestamp","title":"Converting The Raw Timestamp","text":"To convert the raw timestamp field to a human-readable time, use time.localtime().
date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(data[CB_TIME]))\n
Copyright (C) 2023 Alan Yorinks. All Rights Reserved.
"},{"location":"examples/","title":"Downloading And Running The Examples","text":"Once the client and server software have been installed, it would be an excellent time to try the examples.
Examples are provided for all four of the servers.
"},{"location":"examples/#example-naming-conventions","title":"Example Naming Conventions","text":"The naming convention used for the examples prefixes each example with three letters. The first letter is for the board type:
The second letter is for the transport type:
The third is for the concurrency type:
Copyright (C) 2023 Alan Yorinks. All Rights Reserved.
"},{"location":"install_telemetrix/","title":"Installing The Client APIs","text":""},{"location":"install_telemetrix/#installing-for-the-first-time","title":"Installing For The First Time","text":"To install from PyPI, within your virtual environment type:
pip install telemetrix-uno-r4\n
"},{"location":"install_telemetrix/#upgrading-to-a-newer-version","title":"Upgrading To A Newer Version","text":"To upgrade to a newer version from an existing installation, use the following command:
pip install telemetrix-uno-r4 --upgrade\n\n
"},{"location":"install_telemetrix/#what-is-installed","title":"What Is Installed?","text":"The telemetrix-uno-r4 package contains four client APIs. You have the choice of using an API employing a threaded concurrency model or an API using an asyncio concurrency model. The asyncio API names end with _aio.
NOTE: BLE is only supported by telemetrix_uno_r4_wifi_aio.
"},{"location":"install_telemetrix/#arduino-uno-r4-mimima-clients","title":"Arduino UNO R4 Mimima Clients","text":"telemetrix_uno_r4_minima
telemetrix_uno_r4_minima_aio
telemetrix_uno_r4_wifi
telemetrix_uno_r4_wifi_aio
Copyright (C) 2023 Alan Yorinks. All Rights Reserved.
"},{"location":"issues/","title":"Known Issues","text":""},{"location":"issues/#arduino-compiler-warnings","title":"Arduino Compiler Warnings","text":"Telemetrix4UnoR4 uses the NewPing library for HC-SR04 Sonar distance sensor support. You may see the following warning when compiling any of the servers. This warning may be safely ignored.
An issue was created but has not yet been addressed.
WARNING: library NewPing claims to run on avr, megaavr, esp32 architecture(s)\nand may be incompatible with your current board which runs on \nrenesas architecture(s).\n\n
"},{"location":"issues/#ble","title":"BLE","text":""},{"location":"issues/#server-side-issues","title":"Server Side Issues","text":"BLE support for Arduino UNO R4 boards is in a Beta state. Currently, it does not support the Servo library. An issue has been generated against the ArduinoBLE library.
Instructions to install the Beta version of ArduinoBLE may be found here.
"},{"location":"issues/#client-side-issues","title":"Client Side Issues","text":"BLE is only supported using the asyncio API. The threaded API does not support BLE.
Copyright (C) 2023 Alan Yorinks. All Rights Reserved.
"},{"location":"license/","title":"License","text":""},{"location":"license/#gnu-affero-general-public-license","title":"GNU AFFERO GENERAL PUBLIC LICENSE","text":"Version 3, 19 November 2007
Copyright (C) 2007 Free Software Foundation, Inc. https://fsf.org/
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
"},{"location":"license/#preamble","title":"Preamble","text":"The GNU Affero General Public License is a free, copyleft license for software and other kinds of works, specifically designed to ensure cooperation with the community in the case of network server software.
The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, our General Public Licenses are intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users.
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.
Developers that use our General Public Licenses protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License which gives you legal permission to copy, distribute and/or modify the software.
A secondary benefit of defending all users' freedom is that improvements made in alternate versions of the program, if they receive widespread use, become available for other developers to incorporate. Many developers of free software are heartened and encouraged by the resulting cooperation. However, in the case of software used on network servers, this result may fail to come about. The GNU General Public License permits making a modified version and letting the public access it on a server without ever releasing its source code to the public.
The GNU Affero General Public License is designed specifically to ensure that, in such cases, the modified source code becomes available to the community. It requires the operator of a network server to provide the source code of the modified version running there to the users of that server. Therefore, public use of a modified version, on a publicly accessible server, gives the public access to the source code of the modified version.
An older license, called the Affero General Public License and published by Affero, was designed to accomplish similar goals. This is a different license, not a version of the Affero GPL, but Affero has released a new version of the Affero GPL which permits relicensing under this license.
The precise terms and conditions for copying, distribution and modification follow.
"},{"location":"license/#terms-and-conditions","title":"TERMS AND CONDITIONS","text":""},{"location":"license/#0-definitions","title":"0. Definitions.","text":"\"This License\" refers to version 3 of the GNU Affero General Public License.
\"Copyright\" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.
\"The Program\" refers to any copyrightable work licensed under this License. Each licensee is addressed as \"you\". \"Licensees\" and \"recipients\" may be individuals or organizations.
To \"modify\" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a \"modified version\" of the earlier work or a work \"based on\" the earlier work.
A \"covered work\" means either the unmodified Program or a work based on the Program.
To \"propagate\" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well.
To \"convey\" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays \"Appropriate Legal Notices\" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion.
"},{"location":"license/#1-source-code","title":"1. Source Code.","text":"The \"source code\" for a work means the preferred form of the work for making modifications to it. \"Object code\" means any non-source form of a work.
A \"Standard Interface\" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language.
The \"System Libraries\" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A \"Major Component\", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it.
The \"Corresponding Source\" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work.
The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.
The Corresponding Source for a work in source code form is that same work.
"},{"location":"license/#2-basic-permissions","title":"2. Basic Permissions.","text":"All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
"},{"location":"license/#3-protecting-users-legal-rights-from-anti-circumvention-law","title":"3. Protecting Users' Legal Rights From Anti-Circumvention Law.","text":"No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures.
When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures.
"},{"location":"license/#4-conveying-verbatim-copies","title":"4. Conveying Verbatim Copies.","text":"You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee.
"},{"location":"license/#5-conveying-modified-source-versions","title":"5. Conveying Modified Source Versions.","text":"You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:
A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an \"aggregate\" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.
"},{"location":"license/#6-conveying-non-source-forms","title":"6. Conveying Non-Source Forms.","text":"You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways:
A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work.
A \"User Product\" is either (1) a \"consumer product\", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, \"normally used\" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product.
\"Installation Information\" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made.
If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM).
The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying.
"},{"location":"license/#7-additional-terms","title":"7. Additional Terms.","text":"\"Additional permissions\" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms:
All other non-permissive additional terms are considered \"further restrictions\" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way.
"},{"location":"license/#8-termination","title":"8. Termination.","text":"You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11).
However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.
Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10.
"},{"location":"license/#9-acceptance-not-required-for-having-copies","title":"9. Acceptance Not Required for Having Copies.","text":"You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so.
"},{"location":"license/#10-automatic-licensing-of-downstream-recipients","title":"10. Automatic Licensing of Downstream Recipients.","text":"Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License.
An \"entity transaction\" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it.
"},{"location":"license/#11-patents","title":"11. Patents.","text":"A \"contributor\" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's \"contributor version\".
A contributor's \"essential patent claims\" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, \"control\" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version.
In the following three paragraphs, a \"patent license\" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To \"grant\" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party.
If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. \"Knowingly relying\" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it.
A patent license is \"discriminatory\" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law.
"},{"location":"license/#12-no-surrender-of-others-freedom","title":"12. No Surrender of Others' Freedom.","text":"If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program.
"},{"location":"license/#13-remote-network-interaction-use-with-the-gnu-general-public-license","title":"13. Remote Network Interaction; Use with the GNU General Public License.","text":"Notwithstanding any other provision of this License, if you modify the Program, your modified version must prominently offer all users interacting with it remotely through a computer network (if your version supports such interaction) an opportunity to receive the Corresponding Source of your version by providing access to the Corresponding Source from a network server at no charge, through some standard or customary means of facilitating copying of software. This Corresponding Source shall include the Corresponding Source for any work covered by version 3 of the GNU General Public License that is incorporated pursuant to the following paragraph.
Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the work with which it is combined will remain governed by version 3 of the GNU General Public License.
"},{"location":"license/#14-revised-versions-of-this-license","title":"14. Revised Versions of this License.","text":"The Free Software Foundation may publish revised and/or new versions of the GNU Affero General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU Affero General Public License \"or any later version\" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU Affero General Public License, you may choose any version ever published by the Free Software Foundation.
If the Program specifies that a proxy can decide which future versions of the GNU Affero General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program.
Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version.
"},{"location":"license/#15-disclaimer-of-warranty","title":"15. Disclaimer of Warranty.","text":"THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
"},{"location":"license/#16-limitation-of-liability","title":"16. Limitation of Liability.","text":"IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
"},{"location":"license/#17-interpretation-of-sections-15-and-16","title":"17. Interpretation of Sections 15 and 16.","text":"If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
"},{"location":"license/#how-to-apply-these-terms-to-your-new-programs","title":"How to Apply These Terms to Your New Programs","text":"If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the \"copyright\" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>\n Copyright (C) <year> <name of author>\n\n This program is free software: you can redistribute it and/or modify\n it under the terms of the GNU Affero General Public License as\n published by the Free Software Foundation, either version 3 of the\n License, or (at your option) any later version.\n\n This program is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Affero General Public License for more details.\n\n You should have received a copy of the GNU Affero General Public License\n along with this program. If not, see <https://www.gnu.org/licenses/>.\n
Also add information on how to contact you by electronic and paper mail.
If your software can interact with users remotely through a computer network, you should also make sure that it provides a way for users to get its source. For example, if your program is a web application, its interface could display a \"Source\" link that leads users to an archive of the code. There are many ways you could offer source, and different solutions will be better for different programs; see section 13 for the specific requirements.
You should also get your employer (if you work as a programmer) or school, if any, to sign a \"copyright disclaimer\" for the program, if necessary. For more information on this, and how to apply and follow the GNU AGPL, see https://www.gnu.org/licenses/.
"},{"location":"python_3_verify/","title":"Verifying The Python Version","text":"Python 3.8 or greater is required before installing and using the telemetrix-uno-r4 package.
To check that you have the correct version of Python 3 installed, open a command window and type:
python3 -V\n
For Windows, you may need to type:
python -V\n
Executing this command displays the current version of Python 3 installed.
Python 3.11.4\n
If you need to install Python 3, refer to python.org.
Copyright (C) 2023 Alan Yorinks. All Rights Reserved.
"},{"location":"server_config/","title":"Server Configuration","text":""},{"location":"server_config/#arduino-uno-r4-minima","title":"Arduino UNO R4 Minima","text":"The Minima requires no configuration.
"},{"location":"server_config/#arduino-uno-r4-wifi","title":"Arduino UNO R4 WIFI","text":""},{"location":"server_config/#telemetrix4unor4ble","title":"Telemetrix4UnoR4BLE","text":""},{"location":"server_config/#starting-banner-enable","title":"Starting Banner Enable","text":"By default, when you power up the Arduino, the sketch is identified by the message \"Telemetrix BLE\" scrolling across the display. This message will be extinguished once a client application connects.
You may disable the power on scrolling by commenting out the line that says
#define ENABLE_STARTING_BANNER 1\n
The client API method, enable_scroll_message, which allows you to create and scroll your own message across the display, still functions even if you disable the starting banner.
"},{"location":"server_config/#ble-name","title":"BLE Name","text":"The ble_name string is the name the BLE client will search for to connect. You may change the default value, but if you do, you must also set the ble_device_name parameter in the __init__ method when you instantiate telemetrix_uno_r4_wifi_aio.
"},{"location":"server_config/#telemetrix4unor4serialusb","title":"Telemetrix4UnoR4SerialUSB","text":""},{"location":"server_config/#starting-banner-enable_1","title":"Starting Banner Enable","text":"By default, when you power up the Arduino, the sketch is identified by the message \"USBSerial\" scrolling across the display. This message will be extinguished once a client application connects.
You may disable the power on scrolling by commenting out the line that says
#define ENABLE_STARTING_BANNER 1\n
The client API method, enable_scroll_message, allows you to create and scroll your own message across the display, and it still functions even if you disable the starting banner.
"},{"location":"server_config/#telemetrix4unor4wifi","title":"Telemetrix4UnoR4Wifi","text":""},{"location":"server_config/#required-configuration","title":"Required Configuration","text":""},{"location":"server_config/#ssid","title":"SSID","text":"Edit the sketch and place your router's SSID between the quotes.
"},{"location":"server_config/#password","title":"PASSWORD","text":"Edit the sketch and place your router's PASSWORD between the quotes.
"},{"location":"server_config/#starting-banner-enable_2","title":"Starting Banner Enable","text":"If the starting banner is enabled, and you forget to set SSID and PASSWORD in the sketch, a series of question marks will scroll across the screen.
Once you have a valid SSID and PASSWORD configured, the IP address assigned by the router will be displayed.
You may disable the power on scrolling by commenting out the line that says
#define ENABLE_STARTING_BANNER 1\n
The client API method, enable_scroll_message, allows you to create and scroll your own message across the display, and it still functions even if you disable the starting banner.
Copyright (C) 2023 Alan Yorinks. All Rights Reserved.
"},{"location":"server_library_installation/","title":"Install the Telemetrix4Uno Library Into The Arduino IDE","text":""},{"location":"server_library_installation/#add-the-arduino4unor4-library-to-the-ide","title":"Add The Arduino4UnoR4 Library To The IDE","text":"Open the Arduino IDE and click on the library icon.
In the search box, type Telemetrix4UnoR4, and when the library is found, click INSTALL.
You will be prompted to install all of the dependencies. Select INSTALL ALL.
Follow the instructions on this link to make sure that you have the correct version of the radio firmware installed and to install the Beta version of the ArduinoBLE library.
Copyright (C) 2023 Alan Yorinks. All Rights Reserved.
"},{"location":"server_selection/","title":"Select A Server From the Arduino IDE Examples Menu","text":""},{"location":"server_selection/#choose-a-server","title":"Choose A Server","text":"Select File from the Arduino IDE main menu and then select Examples.
Next, select TelemetrixUnoR4 from the example selections.
There are four servers to choose from:
Arduino UNO R4 Minima
Arduino UNO R4 WIFI
Copyright (C) 2023 Alan Yorinks. All Rights Reserved.
"},{"location":"telemetrix_minima_reference/","title":"telemetrix_uno_r4_minima","text":"Copyright (c) 2023 Alan Yorinks All rights reserved.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 as published by the Free Software Foundation; either or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima","title":"TelemetrixUnoR4Minima
","text":" Bases: threading.Thread
This class exposes and implements the telemetrix API. It uses threading to accommodate concurrency. It includes the public API methods as well as a set of private methods.
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
class TelemetrixUnoR4Minima(threading.Thread):\n\"\"\"\n This class exposes and implements the telemetrix API.\n It uses threading to accommodate concurrency.\n It includes the public API methods as well as\n a set of private methods.\n\n \"\"\"\n\n # noinspection PyPep8,PyPep8,PyPep8\n def __init__(self, com_port=None, arduino_instance_id=1,\n arduino_wait=1, sleep_tune=0.000001,\n shutdown_on_exception=True, hard_reset_on_shutdown=True):\n\n\"\"\"\n\n :param com_port: e.g. COM3 or /dev/ttyACM0.\n Only use if you wish to bypass auto com port\n detection.\n\n :param arduino_instance_id: Match with the value installed on the\n arduino-telemetrix sketch.\n\n :param arduino_wait: Amount of time to wait for an Arduino to\n fully reset itself.\n\n :param sleep_tune: A tuning parameter (typically not changed by user)\n\n :param shutdown_on_exception: call shutdown before raising\n a RunTimeError exception, or\n receiving a KeyboardInterrupt exception\n\n :param hard_reset_on_shutdown: reset the board on shutdown\n\n \"\"\"\n\n # initialize threading parent\n threading.Thread.__init__(self)\n\n # create the threads and set them as daemons so\n # that they stop when the program is closed\n\n # create a thread to interpret received serial data\n self.the_reporter_thread = threading.Thread(target=self._reporter)\n self.the_reporter_thread.daemon = True\n\n self.the_data_receive_thread = threading.Thread(target=self._serial_receiver)\n\n self.the_data_receive_thread.daemon = True\n\n # flag to allow the reporter and receive threads to run.\n self.run_event = threading.Event()\n\n # check to make sure that Python interpreter is version 3.7 or greater\n python_version = sys.version_info\n if python_version[0] >= 3:\n if python_version[1] >= 7:\n pass\n else:\n raise RuntimeError(\"ERROR: Python 3.7 or greater is \"\n \"required for use of this program.\")\n\n # save input parameters as instance variables\n self.com_port = com_port\n self.arduino_instance_id = arduino_instance_id\n self.arduino_wait = arduino_wait\n self.sleep_tune = sleep_tune\n self.shutdown_on_exception = shutdown_on_exception\n self.hard_reset_on_shutdown = hard_reset_on_shutdown\n\n # create a deque to receive and process data from the arduino\n self.the_deque = deque()\n\n # The report_dispatch dictionary is used to process\n # incoming report messages by looking up the report message\n # and executing its associated processing method.\n\n self.report_dispatch = {}\n\n # To add a command to the command dispatch table, append here.\n self.report_dispatch.update(\n {PrivateConstants.LOOP_COMMAND: self._report_loop_data})\n self.report_dispatch.update(\n {PrivateConstants.DEBUG_PRINT: self._report_debug_data})\n self.report_dispatch.update(\n {PrivateConstants.DIGITAL_REPORT: self._digital_message})\n self.report_dispatch.update(\n {PrivateConstants.ANALOG_REPORT: self._analog_message})\n self.report_dispatch.update(\n {PrivateConstants.FIRMWARE_REPORT: self._firmware_message})\n self.report_dispatch.update({PrivateConstants.I_AM_HERE_REPORT: self._i_am_here})\n self.report_dispatch.update(\n {PrivateConstants.SERVO_UNAVAILABLE: self._servo_unavailable})\n self.report_dispatch.update(\n {PrivateConstants.I2C_READ_REPORT: self._i2c_read_report})\n self.report_dispatch.update(\n {PrivateConstants.I2C_TOO_FEW_BYTES_RCVD: self._i2c_too_few})\n self.report_dispatch.update(\n {PrivateConstants.I2C_TOO_MANY_BYTES_RCVD: self._i2c_too_many})\n self.report_dispatch.update(\n {PrivateConstants.SONAR_DISTANCE: self._sonar_distance_report})\n self.report_dispatch.update({PrivateConstants.DHT_REPORT: self._dht_report})\n self.report_dispatch.update(\n {PrivateConstants.SPI_REPORT: self._spi_report})\n self.report_dispatch.update(\n {PrivateConstants.ONE_WIRE_REPORT: self._onewire_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_DISTANCE_TO_GO:\n self._stepper_distance_to_go_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_TARGET_POSITION:\n self._stepper_target_position_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_CURRENT_POSITION:\n self._stepper_current_position_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_RUNNING_REPORT:\n self._stepper_is_running_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_RUN_COMPLETE_REPORT:\n self._stepper_run_complete_report})\n\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_DISTANCE_TO_GO:\n self._stepper_distance_to_go_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_TARGET_POSITION:\n self._stepper_target_position_report})\n self.report_dispatch.update(\n {PrivateConstants.FEATURES:\n self._features_report})\n\n # dictionaries to store the callbacks for each pin\n self.analog_callbacks = {}\n\n self.digital_callbacks = {}\n\n self.i2c_callback = None\n self.i2c_callback2 = None\n\n self.i2c_1_active = False\n self.i2c_2_active = False\n\n self.spi_callback = None\n\n self.onewire_callback = None\n\n self.cs_pins_enabled = []\n\n # the trigger pin will be the key to retrieve\n # the callback for a specific HC-SR04\n self.sonar_callbacks = {}\n\n self.sonar_count = 0\n\n self.dht_callbacks = {}\n\n self.dht_count = 0\n\n # serial port in use\n self.serial_port = None\n\n # flag to indicate we are in shutdown mode\n self.shutdown_flag = False\n\n # debug loopback callback method\n self.loop_back_callback = None\n\n # flag to indicate the start of a new report\n # self.new_report_start = True\n\n # firmware version to be stored here\n self.firmware_version = []\n\n # reported arduino instance id\n self.reported_arduino_id = []\n\n # reported features\n self.reported_features = 0\n\n # flag to indicate if i2c was previously enabled\n self.i2c_enabled = False\n\n # flag to indicate if spi is initialized\n self.spi_enabled = False\n\n # flag to indicate if onewire is initialized\n self.onewire_enabled = False\n\n # # stepper motor variables\n #\n # # updated when a new motor is added\n # self.next_stepper_assigned = 0\n #\n # # valid list of stepper motor interface types\n # self.valid_stepper_interfaces = [1, 2, 3, 4, 6, 8]\n #\n # # maximum number of steppers supported\n # self.max_number_of_steppers = 4\n #\n # # number of steppers created - not to exceed the maximum\n # self.number_of_steppers = 0\n #\n # # dictionary to hold stepper motor information\n # self.stepper_info = {'instance': False, 'is_running': None,\n # 'maximum_speed': 1, 'speed': 0, 'acceleration': 0,\n # 'distance_to_go_callback': None,\n # 'target_position_callback': None,\n # 'current_position_callback': None,\n # 'is_running_callback': None,\n # 'motion_complete_callback': None,\n # 'acceleration_callback': None}\n #\n # # build a list of stepper motor info items\n # self.stepper_info_list = []\n # # a list of dictionaries to hold stepper information\n # for motor in range(self.max_number_of_steppers):\n # self.stepper_info_list.append(self.stepper_info)\n\n self.the_reporter_thread.start()\n self.the_data_receive_thread.start()\n\n print(f\"telemetrix_uno_r4_minima: Version\"\n f\" {PrivateConstants.TELEMETRIX_VERSION}\\n\\n\"\n f\"Copyright (c) 2023 Alan Yorinks All Rights Reserved.\\n\")\n\n # using the serial link\n if not self.com_port:\n # user did not specify a com_port\n try:\n self._find_arduino()\n except KeyboardInterrupt:\n if self.shutdown_on_exception:\n self.shutdown()\n else:\n # com_port specified - set com_port and baud rate\n try:\n self._manual_open()\n except KeyboardInterrupt:\n if self.shutdown_on_exception:\n self.shutdown()\n\n if self.serial_port:\n print(\n f\"Arduino compatible device found and connected to {self.serial_port.port}\")\n\n self.serial_port.reset_input_buffer()\n self.serial_port.reset_output_buffer()\n\n # no com_port found - raise a runtime exception\n else:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError('No Arduino Found or User Aborted Program')\n\n # allow the threads to run\n self._run_threads()\n print(f'Reset Complete')\n\n # get telemetrix firmware version and print it\n print('\\nRetrieving Telemetrix4UnoR4Minima firmware ID...')\n self._get_firmware_version()\n if not self.firmware_version:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'Telemetrix4UnoR4Minima firmware version')\n\n else:\n\n print(f'Telemetrix4UnoR4Minima firmware version: {self.firmware_version[0]}.'\n f'{self.firmware_version[1]}.{self.firmware_version[2]}')\n command = [PrivateConstants.ENABLE_ALL_REPORTS]\n self._send_command(command)\n\n # get the features list\n command = [PrivateConstants.GET_FEATURES]\n self._send_command(command)\n time.sleep(.2)\n\n # Have the server reset its data structures\n command = [PrivateConstants.RESET]\n self._send_command(command)\n\n def _find_arduino(self):\n\"\"\"\n This method will search all potential serial ports for an Arduino\n containing a sketch that has a matching arduino_instance_id as\n specified in the input parameters of this class.\n\n This is used explicitly with the Telemetrix4Arduino sketch.\n \"\"\"\n\n # a list of serial ports to be checked\n serial_ports = []\n\n print('Opening all potential serial ports...')\n the_ports_list = list_ports.comports()\n for port in the_ports_list:\n if port.pid is None:\n continue\n try:\n self.serial_port = serial.Serial(port.device, 115200,\n timeout=1, writeTimeout=0)\n except SerialException:\n continue\n # create a list of serial ports that we opened\n serial_ports.append(self.serial_port)\n\n # display to the user\n print('\\t' + port.device)\n\n # clear out any possible data in the input buffer\n # wait for arduino to reset\n print(\n f'\\nWaiting {self.arduino_wait} seconds(arduino_wait) for Arduino devices to '\n 'reset...')\n # temporary for testing\n time.sleep(self.arduino_wait)\n self._run_threads()\n\n for serial_port in serial_ports:\n self.serial_port = serial_port\n\n self._get_arduino_id()\n if self.reported_arduino_id != self.arduino_instance_id:\n continue\n else:\n print('Valid Arduino ID Found.')\n self.serial_port.reset_input_buffer()\n self.serial_port.reset_output_buffer()\n return\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'Incorrect Arduino ID: {self.reported_arduino_id}')\n\n def _manual_open(self):\n\"\"\"\n Com port was specified by the user - try to open up that port\n\n \"\"\"\n # if port is not found, a serial exception will be thrown\n try:\n print(f'Opening {self.com_port}...')\n self.serial_port = serial.Serial(self.com_port, 115200,\n timeout=1, writeTimeout=0)\n\n print(\n f'\\nWaiting {self.arduino_wait} seconds(arduino_wait) for Arduino devices to '\n 'reset...')\n self._run_threads()\n time.sleep(self.arduino_wait)\n\n self._get_arduino_id()\n\n if self.reported_arduino_id != self.arduino_instance_id:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'Incorrect Arduino ID: {self.reported_arduino_id}')\n print('Valid Arduino ID Found.')\n # get arduino firmware version and print it\n print('\\nRetrieving Telemetrix4Arduino firmware ID...')\n self._get_firmware_version()\n\n if not self.firmware_version:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(\n f'Telemetrix4Arduino Sketch Firmware Version Not Found')\n\n else:\n print(f'Telemetrix4UnoR4 firmware version: {self.firmware_version[0]}.'\n f'{self.firmware_version[1]}')\n except KeyboardInterrupt:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError('User Hit Control-C')\n\n def analog_write(self, pin, value):\n\"\"\"\n Set the specified pin to the specified value.\n\n :param pin: arduino pin number\n\n :param value: pin value (maximum 16 bits)\n\n \"\"\"\n value_msb = value >> 8\n value_lsb = value & 0xff\n command = [PrivateConstants.ANALOG_WRITE, pin, value_msb, value_lsb]\n self._send_command(command)\n\n def digital_write(self, pin, value):\n\"\"\"\n Set the specified pin to the specified value.\n\n :param pin: arduino pin number\n\n :param value: pin value (1 or 0)\n\n \"\"\"\n\n command = [PrivateConstants.DIGITAL_WRITE, pin, value]\n self._send_command(command)\n\n def disable_all_reporting(self):\n\"\"\"\n Disable reporting for all digital and analog input pins\n \"\"\"\n command = [PrivateConstants.MODIFY_REPORTING,\n PrivateConstants.REPORTING_DISABLE_ALL, 0]\n self._send_command(command)\n\n def disable_analog_reporting(self, pin):\n\"\"\"\n Disables analog reporting for a single analog pin.\n\n :param pin: Analog pin number. For example for A0, the number is 0.\n\n \"\"\"\n command = [PrivateConstants.MODIFY_REPORTING,\n PrivateConstants.REPORTING_ANALOG_DISABLE, pin]\n self._send_command(command)\n\n def disable_digital_reporting(self, pin):\n\"\"\"\n Disables digital reporting for a single digital input.\n\n :param pin: Pin number.\n\n \"\"\"\n command = [PrivateConstants.MODIFY_REPORTING,\n PrivateConstants.REPORTING_DIGITAL_DISABLE, pin]\n self._send_command(command)\n\n def enable_analog_reporting(self, pin):\n\"\"\"\n Enables analog reporting for the specified pin.\n\n :param pin: Analog pin number. For example for A0, the number is 0.\n\n\n \"\"\"\n command = [PrivateConstants.MODIFY_REPORTING,\n PrivateConstants.REPORTING_ANALOG_ENABLE, pin]\n self._send_command(command)\n\n def enable_digital_reporting(self, pin):\n\"\"\"\n Enable reporting on the specified digital pin.\n\n :param pin: Pin number.\n \"\"\"\n\n command = [PrivateConstants.MODIFY_REPORTING,\n PrivateConstants.REPORTING_DIGITAL_ENABLE, pin]\n self._send_command(command)\n\n def _get_arduino_id(self):\n\"\"\"\n Retrieve arduino-telemetrix arduino id\n\n \"\"\"\n command = [PrivateConstants.ARE_U_THERE]\n self._send_command(command)\n # provide time for the reply\n time.sleep(.5)\n\n def _get_firmware_version(self):\n\"\"\"\n This method retrieves the\n arduino-telemetrix firmware version\n\n \"\"\"\n command = [PrivateConstants.GET_FIRMWARE_VERSION]\n self._send_command(command)\n # provide time for the reply\n time.sleep(.5)\n\n def i2c_read(self, address, register, number_of_bytes,\n callback=None, i2c_port=0,\n write_register=True):\n\"\"\"\n Read the specified number of bytes from the\n specified register for the i2c device.\n\n\n :param address: i2c device address\n\n :param register: i2c register (or None if no register\n selection is needed)\n\n :param number_of_bytes: number of bytes to be read\n\n :param callback: Required callback function to report\n i2c data as a result of read command\n\n :param i2c_port: 0 = default, 1 = secondary\n\n :param write_register: If True, the register is written\n before read\n Else, the write is suppressed\n\n\n callback returns a data list:\n\n [I2C_READ_REPORT, address, register, count of data bytes,\n data bytes, time-stamp]\n\n \"\"\"\n\n self._i2c_read_request(address, register, number_of_bytes,\n callback=callback, i2c_port=i2c_port,\n write_register=write_register)\n\n def i2c_read_restart_transmission(self, address, register,\n number_of_bytes,\n callback=None, i2c_port=0,\n write_register=True):\n\"\"\"\n Read the specified number of bytes from the specified\n register for the i2c device. This restarts the transmission\n after the read. It is required for some i2c devices such as the MMA8452Q\n accelerometer.\n\n\n :param address: i2c device address\n\n :param register: i2c register (or None if no register\n selection is needed)\n\n :param number_of_bytes: number of bytes to be read\n\n :param callback: Required callback function to report i2c\n data as a result of read command\n\n :param i2c_port: 0 = default 1 = secondary\n\n :param write_register: If True, the register is written before read\n Else, the write is suppressed\n\n\n\n callback returns a data list:\n\n [I2C_READ_REPORT, address, register, count of data bytes,\n data bytes, time-stamp]\n\n \"\"\"\n\n self._i2c_read_request(address, register, number_of_bytes,\n stop_transmission=False,\n callback=callback, i2c_port=i2c_port,\n write_register=write_register)\n\n def _i2c_read_request(self, address, register, number_of_bytes,\n stop_transmission=True, callback=None, i2c_port=0,\n write_register=True):\n\"\"\"\n This method requests the read of an i2c device. Results are retrieved\n via callback.\n\n :param address: i2c device address\n\n :param register: register number (or None if no register selection is needed)\n\n :param number_of_bytes: number of bytes expected to be returned\n\n :param stop_transmission: stop transmission after read\n\n :param callback: Required callback function to report i2c data as a\n result of read command.\n\n :param write_register: If True, the register is written before read\n Else, the write is suppressed\n\n \"\"\"\n if not i2c_port:\n if not self.i2c_1_active:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(\n 'I2C Read: set_pin_mode i2c never called for i2c port 1.')\n\n if i2c_port:\n if not self.i2c_2_active:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(\n 'I2C Read: set_pin_mode i2c never called for i2c port 2.')\n\n if not callback:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError('I2C Read: A callback function must be specified.')\n\n if not i2c_port:\n self.i2c_callback = callback\n else:\n self.i2c_callback2 = callback\n\n if not register:\n register = 0\n\n if write_register:\n write_register = 1\n else:\n write_register = 0\n\n # message contains:\n # 1. address\n # 2. register\n # 3. number of bytes\n # 4. restart_transmission - True or False\n # 5. i2c port\n # 6. suppress write flag\n\n command = [PrivateConstants.I2C_READ, address, register, number_of_bytes,\n stop_transmission, i2c_port, write_register]\n self._send_command(command)\n\n def i2c_write(self, address, args, i2c_port=0):\n\"\"\"\n Write data to an i2c device.\n\n :param address: i2c device address\n\n :param i2c_port: 0= port 1, 1 = port 2\n\n :param args: A variable number of bytes to be sent to the device\n passed in as a list\n\n \"\"\"\n if not i2c_port:\n if not self.i2c_1_active:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(\n 'I2C Write: set_pin_mode i2c never called for i2c port 1.')\n\n if i2c_port:\n if not self.i2c_2_active:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(\n 'I2C Write: set_pin_mode i2c never called for i2c port 2.')\n\n command = [PrivateConstants.I2C_WRITE, len(args), address, i2c_port]\n\n for item in args:\n command.append(item)\n\n self._send_command(command)\n\n def loop_back(self, start_character, callback=None):\n\"\"\"\n This is a debugging method to send a character to the\n Arduino device, and have the device loop it back.\n\n :param start_character: The character to loop back. It should be\n an integer.\n\n :param callback: Looped back character will appear in the callback method\n\n \"\"\"\n command = [PrivateConstants.LOOP_COMMAND, ord(start_character)]\n self.loop_back_callback = callback\n self._send_command(command)\n\n def set_analog_scan_interval(self, interval):\n\"\"\"\n Set the analog scanning interval.\n\n :param interval: value of 0 - 255 - milliseconds\n \"\"\"\n\n if 0 <= interval <= 255:\n command = [PrivateConstants.SET_ANALOG_SCANNING_INTERVAL, interval]\n self._send_command(command)\n else:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError('Analog interval must be between 0 and 255')\n\n def set_pin_mode_analog_output(self, pin_number):\n\"\"\"\n Set a pin as a pwm (analog output) pin.\n\n :param pin_number:arduino pin number\n\n \"\"\"\n self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT)\n\n def set_pin_mode_analog_input(self, pin_number, differential=0, callback=None):\n\"\"\"\n Set a pin as an analog input.\n\n :param pin_number: arduino pin number\n\n :param differential: difference in previous to current value before\n report will be generated\n\n :param callback: callback function\n\n\n callback returns a data list:\n\n [pin_type, pin_number, pin_value, raw_time_stamp]\n\n The pin_type for analog input pins = 3\n\n \"\"\"\n self._set_pin_mode(pin_number, PrivateConstants.AT_ANALOG, differential,\n callback)\n\n def set_pin_mode_digital_input(self, pin_number, callback=None):\n\"\"\"\n Set a pin as a digital input.\n\n :param pin_number: arduino pin number\n\n :param callback: callback function\n\n\n callback returns a data list:\n\n [pin_type, pin_number, pin_value, raw_time_stamp]\n\n The pin_type for all digital input pins = 2\n\n \"\"\"\n self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT, callback=callback)\n\n def set_pin_mode_digital_input_pullup(self, pin_number, callback=None):\n\"\"\"\n Set a pin as a digital input with pullup enabled.\n\n :param pin_number: arduino pin number\n\n :param callback: callback function\n\n\n callback returns a data list:\n\n [pin_type, pin_number, pin_value, raw_time_stamp]\n\n The pin_type for all digital input pins = 2\n \"\"\"\n self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT_PULLUP,\n callback=callback)\n\n def set_pin_mode_digital_output(self, pin_number):\n\"\"\"\n Set a pin as a digital output pin.\n\n :param pin_number: arduino pin number\n \"\"\"\n\n self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT)\n\n def set_pin_mode_i2c(self, i2c_port=0):\n\"\"\"\n Establish the standard Arduino i2c pins for i2c utilization.\n\n :param i2c_port: 0 = i2c1, 1 = i2c2\n\n NOTES: 1. THIS METHOD MUST BE CALLED BEFORE ANY I2C REQUEST IS MADE\n 2. Callbacks are set within the individual i2c read methods of this\n API.\n\n See i2c_read, or i2c_read_restart_transmission.\n\n \"\"\"\n # test for i2c port 2\n if i2c_port:\n # if not previously activated set it to activated\n # and the send a begin message for this port\n if not self.i2c_2_active:\n self.i2c_2_active = True\n else:\n return\n # port 1\n else:\n if not self.i2c_1_active:\n self.i2c_1_active = True\n else:\n return\n\n command = [PrivateConstants.I2C_BEGIN, i2c_port]\n self._send_command(command)\n\n def set_pin_mode_dht(self, pin, callback=None, dht_type=22):\n\"\"\"\n\n :param pin: connection pin\n\n :param callback: callback function\n\n :param dht_type: either 22 for DHT22 or 11 for DHT11\n\n Error Callback: [DHT REPORT Type, DHT_ERROR_NUMBER, PIN, DHT_TYPE, Time]\n\n Valid Data Callback: DHT REPORT Type, DHT_DATA=, PIN, DHT_TYPE, Humidity,\n Temperature,\n Time]\n\n DHT_REPORT_TYPE = 12\n \"\"\"\n if self.reported_features & PrivateConstants.DHT_FEATURE:\n if not callback:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError('set_pin_mode_dht: A Callback must be specified')\n\n if self.dht_count < PrivateConstants.MAX_DHTS - 1:\n self.dht_callbacks[pin] = callback\n self.dht_count += 1\n\n if dht_type != 22 and dht_type != 11:\n dht_type = 22\n\n command = [PrivateConstants.DHT_NEW, pin, dht_type]\n self._send_command(command)\n else:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(\n f'Maximum Number Of DHTs Exceeded - set_pin_mode_dht fails for pin {pin}')\n else:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'The DHT feature is disabled in the server.')\n\n # noinspection PyRedundantParentheses\n def set_pin_mode_servo(self, pin_number, min_pulse=544, max_pulse=2400):\n\"\"\"\n\n Attach a pin to a servo motor\n\n :param pin_number: pin\n\n :param min_pulse: minimum pulse width\n\n :param max_pulse: maximum pulse width\n\n \"\"\"\n if self.reported_features & PrivateConstants.SERVO_FEATURE:\n\n minv = (min_pulse).to_bytes(2, byteorder=\"big\")\n maxv = (max_pulse).to_bytes(2, byteorder=\"big\")\n\n command = [PrivateConstants.SERVO_ATTACH, pin_number,\n minv[0], minv[1], maxv[0], maxv[1]]\n self._send_command(command)\n else:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'The SERVO feature is disabled in the server.')\n\n def set_pin_mode_sonar(self, trigger_pin, echo_pin,\n callback=None):\n\"\"\"\n\n :param trigger_pin:\n\n :param echo_pin:\n\n :param callback: callback\n\n callback data: [PrivateConstants.SONAR_DISTANCE, trigger_pin, distance_value, time_stamp]\n\n \"\"\"\n if self.reported_features & PrivateConstants.SONAR_FEATURE:\n\n if not callback:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError('set_pin_mode_sonar: A Callback must be specified')\n\n if self.sonar_count < PrivateConstants.MAX_SONARS - 1:\n self.sonar_callbacks[trigger_pin] = callback\n self.sonar_count += 1\n\n command = [PrivateConstants.SONAR_NEW, trigger_pin, echo_pin]\n self._send_command(command)\n else:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(\n f'Maximum Number Of Sonars Exceeded - set_pin_mode_sonar fails for pin {trigger_pin}')\n else:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'The SONAR feature is disabled in the server.')\n\n def set_pin_mode_spi(self, chip_select_list=None):\n\"\"\"\n Specify the list of chip select pins.\n\n Standard Arduino MISO, MOSI and CLK pins are used for the board in use.\n\n Chip Select is any digital output capable pin.\n\n :param chip_select_list: this is a list of pins to be used for chip select.\n The pins will be configured as output, and set to high\n ready to be used for chip select.\n NOTE: You must specify the chips select pins here!\n\n\n command message: [command, [cs pins...]]\n \"\"\"\n\n if self.reported_features & PrivateConstants.SPI_FEATURE:\n if type(chip_select_list) != list:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError('chip_select_list must be in the form of a list')\n if not chip_select_list:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError('Chip select pins were not specified')\n\n self.spi_enabled = True\n\n command = [PrivateConstants.SPI_INIT, len(chip_select_list)]\n\n for pin in chip_select_list:\n command.append(pin)\n self.cs_pins_enabled.append(pin)\n self._send_command(command)\n else:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'The SPI feature is disabled in the server.')\n\n # def set_pin_mode_stepper(self, interface=1, pin1=2, pin2=3, pin3=4,\n # pin4=5, enable=True):\n # \"\"\"\n # Stepper motor support is implemented as a proxy for the\n # the AccelStepper library for the Arduino.\n #\n # This feature is compatible with the TB6600 Motor Driver\n #\n # Note: It may not work for other driver types!\n #\n # https://github.com/waspinator/AccelStepper\n #\n # Instantiate a stepper motor.\n #\n # Initialize the interface and pins for a stepper motor.\n #\n # :param interface: Motor Interface Type:\n #\n # 1 = Stepper Driver, 2 driver pins required\n #\n # 2 = FULL2WIRE 2 wire stepper, 2 motor pins required\n #\n # 3 = FULL3WIRE 3 wire stepper, such as HDD spindle,\n # 3 motor pins required\n #\n # 4 = FULL4WIRE, 4 wire full stepper, 4 motor pins\n # required\n #\n # 6 = HALF3WIRE, 3 wire half stepper, such as HDD spindle,\n # 3 motor pins required\n #\n # 8 = HALF4WIRE, 4 wire half stepper, 4 motor pins required\n #\n # :param pin1: Arduino digital pin number for motor pin 1\n #\n # :param pin2: Arduino digital pin number for motor pin 2\n #\n # :param pin3: Arduino digital pin number for motor pin 3\n #\n # :param pin4: Arduino digital pin number for motor pin 4\n #\n # :param enable: If this is true, the output pins at construction time.\n #\n # :return: Motor Reference number\n # \"\"\"\n # if self.reported_features & PrivateConstants.STEPPERS_FEATURE:\n #\n # if self.number_of_steppers == self.max_number_of_steppers:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('Maximum number of steppers has already been assigned')\n #\n # if interface not in self.valid_stepper_interfaces:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('Invalid stepper interface')\n #\n # self.number_of_steppers += 1\n #\n # motor_id = self.next_stepper_assigned\n # self.next_stepper_assigned += 1\n # self.stepper_info_list[motor_id]['instance'] = True\n #\n # # build message and send message to server\n # command = [PrivateConstants.SET_PIN_MODE_STEPPER, motor_id, interface, pin1,\n # pin2, pin3, pin4, enable]\n # self._send_command(command)\n #\n # # return motor id\n # return motor_id\n # else:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError(f'The Stepper feature is disabled in the server.')\n\n def servo_write(self, pin_number, angle):\n\"\"\"\n\n Set a servo attached to a pin to a given angle.\n\n :param pin_number: pin\n\n :param angle: angle (0-180)\n\n \"\"\"\n command = [PrivateConstants.SERVO_WRITE, pin_number, angle]\n self._send_command(command)\n\n def servo_detach(self, pin_number):\n\"\"\"\n Detach a servo for reuse\n\n :param pin_number: attached pin\n\n \"\"\"\n command = [PrivateConstants.SERVO_DETACH, pin_number]\n self._send_command(command)\n\n # def stepper_move_to(self, motor_id, position):\n # \"\"\"\n # Set an absolution target position. If position is positive, the movement is\n # clockwise, else it is counter-clockwise.\n #\n # The run() function (below) will try to move the motor (at most one step per call)\n # from the current position to the target position set by the most\n # recent call to this function. Caution: moveTo() also recalculates the\n # speed for the next step.\n # If you are trying to use constant speed movements, you should call setSpeed()\n # after calling moveTo().\n #\n # :param motor_id: motor id: 0 - 3\n #\n # :param position: target position. Maximum value is 32 bits.\n # \"\"\"\n # if position < 0:\n # polarity = 1\n # else:\n # polarity = 0\n # position = abs(position)\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_move_to: Invalid motor_id.')\n #\n # position_bytes = list(position.to_bytes(4, 'big', signed=True))\n #\n # command = [PrivateConstants.STEPPER_MOVE_TO, motor_id]\n # for value in position_bytes:\n # command.append(value)\n # command.append(polarity)\n # self._send_command(command)\n #\n # def stepper_move(self, motor_id, relative_position):\n # \"\"\"\n # Set the target position relative to the current position.\n #\n # :param motor_id: motor id: 0 - 3\n #\n # :param relative_position: The desired position relative to the current\n # position. Negative is anticlockwise from\n # the current position. Maximum value is 32 bits.\n # \"\"\"\n # if relative_position < 0:\n # polarity = 1\n # else:\n # polarity = 0\n #\n # relative_position = abs(relative_position)\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_move: Invalid motor_id.')\n #\n # position_bytes = list(relative_position.to_bytes(4, 'big', signed=True))\n #\n # command = [PrivateConstants.STEPPER_MOVE, motor_id]\n # for value in position_bytes:\n # command.append(value)\n # command.append(polarity)\n # self._send_command(command)\n #\n # def stepper_run(self, motor_id, completion_callback=None):\n # \"\"\"\n # This method steps the selected motor based on the current speed.\n #\n # Once called, the server will continuously attempt to step the motor.\n #\n # :param motor_id: 0 - 3\n #\n # :param completion_callback: call back function to receive motion complete\n # notification\n #\n # callback returns a data list:\n #\n # [report_type, motor_id, raw_time_stamp]\n #\n # The report_type = 19\n # \"\"\"\n # if not completion_callback:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_run: A motion complete callback must be '\n # 'specified.')\n #\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_run: Invalid motor_id.')\n #\n # self.stepper_info_list[motor_id]['motion_complete_callback'] = completion_callback\n # command = [PrivateConstants.STEPPER_RUN, motor_id]\n # self._send_command(command)\n #\n # def stepper_run_speed(self, motor_id):\n # \"\"\"\n # This method steps the selected motor based at a constant speed as set by the most\n # recent call to stepper_set_max_speed(). The motor will run continuously.\n #\n # Once called, the server will continuously attempt to step the motor.\n #\n # :param motor_id: 0 - 3\n #\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_run_speed: Invalid motor_id.')\n #\n # command = [PrivateConstants.STEPPER_RUN_SPEED, motor_id]\n # self._send_command(command)\n #\n # def stepper_set_max_speed(self, motor_id, max_speed):\n # \"\"\"\n # Sets the maximum permitted speed. The stepper_run() function will accelerate\n # up to the speed set by this function.\n #\n # Caution: the maximum speed achievable depends on your processor and clock speed.\n # The default maxSpeed is 1 step per second.\n #\n # Caution: Speeds that exceed the maximum speed supported by the processor may\n # result in non-linear accelerations and decelerations.\n #\n # :param motor_id: 0 - 3\n #\n # :param max_speed: 1 - 1000\n # \"\"\"\n #\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_set_max_speed: Invalid motor_id.')\n #\n # if not 1 < max_speed <= 1000:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_set_max_speed: Speed range is 1 - 1000.')\n #\n # self.stepper_info_list[motor_id]['max_speed'] = max_speed\n # max_speed_msb = (max_speed & 0xff00) >> 8\n # max_speed_lsb = max_speed & 0xff\n #\n # command = [PrivateConstants.STEPPER_SET_MAX_SPEED, motor_id, max_speed_msb,\n # max_speed_lsb]\n # self._send_command(command)\n #\n # def stepper_get_max_speed(self, motor_id):\n # \"\"\"\n # Returns the maximum speed configured for this stepper\n # that was previously set by stepper_set_max_speed()\n #\n # Value is stored in the client, so no callback is required.\n #\n # :param motor_id: 0 - 3\n #\n # :return: The currently configured maximum speed.\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_max_speed: Invalid motor_id.')\n #\n # return self.stepper_info_list[motor_id]['max_speed']\n #\n # def stepper_set_acceleration(self, motor_id, acceleration):\n # \"\"\"\n # Sets the acceleration/deceleration rate.\n #\n # :param motor_id: 0 - 3\n #\n # :param acceleration: The desired acceleration in steps per second\n # per second. Must be > 0.0. This is an\n # expensive call since it requires a square\n # root to be calculated on the server.\n # Dont call more often than needed.\n #\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_set_acceleration: Invalid motor_id.')\n #\n # if not 1 < acceleration <= 1000:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_set_acceleration: Acceleration range is 1 - '\n # '1000.')\n #\n # self.stepper_info_list[motor_id]['acceleration'] = acceleration\n #\n # max_accel_msb = acceleration >> 8\n # max_accel_lsb = acceleration & 0xff\n #\n # command = [PrivateConstants.STEPPER_SET_ACCELERATION, motor_id, max_accel_msb,\n # max_accel_lsb]\n # self._send_command(command)\n #\n # def stepper_set_speed(self, motor_id, speed):\n # \"\"\"\n # Sets the desired constant speed for use with stepper_run_speed().\n #\n # :param motor_id: 0 - 3\n #\n # :param speed: 0 - 1000 The desired constant speed in steps per\n # second. Positive is clockwise. Speeds of more than 1000 steps per\n # second are unreliable. Speed accuracy depends on the Arduino\n # crystal. Jitter depends on how frequently you call the\n # stepper_run_speed() method.\n # The speed will be limited by the current value of\n # stepper_set_max_speed().\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_set_speed: Invalid motor_id.')\n #\n # if not 0 < speed <= 1000:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_set_speed: Speed range is 0 - '\n # '1000.')\n #\n # self.stepper_info_list[motor_id]['speed'] = speed\n #\n # speed_msb = speed >> 8\n # speed_lsb = speed & 0xff\n #\n # command = [PrivateConstants.STEPPER_SET_SPEED, motor_id, speed_msb, speed_lsb]\n # self._send_command(command)\n #\n # def stepper_get_speed(self, motor_id):\n # \"\"\"\n # Returns the most recently set speed.\n # that was previously set by stepper_set_speed();\n #\n # Value is stored in the client, so no callback is required.\n #\n # :param motor_id: 0 - 3\n #\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_get_speed: Invalid motor_id.')\n #\n # return self.stepper_info_list[motor_id]['speed']\n #\n # def stepper_get_distance_to_go(self, motor_id, distance_to_go_callback):\n # \"\"\"\n # Request the distance from the current position to the target position\n # from the server.\n #\n # :param motor_id: 0 - 3\n #\n # :param distance_to_go_callback: required callback function to receive report\n #\n # :return: The distance to go is returned via the callback as a list:\n #\n # [REPORT_TYPE=15, motor_id, distance in steps, time_stamp]\n #\n # A positive distance is clockwise from the current position.\n #\n # \"\"\"\n # if not distance_to_go_callback:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_get_distance_to_go Read: A callback function must be specified.')\n #\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_get_distance_to_go: Invalid motor_id.')\n # self.stepper_info_list[motor_id][\n # 'distance_to_go_callback'] = distance_to_go_callback\n # command = [PrivateConstants.STEPPER_GET_DISTANCE_TO_GO, motor_id]\n # self._send_command(command)\n #\n # def stepper_get_target_position(self, motor_id, target_callback):\n # \"\"\"\n # Request the most recently set target position from the server.\n #\n # :param motor_id: 0 - 3\n #\n # :param target_callback: required callback function to receive report\n #\n # :return: The distance to go is returned via the callback as a list:\n #\n # [REPORT_TYPE=16, motor_id, target position in steps, time_stamp]\n #\n # Positive is clockwise from the 0 position.\n #\n # \"\"\"\n # if not target_callback:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError(\n # 'stepper_get_target_position Read: A callback function must be specified.')\n #\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_get_target_position: Invalid motor_id.')\n #\n # self.stepper_info_list[motor_id][\n # 'target_position_callback'] = target_callback\n #\n # command = [PrivateConstants.STEPPER_GET_TARGET_POSITION, motor_id]\n # self._send_command(command)\n #\n # def stepper_get_current_position(self, motor_id, current_position_callback):\n # \"\"\"\n # Request the current motor position from the server.\n #\n # :param motor_id: 0 - 3\n #\n # :param current_position_callback: required callback function to receive report\n #\n # :return: The current motor position returned via the callback as a list:\n #\n # [REPORT_TYPE=17, motor_id, current position in steps, time_stamp]\n #\n # Positive is clockwise from the 0 position.\n # \"\"\"\n # if not current_position_callback:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError(\n # 'stepper_get_current_position Read: A callback function must be specified.')\n #\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_get_current_position: Invalid motor_id.')\n #\n # self.stepper_info_list[motor_id]['current_position_callback'] = current_position_callback\n #\n # command = [PrivateConstants.STEPPER_GET_CURRENT_POSITION, motor_id]\n # self._send_command(command)\n #\n # def stepper_set_current_position(self, motor_id, position):\n # \"\"\"\n # Resets the current position of the motor, so that wherever the motor\n # happens to be right now is considered to be the new 0 position. Useful\n # for setting a zero position on a stepper after an initial hardware\n # positioning move.\n #\n # Has the side effect of setting the current motor speed to 0.\n #\n # :param motor_id: 0 - 3\n #\n # :param position: Position in steps. This is a 32 bit value\n # \"\"\"\n #\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_set_current_position: Invalid motor_id.')\n # position_bytes = list(position.to_bytes(4, 'big', signed=True))\n #\n # command = [PrivateConstants.STEPPER_SET_CURRENT_POSITION, motor_id]\n # for value in position_bytes:\n # command.append(value)\n # self._send_command(command)\n #\n # def stepper_run_speed_to_position(self, motor_id, completion_callback=None):\n # \"\"\"\n # Runs the motor at the currently selected speed until the target position is\n # reached.\n #\n # Does not implement accelerations.\n #\n # :param motor_id: 0 - 3\n #\n # :param completion_callback: call back function to receive motion complete\n # notification\n #\n # callback returns a data list:\n #\n # [report_type, motor_id, raw_time_stamp]\n #\n # The report_type = 19\n # \"\"\"\n # if not completion_callback:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_run_speed_to_position: A motion complete '\n # 'callback must be '\n # 'specified.')\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_run_speed_to_position: Invalid motor_id.')\n #\n # self.stepper_info_list[motor_id]['motion_complete_callback'] = completion_callback\n # command = [PrivateConstants.STEPPER_RUN_SPEED_TO_POSITION, motor_id]\n # self._send_command(command)\n #\n # def stepper_stop(self, motor_id):\n # \"\"\"\n # Sets a new target position that causes the stepper\n # to stop as quickly as possible, using the current speed and\n # acceleration parameters.\n #\n # :param motor_id: 0 - 3\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_stop: Invalid motor_id.')\n #\n # command = [PrivateConstants.STEPPER_STOP, motor_id]\n # self._send_command(command)\n #\n # def stepper_disable_outputs(self, motor_id):\n # \"\"\"\n # Disable motor pin outputs by setting them all LOW.\n #\n # Depending on the design of your electronics this may turn off\n # the power to the motor coils, saving power.\n #\n # This is useful to support Arduino low power modes: disable the outputs\n # during sleep and then re-enable with enableOutputs() before stepping\n # again.\n #\n # If the enable Pin is defined, sets it to OUTPUT mode and clears\n # the pin to disabled.\n #\n # :param motor_id: 0 - 3\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_disable_outputs: Invalid motor_id.')\n #\n # command = [PrivateConstants.STEPPER_DISABLE_OUTPUTS, motor_id]\n # self._send_command(command)\n #\n # def stepper_enable_outputs(self, motor_id):\n # \"\"\"\n # Enable motor pin outputs by setting the motor pins to OUTPUT\n # mode.\n #\n # If the enable Pin is defined, sets it to OUTPUT mode and sets\n # the pin to enabled.\n #\n # :param motor_id: 0 - 3\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_enable_outputs: Invalid motor_id.')\n #\n # command = [PrivateConstants.STEPPER_ENABLE_OUTPUTS, motor_id]\n # self._send_command(command)\n #\n # def stepper_set_min_pulse_width(self, motor_id, minimum_width):\n # \"\"\"\n # Sets the minimum pulse width allowed by the stepper driver.\n #\n # The minimum practical pulse width is approximately 20 microseconds.\n #\n # Times less than 20 microseconds will usually result in 20 microseconds or so.\n #\n # :param motor_id: 0 -3\n #\n # :param minimum_width: A 16 bit unsigned value expressed in microseconds.\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_set_min_pulse_width: Invalid motor_id.')\n #\n # if not 0 < minimum_width <= 0xff:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_set_min_pulse_width: Pulse width range = '\n # '0-0xffff.')\n #\n # width_msb = minimum_width >> 8\n # width_lsb = minimum_width & 0xff\n #\n # command = [PrivateConstants.STEPPER_SET_MINIMUM_PULSE_WIDTH, motor_id, width_msb,\n # width_lsb]\n # self._send_command(command)\n #\n # def stepper_set_enable_pin(self, motor_id, pin=0xff):\n # \"\"\"\n # Sets the enable pin number for stepper drivers.\n # 0xFF indicates unused (default).\n #\n # Otherwise, if a pin is set, the pin will be turned on when\n # enableOutputs() is called and switched off when disableOutputs()\n # is called.\n #\n # :param motor_id: 0 - 4\n # :param pin: 0-0xff\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_set_enable_pin: Invalid motor_id.')\n #\n # if not 0 < pin <= 0xff:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_set_enable_pin: Pulse width range = '\n # '0-0xff.')\n # command = [PrivateConstants.STEPPER_SET_ENABLE_PIN, motor_id, pin]\n #\n # self._send_command(command)\n #\n # def stepper_set_3_pins_inverted(self, motor_id, direction=False, step=False,\n # enable=False):\n # \"\"\"\n # Sets the inversion for stepper driver pins.\n #\n # :param motor_id: 0 - 3\n #\n # :param direction: True=inverted or False\n #\n # :param step: True=inverted or False\n #\n # :param enable: True=inverted or False\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_set_3_pins_inverted: Invalid motor_id.')\n #\n # command = [PrivateConstants.STEPPER_SET_3_PINS_INVERTED, motor_id, direction,\n # step, enable]\n #\n # self._send_command(command)\n #\n # def stepper_set_4_pins_inverted(self, motor_id, pin1_invert=False, pin2_invert=False,\n # pin3_invert=False, pin4_invert=False, enable=False):\n # \"\"\"\n # Sets the inversion for 2, 3 and 4 wire stepper pins\n #\n # :param motor_id: 0 - 3\n #\n # :param pin1_invert: True=inverted or False\n #\n # :param pin2_invert: True=inverted or False\n #\n # :param pin3_invert: True=inverted or False\n #\n # :param pin4_invert: True=inverted or False\n #\n # :param enable: True=inverted or False\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_set_4_pins_inverted: Invalid motor_id.')\n #\n # command = [PrivateConstants.STEPPER_SET_4_PINS_INVERTED, motor_id, pin1_invert,\n # pin2_invert, pin3_invert, pin4_invert, enable]\n #\n # self._send_command(command)\n #\n # def stepper_is_running(self, motor_id, callback):\n # \"\"\"\n # Checks to see if the motor is currently running to a target.\n #\n # Callback return True if the speed is not zero or not at the target position.\n #\n # :param motor_id: 0-4\n #\n # :param callback: required callback function to receive report\n #\n # :return: The current running state returned via the callback as a list:\n #\n # [REPORT_TYPE=18, motor_id, True or False for running state, time_stamp]\n # \"\"\"\n # if not callback:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError(\n # 'stepper_is_running: A callback function must be specified.')\n #\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_is_running: Invalid motor_id.')\n #\n # self.stepper_info_list[motor_id]['is_running_callback'] = callback\n #\n # command = [PrivateConstants.STEPPER_IS_RUNNING, motor_id]\n # self._send_command(command)\n\n def _set_pin_mode(self, pin_number, pin_state, differential=0, callback=None):\n\"\"\"\n A private method to set the various pin modes.\n\n :param pin_number: arduino pin number\n\n :param pin_state: INPUT/OUTPUT/ANALOG/PWM/PULLUP\n For SERVO use: set_pin_mode_servo\n For DHT use: set_pin_mode_dht\n\n :param differential: for analog inputs - threshold\n value to be achieved for report to\n be generated\n\n :param callback: A reference to a call back function to be\n called when pin data value changes\n\n \"\"\"\n if callback:\n if pin_state == PrivateConstants.AT_INPUT:\n self.digital_callbacks[pin_number] = callback\n elif pin_state == PrivateConstants.AT_INPUT_PULLUP:\n self.digital_callbacks[pin_number] = callback\n elif pin_state == PrivateConstants.AT_ANALOG:\n self.analog_callbacks[pin_number] = callback\n else:\n print('{} {}'.format('set_pin_mode: callback ignored for '\n 'pin state:', pin_state))\n\n if pin_state == PrivateConstants.AT_INPUT:\n command = [PrivateConstants.SET_PIN_MODE, pin_number,\n PrivateConstants.AT_INPUT, 1]\n\n elif pin_state == PrivateConstants.AT_INPUT_PULLUP:\n command = [PrivateConstants.SET_PIN_MODE, pin_number,\n PrivateConstants.AT_INPUT_PULLUP, 1]\n\n elif pin_state == PrivateConstants.AT_OUTPUT:\n command = [PrivateConstants.SET_PIN_MODE, pin_number,\n PrivateConstants.AT_OUTPUT]\n\n elif pin_state == PrivateConstants.AT_ANALOG:\n command = [PrivateConstants.SET_PIN_MODE, pin_number,\n PrivateConstants.AT_ANALOG,\n differential >> 8, differential & 0xff, 1]\n else:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError('Unknown pin state')\n\n if command:\n self._send_command(command)\n\n def shutdown(self):\n\"\"\"\n This method attempts an orderly shutdown\n If any exceptions are thrown, they are ignored.\n \"\"\"\n self.shutdown_flag = True\n\n self._stop_threads()\n\n try:\n command = [PrivateConstants.STOP_ALL_REPORTS]\n self._send_command(command)\n time.sleep(.5)\n\n if self.hard_reset_on_shutdown:\n self.r4_hard_reset()\n else:\n try:\n self.serial_port.reset_input_buffer()\n self.serial_port.reset_output_buffer()\n\n self.serial_port.close()\n\n except (RuntimeError, SerialException, OSError):\n # ignore error on shutdown\n pass\n except Exception:\n # raise RuntimeError('Shutdown failed - could not send stop streaming\n # message')\n pass\n\n def sonar_disable(self):\n\"\"\"\n Disable sonar scanning for all sonar sensors\n \"\"\"\n command = [PrivateConstants.SONAR_DISABLE]\n self._send_command(command)\n\n def sonar_enable(self):\n\"\"\"\n Enable sonar scanning for all sonar sensors\n \"\"\"\n command = [PrivateConstants.SONAR_ENABLE]\n self._send_command(command)\n\n def spi_cs_control(self, chip_select_pin, select):\n\"\"\"\n Control an SPI chip select line\n :param chip_select_pin: pin connected to CS\n\n :param select: 0=select, 1=deselect\n \"\"\"\n if not self.spi_enabled:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'spi_cs_control: SPI interface is not enabled.')\n\n if chip_select_pin not in self.cs_pins_enabled:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'spi_cs_control: chip select pin never enabled.')\n command = [PrivateConstants.SPI_CS_CONTROL, chip_select_pin, select]\n self._send_command(command)\n\n def spi_read_blocking(self, chip_select, register_selection, number_of_bytes_to_read,\n call_back=None):\n\"\"\"\n Read the specified number of bytes from the specified SPI port and\n call the callback function with the reported data.\n\n :param chip_select: chip select pin\n\n :param register_selection: Register to be selected for read.\n\n :param number_of_bytes_to_read: Number of bytes to read\n\n :param call_back: Required callback function to report spi data as a\n result of read command\n\n\n callback returns a data list:\n [SPI_READ_REPORT, chip select pin, SPI Register, count of data bytes read,\n data bytes, time-stamp]\n\n SPI_READ_REPORT = 13\n\n \"\"\"\n\n if not self.spi_enabled:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'spi_read_blocking: SPI interface is not enabled.')\n\n if not call_back:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError('spi_read_blocking: A Callback must be specified')\n\n self.spi_callback = call_back\n\n command = [PrivateConstants.SPI_READ_BLOCKING, chip_select,\n number_of_bytes_to_read,\n register_selection]\n\n self._send_command(command)\n\n def spi_set_format(self, clock_divisor, bit_order, data_mode):\n\"\"\"\n Configure how the SPI serializes and de-serializes data on the wire.\n\n See Arduino SPI reference materials for details.\n\n :param clock_divisor: 1 - 255\n\n :param bit_order:\n\n LSBFIRST = 0\n\n MSBFIRST = 1 (default)\n\n :param data_mode:\n\n SPI_MODE0 = 0x00 (default)\n\n SPI_MODE1 = 1\n\n SPI_MODE2 = 2\n\n SPI_MODE3 = 3\n\n \"\"\"\n\n if not self.spi_enabled:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'spi_set_format: SPI interface is not enabled.')\n\n if not 0 < clock_divisor <= 255:\n raise RuntimeError(f'spi_set_format: illegal clock divisor selected.')\n if bit_order not in [0, 1]:\n raise RuntimeError(f'spi_set_format: illegal bit_order selected.')\n if data_mode not in [0, 1, 2, 3]:\n raise RuntimeError(f'spi_set_format: illegal data_order selected.')\n\n command = [PrivateConstants.SPI_SET_FORMAT, clock_divisor, bit_order,\n data_mode]\n self._send_command(command)\n\n def spi_write_blocking(self, chip_select, bytes_to_write):\n\"\"\"\n Write a list of bytes to the SPI device.\n\n :param chip_select: chip select pin\n\n :param bytes_to_write: A list of bytes to write. This must\n be in the form of a list.\n\n \"\"\"\n\n if not self.spi_enabled:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'spi_write_blocking: SPI interface is not enabled.')\n\n if type(bytes_to_write) is not list:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError('spi_write_blocking: bytes_to_write must be a list.')\n\n command = [PrivateConstants.SPI_WRITE_BLOCKING, chip_select, len(bytes_to_write)]\n\n for data in bytes_to_write:\n command.append(data)\n\n self._send_command(command)\n\n # def set_pin_mode_one_wire(self, pin):\n # \"\"\"\n # Initialize the one wire serial bus.\n #\n # :param pin: Data pin connected to the OneWire device\n # \"\"\"\n # if self.reported_features & PrivateConstants.ONEWIRE_FEATURE:\n # self.onewire_enabled = True\n # command = [PrivateConstants.ONE_WIRE_INIT, pin]\n # self._send_command(command)\n # else:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError(f'The OneWire feature is disabled in the server.')\n #\n # def onewire_reset(self, callback=None):\n # \"\"\"\n # Reset the onewire device\n #\n # :param callback: required function to report reset result\n #\n # callback returns a list:\n # [ReportType = 14, Report Subtype = 25, reset result byte,\n # timestamp]\n # \"\"\"\n # if not self.onewire_enabled:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError(f'onewire_reset: OneWire interface is not enabled.')\n # if not callback:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('onewire_reset: A Callback must be specified')\n #\n # self.onewire_callback = callback\n #\n # command = [PrivateConstants.ONE_WIRE_RESET]\n # self._send_command(command)\n #\n # def onewire_select(self, device_address):\n # \"\"\"\n # Select a device based on its address\n # :param device_address: A bytearray of 8 bytes\n # \"\"\"\n # if not self.onewire_enabled:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError(f'onewire_select: OneWire interface is not enabled.')\n #\n # if type(device_address) is not list:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('onewire_select: device address must be an array of 8 '\n # 'bytes.')\n #\n # if len(device_address) != 8:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('onewire_select: device address must be an array of 8 '\n # 'bytes.')\n # command = [PrivateConstants.ONE_WIRE_SELECT]\n # for data in device_address:\n # command.append(data)\n # self._send_command(command)\n #\n # def onewire_skip(self):\n # \"\"\"\n # Skip the device selection. This only works if you have a\n # single device, but you can avoid searching and use this to\n # immediately access your device.\n # \"\"\"\n # if not self.onewire_enabled:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError(f'onewire_skip: OneWire interface is not enabled.')\n #\n # command = [PrivateConstants.ONE_WIRE_SKIP]\n # self._send_command(command)\n #\n # def onewire_write(self, data, power=0):\n # \"\"\"\n # Write a byte to the onewire device. If 'power' is one\n # then the wire is held high at the end for\n # parasitically powered devices. You\n # are responsible for eventually de-powering it by calling\n # another read or write.\n #\n # :param data: byte to write.\n # :param power: power control (see above)\n # \"\"\"\n # if not self.onewire_enabled:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError(f'onewire_write: OneWire interface is not enabled.')\n # if 0 < data < 255:\n # command = [PrivateConstants.ONE_WIRE_WRITE, data, power]\n # self._send_command(command)\n # else:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('onewire_write: Data must be no larger than 255')\n #\n # def onewire_read(self, callback=None):\n # \"\"\"\n # Read a byte from the onewire device\n # :param callback: required function to report onewire data as a\n # result of read command\n #\n #\n # callback returns a data list:\n # [ONEWIRE_REPORT, ONEWIRE_READ=29, data byte, time-stamp]\n #\n # ONEWIRE_REPORT = 14\n # \"\"\"\n # if not self.onewire_enabled:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError(f'onewire_read: OneWire interface is not enabled.')\n #\n # if not callback:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('onewire_read A Callback must be specified')\n #\n # self.onewire_callback = callback\n #\n # command = [PrivateConstants.ONE_WIRE_READ]\n # self._send_command(command)\n #\n # def onewire_reset_search(self):\n # \"\"\"\n # Begin a new search. The next use of search will begin at the first device\n # \"\"\"\n #\n # if not self.onewire_enabled:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError(f'onewire_reset_search: OneWire interface is not '\n # f'enabled.')\n # else:\n # command = [PrivateConstants.ONE_WIRE_RESET_SEARCH]\n # self._send_command(command)\n #\n # def onewire_search(self, callback=None):\n # \"\"\"\n # Search for the next device. The device address will returned in the callback.\n # If a device is found, the 8 byte address is contained in the callback.\n # If no more devices are found, the address returned contains all elements set\n # to 0xff.\n #\n # :param callback: required function to report a onewire device address\n #\n # callback returns a data list:\n # [ONEWIRE_REPORT, ONEWIRE_SEARCH=31, 8 byte address, time-stamp]\n #\n # ONEWIRE_REPORT = 14\n # \"\"\"\n # if not self.onewire_enabled:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError(f'onewire_search: OneWire interface is not enabled.')\n #\n # if not callback:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('onewire_read A Callback must be specified')\n #\n # self.onewire_callback = callback\n #\n # command = [PrivateConstants.ONE_WIRE_SEARCH]\n # self._send_command(command)\n #\n # def onewire_crc8(self, address_list, callback=None):\n # \"\"\"\n # Compute a CRC check on an array of data.\n # :param address_list:\n #\n # :param callback: required function to report a onewire device address\n #\n # callback returns a data list:\n # [ONEWIRE_REPORT, ONEWIRE_CRC8=32, CRC, time-stamp]\n #\n # ONEWIRE_REPORT = 14\n #\n # \"\"\"\n #\n # if not self.onewire_enabled:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError(f'onewire_crc8: OneWire interface is not enabled.')\n #\n # if not callback:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('onewire_crc8 A Callback must be specified')\n #\n # if type(address_list) is not list:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('onewire_crc8: address list must be a list.')\n #\n # self.onewire_callback = callback\n #\n # address_length = len(address_list)\n #\n # command = [PrivateConstants.ONE_WIRE_CRC8, address_length - 1]\n #\n # for data in address_list:\n # command.append(data)\n #\n # self._send_command(command)\n\n def r4_hard_reset(self):\n\"\"\"\n Place the r4 into hard reset\n \"\"\"\n command = [PrivateConstants.RESET, 1]\n self._send_command(command)\n time.sleep(.5)\n command = [PrivateConstants.BOARD_HARD_RESET, 1]\n self._send_command(command)\n'''\n report message handlers\n '''\n\n def _analog_message(self, data):\n\"\"\"\n This is a private message handler method.\n It is a message handler for analog messages.\n\n :param data: message data\n\n \"\"\"\n pin = data[0]\n value = (data[1] << 8) + data[2]\n # set the current value in the pin structure\n time_stamp = time.time()\n # self.digital_pins[pin].event_time = time_stamp\n if self.analog_callbacks[pin]:\n message = [PrivateConstants.ANALOG_REPORT, pin, value, time_stamp]\n try:\n self.analog_callbacks[pin](message)\n except KeyError:\n pass\n\n def _dht_report(self, data):\n\"\"\"\n This is the dht report handler method.\n\n :param data: data[0] = report error return\n No Errors = 0\n\n Checksum Error = 1\n\n Timeout Error = 2\n\n Invalid Value = 999\n\n data[1] = pin number\n\n data[2] = dht type 11 or 22\n\n data[3] = humidity positivity flag\n\n data[4] = temperature positivity value\n\n data[5] = humidity integer\n\n data[6] = humidity fractional value\n\n data[7] = temperature integer\n\n data[8] = temperature fractional value\n\n\n \"\"\"\n if data[0]: # DHT_ERROR\n # error report\n # data[0] = report sub type, data[1] = pin, data[2] = error message\n if self.dht_callbacks[data[1]]:\n # Callback 0=DHT REPORT, DHT_ERROR, PIN, Time\n message = [PrivateConstants.DHT_REPORT, data[0], data[1], data[2],\n time.time()]\n try:\n self.dht_callbacks[data[1]](message)\n except KeyError:\n pass\n else:\n # got valid data DHT_DATA\n f_humidity = float(data[5] + data[6] / 100)\n if data[3]:\n f_humidity *= -1.0\n f_temperature = float(data[7] + data[8] / 100)\n if data[4]:\n f_temperature *= -1.0\n message = [PrivateConstants.DHT_REPORT, data[0], data[1], data[2],\n f_humidity, f_temperature, time.time()]\n\n try:\n self.dht_callbacks[data[1]](message)\n except KeyError:\n pass\n\n def _digital_message(self, data):\n\"\"\"\n This is a private message handler method.\n It is a message handler for Digital Messages.\n\n :param data: digital message\n\n \"\"\"\n pin = data[0]\n value = data[1]\n\n time_stamp = time.time()\n if self.digital_callbacks[pin]:\n message = [PrivateConstants.DIGITAL_REPORT, pin, value, time_stamp]\n self.digital_callbacks[pin](message)\n\n def _firmware_message(self, data):\n\"\"\"\n Telemetrix4Arduino firmware version message\n\n :param data: data[0] = major number, data[1] = minor number.\n\n data[2] = patch number\n \"\"\"\n\n self.firmware_version = [data[0], data[1], data[2]]\n\n def _i2c_read_report(self, data):\n\"\"\"\n Execute callback for i2c reads.\n\n :param data: [I2C_READ_REPORT, i2c_port, number of bytes read, address, register, bytes read..., time-stamp]\n \"\"\"\n\n # we receive [# data bytes, address, register, data bytes]\n # number of bytes of data returned\n\n # data[0] = number of bytes\n # data[1] = i2c_port\n # data[2] = number of bytes returned\n # data[3] = address\n # data[4] = register\n # data[5] ... all the data bytes\n\n cb_list = [PrivateConstants.I2C_READ_REPORT, data[0], data[1]] + data[2:]\n cb_list.append(time.time())\n\n if cb_list[1]:\n self.i2c_callback2(cb_list)\n else:\n self.i2c_callback(cb_list)\n\n def _i2c_too_few(self, data):\n\"\"\"\n I2c reports too few bytes received\n\n :param data: data[0] = device address\n \"\"\"\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(\n f'i2c too few bytes received from i2c port {data[0]} i2c address {data[1]}')\n\n def _i2c_too_many(self, data):\n\"\"\"\n I2c reports too few bytes received\n\n :param data: data[0] = device address\n \"\"\"\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(\n f'i2c too many bytes received from i2c port {data[0]} i2c address {data[1]}')\n\n def _i_am_here(self, data):\n\"\"\"\n Reply to are_u_there message\n :param data: arduino id\n \"\"\"\n self.reported_arduino_id = data[0]\n\n def _spi_report(self, report):\n\n cb_list = [PrivateConstants.SPI_REPORT, report[0]] + report[1:]\n\n cb_list.append(time.time())\n\n self.spi_callback(cb_list)\n\n def _onewire_report(self, report):\n cb_list = [PrivateConstants.ONE_WIRE_REPORT, report[0]] + report[1:]\n cb_list.append(time.time())\n self.onewire_callback(cb_list)\n\n def _report_debug_data(self, data):\n\"\"\"\n Print debug data sent from Arduino\n :param data: data[0] is a byte followed by 2\n bytes that comprise an integer\n :return:\n \"\"\"\n value = (data[1] << 8) + data[2]\n print(f'DEBUG ID: {data[0]} Value: {value}')\n\n def _report_loop_data(self, data):\n\"\"\"\n Print data that was looped back\n :param data: byte of loop back data\n :return:\n \"\"\"\n if self.loop_back_callback:\n self.loop_back_callback(data)\n\n def _send_command(self, command):\n\"\"\"\n This is a private utility method.\n\n\n :param command: command data in the form of a list\n\n \"\"\"\n # the length of the list is added at the head\n command.insert(0, len(command))\n send_message = bytes(command)\n\n if self.serial_port:\n try:\n self.serial_port.write(send_message)\n except SerialException:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError('write fail in _send_command')\n else:\n raise RuntimeError('No serial port set.')\n\n def _servo_unavailable(self, report):\n\"\"\"\n Message if no servos are available for use.\n :param report: pin number\n \"\"\"\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(\n f'Servo Attach For Pin {report[0]} Failed: No Available Servos')\n\n def _sonar_distance_report(self, report):\n\"\"\"\n\n :param report: data[0] = trigger pin, data[1] and data[2] = distance\n\n callback report format: [PrivateConstants.SONAR_DISTANCE, trigger_pin, distance_value, time_stamp]\n \"\"\"\n\n # get callback from pin number\n cb = self.sonar_callbacks[report[0]]\n\n # build report data\n cb_list = [PrivateConstants.SONAR_DISTANCE, report[0],\n ((report[1] << 8) + report[2]), time.time()]\n\n cb(cb_list)\n\n def _stepper_distance_to_go_report(self, report):\n return # for now\n # \"\"\"\n # Report stepper distance to go.\n #\n # :param report: data[0] = motor_id, data[1] = steps MSB, data[2] = steps byte 1,\n # data[3] = steps bytes 2, data[4] = steps LSB\n #\n # callback report format: [PrivateConstants.STEPPER_DISTANCE_TO_GO, motor_id\n # steps, time_stamp]\n # \"\"\"\n #\n # # get callback\n # cb = self.stepper_info_list[report[0]]['distance_to_go_callback']\n #\n # # isolate the steps bytes and covert list to bytes\n # steps = bytes(report[1:])\n #\n # # get value from steps\n # num_steps = int.from_bytes(steps, byteorder='big', signed=True)\n #\n # cb_list = [PrivateConstants.STEPPER_DISTANCE_TO_GO, report[0], num_steps,\n # time.time()]\n #\n # cb(cb_list)\n #\n\n def _stepper_target_position_report(self, report):\n return # for now\n # \"\"\"\n # Report stepper target position to go.\n #\n # :param report: data[0] = motor_id, data[1] = target position MSB,\n # data[2] = target position byte MSB+1\n # data[3] = target position byte MSB+2\n # data[4] = target position LSB\n #\n # callback report format: [PrivateConstants.STEPPER_TARGET_POSITION, motor_id\n # target_position, time_stamp]\n # \"\"\"\n #\n # # get callback\n # cb = self.stepper_info_list[report[0]]['target_position_callback']\n #\n # # isolate the steps bytes and covert list to bytes\n # target = bytes(report[1:])\n #\n # # get value from steps\n # target_position = int.from_bytes(target, byteorder='big', signed=True)\n #\n # cb_list = [PrivateConstants.STEPPER_TARGET_POSITION, report[0], target_position,\n # time.time()]\n #\n # cb(cb_list)\n #\n\n def _stepper_current_position_report(self, report):\n return # for now\n # \"\"\"\n # Report stepper current position.\n #\n # :param report: data[0] = motor_id, data[1] = current position MSB,\n # data[2] = current position byte MSB+1\n # data[3] = current position byte MSB+2\n # data[4] = current position LSB\n #\n # callback report format: [PrivateConstants.STEPPER_CURRENT_POSITION, motor_id\n # current_position, time_stamp]\n # \"\"\"\n #\n # # get callback\n # cb = self.stepper_info_list[report[0]]['current_position_callback']\n #\n # # isolate the steps bytes and covert list to bytes\n # position = bytes(report[1:])\n #\n # # get value from steps\n # current_position = int.from_bytes(position, byteorder='big', signed=True)\n #\n # cb_list = [PrivateConstants.STEPPER_CURRENT_POSITION, report[0], current_position,\n # time.time()]\n #\n # cb(cb_list)\n #\n\n def _stepper_is_running_report(self, report):\n return # for now\n # \"\"\"\n # Report if the motor is currently running\n #\n # :param report: data[0] = motor_id, True if motor is running or False if it is not.\n #\n # callback report format: [18, motor_id,\n # running_state, time_stamp]\n # \"\"\"\n #\n # # get callback\n # cb = self.stepper_info_list[report[0]]['is_running_callback']\n #\n # cb_list = [PrivateConstants.STEPPER_RUNNING_REPORT, report[0], time.time()]\n #\n # cb(cb_list)\n #\n\n def _stepper_run_complete_report(self, report):\n return # for now\n # \"\"\"\n # The motor completed it motion\n #\n # :param report: data[0] = motor_id\n #\n # callback report format: [PrivateConstants.STEPPER_RUN_COMPLETE_REPORT, motor_id,\n # time_stamp]\n # \"\"\"\n #\n # # get callback\n # cb = self.stepper_info_list[report[0]]['motion_complete_callback']\n #\n # cb_list = [PrivateConstants.STEPPER_RUN_COMPLETE_REPORT, report[0],\n # time.time()]\n #\n # cb(cb_list)\n\n def _features_report(self, report):\n self.reported_features = report[0]\n\n def _run_threads(self):\n self.run_event.set()\n\n def _is_running(self):\n return self.run_event.is_set()\n\n def _stop_threads(self):\n self.run_event.clear()\n\n def _reporter(self):\n\"\"\"\n This is the reporter thread. It continuously pulls data from\n the deque. When a full message is detected, that message is\n processed.\n \"\"\"\n self.run_event.wait()\n\n while self._is_running() and not self.shutdown_flag:\n if len(self.the_deque):\n # response_data will be populated with the received data for the report\n response_data = []\n packet_length = self.the_deque.popleft()\n if packet_length:\n # get all the data for the report and place it into response_data\n for i in range(packet_length):\n while not len(self.the_deque):\n time.sleep(self.sleep_tune)\n data = self.the_deque.popleft()\n response_data.append(data)\n\n # print(f'response_data {response_data}')\n\n # get the report type and look up its dispatch method\n # here we pop the report type off of response_data\n report_type = response_data.pop(0)\n # print(f' reported type {report_type}')\n\n # retrieve the report handler from the dispatch table\n dispatch_entry = self.report_dispatch.get(report_type)\n\n # if there is additional data for the report,\n # it will be contained in response_data\n # noinspection PyArgumentList\n dispatch_entry(response_data)\n continue\n else:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(\n 'A report with a packet length of zero was received.')\n else:\n time.sleep(self.sleep_tune)\n\n def _serial_receiver(self):\n\"\"\"\n Thread to continuously check for incoming data.\n When a byte comes in, place it onto the deque.\n \"\"\"\n self.run_event.wait()\n\n # Don't start this thread if using a tcp/ip transport\n\n while self._is_running() and not self.shutdown_flag:\n # we can get an OSError: [Errno9] Bad file descriptor when shutting down\n # just ignore it\n try:\n if self.serial_port.inWaiting():\n c = self.serial_port.read()\n self.the_deque.append(ord(c))\n # print(ord(c))\n else:\n time.sleep(self.sleep_tune)\n # continue\n except OSError:\n pass\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.__init__","title":"__init__(com_port=None, arduino_instance_id=1, arduino_wait=1, sleep_tune=1e-06, shutdown_on_exception=True, hard_reset_on_shutdown=True)
","text":":param com_port: e.g. COM3 or /dev/ttyACM0. Only use if you wish to bypass auto com port detection.
:param arduino_instance_id: Match with the value installed on the arduino-telemetrix sketch.
:param arduino_wait: Amount of time to wait for an Arduino to fully reset itself.
:param sleep_tune: A tuning parameter (typically not changed by user)
:param shutdown_on_exception: call shutdown before raising a RunTimeError exception, or receiving a KeyboardInterrupt exception
:param hard_reset_on_shutdown: reset the board on shutdown
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def __init__(self, com_port=None, arduino_instance_id=1,\n arduino_wait=1, sleep_tune=0.000001,\n shutdown_on_exception=True, hard_reset_on_shutdown=True):\n\n\"\"\"\n\n :param com_port: e.g. COM3 or /dev/ttyACM0.\n Only use if you wish to bypass auto com port\n detection.\n\n :param arduino_instance_id: Match with the value installed on the\n arduino-telemetrix sketch.\n\n :param arduino_wait: Amount of time to wait for an Arduino to\n fully reset itself.\n\n :param sleep_tune: A tuning parameter (typically not changed by user)\n\n :param shutdown_on_exception: call shutdown before raising\n a RunTimeError exception, or\n receiving a KeyboardInterrupt exception\n\n :param hard_reset_on_shutdown: reset the board on shutdown\n\n \"\"\"\n\n # initialize threading parent\n threading.Thread.__init__(self)\n\n # create the threads and set them as daemons so\n # that they stop when the program is closed\n\n # create a thread to interpret received serial data\n self.the_reporter_thread = threading.Thread(target=self._reporter)\n self.the_reporter_thread.daemon = True\n\n self.the_data_receive_thread = threading.Thread(target=self._serial_receiver)\n\n self.the_data_receive_thread.daemon = True\n\n # flag to allow the reporter and receive threads to run.\n self.run_event = threading.Event()\n\n # check to make sure that Python interpreter is version 3.7 or greater\n python_version = sys.version_info\n if python_version[0] >= 3:\n if python_version[1] >= 7:\n pass\n else:\n raise RuntimeError(\"ERROR: Python 3.7 or greater is \"\n \"required for use of this program.\")\n\n # save input parameters as instance variables\n self.com_port = com_port\n self.arduino_instance_id = arduino_instance_id\n self.arduino_wait = arduino_wait\n self.sleep_tune = sleep_tune\n self.shutdown_on_exception = shutdown_on_exception\n self.hard_reset_on_shutdown = hard_reset_on_shutdown\n\n # create a deque to receive and process data from the arduino\n self.the_deque = deque()\n\n # The report_dispatch dictionary is used to process\n # incoming report messages by looking up the report message\n # and executing its associated processing method.\n\n self.report_dispatch = {}\n\n # To add a command to the command dispatch table, append here.\n self.report_dispatch.update(\n {PrivateConstants.LOOP_COMMAND: self._report_loop_data})\n self.report_dispatch.update(\n {PrivateConstants.DEBUG_PRINT: self._report_debug_data})\n self.report_dispatch.update(\n {PrivateConstants.DIGITAL_REPORT: self._digital_message})\n self.report_dispatch.update(\n {PrivateConstants.ANALOG_REPORT: self._analog_message})\n self.report_dispatch.update(\n {PrivateConstants.FIRMWARE_REPORT: self._firmware_message})\n self.report_dispatch.update({PrivateConstants.I_AM_HERE_REPORT: self._i_am_here})\n self.report_dispatch.update(\n {PrivateConstants.SERVO_UNAVAILABLE: self._servo_unavailable})\n self.report_dispatch.update(\n {PrivateConstants.I2C_READ_REPORT: self._i2c_read_report})\n self.report_dispatch.update(\n {PrivateConstants.I2C_TOO_FEW_BYTES_RCVD: self._i2c_too_few})\n self.report_dispatch.update(\n {PrivateConstants.I2C_TOO_MANY_BYTES_RCVD: self._i2c_too_many})\n self.report_dispatch.update(\n {PrivateConstants.SONAR_DISTANCE: self._sonar_distance_report})\n self.report_dispatch.update({PrivateConstants.DHT_REPORT: self._dht_report})\n self.report_dispatch.update(\n {PrivateConstants.SPI_REPORT: self._spi_report})\n self.report_dispatch.update(\n {PrivateConstants.ONE_WIRE_REPORT: self._onewire_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_DISTANCE_TO_GO:\n self._stepper_distance_to_go_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_TARGET_POSITION:\n self._stepper_target_position_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_CURRENT_POSITION:\n self._stepper_current_position_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_RUNNING_REPORT:\n self._stepper_is_running_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_RUN_COMPLETE_REPORT:\n self._stepper_run_complete_report})\n\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_DISTANCE_TO_GO:\n self._stepper_distance_to_go_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_TARGET_POSITION:\n self._stepper_target_position_report})\n self.report_dispatch.update(\n {PrivateConstants.FEATURES:\n self._features_report})\n\n # dictionaries to store the callbacks for each pin\n self.analog_callbacks = {}\n\n self.digital_callbacks = {}\n\n self.i2c_callback = None\n self.i2c_callback2 = None\n\n self.i2c_1_active = False\n self.i2c_2_active = False\n\n self.spi_callback = None\n\n self.onewire_callback = None\n\n self.cs_pins_enabled = []\n\n # the trigger pin will be the key to retrieve\n # the callback for a specific HC-SR04\n self.sonar_callbacks = {}\n\n self.sonar_count = 0\n\n self.dht_callbacks = {}\n\n self.dht_count = 0\n\n # serial port in use\n self.serial_port = None\n\n # flag to indicate we are in shutdown mode\n self.shutdown_flag = False\n\n # debug loopback callback method\n self.loop_back_callback = None\n\n # flag to indicate the start of a new report\n # self.new_report_start = True\n\n # firmware version to be stored here\n self.firmware_version = []\n\n # reported arduino instance id\n self.reported_arduino_id = []\n\n # reported features\n self.reported_features = 0\n\n # flag to indicate if i2c was previously enabled\n self.i2c_enabled = False\n\n # flag to indicate if spi is initialized\n self.spi_enabled = False\n\n # flag to indicate if onewire is initialized\n self.onewire_enabled = False\n\n # # stepper motor variables\n #\n # # updated when a new motor is added\n # self.next_stepper_assigned = 0\n #\n # # valid list of stepper motor interface types\n # self.valid_stepper_interfaces = [1, 2, 3, 4, 6, 8]\n #\n # # maximum number of steppers supported\n # self.max_number_of_steppers = 4\n #\n # # number of steppers created - not to exceed the maximum\n # self.number_of_steppers = 0\n #\n # # dictionary to hold stepper motor information\n # self.stepper_info = {'instance': False, 'is_running': None,\n # 'maximum_speed': 1, 'speed': 0, 'acceleration': 0,\n # 'distance_to_go_callback': None,\n # 'target_position_callback': None,\n # 'current_position_callback': None,\n # 'is_running_callback': None,\n # 'motion_complete_callback': None,\n # 'acceleration_callback': None}\n #\n # # build a list of stepper motor info items\n # self.stepper_info_list = []\n # # a list of dictionaries to hold stepper information\n # for motor in range(self.max_number_of_steppers):\n # self.stepper_info_list.append(self.stepper_info)\n\n self.the_reporter_thread.start()\n self.the_data_receive_thread.start()\n\n print(f\"telemetrix_uno_r4_minima: Version\"\n f\" {PrivateConstants.TELEMETRIX_VERSION}\\n\\n\"\n f\"Copyright (c) 2023 Alan Yorinks All Rights Reserved.\\n\")\n\n # using the serial link\n if not self.com_port:\n # user did not specify a com_port\n try:\n self._find_arduino()\n except KeyboardInterrupt:\n if self.shutdown_on_exception:\n self.shutdown()\n else:\n # com_port specified - set com_port and baud rate\n try:\n self._manual_open()\n except KeyboardInterrupt:\n if self.shutdown_on_exception:\n self.shutdown()\n\n if self.serial_port:\n print(\n f\"Arduino compatible device found and connected to {self.serial_port.port}\")\n\n self.serial_port.reset_input_buffer()\n self.serial_port.reset_output_buffer()\n\n # no com_port found - raise a runtime exception\n else:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError('No Arduino Found or User Aborted Program')\n\n # allow the threads to run\n self._run_threads()\n print(f'Reset Complete')\n\n # get telemetrix firmware version and print it\n print('\\nRetrieving Telemetrix4UnoR4Minima firmware ID...')\n self._get_firmware_version()\n if not self.firmware_version:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'Telemetrix4UnoR4Minima firmware version')\n\n else:\n\n print(f'Telemetrix4UnoR4Minima firmware version: {self.firmware_version[0]}.'\n f'{self.firmware_version[1]}.{self.firmware_version[2]}')\n command = [PrivateConstants.ENABLE_ALL_REPORTS]\n self._send_command(command)\n\n # get the features list\n command = [PrivateConstants.GET_FEATURES]\n self._send_command(command)\n time.sleep(.2)\n\n # Have the server reset its data structures\n command = [PrivateConstants.RESET]\n self._send_command(command)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.analog_write","title":"analog_write(pin, value)
","text":"Set the specified pin to the specified value.
:param pin: arduino pin number
:param value: pin value (maximum 16 bits)
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def analog_write(self, pin, value):\n\"\"\"\n Set the specified pin to the specified value.\n\n :param pin: arduino pin number\n\n :param value: pin value (maximum 16 bits)\n\n \"\"\"\n value_msb = value >> 8\n value_lsb = value & 0xff\n command = [PrivateConstants.ANALOG_WRITE, pin, value_msb, value_lsb]\n self._send_command(command)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.digital_write","title":"digital_write(pin, value)
","text":"Set the specified pin to the specified value.
:param pin: arduino pin number
:param value: pin value (1 or 0)
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def digital_write(self, pin, value):\n\"\"\"\n Set the specified pin to the specified value.\n\n :param pin: arduino pin number\n\n :param value: pin value (1 or 0)\n\n \"\"\"\n\n command = [PrivateConstants.DIGITAL_WRITE, pin, value]\n self._send_command(command)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.disable_all_reporting","title":"disable_all_reporting()
","text":"Disable reporting for all digital and analog input pins
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def disable_all_reporting(self):\n\"\"\"\n Disable reporting for all digital and analog input pins\n \"\"\"\n command = [PrivateConstants.MODIFY_REPORTING,\n PrivateConstants.REPORTING_DISABLE_ALL, 0]\n self._send_command(command)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.disable_analog_reporting","title":"disable_analog_reporting(pin)
","text":"Disables analog reporting for a single analog pin.
:param pin: Analog pin number. For example for A0, the number is 0.
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def disable_analog_reporting(self, pin):\n\"\"\"\n Disables analog reporting for a single analog pin.\n\n :param pin: Analog pin number. For example for A0, the number is 0.\n\n \"\"\"\n command = [PrivateConstants.MODIFY_REPORTING,\n PrivateConstants.REPORTING_ANALOG_DISABLE, pin]\n self._send_command(command)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.disable_digital_reporting","title":"disable_digital_reporting(pin)
","text":"Disables digital reporting for a single digital input.
:param pin: Pin number.
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def disable_digital_reporting(self, pin):\n\"\"\"\n Disables digital reporting for a single digital input.\n\n :param pin: Pin number.\n\n \"\"\"\n command = [PrivateConstants.MODIFY_REPORTING,\n PrivateConstants.REPORTING_DIGITAL_DISABLE, pin]\n self._send_command(command)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.enable_analog_reporting","title":"enable_analog_reporting(pin)
","text":"Enables analog reporting for the specified pin.
:param pin: Analog pin number. For example for A0, the number is 0.
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def enable_analog_reporting(self, pin):\n\"\"\"\n Enables analog reporting for the specified pin.\n\n :param pin: Analog pin number. For example for A0, the number is 0.\n\n\n \"\"\"\n command = [PrivateConstants.MODIFY_REPORTING,\n PrivateConstants.REPORTING_ANALOG_ENABLE, pin]\n self._send_command(command)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.enable_digital_reporting","title":"enable_digital_reporting(pin)
","text":"Enable reporting on the specified digital pin.
:param pin: Pin number.
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def enable_digital_reporting(self, pin):\n\"\"\"\n Enable reporting on the specified digital pin.\n\n :param pin: Pin number.\n \"\"\"\n\n command = [PrivateConstants.MODIFY_REPORTING,\n PrivateConstants.REPORTING_DIGITAL_ENABLE, pin]\n self._send_command(command)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.i2c_read","title":"i2c_read(address, register, number_of_bytes, callback=None, i2c_port=0, write_register=True)
","text":"Read the specified number of bytes from the specified register for the i2c device.
:param address: i2c device address
:param register: i2c register (or None if no register selection is needed)
:param number_of_bytes: number of bytes to be read
:param callback: Required callback function to report i2c data as a result of read command
:param i2c_port: 0 = default, 1 = secondary
:param write_register: If True, the register is written before read Else, the write is suppressed
callback returns a data list:
[I2C_READ_REPORT, address, register, count of data bytes, data bytes, time-stamp]
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def i2c_read(self, address, register, number_of_bytes,\n callback=None, i2c_port=0,\n write_register=True):\n\"\"\"\n Read the specified number of bytes from the\n specified register for the i2c device.\n\n\n :param address: i2c device address\n\n :param register: i2c register (or None if no register\n selection is needed)\n\n :param number_of_bytes: number of bytes to be read\n\n :param callback: Required callback function to report\n i2c data as a result of read command\n\n :param i2c_port: 0 = default, 1 = secondary\n\n :param write_register: If True, the register is written\n before read\n Else, the write is suppressed\n\n\n callback returns a data list:\n\n [I2C_READ_REPORT, address, register, count of data bytes,\n data bytes, time-stamp]\n\n \"\"\"\n\n self._i2c_read_request(address, register, number_of_bytes,\n callback=callback, i2c_port=i2c_port,\n write_register=write_register)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.i2c_read_restart_transmission","title":"i2c_read_restart_transmission(address, register, number_of_bytes, callback=None, i2c_port=0, write_register=True)
","text":"Read the specified number of bytes from the specified register for the i2c device. This restarts the transmission after the read. It is required for some i2c devices such as the MMA8452Q accelerometer.
:param address: i2c device address
:param register: i2c register (or None if no register selection is needed)
:param number_of_bytes: number of bytes to be read
:param callback: Required callback function to report i2c data as a result of read command
:param i2c_port: 0 = default 1 = secondary
:param write_register: If True, the register is written before read Else, the write is suppressed
callback returns a data list:
[I2C_READ_REPORT, address, register, count of data bytes, data bytes, time-stamp]
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def i2c_read_restart_transmission(self, address, register,\n number_of_bytes,\n callback=None, i2c_port=0,\n write_register=True):\n\"\"\"\n Read the specified number of bytes from the specified\n register for the i2c device. This restarts the transmission\n after the read. It is required for some i2c devices such as the MMA8452Q\n accelerometer.\n\n\n :param address: i2c device address\n\n :param register: i2c register (or None if no register\n selection is needed)\n\n :param number_of_bytes: number of bytes to be read\n\n :param callback: Required callback function to report i2c\n data as a result of read command\n\n :param i2c_port: 0 = default 1 = secondary\n\n :param write_register: If True, the register is written before read\n Else, the write is suppressed\n\n\n\n callback returns a data list:\n\n [I2C_READ_REPORT, address, register, count of data bytes,\n data bytes, time-stamp]\n\n \"\"\"\n\n self._i2c_read_request(address, register, number_of_bytes,\n stop_transmission=False,\n callback=callback, i2c_port=i2c_port,\n write_register=write_register)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.i2c_write","title":"i2c_write(address, args, i2c_port=0)
","text":"Write data to an i2c device.
:param address: i2c device address
:param i2c_port: 0= port 1, 1 = port 2
:param args: A variable number of bytes to be sent to the device passed in as a list
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def i2c_write(self, address, args, i2c_port=0):\n\"\"\"\n Write data to an i2c device.\n\n :param address: i2c device address\n\n :param i2c_port: 0= port 1, 1 = port 2\n\n :param args: A variable number of bytes to be sent to the device\n passed in as a list\n\n \"\"\"\n if not i2c_port:\n if not self.i2c_1_active:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(\n 'I2C Write: set_pin_mode i2c never called for i2c port 1.')\n\n if i2c_port:\n if not self.i2c_2_active:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(\n 'I2C Write: set_pin_mode i2c never called for i2c port 2.')\n\n command = [PrivateConstants.I2C_WRITE, len(args), address, i2c_port]\n\n for item in args:\n command.append(item)\n\n self._send_command(command)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.loop_back","title":"loop_back(start_character, callback=None)
","text":"This is a debugging method to send a character to the Arduino device, and have the device loop it back.
:param start_character: The character to loop back. It should be an integer.
:param callback: Looped back character will appear in the callback method
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def loop_back(self, start_character, callback=None):\n\"\"\"\n This is a debugging method to send a character to the\n Arduino device, and have the device loop it back.\n\n :param start_character: The character to loop back. It should be\n an integer.\n\n :param callback: Looped back character will appear in the callback method\n\n \"\"\"\n command = [PrivateConstants.LOOP_COMMAND, ord(start_character)]\n self.loop_back_callback = callback\n self._send_command(command)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.r4_hard_reset","title":"r4_hard_reset()
","text":"Place the r4 into hard reset
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def r4_hard_reset(self):\n\"\"\"\n Place the r4 into hard reset\n \"\"\"\n command = [PrivateConstants.RESET, 1]\n self._send_command(command)\n time.sleep(.5)\n command = [PrivateConstants.BOARD_HARD_RESET, 1]\n self._send_command(command)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.servo_detach","title":"servo_detach(pin_number)
","text":"Detach a servo for reuse
:param pin_number: attached pin
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def servo_detach(self, pin_number):\n\"\"\"\n Detach a servo for reuse\n\n :param pin_number: attached pin\n\n \"\"\"\n command = [PrivateConstants.SERVO_DETACH, pin_number]\n self._send_command(command)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.servo_write","title":"servo_write(pin_number, angle)
","text":"Set a servo attached to a pin to a given angle.
:param pin_number: pin
:param angle: angle (0-180)
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def servo_write(self, pin_number, angle):\n\"\"\"\n\n Set a servo attached to a pin to a given angle.\n\n :param pin_number: pin\n\n :param angle: angle (0-180)\n\n \"\"\"\n command = [PrivateConstants.SERVO_WRITE, pin_number, angle]\n self._send_command(command)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.set_analog_scan_interval","title":"set_analog_scan_interval(interval)
","text":"Set the analog scanning interval.
:param interval: value of 0 - 255 - milliseconds
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def set_analog_scan_interval(self, interval):\n\"\"\"\n Set the analog scanning interval.\n\n :param interval: value of 0 - 255 - milliseconds\n \"\"\"\n\n if 0 <= interval <= 255:\n command = [PrivateConstants.SET_ANALOG_SCANNING_INTERVAL, interval]\n self._send_command(command)\n else:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError('Analog interval must be between 0 and 255')\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.set_pin_mode_analog_input","title":"set_pin_mode_analog_input(pin_number, differential=0, callback=None)
","text":"Set a pin as an analog input.
:param pin_number: arduino pin number
:param differential: difference in previous to current value before report will be generated
:param callback: callback function
callback returns a data list:
[pin_type, pin_number, pin_value, raw_time_stamp]
The pin_type for analog input pins = 3
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def set_pin_mode_analog_input(self, pin_number, differential=0, callback=None):\n\"\"\"\n Set a pin as an analog input.\n\n :param pin_number: arduino pin number\n\n :param differential: difference in previous to current value before\n report will be generated\n\n :param callback: callback function\n\n\n callback returns a data list:\n\n [pin_type, pin_number, pin_value, raw_time_stamp]\n\n The pin_type for analog input pins = 3\n\n \"\"\"\n self._set_pin_mode(pin_number, PrivateConstants.AT_ANALOG, differential,\n callback)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.set_pin_mode_analog_output","title":"set_pin_mode_analog_output(pin_number)
","text":"Set a pin as a pwm (analog output) pin.
:param pin_number:arduino pin number
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def set_pin_mode_analog_output(self, pin_number):\n\"\"\"\n Set a pin as a pwm (analog output) pin.\n\n :param pin_number:arduino pin number\n\n \"\"\"\n self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.set_pin_mode_dht","title":"set_pin_mode_dht(pin, callback=None, dht_type=22)
","text":":param pin: connection pin
:param callback: callback function
:param dht_type: either 22 for DHT22 or 11 for DHT11
Error Callback: [DHT REPORT Type, DHT_ERROR_NUMBER, PIN, DHT_TYPE, Time]
Valid Data Callback: DHT REPORT Type, DHT_DATA=, PIN, DHT_TYPE, Humidity, Temperature, Time]
DHT_REPORT_TYPE = 12
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def set_pin_mode_dht(self, pin, callback=None, dht_type=22):\n\"\"\"\n\n :param pin: connection pin\n\n :param callback: callback function\n\n :param dht_type: either 22 for DHT22 or 11 for DHT11\n\n Error Callback: [DHT REPORT Type, DHT_ERROR_NUMBER, PIN, DHT_TYPE, Time]\n\n Valid Data Callback: DHT REPORT Type, DHT_DATA=, PIN, DHT_TYPE, Humidity,\n Temperature,\n Time]\n\n DHT_REPORT_TYPE = 12\n \"\"\"\n if self.reported_features & PrivateConstants.DHT_FEATURE:\n if not callback:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError('set_pin_mode_dht: A Callback must be specified')\n\n if self.dht_count < PrivateConstants.MAX_DHTS - 1:\n self.dht_callbacks[pin] = callback\n self.dht_count += 1\n\n if dht_type != 22 and dht_type != 11:\n dht_type = 22\n\n command = [PrivateConstants.DHT_NEW, pin, dht_type]\n self._send_command(command)\n else:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(\n f'Maximum Number Of DHTs Exceeded - set_pin_mode_dht fails for pin {pin}')\n else:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'The DHT feature is disabled in the server.')\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.set_pin_mode_digital_input","title":"set_pin_mode_digital_input(pin_number, callback=None)
","text":"Set a pin as a digital input.
:param pin_number: arduino pin number
:param callback: callback function
callback returns a data list:
[pin_type, pin_number, pin_value, raw_time_stamp]
The pin_type for all digital input pins = 2
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def set_pin_mode_digital_input(self, pin_number, callback=None):\n\"\"\"\n Set a pin as a digital input.\n\n :param pin_number: arduino pin number\n\n :param callback: callback function\n\n\n callback returns a data list:\n\n [pin_type, pin_number, pin_value, raw_time_stamp]\n\n The pin_type for all digital input pins = 2\n\n \"\"\"\n self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT, callback=callback)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.set_pin_mode_digital_input_pullup","title":"set_pin_mode_digital_input_pullup(pin_number, callback=None)
","text":"Set a pin as a digital input with pullup enabled.
:param pin_number: arduino pin number
:param callback: callback function
callback returns a data list:
[pin_type, pin_number, pin_value, raw_time_stamp]
The pin_type for all digital input pins = 2
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def set_pin_mode_digital_input_pullup(self, pin_number, callback=None):\n\"\"\"\n Set a pin as a digital input with pullup enabled.\n\n :param pin_number: arduino pin number\n\n :param callback: callback function\n\n\n callback returns a data list:\n\n [pin_type, pin_number, pin_value, raw_time_stamp]\n\n The pin_type for all digital input pins = 2\n \"\"\"\n self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT_PULLUP,\n callback=callback)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.set_pin_mode_digital_output","title":"set_pin_mode_digital_output(pin_number)
","text":"Set a pin as a digital output pin.
:param pin_number: arduino pin number
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def set_pin_mode_digital_output(self, pin_number):\n\"\"\"\n Set a pin as a digital output pin.\n\n :param pin_number: arduino pin number\n \"\"\"\n\n self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.set_pin_mode_i2c","title":"set_pin_mode_i2c(i2c_port=0)
","text":"Establish the standard Arduino i2c pins for i2c utilization.
:param i2c_port: 0 = i2c1, 1 = i2c2
API.\n\n See i2c_read, or i2c_read_restart_transmission.\n
Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def set_pin_mode_i2c(self, i2c_port=0):\n\"\"\"\n Establish the standard Arduino i2c pins for i2c utilization.\n\n :param i2c_port: 0 = i2c1, 1 = i2c2\n\n NOTES: 1. THIS METHOD MUST BE CALLED BEFORE ANY I2C REQUEST IS MADE\n 2. Callbacks are set within the individual i2c read methods of this\n API.\n\n See i2c_read, or i2c_read_restart_transmission.\n\n \"\"\"\n # test for i2c port 2\n if i2c_port:\n # if not previously activated set it to activated\n # and the send a begin message for this port\n if not self.i2c_2_active:\n self.i2c_2_active = True\n else:\n return\n # port 1\n else:\n if not self.i2c_1_active:\n self.i2c_1_active = True\n else:\n return\n\n command = [PrivateConstants.I2C_BEGIN, i2c_port]\n self._send_command(command)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.set_pin_mode_servo","title":"set_pin_mode_servo(pin_number, min_pulse=544, max_pulse=2400)
","text":"Attach a pin to a servo motor
:param pin_number: pin
:param min_pulse: minimum pulse width
:param max_pulse: maximum pulse width
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def set_pin_mode_servo(self, pin_number, min_pulse=544, max_pulse=2400):\n\"\"\"\n\n Attach a pin to a servo motor\n\n :param pin_number: pin\n\n :param min_pulse: minimum pulse width\n\n :param max_pulse: maximum pulse width\n\n \"\"\"\n if self.reported_features & PrivateConstants.SERVO_FEATURE:\n\n minv = (min_pulse).to_bytes(2, byteorder=\"big\")\n maxv = (max_pulse).to_bytes(2, byteorder=\"big\")\n\n command = [PrivateConstants.SERVO_ATTACH, pin_number,\n minv[0], minv[1], maxv[0], maxv[1]]\n self._send_command(command)\n else:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'The SERVO feature is disabled in the server.')\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.set_pin_mode_sonar","title":"set_pin_mode_sonar(trigger_pin, echo_pin, callback=None)
","text":":param trigger_pin:
:param echo_pin:
:param callback: callback
callback data: [PrivateConstants.SONAR_DISTANCE, trigger_pin, distance_value, time_stamp]
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def set_pin_mode_sonar(self, trigger_pin, echo_pin,\n callback=None):\n\"\"\"\n\n :param trigger_pin:\n\n :param echo_pin:\n\n :param callback: callback\n\n callback data: [PrivateConstants.SONAR_DISTANCE, trigger_pin, distance_value, time_stamp]\n\n \"\"\"\n if self.reported_features & PrivateConstants.SONAR_FEATURE:\n\n if not callback:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError('set_pin_mode_sonar: A Callback must be specified')\n\n if self.sonar_count < PrivateConstants.MAX_SONARS - 1:\n self.sonar_callbacks[trigger_pin] = callback\n self.sonar_count += 1\n\n command = [PrivateConstants.SONAR_NEW, trigger_pin, echo_pin]\n self._send_command(command)\n else:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(\n f'Maximum Number Of Sonars Exceeded - set_pin_mode_sonar fails for pin {trigger_pin}')\n else:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'The SONAR feature is disabled in the server.')\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.set_pin_mode_spi","title":"set_pin_mode_spi(chip_select_list=None)
","text":"Specify the list of chip select pins.
Standard Arduino MISO, MOSI and CLK pins are used for the board in use.
Chip Select is any digital output capable pin.
:param chip_select_list: this is a list of pins to be used for chip select. The pins will be configured as output, and set to high ready to be used for chip select. NOTE: You must specify the chips select pins here!
command message: [command, [cs pins...]]
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def set_pin_mode_spi(self, chip_select_list=None):\n\"\"\"\n Specify the list of chip select pins.\n\n Standard Arduino MISO, MOSI and CLK pins are used for the board in use.\n\n Chip Select is any digital output capable pin.\n\n :param chip_select_list: this is a list of pins to be used for chip select.\n The pins will be configured as output, and set to high\n ready to be used for chip select.\n NOTE: You must specify the chips select pins here!\n\n\n command message: [command, [cs pins...]]\n \"\"\"\n\n if self.reported_features & PrivateConstants.SPI_FEATURE:\n if type(chip_select_list) != list:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError('chip_select_list must be in the form of a list')\n if not chip_select_list:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError('Chip select pins were not specified')\n\n self.spi_enabled = True\n\n command = [PrivateConstants.SPI_INIT, len(chip_select_list)]\n\n for pin in chip_select_list:\n command.append(pin)\n self.cs_pins_enabled.append(pin)\n self._send_command(command)\n else:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'The SPI feature is disabled in the server.')\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.shutdown","title":"shutdown()
","text":"This method attempts an orderly shutdown If any exceptions are thrown, they are ignored.
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def shutdown(self):\n\"\"\"\n This method attempts an orderly shutdown\n If any exceptions are thrown, they are ignored.\n \"\"\"\n self.shutdown_flag = True\n\n self._stop_threads()\n\n try:\n command = [PrivateConstants.STOP_ALL_REPORTS]\n self._send_command(command)\n time.sleep(.5)\n\n if self.hard_reset_on_shutdown:\n self.r4_hard_reset()\n else:\n try:\n self.serial_port.reset_input_buffer()\n self.serial_port.reset_output_buffer()\n\n self.serial_port.close()\n\n except (RuntimeError, SerialException, OSError):\n # ignore error on shutdown\n pass\n except Exception:\n # raise RuntimeError('Shutdown failed - could not send stop streaming\n # message')\n pass\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.sonar_disable","title":"sonar_disable()
","text":"Disable sonar scanning for all sonar sensors
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def sonar_disable(self):\n\"\"\"\n Disable sonar scanning for all sonar sensors\n \"\"\"\n command = [PrivateConstants.SONAR_DISABLE]\n self._send_command(command)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.sonar_enable","title":"sonar_enable()
","text":"Enable sonar scanning for all sonar sensors
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def sonar_enable(self):\n\"\"\"\n Enable sonar scanning for all sonar sensors\n \"\"\"\n command = [PrivateConstants.SONAR_ENABLE]\n self._send_command(command)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.spi_cs_control","title":"spi_cs_control(chip_select_pin, select)
","text":"Control an SPI chip select line :param chip_select_pin: pin connected to CS
:param select: 0=select, 1=deselect
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def spi_cs_control(self, chip_select_pin, select):\n\"\"\"\n Control an SPI chip select line\n :param chip_select_pin: pin connected to CS\n\n :param select: 0=select, 1=deselect\n \"\"\"\n if not self.spi_enabled:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'spi_cs_control: SPI interface is not enabled.')\n\n if chip_select_pin not in self.cs_pins_enabled:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'spi_cs_control: chip select pin never enabled.')\n command = [PrivateConstants.SPI_CS_CONTROL, chip_select_pin, select]\n self._send_command(command)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.spi_read_blocking","title":"spi_read_blocking(chip_select, register_selection, number_of_bytes_to_read, call_back=None)
","text":"Read the specified number of bytes from the specified SPI port and call the callback function with the reported data.
:param chip_select: chip select pin
:param register_selection: Register to be selected for read.
:param number_of_bytes_to_read: Number of bytes to read
:param call_back: Required callback function to report spi data as a result of read command
callback returns a data list: [SPI_READ_REPORT, chip select pin, SPI Register, count of data bytes read, data bytes, time-stamp]
SPI_READ_REPORT = 13
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def spi_read_blocking(self, chip_select, register_selection, number_of_bytes_to_read,\n call_back=None):\n\"\"\"\n Read the specified number of bytes from the specified SPI port and\n call the callback function with the reported data.\n\n :param chip_select: chip select pin\n\n :param register_selection: Register to be selected for read.\n\n :param number_of_bytes_to_read: Number of bytes to read\n\n :param call_back: Required callback function to report spi data as a\n result of read command\n\n\n callback returns a data list:\n [SPI_READ_REPORT, chip select pin, SPI Register, count of data bytes read,\n data bytes, time-stamp]\n\n SPI_READ_REPORT = 13\n\n \"\"\"\n\n if not self.spi_enabled:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'spi_read_blocking: SPI interface is not enabled.')\n\n if not call_back:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError('spi_read_blocking: A Callback must be specified')\n\n self.spi_callback = call_back\n\n command = [PrivateConstants.SPI_READ_BLOCKING, chip_select,\n number_of_bytes_to_read,\n register_selection]\n\n self._send_command(command)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.spi_set_format","title":"spi_set_format(clock_divisor, bit_order, data_mode)
","text":"Configure how the SPI serializes and de-serializes data on the wire.
See Arduino SPI reference materials for details.
:param clock_divisor: 1 - 255
:param bit_order:
LSBFIRST = 0\n\n MSBFIRST = 1 (default)\n
:param data_mode:
SPI_MODE0 = 0x00 (default)\n\n SPI_MODE1 = 1\n\n SPI_MODE2 = 2\n\n SPI_MODE3 = 3\n
Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def spi_set_format(self, clock_divisor, bit_order, data_mode):\n\"\"\"\n Configure how the SPI serializes and de-serializes data on the wire.\n\n See Arduino SPI reference materials for details.\n\n :param clock_divisor: 1 - 255\n\n :param bit_order:\n\n LSBFIRST = 0\n\n MSBFIRST = 1 (default)\n\n :param data_mode:\n\n SPI_MODE0 = 0x00 (default)\n\n SPI_MODE1 = 1\n\n SPI_MODE2 = 2\n\n SPI_MODE3 = 3\n\n \"\"\"\n\n if not self.spi_enabled:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'spi_set_format: SPI interface is not enabled.')\n\n if not 0 < clock_divisor <= 255:\n raise RuntimeError(f'spi_set_format: illegal clock divisor selected.')\n if bit_order not in [0, 1]:\n raise RuntimeError(f'spi_set_format: illegal bit_order selected.')\n if data_mode not in [0, 1, 2, 3]:\n raise RuntimeError(f'spi_set_format: illegal data_order selected.')\n\n command = [PrivateConstants.SPI_SET_FORMAT, clock_divisor, bit_order,\n data_mode]\n self._send_command(command)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.spi_write_blocking","title":"spi_write_blocking(chip_select, bytes_to_write)
","text":"Write a list of bytes to the SPI device.
:param chip_select: chip select pin
:param bytes_to_write: A list of bytes to write. This must be in the form of a list.
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def spi_write_blocking(self, chip_select, bytes_to_write):\n\"\"\"\n Write a list of bytes to the SPI device.\n\n :param chip_select: chip select pin\n\n :param bytes_to_write: A list of bytes to write. This must\n be in the form of a list.\n\n \"\"\"\n\n if not self.spi_enabled:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'spi_write_blocking: SPI interface is not enabled.')\n\n if type(bytes_to_write) is not list:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError('spi_write_blocking: bytes_to_write must be a list.')\n\n command = [PrivateConstants.SPI_WRITE_BLOCKING, chip_select, len(bytes_to_write)]\n\n for data in bytes_to_write:\n command.append(data)\n\n self._send_command(command)\n
"},{"location":"telemetrix_minima_reference_aio/","title":"telemetrix_uno_r4_minima_aio","text":"Copyright (c) 2023 Alan Yorinks All rights reserved.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 as published by the Free Software Foundation; either or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio","title":"TelemetrixUnoR4MinimaAio
","text":"This class exposes and implements the TelemetrixAIO API. It includes the public API methods as well as a set of private methods. This is an asyncio API.
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
class TelemetrixUnoR4MinimaAio:\n\"\"\"\n This class exposes and implements the TelemetrixAIO API.\n It includes the public API methods as well as\n a set of private methods. This is an asyncio API.\n\n \"\"\"\n\n # noinspection PyPep8,PyPep8\n def __init__(self, com_port=None,\n arduino_instance_id=1, arduino_wait=1,\n sleep_tune=0.0001, autostart=True,\n loop=None, shutdown_on_exception=True,\n close_loop_on_shutdown=True, hard_reset_on_shutdown=True):\n\n\"\"\"\n If you have a single Arduino connected to your computer,\n then you may accept all the default values.\n\n Otherwise, specify a unique arduino_instance id for each board in use.\n\n :param com_port: e.g. COM3 or /dev/ttyACM0.\n\n :param arduino_instance_id: Must match value in the Telemetrix4Arduino sketch\n\n :param arduino_wait: Amount of time to wait for an Arduino to\n fully reset itself.\n\n :param sleep_tune: A tuning parameter (typically not changed by user)\n\n :param autostart: If you wish to call the start method within\n your application, then set this to False.\n\n :param loop: optional user provided event loop\n\n :param shutdown_on_exception: call shutdown before raising\n a RunTimeError exception, or\n receiving a KeyboardInterrupt exception\n\n :param close_loop_on_shutdown: stop and close the event loop loop\n when a shutdown is called or a serial\n error occurs\n\n :param hard_reset_on_shutdown: reset the board on shutdown\n\n \"\"\"\n # check to make sure that Python interpreter is version 3.8.3 or greater\n python_version = sys.version_info\n if python_version[0] >= 3:\n if python_version[1] >= 8:\n if python_version[2] >= 3:\n pass\n else:\n raise RuntimeError(\"ERROR: Python 3.7 or greater is \"\n \"required for use of this program.\")\n\n # save input parameters\n self.com_port = com_port\n self.arduino_instance_id = arduino_instance_id\n self.arduino_wait = arduino_wait\n self.sleep_tune = sleep_tune\n self.autostart = autostart\n self.hard_reset_on_shutdown = hard_reset_on_shutdown\n\n # set the event loop\n if loop is None:\n self.loop = asyncio.get_event_loop()\n else:\n self.loop = loop\n\n self.shutdown_on_exception = shutdown_on_exception\n self.close_loop_on_shutdown = close_loop_on_shutdown\n\n # dictionaries to store the callbacks for each pin\n self.analog_callbacks = {}\n\n self.digital_callbacks = {}\n\n self.i2c_callback = None\n self.i2c_callback2 = None\n\n self.i2c_1_active = False\n self.i2c_2_active = False\n\n self.spi_callback = None\n\n self.onewire_callback = None\n\n # debug loopback callback method\n self.loop_back_callback = None\n\n # the trigger pin will be the key to retrieve\n # the callback for a specific HC-SR04\n self.sonar_callbacks = {}\n\n self.sonar_count = 0\n\n self.dht_callbacks = {}\n\n self.dht_count = 0\n\n # serial port in use\n self.serial_port = None\n\n # generic asyncio task holder\n self.the_task = None\n\n # flag to indicate we are in shutdown mode\n self.shutdown_flag = False\n\n self.report_dispatch = {}\n\n # reported features\n self.reported_features = 0\n\n # To add a command to the command dispatch table, append here.\n self.report_dispatch.update(\n {PrivateConstants.LOOP_COMMAND: self._report_loop_data})\n self.report_dispatch.update(\n {PrivateConstants.DEBUG_PRINT: self._report_debug_data})\n self.report_dispatch.update(\n {PrivateConstants.DIGITAL_REPORT: self._digital_message})\n self.report_dispatch.update(\n {PrivateConstants.ANALOG_REPORT: self._analog_message})\n self.report_dispatch.update(\n {PrivateConstants.SERVO_UNAVAILABLE: self._servo_unavailable})\n self.report_dispatch.update(\n {PrivateConstants.I2C_READ_REPORT: self._i2c_read_report})\n self.report_dispatch.update(\n {PrivateConstants.I2C_TOO_FEW_BYTES_RCVD: self._i2c_too_few})\n self.report_dispatch.update(\n {PrivateConstants.I2C_TOO_MANY_BYTES_RCVD: self._i2c_too_many})\n self.report_dispatch.update(\n {PrivateConstants.SONAR_DISTANCE: self._sonar_distance_report})\n self.report_dispatch.update({PrivateConstants.DHT_REPORT: self._dht_report})\n self.report_dispatch.update(\n {PrivateConstants.SPI_REPORT: self._spi_report})\n self.report_dispatch.update(\n {PrivateConstants.ONE_WIRE_REPORT: self._onewire_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_DISTANCE_TO_GO:\n self._stepper_distance_to_go_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_TARGET_POSITION:\n self._stepper_target_position_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_CURRENT_POSITION:\n self._stepper_current_position_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_RUNNING_REPORT:\n self._stepper_is_running_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_RUN_COMPLETE_REPORT:\n self._stepper_run_complete_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_DISTANCE_TO_GO:\n self._stepper_distance_to_go_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_TARGET_POSITION:\n self._stepper_target_position_report})\n self.report_dispatch.update(\n {PrivateConstants.FEATURES:\n self._features_report})\n\n # dictionaries to store the callbacks for each pin\n self.analog_callbacks = {}\n\n self.digital_callbacks = {}\n\n self.i2c_callback = None\n self.i2c_callback2 = None\n\n self.i2c_1_active = False\n self.i2c_2_active = False\n\n self.spi_callback = None\n\n self.onewire_callback = None\n\n self.cs_pins_enabled = []\n\n # flag to indicate if spi is initialized\n self.spi_enabled = False\n\n # flag to indicate if onewire is initialized\n self.onewire_enabled = False\n\n # the trigger pin will be the key to retrieve\n # the callback for a specific HC-SR04\n self.sonar_callbacks = {}\n\n self.sonar_count = 0\n\n self.dht_callbacks = {}\n\n # # stepper motor variables\n #\n # # updated when a new motor is added\n # self.next_stepper_assigned = 0\n #\n # # valid list of stepper motor interface types\n # self.valid_stepper_interfaces = [1, 2, 3, 4, 6, 8]\n #\n # # maximum number of steppers supported\n # self.max_number_of_steppers = 4\n #\n # # number of steppers created - not to exceed the maximum\n # self.number_of_steppers = 0\n #\n # # dictionary to hold stepper motor information\n # self.stepper_info = {'instance': False, 'is_running': None,\n # 'maximum_speed': 1, 'speed': 0, 'acceleration': 0,\n # 'distance_to_go_callback': None,\n # 'target_position_callback': None,\n # 'current_position_callback': None,\n # 'is_running_callback': None,\n # 'motion_complete_callback': None,\n # 'acceleration_callback': None}\n #\n # # build a list of stepper motor info items\n # self.stepper_info_list = []\n # # a list of dictionaries to hold stepper information\n # for motor in range(self.max_number_of_steppers):\n # self.stepper_info_list.append(self.stepper_info)\n\n print(f'telemetrix_uno_r4_minima_aio Version:'\n f' {PrivateConstants.TELEMETRIX_AIO_VERSION}')\n print(f'Copyright (c) 2023 Alan Yorinks All rights reserved.\\n')\n\n if autostart:\n self.loop.run_until_complete(self.start_aio())\n\n async def start_aio(self):\n\"\"\"\n This method may be called directly, if the autostart\n parameter in __init__ is set to false.\n\n This method instantiates the serial interface and then performs auto pin\n discovery if using a serial interface, or creates and connects to\n a TCP/IP enabled device running StandardFirmataWiFi.\n\n Use this method if you wish to start TelemetrixAIO manually from\n an asyncio function.\n \"\"\"\n\n if not self.com_port:\n # user did not specify a com_port\n try:\n await self._find_arduino()\n except KeyboardInterrupt:\n if self.shutdown_on_exception:\n await self.shutdown()\n else:\n # com_port specified - set com_port and baud rate\n try:\n await self._manual_open()\n except KeyboardInterrupt:\n if self.shutdown_on_exception:\n await self.shutdown()\n\n if self.com_port:\n print(f'Telemetrix4UnoR4 found and connected to {self.com_port}')\n\n # no com_port found - raise a runtime exception\n else:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('No Arduino Found or User Aborted Program')\n\n # get arduino firmware version and print it\n firmware_version = await self._get_firmware_version()\n if not firmware_version:\n print('*** Firmware Version retrieval timed out. ***')\n print('\\nDo you have Arduino connectivity and do you have the ')\n print('Telemetrix4UnoR4 sketch uploaded to the board and are connected')\n print('to the correct serial port.\\n')\n print('To see a list of serial ports, type: '\n '\"list_serial_ports\" in your console.')\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError\n else:\n\n print(f'Telemetrix4UnoR4 Version Number: {firmware_version[2]}.'\n f'{firmware_version[3]}.{firmware_version[4]}')\n # start the command dispatcher loop\n command = [PrivateConstants.ENABLE_ALL_REPORTS]\n await self._send_command(command)\n if not self.loop:\n self.loop = asyncio.get_event_loop()\n self.the_task = self.loop.create_task(self._arduino_report_dispatcher())\n\n # get the features list\n command = [PrivateConstants.GET_FEATURES]\n await self._send_command(command)\n await asyncio.sleep(.5)\n\n # Have the server reset its data structures\n command = [PrivateConstants.RESET]\n await self._send_command(command)\n\n async def get_event_loop(self):\n\"\"\"\n Return the currently active asyncio event loop\n\n :return: Active event loop\n\n \"\"\"\n return self.loop\n\n async def _find_arduino(self):\n\"\"\"\n This method will search all potential serial ports for an Arduino\n containing a sketch that has a matching arduino_instance_id as\n specified in the input parameters of this class.\n\n This is used explicitly with the FirmataExpress sketch.\n \"\"\"\n\n # a list of serial ports to be checked\n serial_ports = []\n\n print('Opening all potential serial ports...')\n the_ports_list = list_ports.comports()\n for port in the_ports_list:\n if port.pid is None:\n continue\n print('\\nChecking {}'.format(port.device))\n try:\n self.serial_port = TelemetrixAioSerial(port.device, 115200,\n telemetrix_aio_instance=self,\n close_loop_on_error=self.close_loop_on_shutdown)\n except SerialException:\n continue\n # create a list of serial ports that we opened\n serial_ports.append(self.serial_port)\n\n # display to the user\n print('\\t' + port.device)\n\n # clear out any possible data in the input buffer\n await self.serial_port.reset_input_buffer()\n\n # wait for arduino to reset\n print('\\nWaiting {} seconds(arduino_wait) for Arduino devices to '\n 'reset...'.format(self.arduino_wait))\n await asyncio.sleep(self.arduino_wait)\n\n print('\\nSearching for an Arduino configured with an arduino_instance = ',\n self.arduino_instance_id)\n\n for serial_port in serial_ports:\n self.serial_port = serial_port\n\n command = [PrivateConstants.ARE_U_THERE]\n await self._send_command(command)\n # provide time for the reply\n await asyncio.sleep(.1)\n\n i_am_here = await self.serial_port.read(3)\n\n if not i_am_here:\n continue\n\n # got an I am here message - is it the correct ID?\n if i_am_here[2] == self.arduino_instance_id:\n self.com_port = serial_port.com_port\n return\n\n async def _manual_open(self):\n\"\"\"\n Com port was specified by the user - try to open up that port\n\n \"\"\"\n # if port is not found, a serial exception will be thrown\n print('Opening {} ...'.format(self.com_port))\n self.serial_port = TelemetrixAioSerial(self.com_port, 115200,\n telemetrix_aio_instance=self,\n close_loop_on_error=self.close_loop_on_shutdown)\n\n print('Waiting {} seconds for the Arduino To Reset.'\n .format(self.arduino_wait))\n await asyncio.sleep(self.arduino_wait)\n command = [PrivateConstants.ARE_U_THERE]\n await self._send_command(command)\n # provide time for the reply\n await asyncio.sleep(.1)\n\n print(f'Searching for correct arduino_instance_id: {self.arduino_instance_id}')\n i_am_here = await self.serial_port.read(3)\n\n if not i_am_here:\n print(f'ERROR: correct arduino_instance_id not found')\n\n print('Correct arduino_instance_id found')\n\n async def _get_firmware_version(self):\n\"\"\"\n This method retrieves the Arduino4Telemetrix firmware version\n\n :returns: Firmata firmware version\n \"\"\"\n command = [PrivateConstants.GET_FIRMWARE_VERSION]\n await self._send_command(command)\n # provide time for the reply\n await asyncio.sleep(.1)\n firmware_version = await self.serial_port.read(5)\n\n return firmware_version\n\n async def analog_write(self, pin, value):\n\"\"\"\n Set the specified pin to the specified value.\n\n :param pin: arduino pin number\n\n :param value: pin value (maximum 16 bits)\n\n \"\"\"\n value_msb = value >> 8\n value_lsb = value & 0xff\n command = [PrivateConstants.ANALOG_WRITE, pin, value_msb, value_lsb]\n await self._send_command(command)\n\n async def digital_write(self, pin, value):\n\"\"\"\n Set the specified pin to the specified value.\n\n :param pin: arduino pin number\n\n :param value: pin value (1 or 0)\n\n \"\"\"\n command = [PrivateConstants.DIGITAL_WRITE, pin, value]\n await self._send_command(command)\n\n async def i2c_read(self, address, register, number_of_bytes,\n callback, i2c_port=0,\n write_register=True):\n\"\"\"\n Read the specified number of bytes from the specified register for\n the i2c device.\n\n\n :param address: i2c device address\n\n :param register: i2c register (or None if no register selection is needed)\n\n :param number_of_bytes: number of bytes to be read\n\n :param callback: Required callback function to report i2c data as a\n result of read command\n\n :param i2c_port: select the default port (0) or secondary port (1)\n\n :param write_register: If True, the register is written\n before read\n Else, the write is suppressed\n\n\n callback returns a data list:\n\n [I2C_READ_REPORT, address, register, count of data bytes,\n data bytes, time-stamp]\n\n \"\"\"\n if not callback:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('i2c_read: A Callback must be specified')\n\n await self._i2c_read_request(address, register, number_of_bytes,\n callback=callback, i2c_port=i2c_port,\n write_register=write_register)\n\n async def i2c_read_restart_transmission(self, address, register,\n number_of_bytes,\n callback, i2c_port=0,\n write_register=True):\n\"\"\"\n Read the specified number of bytes from the specified register for\n the i2c device. This restarts the transmission after the read. It is\n required for some i2c devices such as the MMA8452Q accelerometer.\n\n\n :param address: i2c device address\n\n :param register: i2c register (or None if no register\n selection is needed)\n\n :param number_of_bytes: number of bytes to be read\n\n :param callback: Required callback function to report i2c data as a\n result of read command\n\n :param i2c_port: select the default port (0) or secondary port (1)\n\n :param write_register: If True, the register is written\n before read\n Else, the write is suppressed\n\n callback returns a data list:\n\n [I2C_READ_REPORT, address, register, count of data bytes,\n data bytes, time-stamp]\n\n \"\"\"\n if not callback:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(\n 'i2c_read_restart_transmission: A Callback must be specified')\n\n await self._i2c_read_request(address, register, number_of_bytes,\n stop_transmission=False,\n callback=callback, i2c_port=i2c_port,\n write_register=write_register)\n\n async def _i2c_read_request(self, address, register, number_of_bytes,\n stop_transmission=True, callback=None,\n i2c_port=0, write_register=True):\n\"\"\"\n This method requests the read of an i2c device. Results are retrieved\n via callback.\n\n :param address: i2c device address\n\n :param register: register number (or None if no register selection is needed)\n\n :param number_of_bytes: number of bytes expected to be returned\n\n :param stop_transmission: stop transmission after read\n\n :param callback: Required callback function to report i2c data as a\n result of read command.\n\n :param i2c_port: select the default port (0) or secondary port (1)\n\n :param write_register: If True, the register is written\n before read\n Else, the write is suppressed\n\n \"\"\"\n if not i2c_port:\n if not self.i2c_1_active:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(\n 'I2C Read: set_pin_mode i2c never called for i2c port 1.')\n\n if i2c_port:\n if not self.i2c_2_active:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(\n 'I2C Read: set_pin_mode i2c never called for i2c port 2.')\n\n if not callback:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('I2C Read: A callback function must be specified.')\n\n if not i2c_port:\n self.i2c_callback = callback\n else:\n self.i2c_callback2 = callback\n\n if not register:\n register = 0\n\n if write_register:\n write_register = 1\n else:\n write_register = 0\n\n # message contains:\n # 1. address\n # 2. register\n # 3. number of bytes\n # 4. restart_transmission - True or False\n # 5. i2c port\n # 6. suppress write flag\n\n command = [PrivateConstants.I2C_READ, address, register, number_of_bytes,\n stop_transmission, i2c_port, write_register]\n await self._send_command(command)\n\n async def i2c_write(self, address, args, i2c_port=0):\n\"\"\"\n Write data to an i2c device.\n\n :param address: i2c device address\n\n :param i2c_port: 0= port 1, 1 = port 2\n\n :param args: A variable number of bytes to be sent to the device\n passed in as a list\n\n \"\"\"\n if not i2c_port:\n if not self.i2c_1_active:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(\n 'I2C Write: set_pin_mode i2c never called for i2c port 1.')\n\n if i2c_port:\n if not self.i2c_2_active:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(\n 'I2C Write: set_pin_mode i2c never called for i2c port 2.')\n\n command = [PrivateConstants.I2C_WRITE, len(args), address, i2c_port]\n\n for item in args:\n command.append(item)\n\n await self._send_command(command)\n\n async def loop_back(self, start_character, callback):\n\"\"\"\n This is a debugging method to send a character to the\n Arduino device, and have the device loop it back.\n\n :param start_character: The character to loop back. It should be\n an integer.\n\n :param callback: Looped back character will appear in the callback method\n\n \"\"\"\n\n if not callback:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('loop_back: A callback function must be specified.')\n command = [PrivateConstants.LOOP_COMMAND, ord(start_character)]\n self.loop_back_callback = callback\n await self._send_command(command)\n\n async def set_analog_scan_interval(self, interval):\n\"\"\"\n Set the analog scanning interval.\n\n :param interval: value of 0 - 255 - milliseconds\n \"\"\"\n\n if 0 <= interval <= 255:\n command = [PrivateConstants.SET_ANALOG_SCANNING_INTERVAL, interval]\n await self._send_command(command)\n else:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('Analog interval must be between 0 and 255')\n\n async def set_pin_mode_analog_input(self, pin_number, differential=0, callback=None):\n\"\"\"\n Set a pin as an analog input.\n\n :param pin_number: arduino pin number\n\n :param callback: async callback function\n\n :param differential: difference in previous to current value before\n report will be generated\n\n callback returns a data list:\n\n [pin_type, pin_number, pin_value, raw_time_stamp]\n\n The pin_type for analog input pins = 3\n\n \"\"\"\n\n if not callback:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(\n 'set_pin_mode_analog_input: A callback function must be specified.')\n\n await self._set_pin_mode(pin_number, PrivateConstants.AT_ANALOG,\n differential, callback=callback)\n\n async def set_pin_mode_analog_output(self, pin_number):\n\"\"\"\n\n Set a pin as a pwm (analog output) pin.\n\n :param pin_number:arduino pin number\n\n \"\"\"\n\n await self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT, differential=0,\n callback=None)\n\n async def set_pin_mode_digital_input(self, pin_number, callback):\n\"\"\"\n Set a pin as a digital input.\n\n :param pin_number: arduino pin number\n\n :param callback: async callback function\n\n callback returns a data list:\n\n [pin_type, pin_number, pin_value, raw_time_stamp]\n\n The pin_type for all digital input pins = 2\n\n \"\"\"\n await self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT, differential=0,\n callback=callback)\n\n async def set_pin_mode_digital_input_pullup(self, pin_number, callback):\n\"\"\"\n Set a pin as a digital input with pullup enabled.\n\n :param pin_number: arduino pin number\n\n :param callback: async callback function\n\n callback returns a data list:\n\n [pin_type, pin_number, pin_value, raw_time_stamp]\n\n The pin_type for all digital input pins = 2\n\n \"\"\"\n if not callback:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(\n 'set_pin_mode_digital_input_pullup: A callback function must be specified.')\n\n await self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT_PULLUP,\n differential=0, callback=callback)\n\n async def set_pin_mode_digital_output(self, pin_number):\n\"\"\"\n Set a pin as a digital output pin.\n\n :param pin_number: arduino pin number\n \"\"\"\n\n await self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT, differential=0,\n callback=None)\n\n # noinspection PyIncorrectDocstring\n async def set_pin_mode_i2c(self, i2c_port=0):\n\"\"\"\n Establish the standard Arduino i2c pins for i2c utilization.\n\n :param i2c_port: 0 = i2c1, 1 = i2c2\n\n NOTES: 1. THIS METHOD MUST BE CALLED BEFORE ANY I2C REQUEST IS MADE\n 2. Callbacks are set within the individual i2c read methods of this\n API.\n\n See i2c_read, or i2c_read_restart_transmission.\n\n \"\"\"\n # test for i2c port 2\n if i2c_port:\n # if not previously activated set it to activated\n # and the send a begin message for this port\n if not self.i2c_2_active:\n self.i2c_2_active = True\n else:\n return\n # port 1\n else:\n if not self.i2c_1_active:\n self.i2c_1_active = True\n else:\n return\n\n command = [PrivateConstants.I2C_BEGIN, i2c_port]\n await self._send_command(command)\n\n async def set_pin_mode_dht(self, pin, callback=None, dht_type=22):\n\"\"\"\n\n :param pin: connection pin\n\n :param callback: callback function\n\n :param dht_type: either 22 for DHT22 or 11 for DHT11\n\n Error Callback: [DHT REPORT Type, DHT_ERROR_NUMBER, PIN, DHT_TYPE, Time]\n\n Valid Data Callback: DHT REPORT Type, DHT_DATA=, PIN, DHT_TYPE, Humidity,\n Temperature,\n Time]\n\n \"\"\"\n if self.reported_features & PrivateConstants.DHT_FEATURE:\n\n if not callback:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('set_pin_mode_dht: A Callback must be specified')\n\n if self.dht_count < PrivateConstants.MAX_DHTS - 1:\n self.dht_callbacks[pin] = callback\n self.dht_count += 1\n\n if dht_type != 22 and dht_type != 11:\n dht_type = 22\n\n command = [PrivateConstants.DHT_NEW, pin, dht_type]\n await self._send_command(command)\n else:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(\n f'Maximum Number Of DHTs Exceeded - set_pin_mode_dht fails for pin {pin}')\n\n else:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(f'The DHT feature is disabled in the server.')\n\n async def set_pin_mode_servo(self, pin_number, min_pulse=544, max_pulse=2400):\n\"\"\"\n\n Attach a pin to a servo motor\n\n :param pin_number: pin\n\n :param min_pulse: minimum pulse width\n\n :param max_pulse: maximum pulse width\n\n \"\"\"\n if self.reported_features & PrivateConstants.SERVO_FEATURE:\n\n minv = (min_pulse).to_bytes(2, byteorder=\"big\")\n maxv = (max_pulse).to_bytes(2, byteorder=\"big\")\n\n command = [PrivateConstants.SERVO_ATTACH, pin_number,\n minv[0], minv[1], maxv[0], maxv[1]]\n await self._send_command(command)\n else:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(f'The SERVO feature is disabled in the server.')\n\n async def set_pin_mode_sonar(self, trigger_pin, echo_pin,\n callback):\n\"\"\"\n\n :param trigger_pin:\n\n :param echo_pin:\n\n :param callback: callback\n\n \"\"\"\n if self.reported_features & PrivateConstants.SONAR_FEATURE:\n\n if not callback:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('set_pin_mode_sonar: A Callback must be specified')\n\n if self.sonar_count < PrivateConstants.MAX_SONARS - 1:\n self.sonar_callbacks[trigger_pin] = callback\n self.sonar_count += 1\n\n command = [PrivateConstants.SONAR_NEW, trigger_pin, echo_pin]\n await self._send_command(command)\n else:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(\n f'Maximum Number Of Sonars Exceeded - set_pin_mode_sonar fails for pin {trigger_pin}')\n else:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(f'The SONAR feature is disabled in the server.')\n\n async def set_pin_mode_spi(self, chip_select_list=None):\n\"\"\"\n Specify the list of chip select pins.\n\n Standard Arduino MISO, MOSI and CLK pins are used for the board in use.\n\n Chip Select is any digital output capable pin.\n\n :param chip_select_list: this is a list of pins to be used for chip select.\n The pins will be configured as output, and set to high\n ready to be used for chip select.\n NOTE: You must specify the chips select pins here!\n\n\n command message: [command, number of cs pins, [cs pins...]]\n \"\"\"\n if self.reported_features & PrivateConstants.SPI_FEATURE:\n\n if type(chip_select_list) != list:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('chip_select_list must be in the form of a list')\n if not chip_select_list:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('Chip select pins were not specified')\n\n self.spi_enabled = True\n\n command = [PrivateConstants.SPI_INIT, len(chip_select_list)]\n\n for pin in chip_select_list:\n command.append(pin)\n self.cs_pins_enabled.append(pin)\n await self._send_command(command)\n else:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(f'The SPI feature is disabled in the server.')\n\n # async def set_pin_mode_stepper(self, interface=1, pin1=2, pin2=3, pin3=4,\n # pin4=5, enable=True):\n # \"\"\"\n # Stepper motor support is implemented as a proxy for the\n # the AccelStepper library for the Arduino.\n #\n # This feature is compatible with the TB6600 Motor Driver\n #\n # Note: It may not work for other driver types!\n #\n # https://github.com/waspinator/AccelStepper\n #\n # Instantiate a stepper motor.\n #\n # Initialize the interface and pins for a stepper motor.\n #\n # :param interface: Motor Interface Type:\n #\n # 1 = Stepper Driver, 2 driver pins required\n #\n # 2 = FULL2WIRE 2 wire stepper, 2 motor pins required\n #\n # 3 = FULL3WIRE 3 wire stepper, such as HDD spindle,\n # 3 motor pins required\n #\n # 4 = FULL4WIRE, 4 wire full stepper, 4 motor pins\n # required\n #\n # 6 = HALF3WIRE, 3 wire half stepper, such as HDD spindle,\n # 3 motor pins required\n #\n # 8 = HALF4WIRE, 4 wire half stepper, 4 motor pins required\n #\n # :param pin1: Arduino digital pin number for motor pin 1\n #\n # :param pin2: Arduino digital pin number for motor pin 2\n #\n # :param pin3: Arduino digital pin number for motor pin 3\n #\n # :param pin4: Arduino digital pin number for motor pin 4\n #\n # :param enable: If this is true, the output pins at construction time.\n #\n # :return: Motor Reference number\n # \"\"\"\n # if self.reported_features & PrivateConstants.STEPPERS_FEATURE:\n #\n # if self.number_of_steppers == self.max_number_of_steppers:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('Maximum number of steppers has already been assigned')\n #\n # if interface not in self.valid_stepper_interfaces:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('Invalid stepper interface')\n #\n # self.number_of_steppers += 1\n #\n # motor_id = self.next_stepper_assigned\n # self.next_stepper_assigned += 1\n # self.stepper_info_list[motor_id]['instance'] = True\n #\n # # build message and send message to server\n # command = [PrivateConstants.SET_PIN_MODE_STEPPER, motor_id, interface, pin1,\n # pin2, pin3, pin4, enable]\n # await self._send_command(command)\n #\n # # return motor id\n # return motor_id\n # else:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError(f'The Stepper feature is disabled in the server.')\n\n async def sonar_disable(self):\n\"\"\"\n Disable sonar scanning for all sonar sensors\n \"\"\"\n command = [PrivateConstants.SONAR_DISABLE]\n await self._send_command(command)\n\n async def sonar_enable(self):\n\"\"\"\n Enable sonar scanning for all sonar sensors\n \"\"\"\n command = [PrivateConstants.SONAR_ENABLE]\n await self._send_command(command)\n\n async def spi_cs_control(self, chip_select_pin, select):\n\"\"\"\n Control an SPI chip select line\n :param chip_select_pin: pin connected to CS\n\n :param select: 0=select, 1=deselect\n \"\"\"\n if not self.spi_enabled:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(f'spi_cs_control: SPI interface is not enabled.')\n\n if chip_select_pin not in self.cs_pins_enabled:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(f'spi_cs_control: chip select pin never enabled.')\n command = [PrivateConstants.SPI_CS_CONTROL, chip_select_pin, select]\n await self._send_command(command)\n\n async def spi_read_blocking(self, chip_select, register_selection,\n number_of_bytes_to_read,\n call_back=None):\n\"\"\"\n Read the specified number of bytes from the specified SPI port and\n call the callback function with the reported data.\n\n :param chip_select: chip select pin\n\n :param register_selection: Register to be selected for read.\n\n :param number_of_bytes_to_read: Number of bytes to read\n\n :param call_back: Required callback function to report spi data as a\n result of read command\n\n\n callback returns a data list:\n [SPI_READ_REPORT, chip select pin, SPI Register, count of data bytes read,\n data bytes, time-stamp]\n SPI_READ_REPORT = 13\n\n \"\"\"\n\n if not self.spi_enabled:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(f'spi_read_blocking: SPI interface is not enabled.')\n\n if not call_back:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('spi_read_blocking: A Callback must be specified')\n\n self.spi_callback = call_back\n\n command = [PrivateConstants.SPI_READ_BLOCKING, chip_select,\n number_of_bytes_to_read,\n register_selection]\n\n await self._send_command(command)\n\n async def spi_set_format(self, clock_divisor, bit_order, data_mode):\n\"\"\"\n Configure how the SPI serializes and de-serializes data on the wire.\n\n See Arduino SPI reference materials for details.\n\n :param clock_divisor: 1 - 255\n\n :param bit_order:\n\n LSBFIRST = 0\n\n MSBFIRST = 1 (default)\n\n :param data_mode:\n\n SPI_MODE0 = 0x00 (default)\n\n SPI_MODE1 = 1\n\n SPI_MODE2 = 2\n\n SPI_MODE3 = 3\n\n \"\"\"\n\n if not self.spi_enabled:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(f'spi_set_format: SPI interface is not enabled.')\n\n if not 0 < clock_divisor <= 255:\n raise RuntimeError(f'spi_set_format: illegal clock divisor selected.')\n if bit_order not in [0, 1]:\n raise RuntimeError(f'spi_set_format: illegal bit_order selected.')\n if data_mode not in [0, 1, 2, 3]:\n raise RuntimeError(f'spi_set_format: illegal data_order selected.')\n\n command = [PrivateConstants.SPI_SET_FORMAT, clock_divisor, bit_order,\n data_mode]\n await self._send_command(command)\n\n async def spi_write_blocking(self, chip_select, bytes_to_write):\n\"\"\"\n Write a list of bytes to the SPI device.\n\n :param chip_select: chip select pin\n\n :param bytes_to_write: A list of bytes to write. This must\n be in the form of a list.\n\n \"\"\"\n\n if not self.spi_enabled:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(f'spi_write_blocking: SPI interface is not enabled.')\n\n if type(bytes_to_write) is not list:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('spi_write_blocking: bytes_to_write must be a list.')\n\n command = [PrivateConstants.SPI_WRITE_BLOCKING, chip_select, len(bytes_to_write)]\n\n for data in bytes_to_write:\n command.append(data)\n\n await self._send_command(command)\n\n # async def set_pin_mode_one_wire(self, pin):\n # \"\"\"\n # Initialize the one wire serial bus.\n #\n # :param pin: Data pin connected to the OneWire device\n # \"\"\"\n # self.onewire_enabled = True\n # command = [PrivateConstants.ONE_WIRE_INIT, pin]\n # await self._send_command(command)\n #\n # async def onewire_reset(self, callback=None):\n # \"\"\"\n # Reset the onewire device\n #\n # :param callback: required function to report reset result\n #\n # callback returns a list:\n # [ReportType = 14, Report Subtype = 25, reset result byte,\n # timestamp]\n # \"\"\"\n # if not self.onewire_enabled:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError(f'onewire_reset: OneWire interface is not enabled.')\n # if not callback:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('onewire_reset: A Callback must be specified')\n #\n # self.onewire_callback = callback\n #\n # command = [PrivateConstants.ONE_WIRE_RESET]\n # await self._send_command(command)\n #\n # async def onewire_select(self, device_address):\n # \"\"\"\n # Select a device based on its address\n # :param device_address: A bytearray of 8 bytes\n # \"\"\"\n # if not self.onewire_enabled:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError(f'onewire_select: OneWire interface is not enabled.')\n #\n # if type(device_address) is not list:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('onewire_select: device address must be an array of 8 '\n # 'bytes.')\n #\n # if len(device_address) != 8:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('onewire_select: device address must be an array of 8 '\n # 'bytes.')\n # command = [PrivateConstants.ONE_WIRE_SELECT]\n # for data in device_address:\n # command.append(data)\n # await self._send_command(command)\n #\n # async def onewire_skip(self):\n # \"\"\"\n # Skip the device selection. This only works if you have a\n # single device, but you can avoid searching and use this to\n # immediately access your device.\n # \"\"\"\n # if not self.onewire_enabled:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError(f'onewire_skip: OneWire interface is not enabled.')\n #\n # command = [PrivateConstants.ONE_WIRE_SKIP]\n # await self._send_command(command)\n #\n # async def onewire_write(self, data, power=0):\n # \"\"\"\n # Write a byte to the onewire device. If 'power' is one\n # then the wire is held high at the end for\n # parasitically powered devices. You\n # are responsible for eventually de-powering it by calling\n # another read or write.\n #\n # :param data: byte to write.\n # :param power: power control (see above)\n # \"\"\"\n # if not self.onewire_enabled:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError(f'onewire_write: OneWire interface is not enabled.')\n # if 0 < data < 255:\n # command = [PrivateConstants.ONE_WIRE_WRITE, data, power]\n # await self._send_command(command)\n # else:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('onewire_write: Data must be no larger than 255')\n #\n # async def onewire_read(self, callback=None):\n # \"\"\"\n # Read a byte from the onewire device\n # :param callback: required function to report onewire data as a\n # result of read command\n #\n #\n # callback returns a data list:\n # [ONEWIRE_REPORT, ONEWIRE_READ=29, data byte, time-stamp]\n #\n # ONEWIRE_REPORT = 14\n # \"\"\"\n # if not self.onewire_enabled:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError(f'onewire_read: OneWire interface is not enabled.')\n #\n # if not callback:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('onewire_read A Callback must be specified')\n #\n # self.onewire_callback = callback\n #\n # command = [PrivateConstants.ONE_WIRE_READ]\n # await self._send_command(command)\n #\n # async def onewire_reset_search(self):\n # \"\"\"\n # Begin a new search. The next use of search will begin at the first device\n # \"\"\"\n #\n # if not self.onewire_enabled:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError(f'onewire_reset_search: OneWire interface is not '\n # f'enabled.')\n # else:\n # command = [PrivateConstants.ONE_WIRE_RESET_SEARCH]\n # await self._send_command(command)\n #\n # async def onewire_search(self, callback=None):\n # \"\"\"\n # Search for the next device. The device address will returned in the callback.\n # If a device is found, the 8 byte address is contained in the callback.\n # If no more devices are found, the address returned contains all elements set\n # to 0xff.\n #\n # :param callback: required function to report a onewire device address\n #\n # callback returns a data list:\n # [ONEWIRE_REPORT, ONEWIRE_SEARCH=31, 8 byte address, time-stamp]\n #\n # ONEWIRE_REPORT = 14\n # \"\"\"\n # if not self.onewire_enabled:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError(f'onewire_search: OneWire interface is not enabled.')\n #\n # if not callback:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('onewire_read A Callback must be specified')\n #\n # self.onewire_callback = callback\n #\n # command = [PrivateConstants.ONE_WIRE_SEARCH]\n # await self._send_command(command)\n #\n # async def onewire_crc8(self, address_list, callback=None):\n # \"\"\"\n # Compute a CRC check on an array of data.\n # :param address_list:\n #\n # :param callback: required function to report a onewire device address\n #\n # callback returns a data list:\n # [ONEWIRE_REPORT, ONEWIRE_CRC8=32, CRC, time-stamp]\n #\n # ONEWIRE_REPORT = 14\n #\n # \"\"\"\n #\n # if not self.onewire_enabled:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError(f'onewire_crc8: OneWire interface is not enabled.')\n #\n # if not callback:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('onewire_crc8 A Callback must be specified')\n #\n # if type(address_list) is not list:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('onewire_crc8: address list must be a list.')\n #\n # self.onewire_callback = callback\n #\n # address_length = len(address_list)\n #\n # command = [PrivateConstants.ONE_WIRE_CRC8, address_length - 1]\n #\n # for data in address_list:\n # command.append(data)\n #\n # await self._send_command(command)\n\n async def _set_pin_mode(self, pin_number, pin_state, differential, callback):\n\"\"\"\n A private method to set the various pin modes.\n\n :param pin_number: arduino pin number\n\n :param pin_state: INPUT/OUTPUT/ANALOG/PWM/PULLUP - for SERVO use\n servo_config()\n For DHT use: set_pin_mode_dht\n\n :param differential: for analog inputs - threshold\n value to be achieved for report to\n be generated\n\n :param callback: A reference to an async call back function to be\n called when pin data value changes\n\n \"\"\"\n if not callback and pin_state != PrivateConstants.AT_OUTPUT:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('_set_pin_mode: A Callback must be specified')\n else:\n if pin_state == PrivateConstants.AT_INPUT:\n command = [PrivateConstants.SET_PIN_MODE, pin_number,\n PrivateConstants.AT_INPUT, 1]\n self.digital_callbacks[pin_number] = callback\n elif pin_state == PrivateConstants.AT_INPUT_PULLUP:\n command = [PrivateConstants.SET_PIN_MODE, pin_number,\n PrivateConstants.AT_INPUT_PULLUP, 1]\n self.digital_callbacks[pin_number] = callback\n elif pin_state == PrivateConstants.AT_ANALOG:\n command = [PrivateConstants.SET_PIN_MODE, pin_number,\n PrivateConstants.AT_ANALOG,\n differential >> 8, differential & 0xff, 1]\n self.analog_callbacks[pin_number] = callback\n elif pin_state == PrivateConstants.AT_OUTPUT:\n command = [PrivateConstants.SET_PIN_MODE, pin_number,\n PrivateConstants.AT_OUTPUT, 1]\n else:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('Unknown pin state')\n\n if command:\n await self._send_command(command)\n\n await asyncio.sleep(.05)\n\n async def servo_detach(self, pin_number):\n\"\"\"\n Detach a servo for reuse\n :param pin_number: attached pin\n \"\"\"\n command = [PrivateConstants.SERVO_DETACH, pin_number]\n await self._send_command(command)\n\n async def servo_write(self, pin_number, angle):\n\"\"\"\n\n Set a servo attached to a pin to a given angle.\n\n :param pin_number: pin\n\n :param angle: angle (0-180)\n\n \"\"\"\n command = [PrivateConstants.SERVO_WRITE, pin_number, angle]\n await self._send_command(command)\n\n # async def stepper_move_to(self, motor_id, position):\n # \"\"\"\n # Set an absolution target position. If position is positive, the movement is\n # clockwise, else it is counter-clockwise.\n #\n # The run() function (below) will try to move the motor (at most one step per call)\n # from the current position to the target position set by the most\n # recent call to this function. Caution: moveTo() also recalculates the\n # speed for the next step.\n # If you are trying to use constant speed movements, you should call setSpeed()\n # after calling moveTo().\n #\n # :param motor_id: motor id: 0 - 3\n #\n # :param position: target position. Maximum value is 32 bits.\n # \"\"\"\n #\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_move_to: Invalid motor_id.')\n #\n # if position < 0:\n # polarity = 1\n # else:\n # polarity = 0\n # position = abs(position)\n #\n # position_bytes = list(position.to_bytes(4, 'big', signed=True))\n #\n # command = [PrivateConstants.STEPPER_MOVE_TO, motor_id]\n # for value in position_bytes:\n # command.append(value)\n # command.append(polarity)\n #\n # await self._send_command(command)\n #\n # async def stepper_move(self, motor_id, relative_position):\n # \"\"\"\n # Set the target position relative to the current position.\n #\n # :param motor_id: motor id: 0 - 3\n #\n # :param relative_position: The desired position relative to the current\n # position. Negative is anticlockwise from\n # the current position. Maximum value is 32 bits.\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_move: Invalid motor_id.')\n #\n # if relative_position < 0:\n # polarity = 1\n # else:\n # polarity = 0\n # position = abs(relative_position)\n #\n # position_bytes = list(position.to_bytes(4, 'big', signed=True))\n #\n # command = [PrivateConstants.STEPPER_MOVE, motor_id]\n # for value in position_bytes:\n # command.append(value)\n # command.append(polarity)\n # await self._send_command(command)\n #\n # async def stepper_run(self, motor_id, completion_callback=None):\n # \"\"\"\n # This method steps the selected motor based on the current speed.\n #\n # Once called, the server will continuously attempt to step the motor.\n #\n # :param motor_id: 0 - 3\n #\n # :param completion_callback: call back function to receive motion complete\n # notification\n #\n # callback returns a data list:\n #\n # [report_type, motor_id, raw_time_stamp]\n #\n # The report_type = 19\n # \"\"\"\n # if not completion_callback:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_run: A motion complete callback must be '\n # 'specified.')\n #\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_run: Invalid motor_id.')\n #\n # self.stepper_info_list[motor_id]['motion_complete_callback'] = completion_callback\n # command = [PrivateConstants.STEPPER_RUN, motor_id]\n # await self._send_command(command)\n #\n # async def stepper_run_speed(self, motor_id):\n # \"\"\"\n # This method steps the selected motor based at a constant speed as set by the most\n # recent call to stepper_set_max_speed(). The motor will run continuously.\n #\n # Once called, the server will continuously attempt to step the motor.\n #\n # :param motor_id: 0 - 3\n #\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_run_speed: Invalid motor_id.')\n #\n # command = [PrivateConstants.STEPPER_RUN_SPEED, motor_id]\n # await self._send_command(command)\n #\n # async def stepper_set_max_speed(self, motor_id, max_speed):\n # \"\"\"\n # Sets the maximum permitted speed. The stepper_run() function will accelerate\n # up to the speed set by this function.\n #\n # Caution: the maximum speed achievable depends on your processor and clock speed.\n # The default maxSpeed is 1 step per second.\n #\n # Caution: Speeds that exceed the maximum speed supported by the processor may\n # result in non-linear accelerations and decelerations.\n #\n # :param motor_id: 0 - 3\n #\n # :param max_speed: 1 - 1000\n # \"\"\"\n #\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_set_max_speed: Invalid motor_id.')\n #\n # if not 1 < max_speed <= 1000:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_set_max_speed: Speed range is 1 - 1000.')\n #\n # self.stepper_info_list[motor_id]['max_speed'] = max_speed\n # max_speed_msb = (max_speed & 0xff00) >> 8\n # max_speed_lsb = max_speed & 0xff\n #\n # command = [PrivateConstants.STEPPER_SET_MAX_SPEED, motor_id, max_speed_msb,\n # max_speed_lsb]\n # await self._send_command(command)\n #\n # async def stepper_get_max_speed(self, motor_id):\n # \"\"\"\n # Returns the maximum speed configured for this stepper\n # that was previously set by stepper_set_max_speed()\n #\n # Value is stored in the client, so no callback is required.\n #\n # :param motor_id: 0 - 3\n #\n # :return: The currently configured maximum speed.\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_max_speed: Invalid motor_id.')\n #\n # return self.stepper_info_list[motor_id]['max_speed']\n #\n # async def stepper_set_acceleration(self, motor_id, acceleration):\n # \"\"\"\n # Sets the acceleration/deceleration rate.\n #\n # :param motor_id: 0 - 3\n #\n # :param acceleration: The desired acceleration in steps per second\n # per second. Must be > 0.0. This is an\n # expensive call since it requires a square\n # root to be calculated on the server.\n # Dont call more often than needed.\n #\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_set_acceleration: Invalid motor_id.')\n #\n # if not 1 < acceleration <= 1000:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_set_acceleration: Acceleration range is 1 - '\n # '1000.')\n #\n # self.stepper_info_list[motor_id]['acceleration'] = acceleration\n #\n # max_accel_msb = acceleration >> 8\n # max_accel_lsb = acceleration & 0xff\n #\n # command = [PrivateConstants.STEPPER_SET_ACCELERATION, motor_id, max_accel_msb,\n # max_accel_lsb]\n # await self._send_command(command)\n #\n # async def stepper_set_speed(self, motor_id, speed):\n # \"\"\"\n # Sets the desired constant speed for use with stepper_run_speed().\n #\n # :param motor_id: 0 - 3\n #\n # :param speed: 0 - 1000 The desired constant speed in steps per\n # second. Positive is clockwise. Speeds of more than 1000 steps per\n # second are unreliable. Speed accuracy depends on the Arduino\n # crystal. Jitter depends on how frequently you call the\n # stepper_run_speed() method.\n # The speed will be limited by the current value of\n # stepper_set_max_speed().\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_set_speed: Invalid motor_id.')\n #\n # if not 0 < speed <= 1000:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_set_speed: Speed range is 0 - '\n # '1000.')\n #\n # self.stepper_info_list[motor_id]['speed'] = speed\n #\n # speed_msb = speed >> 8\n # speed_lsb = speed & 0xff\n #\n # command = [PrivateConstants.STEPPER_SET_SPEED, motor_id, speed_msb, speed_lsb]\n # await self._send_command(command)\n #\n # async def stepper_get_speed(self, motor_id):\n # \"\"\"\n # Returns the most recently set speed.\n # that was previously set by stepper_set_speed();\n #\n # Value is stored in the client, so no callback is required.\n #\n # :param motor_id: 0 - 3\n #\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_get_speed: Invalid motor_id.')\n #\n # return self.stepper_info_list[motor_id]['speed']\n #\n # async def stepper_get_distance_to_go(self, motor_id, distance_to_go_callback):\n # \"\"\"\n # Request the distance from the current position to the target position\n # from the server.\n #\n # :param motor_id: 0 - 3\n #\n # :param distance_to_go_callback: required callback function to receive report\n #\n # :return: The distance to go is returned via the callback as a list:\n #\n # [REPORT_TYPE=15, motor_id, distance in steps, time_stamp]\n #\n # A positive distance is clockwise from the current position.\n #\n # \"\"\"\n # if not distance_to_go_callback:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_get_distance_to_go Read: A callback function must be specified.')\n #\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_get_distance_to_go: Invalid motor_id.')\n # self.stepper_info_list[motor_id][\n # 'distance_to_go_callback'] = distance_to_go_callback\n # command = [PrivateConstants.STEPPER_GET_DISTANCE_TO_GO, motor_id]\n # await self._send_command(command)\n #\n # async def stepper_get_target_position(self, motor_id, target_callback):\n # \"\"\"\n # Request the most recently set target position from the server.\n #\n # :param motor_id: 0 - 3\n #\n # :param target_callback: required callback function to receive report\n #\n # :return: The distance to go is returned via the callback as a list:\n #\n # [REPORT_TYPE=16, motor_id, target position in steps, time_stamp]\n #\n # Positive is clockwise from the 0 position.\n #\n # \"\"\"\n # if not target_callback:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError(\n # 'stepper_get_target_position Read: A callback function must be specified.')\n #\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_get_target_position: Invalid motor_id.')\n #\n # self.stepper_info_list[motor_id][\n # 'target_position_callback'] = target_callback\n #\n # command = [PrivateConstants.STEPPER_GET_TARGET_POSITION, motor_id]\n # await self._send_command(command)\n #\n # async def stepper_get_current_position(self, motor_id, current_position_callback):\n # \"\"\"\n # Request the current motor position from the server.\n #\n # :param motor_id: 0 - 3\n #\n # :param current_position_callback: required callback function to receive report\n #\n # :return: The current motor position returned via the callback as a list:\n #\n # [REPORT_TYPE=17, motor_id, current position in steps, time_stamp]\n #\n # Positive is clockwise from the 0 position.\n # \"\"\"\n # if not current_position_callback:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError(\n # 'stepper_get_current_position Read: A callback function must be specified.')\n #\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_get_current_position: Invalid motor_id.')\n #\n # self.stepper_info_list[motor_id]['current_position_callback'] = current_position_callback\n #\n # command = [PrivateConstants.STEPPER_GET_CURRENT_POSITION, motor_id]\n # await self._send_command(command)\n #\n # async def stepper_set_current_position(self, motor_id, position):\n # \"\"\"\n # Resets the current position of the motor, so that wherever the motor\n # happens to be right now is considered to be the new 0 position. Useful\n # for setting a zero position on a stepper after an initial hardware\n # positioning move.\n #\n # Has the side effect of setting the current motor speed to 0.\n #\n # :param motor_id: 0 - 3\n #\n # :param position: Position in steps. This is a 32 bit value\n # \"\"\"\n #\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_set_current_position: Invalid motor_id.')\n # position_bytes = list(position.to_bytes(4, 'big', signed=True))\n #\n # command = [PrivateConstants.STEPPER_SET_CURRENT_POSITION, motor_id]\n # for value in position_bytes:\n # command.append(value)\n # await self._send_command(command)\n #\n # async def stepper_run_speed_to_position(self, motor_id, completion_callback=None):\n # \"\"\"\n # Runs the motor at the currently selected speed until the target position is\n # reached.\n #\n # Does not implement accelerations.\n #\n # :param motor_id: 0 - 3\n #\n # :param completion_callback: call back function to receive motion complete\n # notification\n #\n # callback returns a data list:\n #\n # [report_type, motor_id, raw_time_stamp]\n #\n # The report_type = 19\n # \"\"\"\n # if not completion_callback:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_run_speed_to_position: A motion complete '\n # 'callback must be '\n # 'specified.')\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_run_speed_to_position: Invalid motor_id.')\n #\n # self.stepper_info_list[motor_id]['motion_complete_callback'] = completion_callback\n # command = [PrivateConstants.STEPPER_RUN_SPEED_TO_POSITION, motor_id]\n # await self._send_command(command)\n #\n # async def stepper_stop(self, motor_id):\n # \"\"\"\n # Sets a new target position that causes the stepper\n # to stop as quickly as possible, using the current speed and\n # acceleration parameters.\n #\n # :param motor_id: 0 - 3\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_stop: Invalid motor_id.')\n #\n # command = [PrivateConstants.STEPPER_STOP, motor_id]\n # await self._send_command(command)\n #\n # async def stepper_disable_outputs(self, motor_id):\n # \"\"\"\n # Disable motor pin outputs by setting them all LOW.\n #\n # Depending on the design of your electronics this may turn off\n # the power to the motor coils, saving power.\n #\n # This is useful to support Arduino low power modes: disable the outputs\n # during sleep and then re-enable with enableOutputs() before stepping\n # again.\n #\n # If the enable Pin is defined, sets it to OUTPUT mode and clears\n # the pin to disabled.\n #\n # :param motor_id: 0 - 3\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_disable_outputs: Invalid motor_id.')\n #\n # command = [PrivateConstants.STEPPER_DISABLE_OUTPUTS, motor_id]\n # await self._send_command(command)\n #\n # async def stepper_enable_outputs(self, motor_id):\n # \"\"\"\n # Enable motor pin outputs by setting the motor pins to OUTPUT\n # mode.\n #\n # If the enable Pin is defined, sets it to OUTPUT mode and sets\n # the pin to enabled.\n #\n # :param motor_id: 0 - 3\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_enable_outputs: Invalid motor_id.')\n #\n # command = [PrivateConstants.STEPPER_ENABLE_OUTPUTS, motor_id]\n # await self._send_command(command)\n #\n # async def stepper_set_min_pulse_width(self, motor_id, minimum_width):\n # \"\"\"\n # Sets the minimum pulse width allowed by the stepper driver.\n #\n # The minimum practical pulse width is approximately 20 microseconds.\n #\n # Times less than 20 microseconds will usually result in 20 microseconds or so.\n #\n # :param motor_id: 0 -3\n #\n # :param minimum_width: A 16 bit unsigned value expressed in microseconds.\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_set_min_pulse_width: Invalid motor_id.')\n #\n # if not 0 < minimum_width <= 0xff:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_set_min_pulse_width: Pulse width range = '\n # '0-0xffff.')\n #\n # width_msb = minimum_width >> 8\n # width_lsb = minimum_width & 0xff\n #\n # command = [PrivateConstants.STEPPER_SET_MINIMUM_PULSE_WIDTH, motor_id, width_msb,\n # width_lsb]\n # await self._send_command(command)\n #\n # async def stepper_set_enable_pin(self, motor_id, pin=0xff):\n # \"\"\"\n # Sets the enable pin number for stepper drivers.\n # 0xFF indicates unused (default).\n #\n # Otherwise, if a pin is set, the pin will be turned on when\n # enableOutputs() is called and switched off when disableOutputs()\n # is called.\n #\n # :param motor_id: 0 - 4\n # :param pin: 0-0xff\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_set_enable_pin: Invalid motor_id.')\n #\n # if not 0 < pin <= 0xff:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_set_enable_pin: Pulse width range = '\n # '0-0xff.')\n # command = [PrivateConstants.STEPPER_SET_ENABLE_PIN, motor_id, pin]\n #\n # await self._send_command(command)\n #\n # async def stepper_set_3_pins_inverted(self, motor_id, direction=False, step=False,\n # enable=False):\n # \"\"\"\n # Sets the inversion for stepper driver pins.\n #\n # :param motor_id: 0 - 3\n #\n # :param direction: True=inverted or False\n #\n # :param step: True=inverted or False\n #\n # :param enable: True=inverted or False\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_set_3_pins_inverted: Invalid motor_id.')\n #\n # command = [PrivateConstants.STEPPER_SET_3_PINS_INVERTED, motor_id, direction,\n # step, enable]\n #\n # await self._send_command(command)\n #\n # async def stepper_set_4_pins_inverted(self, motor_id, pin1_invert=False,\n # pin2_invert=False,\n # pin3_invert=False, pin4_invert=False, enable=False):\n # \"\"\"\n # Sets the inversion for 2, 3 and 4 wire stepper pins\n #\n # :param motor_id: 0 - 3\n #\n # :param pin1_invert: True=inverted or False\n #\n # :param pin2_invert: True=inverted or False\n #\n # :param pin3_invert: True=inverted or False\n #\n # :param pin4_invert: True=inverted or False\n #\n # :param enable: True=inverted or False\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_set_4_pins_inverted: Invalid motor_id.')\n #\n # command = [PrivateConstants.STEPPER_SET_4_PINS_INVERTED, motor_id, pin1_invert,\n # pin2_invert, pin3_invert, pin4_invert, enable]\n #\n # await self._send_command(command)\n #\n # async def stepper_is_running(self, motor_id, callback):\n # \"\"\"\n # Checks to see if the motor is currently running to a target.\n #\n # Callback return True if the speed is not zero or not at the target position.\n #\n # :param motor_id: 0-4\n #\n # :param callback: required callback function to receive report\n #\n # :return: The current running state returned via the callback as a list:\n #\n # [REPORT_TYPE=18, motor_id, True or False for running state, time_stamp]\n # \"\"\"\n # if not callback:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError(\n # 'stepper_is_running: A callback function must be specified.')\n #\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_is_running: Invalid motor_id.')\n #\n # self.stepper_info_list[motor_id]['is_running_callback'] = callback\n #\n # command = [PrivateConstants.STEPPER_IS_RUNNING, motor_id]\n # await self._send_command(command)\n\n async def shutdown(self):\n\"\"\"\n This method attempts an orderly shutdown\n If any exceptions are thrown, they are ignored.\n\n \"\"\"\n self.shutdown_flag = True\n\n if self.hard_reset_on_shutdown:\n await self.r4_hard_reset()\n # stop all reporting - both analog and digital\n else:\n try:\n command = [PrivateConstants.STOP_ALL_REPORTS]\n await self._send_command(command)\n\n await asyncio.sleep(.5)\n await self.serial_port.reset_input_buffer()\n await self.serial_port.close()\n if self.close_loop_on_shutdown:\n self.loop.stop()\n except (RuntimeError, SerialException):\n pass\n\n async def r4_hard_reset(self):\n\"\"\"\n Place the r4 into hard reset\n \"\"\"\n command = [PrivateConstants.BOARD_HARD_RESET, 1]\n await self._send_command(command)\n\n async def disable_all_reporting(self):\n\"\"\"\n Disable reporting for all digital and analog input pins\n \"\"\"\n command = [PrivateConstants.MODIFY_REPORTING,\n PrivateConstants.REPORTING_DISABLE_ALL, 0]\n await self._send_command(command)\n\n async def disable_analog_reporting(self, pin):\n\"\"\"\n Disables analog reporting for a single analog pin.\n\n :param pin: Analog pin number. For example for A0, the number is 0.\n\n \"\"\"\n command = [PrivateConstants.MODIFY_REPORTING,\n PrivateConstants.REPORTING_ANALOG_DISABLE, pin]\n await self._send_command(command)\n\n async def disable_digital_reporting(self, pin):\n\"\"\"\n Disables digital reporting for a single digital pin\n\n\n :param pin: pin number\n\n \"\"\"\n command = [PrivateConstants.MODIFY_REPORTING,\n PrivateConstants.REPORTING_DIGITAL_DISABLE, pin]\n await self._send_command(command)\n\n async def enable_analog_reporting(self, pin):\n\"\"\"\n Enables analog reporting for the specified pin.\n\n :param pin: Analog pin number. For example for A0, the number is 0.\n\n\n \"\"\"\n command = [PrivateConstants.MODIFY_REPORTING,\n PrivateConstants.REPORTING_ANALOG_ENABLE, pin]\n await self._send_command(command)\n\n async def enable_digital_reporting(self, pin):\n\"\"\"\n Enable reporting on the specified digital pin.\n\n :param pin: Pin number.\n \"\"\"\n\n command = [PrivateConstants.MODIFY_REPORTING,\n PrivateConstants.REPORTING_DIGITAL_ENABLE, pin]\n await self._send_command(command)\n\n async def _arduino_report_dispatcher(self):\n\"\"\"\n This is a private method.\n It continually accepts and interprets data coming from Telemetrix4Arduino,and then\n dispatches the correct handler to process the data.\n\n It first receives the length of the packet, and then reads in the rest of the\n packet. A packet consists of a length, report identifier and then the report data.\n Using the report identifier, the report handler is fetched from report_dispatch.\n\n :returns: This method never returns\n \"\"\"\n\n while True:\n if self.shutdown_flag:\n break\n try:\n packet_length = await self.serial_port.read()\n except TypeError:\n continue\n\n # get the rest of the packet\n packet = await self.serial_port.read(packet_length)\n\n report = packet[0]\n # print(report)\n # handle all other messages by looking them up in the\n # command dictionary\n\n await self.report_dispatch[report](packet[1:])\n await asyncio.sleep(self.sleep_tune)\n\n'''\n Report message handlers\n '''\n\n async def _report_loop_data(self, data):\n\"\"\"\n Print data that was looped back\n\n :param data: byte of loop back data\n \"\"\"\n if self.loop_back_callback:\n await self.loop_back_callback(data)\n\n async def _spi_report(self, report):\n\n cb_list = [PrivateConstants.SPI_REPORT, report[0]] + report[1:]\n\n cb_list.append(time.time())\n\n await self.spi_callback(cb_list)\n\n async def _onewire_report(self, report):\n cb_list = [PrivateConstants.ONE_WIRE_REPORT, report[0]] + report[1:]\n cb_list.append(time.time())\n await self.onewire_callback(cb_list)\n\n async def _report_debug_data(self, data):\n\"\"\"\n Print debug data sent from Arduino\n\n :param data: data[0] is a byte followed by 2\n bytes that comprise an integer\n \"\"\"\n value = (data[1] << 8) + data[2]\n print(f'DEBUG ID: {data[0]} Value: {value}')\n\n async def _analog_message(self, data):\n\"\"\"\n This is a private message handler method.\n It is a message handler for analog messages.\n\n :param data: message data\n\n \"\"\"\n pin = data[0]\n value = (data[1] << 8) + data[2]\n\n time_stamp = time.time()\n\n # append pin number, pin value, and pin type to return value and return as a list\n message = [PrivateConstants.AT_ANALOG, pin, value, time_stamp]\n\n await self.analog_callbacks[pin](message)\n\n async def _dht_report(self, data):\n\"\"\"\n This is a private message handler for dht reports\n\n :param data: data[0] = report error return\n No Errors = 0\n\n Checksum Error = 1\n\n Timeout Error = 2\n\n Invalid Value = 999\n\n data[1] = pin number\n\n data[2] = dht type 11 or 22\n\n data[3] = humidity positivity flag\n\n data[4] = temperature positivity value\n\n data[5] = humidity integer\n\n data[6] = humidity fractional value\n\n data[7] = temperature integer\n\n data[8] = temperature fractional value\n \"\"\"\n if data[0]: # DHT_ERROR\n # error report\n # data[0] = report sub type, data[1] = pin, data[2] = error message\n if self.dht_callbacks[data[1]]:\n # Callback 0=DHT REPORT, DHT_ERROR, PIN, Time\n message = [PrivateConstants.DHT_REPORT, data[0], data[1], data[2],\n time.time()]\n await self.dht_callbacks[data[1]](message)\n else:\n # got valid data DHT_DATA\n f_humidity = float(data[5] + data[6] / 100)\n if data[3]:\n f_humidity *= -1.0\n f_temperature = float(data[7] + data[8] / 100)\n if data[4]:\n f_temperature *= -1.0\n message = [PrivateConstants.DHT_REPORT, data[0], data[1], data[2],\n f_humidity, f_temperature, time.time()]\n\n await self.dht_callbacks[data[1]](message)\n\n async def _digital_message(self, data):\n\"\"\"\n This is a private message handler method.\n It is a message handler for Digital Messages.\n\n :param data: digital message\n\n \"\"\"\n pin = data[0]\n value = data[1]\n\n time_stamp = time.time()\n if self.digital_callbacks[pin]:\n message = [PrivateConstants.DIGITAL_REPORT, pin, value, time_stamp]\n await self.digital_callbacks[pin](message)\n\n async def _servo_unavailable(self, report):\n\"\"\"\n Message if no servos are available for use.\n\n :param report: pin number\n \"\"\"\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(\n f'Servo Attach For Pin {report[0]} Failed: No Available Servos')\n\n async def _i2c_read_report(self, data):\n\"\"\"\n Execute callback for i2c reads.\n\n :param data: [I2C_READ_REPORT, i2c_port, number of bytes read, address, register, bytes read..., time-stamp]\n \"\"\"\n\n # we receive [# data bytes, address, register, data bytes]\n # number of bytes of data returned\n\n # data[0] = number of bytes\n # data[1] = i2c_port\n # data[2] = number of bytes returned\n # data[3] = address\n # data[4] = register\n # data[5] ... all the data bytes\n\n cb_list = [PrivateConstants.I2C_READ_REPORT, data[0], data[1]] + data[2:]\n cb_list.append(time.time())\n\n if cb_list[1]:\n await self.i2c_callback2(cb_list)\n else:\n await self.i2c_callback(cb_list)\n\n async def _i2c_too_few(self, data):\n\"\"\"\n I2c reports too few bytes received\n\n :param data: data[0] = device address\n \"\"\"\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(\n f'i2c too few bytes received from i2c port {data[0]} i2c address {data[1]}')\n\n async def _i2c_too_many(self, data):\n\"\"\"\n I2c reports too few bytes received\n\n :param data: data[0] = device address\n \"\"\"\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(\n f'i2c too many bytes received from i2c port {data[0]} i2c address {data[1]}')\n\n async def _sonar_distance_report(self, report):\n\"\"\"\n\n :param report: data[0] = trigger pin, data[1] and data[2] = distance\n\n callback report format: [PrivateConstants.SONAR_DISTANCE, trigger_pin, distance_value, time_stamp]\n \"\"\"\n\n # get callback from pin number\n cb = self.sonar_callbacks[report[0]]\n\n # build report data\n cb_list = [PrivateConstants.SONAR_DISTANCE, report[0],\n ((report[1] << 8) + report[2]), time.time()]\n\n await cb(cb_list)\n\n async def _stepper_distance_to_go_report(self, report):\n return # for now\n # \"\"\"\n # Report stepper distance to go.\n #\n # :param report: data[0] = motor_id, data[1] = steps MSB, data[2] = steps byte 1,\n # data[3] = steps bytes 2, data[4] = steps LSB\n #\n # callback report format: [PrivateConstants.STEPPER_DISTANCE_TO_GO, motor_id\n # steps, time_stamp]\n # \"\"\"\n #\n # # get callback\n # cb = self.stepper_info_list[report[0]]['distance_to_go_callback']\n #\n # # isolate the steps bytes and covert list to bytes\n # steps = bytes(report[1:])\n #\n # # get value from steps\n # num_steps = int.from_bytes(steps, byteorder='big', signed=True)\n #\n # cb_list = [PrivateConstants.STEPPER_DISTANCE_TO_GO, report[0], num_steps,\n # time.time()]\n #\n # await cb(cb_list)\n #\n\n async def _stepper_target_position_report(self, report):\n return # for now\n\n # \"\"\"\n # Report stepper target position to go.\n #\n # :param report: data[0] = motor_id, data[1] = target position MSB,\n # data[2] = target position byte MSB+1\n # data[3] = target position byte MSB+2\n # data[4] = target position LSB\n #\n # callback report format: [PrivateConstants.STEPPER_TARGET_POSITION, motor_id\n # target_position, time_stamp]\n # \"\"\"\n #\n # # get callback\n # cb = self.stepper_info_list[report[0]]['target_position_callback']\n #\n # # isolate the steps bytes and covert list to bytes\n # target = bytes(report[1:])\n #\n # # get value from steps\n # target_position = int.from_bytes(target, byteorder='big', signed=True)\n #\n # cb_list = [PrivateConstants.STEPPER_TARGET_POSITION, report[0], target_position,\n # time.time()]\n #\n # await cb(cb_list)\n #\n async def _stepper_current_position_report(self, report):\n return # for now\n\n # \"\"\"\n # Report stepper current position.\n #\n # :param report: data[0] = motor_id, data[1] = current position MSB,\n # data[2] = current position byte MSB+1\n # data[3] = current position byte MSB+2\n # data[4] = current position LSB\n #\n # callback report format: [PrivateConstants.STEPPER_CURRENT_POSITION, motor_id\n # current_position, time_stamp]\n # \"\"\"\n #\n # # get callback\n # cb = self.stepper_info_list[report[0]]['current_position_callback']\n #\n # # isolate the steps bytes and covert list to bytes\n # position = bytes(report[1:])\n #\n # # get value from steps\n # current_position = int.from_bytes(position, byteorder='big', signed=True)\n #\n # cb_list = [PrivateConstants.STEPPER_CURRENT_POSITION, report[0], current_position,\n # time.time()]\n #\n # await cb(cb_list)\n #\n async def _stepper_is_running_report(self, report):\n return # for now\n\n # \"\"\"\n # Report if the motor is currently running\n #\n # :param report: data[0] = motor_id, True if motor is running or False if it is not.\n #\n # callback report format: [18, motor_id,\n # running_state, time_stamp]\n # \"\"\"\n #\n # # get callback\n # cb = self.stepper_info_list[report[0]]['is_running_callback']\n #\n # cb_list = [PrivateConstants.STEPPER_RUNNING_REPORT, report[0], time.time()]\n #\n # await cb(cb_list)\n #\n async def _stepper_run_complete_report(self, report):\n return # for now\n\n # \"\"\"\n # The motor completed it motion\n #\n # :param report: data[0] = motor_id\n #\n # callback report format: [PrivateConstants.STEPPER_RUN_COMPLETE_REPORT, motor_id,\n # time_stamp]\n # \"\"\"\n #\n # # get callback\n # cb = self.stepper_info_list[report[0]]['motion_complete_callback']\n #\n # cb_list = [PrivateConstants.STEPPER_RUN_COMPLETE_REPORT, report[0],\n # time.time()]\n #\n # await cb(cb_list)\n\n async def _features_report(self, report):\n self.reported_features = report[0]\n\n async def _send_command(self, command):\n\"\"\"\n This is a private utility method.\n\n\n :param command: command data in the form of a list\n\n :returns: number of bytes sent\n \"\"\"\n # the length of the list is added at the head\n command.insert(0, len(command))\n # print(command)\n send_message = bytes(command)\n\n await self.serial_port.write(send_message)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.__init__","title":"__init__(com_port=None, arduino_instance_id=1, arduino_wait=1, sleep_tune=0.0001, autostart=True, loop=None, shutdown_on_exception=True, close_loop_on_shutdown=True, hard_reset_on_shutdown=True)
","text":"If you have a single Arduino connected to your computer, then you may accept all the default values.
Otherwise, specify a unique arduino_instance id for each board in use.
:param com_port: e.g. COM3 or /dev/ttyACM0.
:param arduino_instance_id: Must match value in the Telemetrix4Arduino sketch
:param arduino_wait: Amount of time to wait for an Arduino to fully reset itself.
:param sleep_tune: A tuning parameter (typically not changed by user)
:param autostart: If you wish to call the start method within your application, then set this to False.
:param loop: optional user provided event loop
:param shutdown_on_exception: call shutdown before raising a RunTimeError exception, or receiving a KeyboardInterrupt exception
:param close_loop_on_shutdown: stop and close the event loop loop when a shutdown is called or a serial error occurs
:param hard_reset_on_shutdown: reset the board on shutdown
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
def __init__(self, com_port=None,\n arduino_instance_id=1, arduino_wait=1,\n sleep_tune=0.0001, autostart=True,\n loop=None, shutdown_on_exception=True,\n close_loop_on_shutdown=True, hard_reset_on_shutdown=True):\n\n\"\"\"\n If you have a single Arduino connected to your computer,\n then you may accept all the default values.\n\n Otherwise, specify a unique arduino_instance id for each board in use.\n\n :param com_port: e.g. COM3 or /dev/ttyACM0.\n\n :param arduino_instance_id: Must match value in the Telemetrix4Arduino sketch\n\n :param arduino_wait: Amount of time to wait for an Arduino to\n fully reset itself.\n\n :param sleep_tune: A tuning parameter (typically not changed by user)\n\n :param autostart: If you wish to call the start method within\n your application, then set this to False.\n\n :param loop: optional user provided event loop\n\n :param shutdown_on_exception: call shutdown before raising\n a RunTimeError exception, or\n receiving a KeyboardInterrupt exception\n\n :param close_loop_on_shutdown: stop and close the event loop loop\n when a shutdown is called or a serial\n error occurs\n\n :param hard_reset_on_shutdown: reset the board on shutdown\n\n \"\"\"\n # check to make sure that Python interpreter is version 3.8.3 or greater\n python_version = sys.version_info\n if python_version[0] >= 3:\n if python_version[1] >= 8:\n if python_version[2] >= 3:\n pass\n else:\n raise RuntimeError(\"ERROR: Python 3.7 or greater is \"\n \"required for use of this program.\")\n\n # save input parameters\n self.com_port = com_port\n self.arduino_instance_id = arduino_instance_id\n self.arduino_wait = arduino_wait\n self.sleep_tune = sleep_tune\n self.autostart = autostart\n self.hard_reset_on_shutdown = hard_reset_on_shutdown\n\n # set the event loop\n if loop is None:\n self.loop = asyncio.get_event_loop()\n else:\n self.loop = loop\n\n self.shutdown_on_exception = shutdown_on_exception\n self.close_loop_on_shutdown = close_loop_on_shutdown\n\n # dictionaries to store the callbacks for each pin\n self.analog_callbacks = {}\n\n self.digital_callbacks = {}\n\n self.i2c_callback = None\n self.i2c_callback2 = None\n\n self.i2c_1_active = False\n self.i2c_2_active = False\n\n self.spi_callback = None\n\n self.onewire_callback = None\n\n # debug loopback callback method\n self.loop_back_callback = None\n\n # the trigger pin will be the key to retrieve\n # the callback for a specific HC-SR04\n self.sonar_callbacks = {}\n\n self.sonar_count = 0\n\n self.dht_callbacks = {}\n\n self.dht_count = 0\n\n # serial port in use\n self.serial_port = None\n\n # generic asyncio task holder\n self.the_task = None\n\n # flag to indicate we are in shutdown mode\n self.shutdown_flag = False\n\n self.report_dispatch = {}\n\n # reported features\n self.reported_features = 0\n\n # To add a command to the command dispatch table, append here.\n self.report_dispatch.update(\n {PrivateConstants.LOOP_COMMAND: self._report_loop_data})\n self.report_dispatch.update(\n {PrivateConstants.DEBUG_PRINT: self._report_debug_data})\n self.report_dispatch.update(\n {PrivateConstants.DIGITAL_REPORT: self._digital_message})\n self.report_dispatch.update(\n {PrivateConstants.ANALOG_REPORT: self._analog_message})\n self.report_dispatch.update(\n {PrivateConstants.SERVO_UNAVAILABLE: self._servo_unavailable})\n self.report_dispatch.update(\n {PrivateConstants.I2C_READ_REPORT: self._i2c_read_report})\n self.report_dispatch.update(\n {PrivateConstants.I2C_TOO_FEW_BYTES_RCVD: self._i2c_too_few})\n self.report_dispatch.update(\n {PrivateConstants.I2C_TOO_MANY_BYTES_RCVD: self._i2c_too_many})\n self.report_dispatch.update(\n {PrivateConstants.SONAR_DISTANCE: self._sonar_distance_report})\n self.report_dispatch.update({PrivateConstants.DHT_REPORT: self._dht_report})\n self.report_dispatch.update(\n {PrivateConstants.SPI_REPORT: self._spi_report})\n self.report_dispatch.update(\n {PrivateConstants.ONE_WIRE_REPORT: self._onewire_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_DISTANCE_TO_GO:\n self._stepper_distance_to_go_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_TARGET_POSITION:\n self._stepper_target_position_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_CURRENT_POSITION:\n self._stepper_current_position_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_RUNNING_REPORT:\n self._stepper_is_running_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_RUN_COMPLETE_REPORT:\n self._stepper_run_complete_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_DISTANCE_TO_GO:\n self._stepper_distance_to_go_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_TARGET_POSITION:\n self._stepper_target_position_report})\n self.report_dispatch.update(\n {PrivateConstants.FEATURES:\n self._features_report})\n\n # dictionaries to store the callbacks for each pin\n self.analog_callbacks = {}\n\n self.digital_callbacks = {}\n\n self.i2c_callback = None\n self.i2c_callback2 = None\n\n self.i2c_1_active = False\n self.i2c_2_active = False\n\n self.spi_callback = None\n\n self.onewire_callback = None\n\n self.cs_pins_enabled = []\n\n # flag to indicate if spi is initialized\n self.spi_enabled = False\n\n # flag to indicate if onewire is initialized\n self.onewire_enabled = False\n\n # the trigger pin will be the key to retrieve\n # the callback for a specific HC-SR04\n self.sonar_callbacks = {}\n\n self.sonar_count = 0\n\n self.dht_callbacks = {}\n\n # # stepper motor variables\n #\n # # updated when a new motor is added\n # self.next_stepper_assigned = 0\n #\n # # valid list of stepper motor interface types\n # self.valid_stepper_interfaces = [1, 2, 3, 4, 6, 8]\n #\n # # maximum number of steppers supported\n # self.max_number_of_steppers = 4\n #\n # # number of steppers created - not to exceed the maximum\n # self.number_of_steppers = 0\n #\n # # dictionary to hold stepper motor information\n # self.stepper_info = {'instance': False, 'is_running': None,\n # 'maximum_speed': 1, 'speed': 0, 'acceleration': 0,\n # 'distance_to_go_callback': None,\n # 'target_position_callback': None,\n # 'current_position_callback': None,\n # 'is_running_callback': None,\n # 'motion_complete_callback': None,\n # 'acceleration_callback': None}\n #\n # # build a list of stepper motor info items\n # self.stepper_info_list = []\n # # a list of dictionaries to hold stepper information\n # for motor in range(self.max_number_of_steppers):\n # self.stepper_info_list.append(self.stepper_info)\n\n print(f'telemetrix_uno_r4_minima_aio Version:'\n f' {PrivateConstants.TELEMETRIX_AIO_VERSION}')\n print(f'Copyright (c) 2023 Alan Yorinks All rights reserved.\\n')\n\n if autostart:\n self.loop.run_until_complete(self.start_aio())\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.analog_write","title":"analog_write(pin, value)
async
","text":"Set the specified pin to the specified value.
:param pin: arduino pin number
:param value: pin value (maximum 16 bits)
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def analog_write(self, pin, value):\n\"\"\"\n Set the specified pin to the specified value.\n\n :param pin: arduino pin number\n\n :param value: pin value (maximum 16 bits)\n\n \"\"\"\n value_msb = value >> 8\n value_lsb = value & 0xff\n command = [PrivateConstants.ANALOG_WRITE, pin, value_msb, value_lsb]\n await self._send_command(command)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.digital_write","title":"digital_write(pin, value)
async
","text":"Set the specified pin to the specified value.
:param pin: arduino pin number
:param value: pin value (1 or 0)
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def digital_write(self, pin, value):\n\"\"\"\n Set the specified pin to the specified value.\n\n :param pin: arduino pin number\n\n :param value: pin value (1 or 0)\n\n \"\"\"\n command = [PrivateConstants.DIGITAL_WRITE, pin, value]\n await self._send_command(command)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.disable_all_reporting","title":"disable_all_reporting()
async
","text":"Disable reporting for all digital and analog input pins
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def disable_all_reporting(self):\n\"\"\"\n Disable reporting for all digital and analog input pins\n \"\"\"\n command = [PrivateConstants.MODIFY_REPORTING,\n PrivateConstants.REPORTING_DISABLE_ALL, 0]\n await self._send_command(command)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.disable_analog_reporting","title":"disable_analog_reporting(pin)
async
","text":"Disables analog reporting for a single analog pin.
:param pin: Analog pin number. For example for A0, the number is 0.
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def disable_analog_reporting(self, pin):\n\"\"\"\n Disables analog reporting for a single analog pin.\n\n :param pin: Analog pin number. For example for A0, the number is 0.\n\n \"\"\"\n command = [PrivateConstants.MODIFY_REPORTING,\n PrivateConstants.REPORTING_ANALOG_DISABLE, pin]\n await self._send_command(command)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.disable_digital_reporting","title":"disable_digital_reporting(pin)
async
","text":"Disables digital reporting for a single digital pin
:param pin: pin number
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def disable_digital_reporting(self, pin):\n\"\"\"\n Disables digital reporting for a single digital pin\n\n\n :param pin: pin number\n\n \"\"\"\n command = [PrivateConstants.MODIFY_REPORTING,\n PrivateConstants.REPORTING_DIGITAL_DISABLE, pin]\n await self._send_command(command)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.enable_analog_reporting","title":"enable_analog_reporting(pin)
async
","text":"Enables analog reporting for the specified pin.
:param pin: Analog pin number. For example for A0, the number is 0.
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def enable_analog_reporting(self, pin):\n\"\"\"\n Enables analog reporting for the specified pin.\n\n :param pin: Analog pin number. For example for A0, the number is 0.\n\n\n \"\"\"\n command = [PrivateConstants.MODIFY_REPORTING,\n PrivateConstants.REPORTING_ANALOG_ENABLE, pin]\n await self._send_command(command)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.enable_digital_reporting","title":"enable_digital_reporting(pin)
async
","text":"Enable reporting on the specified digital pin.
:param pin: Pin number.
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def enable_digital_reporting(self, pin):\n\"\"\"\n Enable reporting on the specified digital pin.\n\n :param pin: Pin number.\n \"\"\"\n\n command = [PrivateConstants.MODIFY_REPORTING,\n PrivateConstants.REPORTING_DIGITAL_ENABLE, pin]\n await self._send_command(command)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.get_event_loop","title":"get_event_loop()
async
","text":"Return the currently active asyncio event loop
:return: Active event loop
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def get_event_loop(self):\n\"\"\"\n Return the currently active asyncio event loop\n\n :return: Active event loop\n\n \"\"\"\n return self.loop\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.i2c_read","title":"i2c_read(address, register, number_of_bytes, callback, i2c_port=0, write_register=True)
async
","text":"Read the specified number of bytes from the specified register for the i2c device.
:param address: i2c device address
:param register: i2c register (or None if no register selection is needed)
:param number_of_bytes: number of bytes to be read
:param callback: Required callback function to report i2c data as a result of read command
:param i2c_port: select the default port (0) or secondary port (1)
:param write_register: If True, the register is written before read Else, the write is suppressed
callback returns a data list:
[I2C_READ_REPORT, address, register, count of data bytes, data bytes, time-stamp]
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def i2c_read(self, address, register, number_of_bytes,\n callback, i2c_port=0,\n write_register=True):\n\"\"\"\n Read the specified number of bytes from the specified register for\n the i2c device.\n\n\n :param address: i2c device address\n\n :param register: i2c register (or None if no register selection is needed)\n\n :param number_of_bytes: number of bytes to be read\n\n :param callback: Required callback function to report i2c data as a\n result of read command\n\n :param i2c_port: select the default port (0) or secondary port (1)\n\n :param write_register: If True, the register is written\n before read\n Else, the write is suppressed\n\n\n callback returns a data list:\n\n [I2C_READ_REPORT, address, register, count of data bytes,\n data bytes, time-stamp]\n\n \"\"\"\n if not callback:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('i2c_read: A Callback must be specified')\n\n await self._i2c_read_request(address, register, number_of_bytes,\n callback=callback, i2c_port=i2c_port,\n write_register=write_register)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.i2c_read_restart_transmission","title":"i2c_read_restart_transmission(address, register, number_of_bytes, callback, i2c_port=0, write_register=True)
async
","text":"Read the specified number of bytes from the specified register for the i2c device. This restarts the transmission after the read. It is required for some i2c devices such as the MMA8452Q accelerometer.
:param address: i2c device address
:param register: i2c register (or None if no register selection is needed)
:param number_of_bytes: number of bytes to be read
:param callback: Required callback function to report i2c data as a result of read command
:param i2c_port: select the default port (0) or secondary port (1)
:param write_register: If True, the register is written before read Else, the write is suppressed
callback returns a data list:
[I2C_READ_REPORT, address, register, count of data bytes, data bytes, time-stamp]
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def i2c_read_restart_transmission(self, address, register,\n number_of_bytes,\n callback, i2c_port=0,\n write_register=True):\n\"\"\"\n Read the specified number of bytes from the specified register for\n the i2c device. This restarts the transmission after the read. It is\n required for some i2c devices such as the MMA8452Q accelerometer.\n\n\n :param address: i2c device address\n\n :param register: i2c register (or None if no register\n selection is needed)\n\n :param number_of_bytes: number of bytes to be read\n\n :param callback: Required callback function to report i2c data as a\n result of read command\n\n :param i2c_port: select the default port (0) or secondary port (1)\n\n :param write_register: If True, the register is written\n before read\n Else, the write is suppressed\n\n callback returns a data list:\n\n [I2C_READ_REPORT, address, register, count of data bytes,\n data bytes, time-stamp]\n\n \"\"\"\n if not callback:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(\n 'i2c_read_restart_transmission: A Callback must be specified')\n\n await self._i2c_read_request(address, register, number_of_bytes,\n stop_transmission=False,\n callback=callback, i2c_port=i2c_port,\n write_register=write_register)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.i2c_write","title":"i2c_write(address, args, i2c_port=0)
async
","text":"Write data to an i2c device.
:param address: i2c device address
:param i2c_port: 0= port 1, 1 = port 2
:param args: A variable number of bytes to be sent to the device passed in as a list
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def i2c_write(self, address, args, i2c_port=0):\n\"\"\"\n Write data to an i2c device.\n\n :param address: i2c device address\n\n :param i2c_port: 0= port 1, 1 = port 2\n\n :param args: A variable number of bytes to be sent to the device\n passed in as a list\n\n \"\"\"\n if not i2c_port:\n if not self.i2c_1_active:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(\n 'I2C Write: set_pin_mode i2c never called for i2c port 1.')\n\n if i2c_port:\n if not self.i2c_2_active:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(\n 'I2C Write: set_pin_mode i2c never called for i2c port 2.')\n\n command = [PrivateConstants.I2C_WRITE, len(args), address, i2c_port]\n\n for item in args:\n command.append(item)\n\n await self._send_command(command)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.loop_back","title":"loop_back(start_character, callback)
async
","text":"This is a debugging method to send a character to the Arduino device, and have the device loop it back.
:param start_character: The character to loop back. It should be an integer.
:param callback: Looped back character will appear in the callback method
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def loop_back(self, start_character, callback):\n\"\"\"\n This is a debugging method to send a character to the\n Arduino device, and have the device loop it back.\n\n :param start_character: The character to loop back. It should be\n an integer.\n\n :param callback: Looped back character will appear in the callback method\n\n \"\"\"\n\n if not callback:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('loop_back: A callback function must be specified.')\n command = [PrivateConstants.LOOP_COMMAND, ord(start_character)]\n self.loop_back_callback = callback\n await self._send_command(command)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.r4_hard_reset","title":"r4_hard_reset()
async
","text":"Place the r4 into hard reset
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def r4_hard_reset(self):\n\"\"\"\n Place the r4 into hard reset\n \"\"\"\n command = [PrivateConstants.BOARD_HARD_RESET, 1]\n await self._send_command(command)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.servo_detach","title":"servo_detach(pin_number)
async
","text":"Detach a servo for reuse :param pin_number: attached pin
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def servo_detach(self, pin_number):\n\"\"\"\n Detach a servo for reuse\n :param pin_number: attached pin\n \"\"\"\n command = [PrivateConstants.SERVO_DETACH, pin_number]\n await self._send_command(command)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.servo_write","title":"servo_write(pin_number, angle)
async
","text":"Set a servo attached to a pin to a given angle.
:param pin_number: pin
:param angle: angle (0-180)
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def servo_write(self, pin_number, angle):\n\"\"\"\n\n Set a servo attached to a pin to a given angle.\n\n :param pin_number: pin\n\n :param angle: angle (0-180)\n\n \"\"\"\n command = [PrivateConstants.SERVO_WRITE, pin_number, angle]\n await self._send_command(command)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.set_analog_scan_interval","title":"set_analog_scan_interval(interval)
async
","text":"Set the analog scanning interval.
:param interval: value of 0 - 255 - milliseconds
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def set_analog_scan_interval(self, interval):\n\"\"\"\n Set the analog scanning interval.\n\n :param interval: value of 0 - 255 - milliseconds\n \"\"\"\n\n if 0 <= interval <= 255:\n command = [PrivateConstants.SET_ANALOG_SCANNING_INTERVAL, interval]\n await self._send_command(command)\n else:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('Analog interval must be between 0 and 255')\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.set_pin_mode_analog_input","title":"set_pin_mode_analog_input(pin_number, differential=0, callback=None)
async
","text":"Set a pin as an analog input.
:param pin_number: arduino pin number
:param callback: async callback function
:param differential: difference in previous to current value before report will be generated
callback returns a data list:
[pin_type, pin_number, pin_value, raw_time_stamp]
The pin_type for analog input pins = 3
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def set_pin_mode_analog_input(self, pin_number, differential=0, callback=None):\n\"\"\"\n Set a pin as an analog input.\n\n :param pin_number: arduino pin number\n\n :param callback: async callback function\n\n :param differential: difference in previous to current value before\n report will be generated\n\n callback returns a data list:\n\n [pin_type, pin_number, pin_value, raw_time_stamp]\n\n The pin_type for analog input pins = 3\n\n \"\"\"\n\n if not callback:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(\n 'set_pin_mode_analog_input: A callback function must be specified.')\n\n await self._set_pin_mode(pin_number, PrivateConstants.AT_ANALOG,\n differential, callback=callback)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.set_pin_mode_analog_output","title":"set_pin_mode_analog_output(pin_number)
async
","text":"Set a pin as a pwm (analog output) pin.
:param pin_number:arduino pin number
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def set_pin_mode_analog_output(self, pin_number):\n\"\"\"\n\n Set a pin as a pwm (analog output) pin.\n\n :param pin_number:arduino pin number\n\n \"\"\"\n\n await self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT, differential=0,\n callback=None)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.set_pin_mode_dht","title":"set_pin_mode_dht(pin, callback=None, dht_type=22)
async
","text":":param pin: connection pin
:param callback: callback function
:param dht_type: either 22 for DHT22 or 11 for DHT11
Error Callback: [DHT REPORT Type, DHT_ERROR_NUMBER, PIN, DHT_TYPE, Time]
Valid Data Callback: DHT REPORT Type, DHT_DATA=, PIN, DHT_TYPE, Humidity, Temperature, Time]
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def set_pin_mode_dht(self, pin, callback=None, dht_type=22):\n\"\"\"\n\n :param pin: connection pin\n\n :param callback: callback function\n\n :param dht_type: either 22 for DHT22 or 11 for DHT11\n\n Error Callback: [DHT REPORT Type, DHT_ERROR_NUMBER, PIN, DHT_TYPE, Time]\n\n Valid Data Callback: DHT REPORT Type, DHT_DATA=, PIN, DHT_TYPE, Humidity,\n Temperature,\n Time]\n\n \"\"\"\n if self.reported_features & PrivateConstants.DHT_FEATURE:\n\n if not callback:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('set_pin_mode_dht: A Callback must be specified')\n\n if self.dht_count < PrivateConstants.MAX_DHTS - 1:\n self.dht_callbacks[pin] = callback\n self.dht_count += 1\n\n if dht_type != 22 and dht_type != 11:\n dht_type = 22\n\n command = [PrivateConstants.DHT_NEW, pin, dht_type]\n await self._send_command(command)\n else:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(\n f'Maximum Number Of DHTs Exceeded - set_pin_mode_dht fails for pin {pin}')\n\n else:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(f'The DHT feature is disabled in the server.')\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.set_pin_mode_digital_input","title":"set_pin_mode_digital_input(pin_number, callback)
async
","text":"Set a pin as a digital input.
:param pin_number: arduino pin number
:param callback: async callback function
callback returns a data list:
[pin_type, pin_number, pin_value, raw_time_stamp]
The pin_type for all digital input pins = 2
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def set_pin_mode_digital_input(self, pin_number, callback):\n\"\"\"\n Set a pin as a digital input.\n\n :param pin_number: arduino pin number\n\n :param callback: async callback function\n\n callback returns a data list:\n\n [pin_type, pin_number, pin_value, raw_time_stamp]\n\n The pin_type for all digital input pins = 2\n\n \"\"\"\n await self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT, differential=0,\n callback=callback)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.set_pin_mode_digital_input_pullup","title":"set_pin_mode_digital_input_pullup(pin_number, callback)
async
","text":"Set a pin as a digital input with pullup enabled.
:param pin_number: arduino pin number
:param callback: async callback function
callback returns a data list:
[pin_type, pin_number, pin_value, raw_time_stamp]
The pin_type for all digital input pins = 2
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def set_pin_mode_digital_input_pullup(self, pin_number, callback):\n\"\"\"\n Set a pin as a digital input with pullup enabled.\n\n :param pin_number: arduino pin number\n\n :param callback: async callback function\n\n callback returns a data list:\n\n [pin_type, pin_number, pin_value, raw_time_stamp]\n\n The pin_type for all digital input pins = 2\n\n \"\"\"\n if not callback:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(\n 'set_pin_mode_digital_input_pullup: A callback function must be specified.')\n\n await self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT_PULLUP,\n differential=0, callback=callback)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.set_pin_mode_digital_output","title":"set_pin_mode_digital_output(pin_number)
async
","text":"Set a pin as a digital output pin.
:param pin_number: arduino pin number
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def set_pin_mode_digital_output(self, pin_number):\n\"\"\"\n Set a pin as a digital output pin.\n\n :param pin_number: arduino pin number\n \"\"\"\n\n await self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT, differential=0,\n callback=None)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.set_pin_mode_i2c","title":"set_pin_mode_i2c(i2c_port=0)
async
","text":"Establish the standard Arduino i2c pins for i2c utilization.
:param i2c_port: 0 = i2c1, 1 = i2c2
API.\n\n See i2c_read, or i2c_read_restart_transmission.\n
Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def set_pin_mode_i2c(self, i2c_port=0):\n\"\"\"\n Establish the standard Arduino i2c pins for i2c utilization.\n\n :param i2c_port: 0 = i2c1, 1 = i2c2\n\n NOTES: 1. THIS METHOD MUST BE CALLED BEFORE ANY I2C REQUEST IS MADE\n 2. Callbacks are set within the individual i2c read methods of this\n API.\n\n See i2c_read, or i2c_read_restart_transmission.\n\n \"\"\"\n # test for i2c port 2\n if i2c_port:\n # if not previously activated set it to activated\n # and the send a begin message for this port\n if not self.i2c_2_active:\n self.i2c_2_active = True\n else:\n return\n # port 1\n else:\n if not self.i2c_1_active:\n self.i2c_1_active = True\n else:\n return\n\n command = [PrivateConstants.I2C_BEGIN, i2c_port]\n await self._send_command(command)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.set_pin_mode_servo","title":"set_pin_mode_servo(pin_number, min_pulse=544, max_pulse=2400)
async
","text":"Attach a pin to a servo motor
:param pin_number: pin
:param min_pulse: minimum pulse width
:param max_pulse: maximum pulse width
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def set_pin_mode_servo(self, pin_number, min_pulse=544, max_pulse=2400):\n\"\"\"\n\n Attach a pin to a servo motor\n\n :param pin_number: pin\n\n :param min_pulse: minimum pulse width\n\n :param max_pulse: maximum pulse width\n\n \"\"\"\n if self.reported_features & PrivateConstants.SERVO_FEATURE:\n\n minv = (min_pulse).to_bytes(2, byteorder=\"big\")\n maxv = (max_pulse).to_bytes(2, byteorder=\"big\")\n\n command = [PrivateConstants.SERVO_ATTACH, pin_number,\n minv[0], minv[1], maxv[0], maxv[1]]\n await self._send_command(command)\n else:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(f'The SERVO feature is disabled in the server.')\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.set_pin_mode_sonar","title":"set_pin_mode_sonar(trigger_pin, echo_pin, callback)
async
","text":":param trigger_pin:
:param echo_pin:
:param callback: callback
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def set_pin_mode_sonar(self, trigger_pin, echo_pin,\n callback):\n\"\"\"\n\n :param trigger_pin:\n\n :param echo_pin:\n\n :param callback: callback\n\n \"\"\"\n if self.reported_features & PrivateConstants.SONAR_FEATURE:\n\n if not callback:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('set_pin_mode_sonar: A Callback must be specified')\n\n if self.sonar_count < PrivateConstants.MAX_SONARS - 1:\n self.sonar_callbacks[trigger_pin] = callback\n self.sonar_count += 1\n\n command = [PrivateConstants.SONAR_NEW, trigger_pin, echo_pin]\n await self._send_command(command)\n else:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(\n f'Maximum Number Of Sonars Exceeded - set_pin_mode_sonar fails for pin {trigger_pin}')\n else:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(f'The SONAR feature is disabled in the server.')\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.set_pin_mode_spi","title":"set_pin_mode_spi(chip_select_list=None)
async
","text":"Specify the list of chip select pins.
Standard Arduino MISO, MOSI and CLK pins are used for the board in use.
Chip Select is any digital output capable pin.
:param chip_select_list: this is a list of pins to be used for chip select. The pins will be configured as output, and set to high ready to be used for chip select. NOTE: You must specify the chips select pins here!
command message: [command, number of cs pins, [cs pins...]]
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def set_pin_mode_spi(self, chip_select_list=None):\n\"\"\"\n Specify the list of chip select pins.\n\n Standard Arduino MISO, MOSI and CLK pins are used for the board in use.\n\n Chip Select is any digital output capable pin.\n\n :param chip_select_list: this is a list of pins to be used for chip select.\n The pins will be configured as output, and set to high\n ready to be used for chip select.\n NOTE: You must specify the chips select pins here!\n\n\n command message: [command, number of cs pins, [cs pins...]]\n \"\"\"\n if self.reported_features & PrivateConstants.SPI_FEATURE:\n\n if type(chip_select_list) != list:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('chip_select_list must be in the form of a list')\n if not chip_select_list:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('Chip select pins were not specified')\n\n self.spi_enabled = True\n\n command = [PrivateConstants.SPI_INIT, len(chip_select_list)]\n\n for pin in chip_select_list:\n command.append(pin)\n self.cs_pins_enabled.append(pin)\n await self._send_command(command)\n else:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(f'The SPI feature is disabled in the server.')\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.shutdown","title":"shutdown()
async
","text":"This method attempts an orderly shutdown If any exceptions are thrown, they are ignored.
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def shutdown(self):\n\"\"\"\n This method attempts an orderly shutdown\n If any exceptions are thrown, they are ignored.\n\n \"\"\"\n self.shutdown_flag = True\n\n if self.hard_reset_on_shutdown:\n await self.r4_hard_reset()\n # stop all reporting - both analog and digital\n else:\n try:\n command = [PrivateConstants.STOP_ALL_REPORTS]\n await self._send_command(command)\n\n await asyncio.sleep(.5)\n await self.serial_port.reset_input_buffer()\n await self.serial_port.close()\n if self.close_loop_on_shutdown:\n self.loop.stop()\n except (RuntimeError, SerialException):\n pass\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.sonar_disable","title":"sonar_disable()
async
","text":"Disable sonar scanning for all sonar sensors
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def sonar_disable(self):\n\"\"\"\n Disable sonar scanning for all sonar sensors\n \"\"\"\n command = [PrivateConstants.SONAR_DISABLE]\n await self._send_command(command)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.sonar_enable","title":"sonar_enable()
async
","text":"Enable sonar scanning for all sonar sensors
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def sonar_enable(self):\n\"\"\"\n Enable sonar scanning for all sonar sensors\n \"\"\"\n command = [PrivateConstants.SONAR_ENABLE]\n await self._send_command(command)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.spi_cs_control","title":"spi_cs_control(chip_select_pin, select)
async
","text":"Control an SPI chip select line :param chip_select_pin: pin connected to CS
:param select: 0=select, 1=deselect
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def spi_cs_control(self, chip_select_pin, select):\n\"\"\"\n Control an SPI chip select line\n :param chip_select_pin: pin connected to CS\n\n :param select: 0=select, 1=deselect\n \"\"\"\n if not self.spi_enabled:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(f'spi_cs_control: SPI interface is not enabled.')\n\n if chip_select_pin not in self.cs_pins_enabled:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(f'spi_cs_control: chip select pin never enabled.')\n command = [PrivateConstants.SPI_CS_CONTROL, chip_select_pin, select]\n await self._send_command(command)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.spi_read_blocking","title":"spi_read_blocking(chip_select, register_selection, number_of_bytes_to_read, call_back=None)
async
","text":"Read the specified number of bytes from the specified SPI port and call the callback function with the reported data.
:param chip_select: chip select pin
:param register_selection: Register to be selected for read.
:param number_of_bytes_to_read: Number of bytes to read
:param call_back: Required callback function to report spi data as a result of read command
callback returns a data list[SPI_READ_REPORT, chip select pin, SPI Register, count of data bytes read, data bytes, time-stamp]
SPI_READ_REPORT = 13
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def spi_read_blocking(self, chip_select, register_selection,\n number_of_bytes_to_read,\n call_back=None):\n\"\"\"\n Read the specified number of bytes from the specified SPI port and\n call the callback function with the reported data.\n\n :param chip_select: chip select pin\n\n :param register_selection: Register to be selected for read.\n\n :param number_of_bytes_to_read: Number of bytes to read\n\n :param call_back: Required callback function to report spi data as a\n result of read command\n\n\n callback returns a data list:\n [SPI_READ_REPORT, chip select pin, SPI Register, count of data bytes read,\n data bytes, time-stamp]\n SPI_READ_REPORT = 13\n\n \"\"\"\n\n if not self.spi_enabled:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(f'spi_read_blocking: SPI interface is not enabled.')\n\n if not call_back:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('spi_read_blocking: A Callback must be specified')\n\n self.spi_callback = call_back\n\n command = [PrivateConstants.SPI_READ_BLOCKING, chip_select,\n number_of_bytes_to_read,\n register_selection]\n\n await self._send_command(command)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.spi_set_format","title":"spi_set_format(clock_divisor, bit_order, data_mode)
async
","text":"Configure how the SPI serializes and de-serializes data on the wire.
See Arduino SPI reference materials for details.
:param clock_divisor: 1 - 255
:param bit_order:
LSBFIRST = 0\n\n MSBFIRST = 1 (default)\n
:param data_mode:
SPI_MODE0 = 0x00 (default)\n\n SPI_MODE1 = 1\n\n SPI_MODE2 = 2\n\n SPI_MODE3 = 3\n
Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def spi_set_format(self, clock_divisor, bit_order, data_mode):\n\"\"\"\n Configure how the SPI serializes and de-serializes data on the wire.\n\n See Arduino SPI reference materials for details.\n\n :param clock_divisor: 1 - 255\n\n :param bit_order:\n\n LSBFIRST = 0\n\n MSBFIRST = 1 (default)\n\n :param data_mode:\n\n SPI_MODE0 = 0x00 (default)\n\n SPI_MODE1 = 1\n\n SPI_MODE2 = 2\n\n SPI_MODE3 = 3\n\n \"\"\"\n\n if not self.spi_enabled:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(f'spi_set_format: SPI interface is not enabled.')\n\n if not 0 < clock_divisor <= 255:\n raise RuntimeError(f'spi_set_format: illegal clock divisor selected.')\n if bit_order not in [0, 1]:\n raise RuntimeError(f'spi_set_format: illegal bit_order selected.')\n if data_mode not in [0, 1, 2, 3]:\n raise RuntimeError(f'spi_set_format: illegal data_order selected.')\n\n command = [PrivateConstants.SPI_SET_FORMAT, clock_divisor, bit_order,\n data_mode]\n await self._send_command(command)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.spi_write_blocking","title":"spi_write_blocking(chip_select, bytes_to_write)
async
","text":"Write a list of bytes to the SPI device.
:param chip_select: chip select pin
:param bytes_to_write: A list of bytes to write. This must be in the form of a list.
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def spi_write_blocking(self, chip_select, bytes_to_write):\n\"\"\"\n Write a list of bytes to the SPI device.\n\n :param chip_select: chip select pin\n\n :param bytes_to_write: A list of bytes to write. This must\n be in the form of a list.\n\n \"\"\"\n\n if not self.spi_enabled:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(f'spi_write_blocking: SPI interface is not enabled.')\n\n if type(bytes_to_write) is not list:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('spi_write_blocking: bytes_to_write must be a list.')\n\n command = [PrivateConstants.SPI_WRITE_BLOCKING, chip_select, len(bytes_to_write)]\n\n for data in bytes_to_write:\n command.append(data)\n\n await self._send_command(command)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.start_aio","title":"start_aio()
async
","text":"This method may be called directly, if the autostart parameter in init is set to false.
This method instantiates the serial interface and then performs auto pin discovery if using a serial interface, or creates and connects to a TCP/IP enabled device running StandardFirmataWiFi.
Use this method if you wish to start TelemetrixAIO manually from an asyncio function.
Source code intelemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def start_aio(self):\n\"\"\"\n This method may be called directly, if the autostart\n parameter in __init__ is set to false.\n\n This method instantiates the serial interface and then performs auto pin\n discovery if using a serial interface, or creates and connects to\n a TCP/IP enabled device running StandardFirmataWiFi.\n\n Use this method if you wish to start TelemetrixAIO manually from\n an asyncio function.\n \"\"\"\n\n if not self.com_port:\n # user did not specify a com_port\n try:\n await self._find_arduino()\n except KeyboardInterrupt:\n if self.shutdown_on_exception:\n await self.shutdown()\n else:\n # com_port specified - set com_port and baud rate\n try:\n await self._manual_open()\n except KeyboardInterrupt:\n if self.shutdown_on_exception:\n await self.shutdown()\n\n if self.com_port:\n print(f'Telemetrix4UnoR4 found and connected to {self.com_port}')\n\n # no com_port found - raise a runtime exception\n else:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('No Arduino Found or User Aborted Program')\n\n # get arduino firmware version and print it\n firmware_version = await self._get_firmware_version()\n if not firmware_version:\n print('*** Firmware Version retrieval timed out. ***')\n print('\\nDo you have Arduino connectivity and do you have the ')\n print('Telemetrix4UnoR4 sketch uploaded to the board and are connected')\n print('to the correct serial port.\\n')\n print('To see a list of serial ports, type: '\n '\"list_serial_ports\" in your console.')\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError\n else:\n\n print(f'Telemetrix4UnoR4 Version Number: {firmware_version[2]}.'\n f'{firmware_version[3]}.{firmware_version[4]}')\n # start the command dispatcher loop\n command = [PrivateConstants.ENABLE_ALL_REPORTS]\n await self._send_command(command)\n if not self.loop:\n self.loop = asyncio.get_event_loop()\n self.the_task = self.loop.create_task(self._arduino_report_dispatcher())\n\n # get the features list\n command = [PrivateConstants.GET_FEATURES]\n await self._send_command(command)\n await asyncio.sleep(.5)\n\n # Have the server reset its data structures\n command = [PrivateConstants.RESET]\n await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/","title":"telemetrix_uno_r4_wifi","text":"Copyright (c) 2023 Alan Yorinks All rights reserved.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 as published by the Free Software Foundation; either or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi","title":"TelemetrixUnoR4WiFi
","text":" Bases: threading.Thread
This class exposes and implements the telemetrix API. It uses threading to accommodate concurrency. It includes the public API methods as well as a set of private methods.
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
class TelemetrixUnoR4WiFi(threading.Thread):\n\"\"\"\n This class exposes and implements the telemetrix API.\n It uses threading to accommodate concurrency.\n It includes the public API methods as well as\n a set of private methods.\n\n \"\"\"\n\n # noinspection PyPep8,PyPep8,PyPep8\n def __init__(self, com_port=None, arduino_instance_id=1,\n arduino_wait=1, sleep_tune=0.000001,\n shutdown_on_exception=True, hard_reset_on_shutdown=True,\n transport_address=None, ip_port=31336, transport_type=0):\n\n\"\"\"\n\n :param com_port: e.g. COM3 or /dev/ttyACM0.\n Only use if you wish to bypass auto com port\n detection.\n\n :param arduino_instance_id: Match with the value installed on the\n arduino-telemetrix sketch.\n\n :param arduino_wait: Amount of time to wait for an Arduino to\n fully reset itself.\n\n :param sleep_tune: A tuning parameter (typically not changed by user)\n\n :param shutdown_on_exception: call shutdown before raising\n a RunTimeError exception, or\n receiving a KeyboardInterrupt exception\n\n :param hard_reset_on_shutdown: reset the board on shutdown\n\n :param transport_address: ip address of tcp/ip connected device.\n\n :param ip_port: ip port of tcp/ip connected device\n\n :param transport_type: 0 = WiFI\n 1 = USBSerial\n 2 = BLE\n\n\n \"\"\"\n\n # initialize threading parent\n threading.Thread.__init__(self)\n\n # create the threads and set them as daemons so\n # that they stop when the program is closed\n\n # create a thread to interpret received serial data\n self.the_reporter_thread = threading.Thread(target=self._reporter)\n self.the_reporter_thread.daemon = True\n\n self.transport_address = transport_address\n self.ip_port = ip_port\n\n if transport_type not in [0, 1, 2]:\n raise RuntimeError(\"Valid transport_type value is 0, 1, or 2\")\n\n self.transport_type = transport_type\n\n if transport_type == 0:\n if not transport_address:\n raise RuntimeError(\"An IP address must be specified.\")\n\n if not self.transport_address:\n self.the_data_receive_thread = threading.Thread(target=self._serial_receiver)\n else:\n self.the_data_receive_thread = threading.Thread(target=self._tcp_receiver)\n\n self.the_data_receive_thread.daemon = True\n\n # flag to allow the reporter and receive threads to run.\n self.run_event = threading.Event()\n\n # check to make sure that Python interpreter is version 3.7 or greater\n python_version = sys.version_info\n if python_version[0] >= 3:\n if python_version[1] >= 7:\n pass\n else:\n raise RuntimeError(\"ERROR: Python 3.7 or greater is \"\n \"required for use of this program.\")\n\n # save input parameters as instance variables\n self.com_port = com_port\n self.arduino_instance_id = arduino_instance_id\n self.arduino_wait = arduino_wait\n self.sleep_tune = sleep_tune\n self.shutdown_on_exception = shutdown_on_exception\n self.hard_reset_on_shutdown = hard_reset_on_shutdown\n\n # create a deque to receive and process data from the arduino\n self.the_deque = deque()\n\n # The report_dispatch dictionary is used to process\n # incoming report messages by looking up the report message\n # and executing its associated processing method.\n\n self.report_dispatch = {}\n\n # To add a command to the command dispatch table, append here.\n self.report_dispatch.update(\n {PrivateConstants.LOOP_COMMAND: self._report_loop_data})\n self.report_dispatch.update(\n {PrivateConstants.DEBUG_PRINT: self._report_debug_data})\n self.report_dispatch.update(\n {PrivateConstants.DIGITAL_REPORT: self._digital_message})\n self.report_dispatch.update(\n {PrivateConstants.ANALOG_REPORT: self._analog_message})\n self.report_dispatch.update(\n {PrivateConstants.FIRMWARE_REPORT: self._firmware_message})\n self.report_dispatch.update({PrivateConstants.I_AM_HERE_REPORT: self._i_am_here})\n self.report_dispatch.update(\n {PrivateConstants.SERVO_UNAVAILABLE: self._servo_unavailable})\n self.report_dispatch.update(\n {PrivateConstants.I2C_READ_REPORT: self._i2c_read_report})\n self.report_dispatch.update(\n {PrivateConstants.I2C_TOO_FEW_BYTES_RCVD: self._i2c_too_few})\n self.report_dispatch.update(\n {PrivateConstants.I2C_TOO_MANY_BYTES_RCVD: self._i2c_too_many})\n self.report_dispatch.update(\n {PrivateConstants.SONAR_DISTANCE: self._sonar_distance_report})\n self.report_dispatch.update({PrivateConstants.DHT_REPORT: self._dht_report})\n self.report_dispatch.update(\n {PrivateConstants.SPI_REPORT: self._spi_report})\n self.report_dispatch.update(\n {PrivateConstants.ONE_WIRE_REPORT: self._onewire_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_DISTANCE_TO_GO:\n self._stepper_distance_to_go_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_TARGET_POSITION:\n self._stepper_target_position_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_CURRENT_POSITION:\n self._stepper_current_position_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_RUNNING_REPORT:\n self._stepper_is_running_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_RUN_COMPLETE_REPORT:\n self._stepper_run_complete_report})\n\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_DISTANCE_TO_GO:\n self._stepper_distance_to_go_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_TARGET_POSITION:\n self._stepper_target_position_report})\n self.report_dispatch.update(\n {PrivateConstants.FEATURES:\n self._features_report})\n\n # dictionaries to store the callbacks for each pin\n self.analog_callbacks = {}\n\n self.digital_callbacks = {}\n\n self.i2c_callback = None\n self.i2c_callback2 = None\n\n self.i2c_1_active = False\n self.i2c_2_active = False\n\n self.spi_callback = None\n\n self.onewire_callback = None\n\n self.cs_pins_enabled = []\n\n # the trigger pin will be the key to retrieve\n # the callback for a specific HC-SR04\n self.sonar_callbacks = {}\n\n self.sonar_count = 0\n\n self.dht_callbacks = {}\n\n self.dht_count = 0\n\n # serial port in use\n self.serial_port = None\n\n # socket for tcp/ip communications\n self.sock = None\n\n # flag to indicate we are in shutdown mode\n self.shutdown_flag = False\n\n # debug loopback callback method\n self.loop_back_callback = None\n\n # flag to indicate the start of a new report\n # self.new_report_start = True\n\n # firmware version to be stored here\n self.firmware_version = []\n\n # reported arduino instance id\n self.reported_arduino_id = []\n\n # reported features\n self.reported_features = 0\n\n # flag to indicate if i2c was previously enabled\n self.i2c_enabled = False\n\n # flag to indicate if spi is initialized\n self.spi_enabled = False\n\n # flag to indicate if onewire is initialized\n self.onewire_enabled = False\n\n # stepper motor variables\n\n # updated when a new motor is added\n # self.next_stepper_assigned = 0\n #\n # # valid list of stepper motor interface types\n # self.valid_stepper_interfaces = [1, 2, 3, 4, 6, 8]\n #\n # # maximum number of steppers supported\n # self.max_number_of_steppers = 4\n #\n # # number of steppers created - not to exceed the maximum\n # self.number_of_steppers = 0\n #\n # # dictionary to hold stepper motor information\n # self.stepper_info = {'instance': False, 'is_running': None,\n # 'maximum_speed': 1, 'speed': 0, 'acceleration': 0,\n # 'distance_to_go_callback': None,\n # 'target_position_callback': None,\n # 'current_position_callback': None,\n # 'is_running_callback': None,\n # 'motion_complete_callback': None,\n # 'acceleration_callback': None}\n #\n # # build a list of stepper motor info items\n # self.stepper_info_list = []\n # # a list of dictionaries to hold stepper information\n # for motor in range(self.max_number_of_steppers):\n # self.stepper_info_list.append(self.stepper_info)\n\n self.the_reporter_thread.start()\n self.the_data_receive_thread.start()\n\n print(f\"telemetrix_uno_r4_wifi: Version\"\n f\" {PrivateConstants.TELEMETRIX_VERSION}\\n\\n\"\n f\"Copyright (c) 2023 Alan Yorinks All Rights Reserved.\\n\")\n\n # using the serial link\n if not self.transport_address:\n if not self.com_port:\n # user did not specify a com_port\n try:\n self._find_arduino()\n except KeyboardInterrupt:\n if self.shutdown_on_exception:\n self.shutdown()\n else:\n # com_port specified - set com_port and baud rate\n try:\n self._manual_open()\n except KeyboardInterrupt:\n if self.shutdown_on_exception:\n self.shutdown()\n\n if self.serial_port:\n print(\n f\"Arduino compatible device found and connected to {self.serial_port.port}\")\n\n self.serial_port.reset_input_buffer()\n self.serial_port.reset_output_buffer()\n self.disable_scroll_message()\n\n # no com_port found - raise a runtime exception\n else:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError('No Arduino Found or User Aborted Program')\n else:\n self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n self.sock.connect((self.transport_address, self.ip_port))\n print(f'Successfully connected to: {self.transport_address}:{self.ip_port}')\n\n # allow the threads to run\n self._run_threads()\n print(f'Waiting for Arduino to reset')\n print(f'Reset Complete')\n\n # get telemetrix firmware version and print it\n print('\\nRetrieving Telemetrix4UnoR4WiFi firmware ID...')\n self._get_firmware_version()\n if not self.firmware_version:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'Telemetrix4UnoR4WiFi firmware version')\n\n else:\n\n print(f'Telemetrix4UnoR4WiFi firmware version: {self.firmware_version[0]}.'\n f'{self.firmware_version[1]}.{self.firmware_version[2]}')\n command = [PrivateConstants.ENABLE_ALL_REPORTS]\n self._send_command(command)\n\n # get the features list\n command = [PrivateConstants.GET_FEATURES]\n self._send_command(command)\n time.sleep(.2)\n\n # Have the server reset its data structures\n command = [PrivateConstants.RESET]\n self._send_command(command)\n time.sleep(.2)\n\n def _find_arduino(self):\n\"\"\"\n This method will search all potential serial ports for an Arduino\n containing a sketch that has a matching arduino_instance_id as\n specified in the input parameters of this class.\n\n This is used explicitly with the Telemetrix4Arduino sketch.\n \"\"\"\n\n # a list of serial ports to be checked\n serial_ports = []\n\n print('Opening all potential serial ports...')\n the_ports_list = list_ports.comports()\n for port in the_ports_list:\n if port.pid is None:\n continue\n try:\n self.serial_port = serial.Serial(port.device, 115200,\n timeout=1, writeTimeout=0)\n except SerialException:\n continue\n # create a list of serial ports that we opened\n serial_ports.append(self.serial_port)\n\n # display to the user\n print('\\t' + port.device)\n\n # clear out any possible data in the input buffer\n # wait for arduino to reset\n print(\n f'\\nWaiting {self.arduino_wait} seconds(arduino_wait) for Arduino devices to '\n 'reset...')\n # temporary for testing\n time.sleep(self.arduino_wait)\n self._run_threads()\n\n for serial_port in serial_ports:\n self.serial_port = serial_port\n\n self._get_arduino_id()\n if self.reported_arduino_id != self.arduino_instance_id:\n continue\n else:\n print('Valid Arduino ID Found.')\n self.serial_port.reset_input_buffer()\n self.serial_port.reset_output_buffer()\n return\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'Incorrect Arduino ID: {self.reported_arduino_id}')\n\n def _manual_open(self):\n\"\"\"\n Com port was specified by the user - try to open up that port\n\n \"\"\"\n # if port is not found, a serial exception will be thrown\n try:\n print(f'Opening {self.com_port}...')\n self.serial_port = serial.Serial(self.com_port, 115200,\n timeout=1, writeTimeout=0)\n\n print(\n f'\\nWaiting {self.arduino_wait} seconds(arduino_wait) for Arduino devices to '\n 'reset...')\n self._run_threads()\n time.sleep(self.arduino_wait)\n\n self._get_arduino_id()\n\n if self.reported_arduino_id != self.arduino_instance_id:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'Incorrect Arduino ID: {self.reported_arduino_id}')\n print('Valid Arduino ID Found.')\n # get arduino firmware version and print it\n print('\\nRetrieving Telemetrix4Arduino firmware ID...')\n self._get_firmware_version()\n\n if not self.firmware_version:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(\n f'Telemetrix4Arduino Sketch Firmware Version Not Found')\n\n else:\n print(f'Telemetrix4UnoR4 firmware version: {self.firmware_version[0]}.'\n f'{self.firmware_version[1]}')\n except KeyboardInterrupt:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError('User Hit Control-C')\n\n def analog_write(self, pin, value):\n\"\"\"\n Set the specified pin to the specified value.\n\n :param pin: arduino pin number\n\n :param value: pin value (maximum 16 bits)\n\n \"\"\"\n value_msb = value >> 8\n value_lsb = value & 0xff\n command = [PrivateConstants.ANALOG_WRITE, pin, value_msb, value_lsb]\n self._send_command(command)\n\n def digital_write(self, pin, value):\n\"\"\"\n Set the specified pin to the specified value.\n\n :param pin: arduino pin number\n\n :param value: pin value (1 or 0)\n\n \"\"\"\n\n command = [PrivateConstants.DIGITAL_WRITE, pin, value]\n self._send_command(command)\n\n def disable_all_reporting(self):\n\"\"\"\n Disable reporting for all digital and analog input pins\n \"\"\"\n command = [PrivateConstants.MODIFY_REPORTING,\n PrivateConstants.REPORTING_DISABLE_ALL, 0]\n self._send_command(command)\n\n def disable_analog_reporting(self, pin):\n\"\"\"\n Disables analog reporting for a single analog pin.\n\n :param pin: Analog pin number. For example for A0, the number is 0.\n\n \"\"\"\n command = [PrivateConstants.MODIFY_REPORTING,\n PrivateConstants.REPORTING_ANALOG_DISABLE, pin]\n self._send_command(command)\n\n def disable_digital_reporting(self, pin):\n\"\"\"\n Disables digital reporting for a single digital input.\n\n :param pin: Pin number.\n\n \"\"\"\n command = [PrivateConstants.MODIFY_REPORTING,\n PrivateConstants.REPORTING_DIGITAL_DISABLE, pin]\n self._send_command(command)\n\n def enable_analog_reporting(self, pin):\n\"\"\"\n Enables analog reporting for the specified pin.\n\n :param pin: Analog pin number. For example for A0, the number is 0.\n\n\n \"\"\"\n command = [PrivateConstants.MODIFY_REPORTING,\n PrivateConstants.REPORTING_ANALOG_ENABLE, pin]\n self._send_command(command)\n\n def enable_digital_reporting(self, pin):\n\"\"\"\n Enable reporting on the specified digital pin.\n\n :param pin: Pin number.\n \"\"\"\n\n command = [PrivateConstants.MODIFY_REPORTING,\n PrivateConstants.REPORTING_DIGITAL_ENABLE, pin]\n self._send_command(command)\n\n def _get_arduino_id(self):\n\"\"\"\n Retrieve arduino-telemetrix arduino id\n\n \"\"\"\n command = [PrivateConstants.ARE_U_THERE]\n self._send_command(command)\n # provide time for the reply\n time.sleep(.5)\n\n def _get_firmware_version(self):\n\"\"\"\n This method retrieves the\n arduino-telemetrix firmware version\n\n \"\"\"\n command = [PrivateConstants.GET_FIRMWARE_VERSION]\n self._send_command(command)\n # provide time for the reply\n time.sleep(.5)\n\n def i2c_read(self, address, register, number_of_bytes,\n callback=None, i2c_port=0,\n write_register=True):\n\"\"\"\n Read the specified number of bytes from the\n specified register for the i2c device.\n\n\n :param address: i2c device address\n\n :param register: i2c register (or None if no register\n selection is needed)\n\n :param number_of_bytes: number of bytes to be read\n\n :param callback: Required callback function to report\n i2c data as a result of read command\n\n :param i2c_port: 0 = default, 1 = secondary\n\n :param write_register: If True, the register is written\n before read\n Else, the write is suppressed\n\n\n callback returns a data list:\n\n [I2C_READ_REPORT, address, register, count of data bytes,\n data bytes, time-stamp]\n\n \"\"\"\n\n self._i2c_read_request(address, register, number_of_bytes,\n callback=callback, i2c_port=i2c_port,\n write_register=write_register)\n\n def i2c_read_restart_transmission(self, address, register,\n number_of_bytes,\n callback=None, i2c_port=0,\n write_register=True):\n\"\"\"\n Read the specified number of bytes from the specified\n register for the i2c device. This restarts the transmission\n after the read. It is required for some i2c devices such as the MMA8452Q\n accelerometer.\n\n\n :param address: i2c device address\n\n :param register: i2c register (or None if no register\n selection is needed)\n\n :param number_of_bytes: number of bytes to be read\n\n :param callback: Required callback function to report i2c\n data as a result of read command\n\n :param i2c_port: 0 = default 1 = secondary\n\n :param write_register: If True, the register is written before read\n Else, the write is suppressed\n\n\n\n callback returns a data list:\n\n [I2C_READ_REPORT, address, register, count of data bytes,\n data bytes, time-stamp]\n\n \"\"\"\n\n self._i2c_read_request(address, register, number_of_bytes,\n stop_transmission=False,\n callback=callback, i2c_port=i2c_port,\n write_register=write_register)\n\n def _i2c_read_request(self, address, register, number_of_bytes,\n stop_transmission=True, callback=None, i2c_port=0,\n write_register=True):\n\"\"\"\n This method requests the read of an i2c device. Results are retrieved\n via callback.\n\n :param address: i2c device address\n\n :param register: register number (or None if no register selection is needed)\n\n :param number_of_bytes: number of bytes expected to be returned\n\n :param stop_transmission: stop transmission after read\n\n :param callback: Required callback function to report i2c data as a\n result of read command.\n\n :param write_register: If True, the register is written before read\n Else, the write is suppressed\n\n \"\"\"\n if not i2c_port:\n if not self.i2c_1_active:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(\n 'I2C Read: set_pin_mode i2c never called for i2c port 1.')\n\n if i2c_port:\n if not self.i2c_2_active:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(\n 'I2C Read: set_pin_mode i2c never called for i2c port 2.')\n\n if not callback:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError('I2C Read: A callback function must be specified.')\n\n if not i2c_port:\n self.i2c_callback = callback\n else:\n self.i2c_callback2 = callback\n\n if not register:\n register = 0\n\n if write_register:\n write_register = 1\n else:\n write_register = 0\n\n # message contains:\n # 1. address\n # 2. register\n # 3. number of bytes\n # 4. restart_transmission - True or False\n # 5. i2c port\n # 6. suppress write flag\n\n command = [PrivateConstants.I2C_READ, address, register, number_of_bytes,\n stop_transmission, i2c_port, write_register]\n self._send_command(command)\n\n def i2c_write(self, address, args, i2c_port=0):\n\"\"\"\n Write data to an i2c device.\n\n :param address: i2c device address\n\n :param i2c_port: 0= port 1, 1 = port 2\n\n :param args: A variable number of bytes to be sent to the device\n passed in as a list\n\n \"\"\"\n if not i2c_port:\n if not self.i2c_1_active:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(\n 'I2C Write: set_pin_mode i2c never called for i2c port 1.')\n\n if i2c_port:\n if not self.i2c_2_active:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(\n 'I2C Write: set_pin_mode i2c never called for i2c port 2.')\n\n command = [PrivateConstants.I2C_WRITE, len(args), address, i2c_port]\n\n for item in args:\n command.append(item)\n\n self._send_command(command)\n\n def loop_back(self, start_character, callback=None):\n\"\"\"\n This is a debugging method to send a character to the\n Arduino device, and have the device loop it back.\n\n :param start_character: The character to loop back. It should be\n an integer.\n\n :param callback: Looped back character will appear in the callback method\n\n \"\"\"\n command = [PrivateConstants.LOOP_COMMAND, ord(start_character)]\n self.loop_back_callback = callback\n self._send_command(command)\n\n def set_analog_scan_interval(self, interval):\n\"\"\"\n Set the analog scanning interval.\n\n :param interval: value of 0 - 255 - milliseconds\n \"\"\"\n\n if 0 <= interval <= 255:\n command = [PrivateConstants.SET_ANALOG_SCANNING_INTERVAL, interval]\n self._send_command(command)\n else:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError('Analog interval must be between 0 and 255')\n\n def set_pin_mode_analog_output(self, pin_number):\n\"\"\"\n Set a pin as a pwm (analog output) pin.\n\n :param pin_number:arduino pin number\n\n \"\"\"\n self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT)\n\n def set_pin_mode_analog_input(self, pin_number, differential=0, callback=None):\n\"\"\"\n Set a pin as an analog input.\n\n :param pin_number: arduino pin number\n\n :param differential: difference in previous to current value before\n report will be generated\n\n :param callback: callback function\n\n\n callback returns a data list:\n\n [pin_type, pin_number, pin_value, raw_time_stamp]\n\n The pin_type for analog input pins = 3\n\n \"\"\"\n self._set_pin_mode(pin_number, PrivateConstants.AT_ANALOG, differential,\n callback)\n\n def set_pin_mode_digital_input(self, pin_number, callback=None):\n\"\"\"\n Set a pin as a digital input.\n\n :param pin_number: arduino pin number\n\n :param callback: callback function\n\n\n callback returns a data list:\n\n [pin_type, pin_number, pin_value, raw_time_stamp]\n\n The pin_type for all digital input pins = 2\n\n \"\"\"\n self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT, callback=callback)\n\n def set_pin_mode_digital_input_pullup(self, pin_number, callback=None):\n\"\"\"\n Set a pin as a digital input with pullup enabled.\n\n :param pin_number: arduino pin number\n\n :param callback: callback function\n\n\n callback returns a data list:\n\n [pin_type, pin_number, pin_value, raw_time_stamp]\n\n The pin_type for all digital input pins = 2\n \"\"\"\n self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT_PULLUP,\n callback=callback)\n\n def set_pin_mode_digital_output(self, pin_number):\n\"\"\"\n Set a pin as a digital output pin.\n\n :param pin_number: arduino pin number\n \"\"\"\n\n self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT)\n\n def set_pin_mode_i2c(self, i2c_port=0):\n\"\"\"\n Establish the standard Arduino i2c pins for i2c utilization.\n\n :param i2c_port: 0 = i2c1, 1 = i2c2\n\n NOTES: 1. THIS METHOD MUST BE CALLED BEFORE ANY I2C REQUEST IS MADE\n 2. Callbacks are set within the individual i2c read methods of this\n API.\n\n See i2c_read, or i2c_read_restart_transmission.\n\n \"\"\"\n # test for i2c port 2\n if i2c_port:\n # if not previously activated set it to activated\n # and the send a begin message for this port\n if not self.i2c_2_active:\n self.i2c_2_active = True\n else:\n return\n # port 1\n else:\n if not self.i2c_1_active:\n self.i2c_1_active = True\n else:\n return\n\n command = [PrivateConstants.I2C_BEGIN, i2c_port]\n self._send_command(command)\n\n def set_pin_mode_dht(self, pin, callback=None, dht_type=22):\n\"\"\"\n\n :param pin: connection pin\n\n :param callback: callback function\n\n :param dht_type: either 22 for DHT22 or 11 for DHT11\n\n Error Callback: [DHT REPORT Type, DHT_ERROR_NUMBER, PIN, DHT_TYPE, Time]\n\n Valid Data Callback: DHT REPORT Type, DHT_DATA=, PIN, DHT_TYPE, Humidity,\n Temperature,\n Time]\n\n DHT_REPORT_TYPE = 12\n \"\"\"\n if self.reported_features & PrivateConstants.DHT_FEATURE:\n if not callback:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError('set_pin_mode_dht: A Callback must be specified')\n\n if self.dht_count < PrivateConstants.MAX_DHTS - 1:\n self.dht_callbacks[pin] = callback\n self.dht_count += 1\n\n if dht_type != 22 and dht_type != 11:\n dht_type = 22\n\n command = [PrivateConstants.DHT_NEW, pin, dht_type]\n self._send_command(command)\n else:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(\n f'Maximum Number Of DHTs Exceeded - set_pin_mode_dht fails for pin {pin}')\n else:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'The DHT feature is disabled in the server.')\n\n # noinspection PyRedundantParentheses\n def set_pin_mode_servo(self, pin_number, min_pulse=544, max_pulse=2400):\n\"\"\"\n\n Attach a pin to a servo motor\n\n :param pin_number: pin\n\n :param min_pulse: minimum pulse width\n\n :param max_pulse: maximum pulse width\n\n \"\"\"\n if self.reported_features & PrivateConstants.SERVO_FEATURE:\n\n minv = (min_pulse).to_bytes(2, byteorder=\"big\")\n maxv = (max_pulse).to_bytes(2, byteorder=\"big\")\n\n command = [PrivateConstants.SERVO_ATTACH, pin_number,\n minv[0], minv[1], maxv[0], maxv[1]]\n self._send_command(command)\n else:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'The SERVO feature is disabled in the server.')\n\n def set_pin_mode_sonar(self, trigger_pin, echo_pin,\n callback=None):\n\"\"\"\n\n :param trigger_pin:\n\n :param echo_pin:\n\n :param callback: callback\n\n callback data: [PrivateConstants.SONAR_DISTANCE, trigger_pin, distance_value, time_stamp]\n\n \"\"\"\n if self.reported_features & PrivateConstants.SONAR_FEATURE:\n\n if not callback:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError('set_pin_mode_sonar: A Callback must be specified')\n\n if self.sonar_count < PrivateConstants.MAX_SONARS - 1:\n self.sonar_callbacks[trigger_pin] = callback\n self.sonar_count += 1\n\n command = [PrivateConstants.SONAR_NEW, trigger_pin, echo_pin]\n self._send_command(command)\n else:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(\n f'Maximum Number Of Sonars Exceeded - set_pin_mode_sonar fails for pin {trigger_pin}')\n else:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'The SONAR feature is disabled in the server.')\n\n def set_pin_mode_spi(self, chip_select_list=None):\n\"\"\"\n Specify the list of chip select pins.\n\n Standard Arduino MISO, MOSI and CLK pins are used for the board in use.\n\n Chip Select is any digital output capable pin.\n\n :param chip_select_list: this is a list of pins to be used for chip select.\n The pins will be configured as output, and set to high\n ready to be used for chip select.\n NOTE: You must specify the chips select pins here!\n\n\n command message: [command, [cs pins...]]\n \"\"\"\n\n if self.reported_features & PrivateConstants.SPI_FEATURE:\n if type(chip_select_list) != list:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError('chip_select_list must be in the form of a list')\n if not chip_select_list:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError('Chip select pins were not specified')\n\n self.spi_enabled = True\n\n command = [PrivateConstants.SPI_INIT, len(chip_select_list)]\n\n for pin in chip_select_list:\n command.append(pin)\n self.cs_pins_enabled.append(pin)\n self._send_command(command)\n else:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'The SPI feature is disabled in the server.')\n\n # def set_pin_mode_stepper(self, interface=1, pin1=2, pin2=3, pin3=4,\n # pin4=5, enable=True):\n # \"\"\"\n # Stepper motor support is implemented as a proxy for the\n # the AccelStepper library for the Arduino.\n #\n # This feature is compatible with the TB6600 Motor Driver\n #\n # Note: It may not work for other driver types!\n #\n # https://github.com/waspinator/AccelStepper\n #\n # Instantiate a stepper motor.\n #\n # Initialize the interface and pins for a stepper motor.\n #\n # :param interface: Motor Interface Type:\n #\n # 1 = Stepper Driver, 2 driver pins required\n #\n # 2 = FULL2WIRE 2 wire stepper, 2 motor pins required\n #\n # 3 = FULL3WIRE 3 wire stepper, such as HDD spindle,\n # 3 motor pins required\n #\n # 4 = FULL4WIRE, 4 wire full stepper, 4 motor pins\n # required\n #\n # 6 = HALF3WIRE, 3 wire half stepper, such as HDD spindle,\n # 3 motor pins required\n #\n # 8 = HALF4WIRE, 4 wire half stepper, 4 motor pins required\n #\n # :param pin1: Arduino digital pin number for motor pin 1\n #\n # :param pin2: Arduino digital pin number for motor pin 2\n #\n # :param pin3: Arduino digital pin number for motor pin 3\n #\n # :param pin4: Arduino digital pin number for motor pin 4\n #\n # :param enable: If this is true, the output pins at construction time.\n #\n # :return: Motor Reference number\n # \"\"\"\n # if self.reported_features & PrivateConstants.STEPPERS_FEATURE:\n #\n # if self.number_of_steppers == self.max_number_of_steppers:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('Maximum number of steppers has already been assigned')\n #\n # if interface not in self.valid_stepper_interfaces:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('Invalid stepper interface')\n #\n # self.number_of_steppers += 1\n #\n # motor_id = self.next_stepper_assigned\n # self.next_stepper_assigned += 1\n # self.stepper_info_list[motor_id]['instance'] = True\n #\n # # build message and send message to server\n # command = [PrivateConstants.SET_PIN_MODE_STEPPER, motor_id, interface, pin1,\n # pin2, pin3, pin4, enable]\n # self._send_command(command)\n #\n # # return motor id\n # return motor_id\n # else:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError(f'The Stepper feature is disabled in the server.')\n\n def servo_write(self, pin_number, angle):\n\"\"\"\n\n Set a servo attached to a pin to a given angle.\n\n :param pin_number: pin\n\n :param angle: angle (0-180)\n\n \"\"\"\n command = [PrivateConstants.SERVO_WRITE, pin_number, angle]\n self._send_command(command)\n\n def servo_detach(self, pin_number):\n\"\"\"\n Detach a servo for reuse\n\n :param pin_number: attached pin\n\n \"\"\"\n command = [PrivateConstants.SERVO_DETACH, pin_number]\n self._send_command(command)\n\n # def stepper_move_to(self, motor_id, position):\n # \"\"\"\n # Set an absolution target position. If position is positive, the movement is\n # clockwise, else it is counter-clockwise.\n #\n # The run() function (below) will try to move the motor (at most one step per call)\n # from the current position to the target position set by the most\n # recent call to this function. Caution: moveTo() also recalculates the\n # speed for the next step.\n # If you are trying to use constant speed movements, you should call setSpeed()\n # after calling moveTo().\n #\n # :param motor_id: motor id: 0 - 3\n #\n # :param position: target position. Maximum value is 32 bits.\n # \"\"\"\n # if position < 0:\n # polarity = 1\n # else:\n # polarity = 0\n # position = abs(position)\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_move_to: Invalid motor_id.')\n #\n # position_bytes = list(position.to_bytes(4, 'big', signed=True))\n #\n # command = [PrivateConstants.STEPPER_MOVE_TO, motor_id]\n # for value in position_bytes:\n # command.append(value)\n # command.append(polarity)\n # self._send_command(command)\n #\n # def stepper_move(self, motor_id, relative_position):\n # \"\"\"\n # Set the target position relative to the current position.\n #\n # :param motor_id: motor id: 0 - 3\n #\n # :param relative_position: The desired position relative to the current\n # position. Negative is anticlockwise from\n # the current position. Maximum value is 32 bits.\n # \"\"\"\n # if relative_position < 0:\n # polarity = 1\n # else:\n # polarity = 0\n #\n # relative_position = abs(relative_position)\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_move: Invalid motor_id.')\n #\n # position_bytes = list(relative_position.to_bytes(4, 'big', signed=True))\n #\n # command = [PrivateConstants.STEPPER_MOVE, motor_id]\n # for value in position_bytes:\n # command.append(value)\n # command.append(polarity)\n # self._send_command(command)\n #\n # def stepper_run(self, motor_id, completion_callback=None):\n # \"\"\"\n # This method steps the selected motor based on the current speed.\n #\n # Once called, the server will continuously attempt to step the motor.\n #\n # :param motor_id: 0 - 3\n #\n # :param completion_callback: call back function to receive motion complete\n # notification\n #\n # callback returns a data list:\n #\n # [report_type, motor_id, raw_time_stamp]\n #\n # The report_type = 19\n # \"\"\"\n # if not completion_callback:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_run: A motion complete callback must be '\n # 'specified.')\n #\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_run: Invalid motor_id.')\n #\n # self.stepper_info_list[motor_id]['motion_complete_callback'] = completion_callback\n # command = [PrivateConstants.STEPPER_RUN, motor_id]\n # self._send_command(command)\n #\n # def stepper_run_speed(self, motor_id):\n # \"\"\"\n # This method steps the selected motor based at a constant speed as set by the most\n # recent call to stepper_set_max_speed(). The motor will run continuously.\n #\n # Once called, the server will continuously attempt to step the motor.\n #\n # :param motor_id: 0 - 3\n #\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_run_speed: Invalid motor_id.')\n #\n # command = [PrivateConstants.STEPPER_RUN_SPEED, motor_id]\n # self._send_command(command)\n #\n # def stepper_set_max_speed(self, motor_id, max_speed):\n # \"\"\"\n # Sets the maximum permitted speed. The stepper_run() function will accelerate\n # up to the speed set by this function.\n #\n # Caution: the maximum speed achievable depends on your processor and clock speed.\n # The default maxSpeed is 1 step per second.\n #\n # Caution: Speeds that exceed the maximum speed supported by the processor may\n # result in non-linear accelerations and decelerations.\n #\n # :param motor_id: 0 - 3\n #\n # :param max_speed: 1 - 1000\n # \"\"\"\n #\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_set_max_speed: Invalid motor_id.')\n #\n # if not 1 < max_speed <= 1000:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_set_max_speed: Speed range is 1 - 1000.')\n #\n # self.stepper_info_list[motor_id]['max_speed'] = max_speed\n # max_speed_msb = (max_speed & 0xff00) >> 8\n # max_speed_lsb = max_speed & 0xff\n #\n # command = [PrivateConstants.STEPPER_SET_MAX_SPEED, motor_id, max_speed_msb,\n # max_speed_lsb]\n # self._send_command(command)\n #\n # def stepper_get_max_speed(self, motor_id):\n # \"\"\"\n # Returns the maximum speed configured for this stepper\n # that was previously set by stepper_set_max_speed()\n #\n # Value is stored in the client, so no callback is required.\n #\n # :param motor_id: 0 - 3\n #\n # :return: The currently configured maximum speed.\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_max_speed: Invalid motor_id.')\n #\n # return self.stepper_info_list[motor_id]['max_speed']\n #\n # def stepper_set_acceleration(self, motor_id, acceleration):\n # \"\"\"\n # Sets the acceleration/deceleration rate.\n #\n # :param motor_id: 0 - 3\n #\n # :param acceleration: The desired acceleration in steps per second\n # per second. Must be > 0.0. This is an\n # expensive call since it requires a square\n # root to be calculated on the server.\n # Dont call more often than needed.\n #\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_set_acceleration: Invalid motor_id.')\n #\n # if not 1 < acceleration <= 1000:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_set_acceleration: Acceleration range is 1 - '\n # '1000.')\n #\n # self.stepper_info_list[motor_id]['acceleration'] = acceleration\n #\n # max_accel_msb = acceleration >> 8\n # max_accel_lsb = acceleration & 0xff\n #\n # command = [PrivateConstants.STEPPER_SET_ACCELERATION, motor_id, max_accel_msb,\n # max_accel_lsb]\n # self._send_command(command)\n #\n # def stepper_set_speed(self, motor_id, speed):\n # \"\"\"\n # Sets the desired constant speed for use with stepper_run_speed().\n #\n # :param motor_id: 0 - 3\n #\n # :param speed: 0 - 1000 The desired constant speed in steps per\n # second. Positive is clockwise. Speeds of more than 1000 steps per\n # second are unreliable. Speed accuracy depends on the Arduino\n # crystal. Jitter depends on how frequently you call the\n # stepper_run_speed() method.\n # The speed will be limited by the current value of\n # stepper_set_max_speed().\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_set_speed: Invalid motor_id.')\n #\n # if not 0 < speed <= 1000:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_set_speed: Speed range is 0 - '\n # '1000.')\n #\n # self.stepper_info_list[motor_id]['speed'] = speed\n #\n # speed_msb = speed >> 8\n # speed_lsb = speed & 0xff\n #\n # command = [PrivateConstants.STEPPER_SET_SPEED, motor_id, speed_msb, speed_lsb]\n # self._send_command(command)\n #\n # def stepper_get_speed(self, motor_id):\n # \"\"\"\n # Returns the most recently set speed.\n # that was previously set by stepper_set_speed();\n #\n # Value is stored in the client, so no callback is required.\n #\n # :param motor_id: 0 - 3\n #\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_get_speed: Invalid motor_id.')\n #\n # return self.stepper_info_list[motor_id]['speed']\n #\n # def stepper_get_distance_to_go(self, motor_id, distance_to_go_callback):\n # \"\"\"\n # Request the distance from the current position to the target position\n # from the server.\n #\n # :param motor_id: 0 - 3\n #\n # :param distance_to_go_callback: required callback function to receive report\n #\n # :return: The distance to go is returned via the callback as a list:\n #\n # [REPORT_TYPE=15, motor_id, distance in steps, time_stamp]\n #\n # A positive distance is clockwise from the current position.\n #\n # \"\"\"\n # if not distance_to_go_callback:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_get_distance_to_go Read: A callback function must be specified.')\n #\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_get_distance_to_go: Invalid motor_id.')\n # self.stepper_info_list[motor_id][\n # 'distance_to_go_callback'] = distance_to_go_callback\n # command = [PrivateConstants.STEPPER_GET_DISTANCE_TO_GO, motor_id]\n # self._send_command(command)\n #\n # def stepper_get_target_position(self, motor_id, target_callback):\n # \"\"\"\n # Request the most recently set target position from the server.\n #\n # :param motor_id: 0 - 3\n #\n # :param target_callback: required callback function to receive report\n #\n # :return: The distance to go is returned via the callback as a list:\n #\n # [REPORT_TYPE=16, motor_id, target position in steps, time_stamp]\n #\n # Positive is clockwise from the 0 position.\n #\n # \"\"\"\n # if not target_callback:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError(\n # 'stepper_get_target_position Read: A callback function must be specified.')\n #\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_get_target_position: Invalid motor_id.')\n #\n # self.stepper_info_list[motor_id][\n # 'target_position_callback'] = target_callback\n #\n # command = [PrivateConstants.STEPPER_GET_TARGET_POSITION, motor_id]\n # self._send_command(command)\n #\n # def stepper_get_current_position(self, motor_id, current_position_callback):\n # \"\"\"\n # Request the current motor position from the server.\n #\n # :param motor_id: 0 - 3\n #\n # :param current_position_callback: required callback function to receive report\n #\n # :return: The current motor position returned via the callback as a list:\n #\n # [REPORT_TYPE=17, motor_id, current position in steps, time_stamp]\n #\n # Positive is clockwise from the 0 position.\n # \"\"\"\n # if not current_position_callback:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError(\n # 'stepper_get_current_position Read: A callback function must be specified.')\n #\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_get_current_position: Invalid motor_id.')\n #\n # self.stepper_info_list[motor_id]['current_position_callback'] = current_position_callback\n #\n # command = [PrivateConstants.STEPPER_GET_CURRENT_POSITION, motor_id]\n # self._send_command(command)\n #\n # def stepper_set_current_position(self, motor_id, position):\n # \"\"\"\n # Resets the current position of the motor, so that wherever the motor\n # happens to be right now is considered to be the new 0 position. Useful\n # for setting a zero position on a stepper after an initial hardware\n # positioning move.\n #\n # Has the side effect of setting the current motor speed to 0.\n #\n # :param motor_id: 0 - 3\n #\n # :param position: Position in steps. This is a 32 bit value\n # \"\"\"\n #\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_set_current_position: Invalid motor_id.')\n # position_bytes = list(position.to_bytes(4, 'big', signed=True))\n #\n # command = [PrivateConstants.STEPPER_SET_CURRENT_POSITION, motor_id]\n # for value in position_bytes:\n # command.append(value)\n # self._send_command(command)\n #\n # def stepper_run_speed_to_position(self, motor_id, completion_callback=None):\n # \"\"\"\n # Runs the motor at the currently selected speed until the target position is\n # reached.\n #\n # Does not implement accelerations.\n #\n # :param motor_id: 0 - 3\n #\n # :param completion_callback: call back function to receive motion complete\n # notification\n #\n # callback returns a data list:\n #\n # [report_type, motor_id, raw_time_stamp]\n #\n # The report_type = 19\n # \"\"\"\n # if not completion_callback:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_run_speed_to_position: A motion complete '\n # 'callback must be '\n # 'specified.')\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_run_speed_to_position: Invalid motor_id.')\n #\n # self.stepper_info_list[motor_id]['motion_complete_callback'] = completion_callback\n # command = [PrivateConstants.STEPPER_RUN_SPEED_TO_POSITION, motor_id]\n # self._send_command(command)\n #\n # def stepper_stop(self, motor_id):\n # \"\"\"\n # Sets a new target position that causes the stepper\n # to stop as quickly as possible, using the current speed and\n # acceleration parameters.\n #\n # :param motor_id: 0 - 3\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_stop: Invalid motor_id.')\n #\n # command = [PrivateConstants.STEPPER_STOP, motor_id]\n # self._send_command(command)\n #\n # def stepper_disable_outputs(self, motor_id):\n # \"\"\"\n # Disable motor pin outputs by setting them all LOW.\n #\n # Depending on the design of your electronics this may turn off\n # the power to the motor coils, saving power.\n #\n # This is useful to support Arduino low power modes: disable the outputs\n # during sleep and then re-enable with enableOutputs() before stepping\n # again.\n #\n # If the enable Pin is defined, sets it to OUTPUT mode and clears\n # the pin to disabled.\n #\n # :param motor_id: 0 - 3\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_disable_outputs: Invalid motor_id.')\n #\n # command = [PrivateConstants.STEPPER_DISABLE_OUTPUTS, motor_id]\n # self._send_command(command)\n #\n # def stepper_enable_outputs(self, motor_id):\n # \"\"\"\n # Enable motor pin outputs by setting the motor pins to OUTPUT\n # mode.\n #\n # If the enable Pin is defined, sets it to OUTPUT mode and sets\n # the pin to enabled.\n #\n # :param motor_id: 0 - 3\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_enable_outputs: Invalid motor_id.')\n #\n # command = [PrivateConstants.STEPPER_ENABLE_OUTPUTS, motor_id]\n # self._send_command(command)\n #\n # def stepper_set_min_pulse_width(self, motor_id, minimum_width):\n # \"\"\"\n # Sets the minimum pulse width allowed by the stepper driver.\n #\n # The minimum practical pulse width is approximately 20 microseconds.\n #\n # Times less than 20 microseconds will usually result in 20 microseconds or so.\n #\n # :param motor_id: 0 -3\n #\n # :param minimum_width: A 16 bit unsigned value expressed in microseconds.\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_set_min_pulse_width: Invalid motor_id.')\n #\n # if not 0 < minimum_width <= 0xff:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_set_min_pulse_width: Pulse width range = '\n # '0-0xffff.')\n #\n # width_msb = minimum_width >> 8\n # width_lsb = minimum_width & 0xff\n #\n # command = [PrivateConstants.STEPPER_SET_MINIMUM_PULSE_WIDTH, motor_id, width_msb,\n # width_lsb]\n # self._send_command(command)\n #\n # def stepper_set_enable_pin(self, motor_id, pin=0xff):\n # \"\"\"\n # Sets the enable pin number for stepper drivers.\n # 0xFF indicates unused (default).\n #\n # Otherwise, if a pin is set, the pin will be turned on when\n # enableOutputs() is called and switched off when disableOutputs()\n # is called.\n #\n # :param motor_id: 0 - 4\n # :param pin: 0-0xff\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_set_enable_pin: Invalid motor_id.')\n #\n # if not 0 < pin <= 0xff:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_set_enable_pin: Pulse width range = '\n # '0-0xff.')\n # command = [PrivateConstants.STEPPER_SET_ENABLE_PIN, motor_id, pin]\n #\n # self._send_command(command)\n #\n # def stepper_set_3_pins_inverted(self, motor_id, direction=False, step=False,\n # enable=False):\n # \"\"\"\n # Sets the inversion for stepper driver pins.\n #\n # :param motor_id: 0 - 3\n #\n # :param direction: True=inverted or False\n #\n # :param step: True=inverted or False\n #\n # :param enable: True=inverted or False\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_set_3_pins_inverted: Invalid motor_id.')\n #\n # command = [PrivateConstants.STEPPER_SET_3_PINS_INVERTED, motor_id, direction,\n # step, enable]\n #\n # self._send_command(command)\n #\n # def stepper_set_4_pins_inverted(self, motor_id, pin1_invert=False, pin2_invert=False,\n # pin3_invert=False, pin4_invert=False, enable=False):\n # \"\"\"\n # Sets the inversion for 2, 3 and 4 wire stepper pins\n #\n # :param motor_id: 0 - 3\n #\n # :param pin1_invert: True=inverted or False\n #\n # :param pin2_invert: True=inverted or False\n #\n # :param pin3_invert: True=inverted or False\n #\n # :param pin4_invert: True=inverted or False\n #\n # :param enable: True=inverted or False\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_set_4_pins_inverted: Invalid motor_id.')\n #\n # command = [PrivateConstants.STEPPER_SET_4_PINS_INVERTED, motor_id, pin1_invert,\n # pin2_invert, pin3_invert, pin4_invert, enable]\n #\n # self._send_command(command)\n #\n # def stepper_is_running(self, motor_id, callback):\n # \"\"\"\n # Checks to see if the motor is currently running to a target.\n #\n # Callback return True if the speed is not zero or not at the target position.\n #\n # :param motor_id: 0-4\n #\n # :param callback: required callback function to receive report\n #\n # :return: The current running state returned via the callback as a list:\n #\n # [REPORT_TYPE=18, motor_id, True or False for running state, time_stamp]\n # \"\"\"\n # if not callback:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError(\n # 'stepper_is_running: A callback function must be specified.')\n #\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('stepper_is_running: Invalid motor_id.')\n #\n # self.stepper_info_list[motor_id]['is_running_callback'] = callback\n #\n # command = [PrivateConstants.STEPPER_IS_RUNNING, motor_id]\n # self._send_command(command)\n\n def _set_pin_mode(self, pin_number, pin_state, differential=0, callback=None):\n\"\"\"\n A private method to set the various pin modes.\n\n :param pin_number: arduino pin number\n\n :param pin_state: INPUT/OUTPUT/ANALOG/PWM/PULLUP\n For SERVO use: set_pin_mode_servo\n For DHT use: set_pin_mode_dht\n\n :param differential: for analog inputs - threshold\n value to be achieved for report to\n be generated\n\n :param callback: A reference to a call back function to be\n called when pin data value changes\n\n \"\"\"\n if callback:\n if pin_state == PrivateConstants.AT_INPUT:\n self.digital_callbacks[pin_number] = callback\n elif pin_state == PrivateConstants.AT_INPUT_PULLUP:\n self.digital_callbacks[pin_number] = callback\n elif pin_state == PrivateConstants.AT_ANALOG:\n self.analog_callbacks[pin_number] = callback\n else:\n print('{} {}'.format('set_pin_mode: callback ignored for '\n 'pin state:', pin_state))\n\n if pin_state == PrivateConstants.AT_INPUT:\n command = [PrivateConstants.SET_PIN_MODE, pin_number,\n PrivateConstants.AT_INPUT, 1]\n\n elif pin_state == PrivateConstants.AT_INPUT_PULLUP:\n command = [PrivateConstants.SET_PIN_MODE, pin_number,\n PrivateConstants.AT_INPUT_PULLUP, 1]\n\n elif pin_state == PrivateConstants.AT_OUTPUT:\n command = [PrivateConstants.SET_PIN_MODE, pin_number,\n PrivateConstants.AT_OUTPUT]\n\n elif pin_state == PrivateConstants.AT_ANALOG:\n command = [PrivateConstants.SET_PIN_MODE, pin_number,\n PrivateConstants.AT_ANALOG,\n differential >> 8, differential & 0xff, 1]\n else:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError('Unknown pin state')\n\n if command:\n self._send_command(command)\n\n def shutdown(self):\n\"\"\"\n This method attempts an orderly shutdown\n If any exceptions are thrown, they are ignored.\n \"\"\"\n self.shutdown_flag = True\n\n self._stop_threads()\n\n try:\n command = [PrivateConstants.STOP_ALL_REPORTS]\n self._send_command(command)\n time.sleep(.5)\n\n if self.hard_reset_on_shutdown:\n self.r4_hard_reset()\n\n if self.transport_address:\n try:\n self.sock.shutdown(socket.SHUT_RDWR)\n self.sock.close()\n except Exception:\n pass\n else:\n try:\n self.serial_port.reset_input_buffer()\n self.serial_port.reset_output_buffer()\n\n self.serial_port.close()\n\n except (RuntimeError, SerialException, OSError):\n # ignore error on shutdown\n pass\n except Exception:\n # raise RuntimeError('Shutdown failed - could not send stop streaming\n # message')\n pass\n\n def sonar_disable(self):\n\"\"\"\n Disable sonar scanning for all sonar sensors\n \"\"\"\n command = [PrivateConstants.SONAR_DISABLE]\n self._send_command(command)\n\n def sonar_enable(self):\n\"\"\"\n Enable sonar scanning for all sonar sensors\n \"\"\"\n command = [PrivateConstants.SONAR_ENABLE]\n self._send_command(command)\n\n def spi_cs_control(self, chip_select_pin, select):\n\"\"\"\n Control an SPI chip select line\n :param chip_select_pin: pin connected to CS\n\n :param select: 0=select, 1=deselect\n \"\"\"\n if not self.spi_enabled:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'spi_cs_control: SPI interface is not enabled.')\n\n if chip_select_pin not in self.cs_pins_enabled:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'spi_cs_control: chip select pin never enabled.')\n command = [PrivateConstants.SPI_CS_CONTROL, chip_select_pin, select]\n self._send_command(command)\n\n def spi_read_blocking(self, chip_select, register_selection, number_of_bytes_to_read,\n call_back=None):\n\"\"\"\n Read the specified number of bytes from the specified SPI port and\n call the callback function with the reported data.\n\n :param chip_select: chip select pin\n\n :param register_selection: Register to be selected for read.\n\n :param number_of_bytes_to_read: Number of bytes to read\n\n :param call_back: Required callback function to report spi data as a\n result of read command\n\n\n callback returns a data list:\n [SPI_READ_REPORT, chip select pin, SPI Register, count of data bytes read,\n data bytes, time-stamp]\n\n SPI_READ_REPORT = 13\n\n \"\"\"\n\n if not self.spi_enabled:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'spi_read_blocking: SPI interface is not enabled.')\n\n if not call_back:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError('spi_read_blocking: A Callback must be specified')\n\n self.spi_callback = call_back\n\n command = [PrivateConstants.SPI_READ_BLOCKING, chip_select,\n number_of_bytes_to_read,\n register_selection]\n\n self._send_command(command)\n\n def spi_set_format(self, clock_divisor, bit_order, data_mode):\n\"\"\"\n Configure how the SPI serializes and de-serializes data on the wire.\n\n See Arduino SPI reference materials for details.\n\n :param clock_divisor: 1 - 255\n\n :param bit_order:\n\n LSBFIRST = 0\n\n MSBFIRST = 1 (default)\n\n :param data_mode:\n\n SPI_MODE0 = 0x00 (default)\n\n SPI_MODE1 = 1\n\n SPI_MODE2 = 2\n\n SPI_MODE3 = 3\n\n \"\"\"\n\n if not self.spi_enabled:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'spi_set_format: SPI interface is not enabled.')\n\n if not 0 < clock_divisor <= 255:\n raise RuntimeError(f'spi_set_format: illegal clock divisor selected.')\n if bit_order not in [0, 1]:\n raise RuntimeError(f'spi_set_format: illegal bit_order selected.')\n if data_mode not in [0, 1, 2, 3]:\n raise RuntimeError(f'spi_set_format: illegal data_order selected.')\n\n command = [PrivateConstants.SPI_SET_FORMAT, clock_divisor, bit_order,\n data_mode]\n self._send_command(command)\n\n def spi_write_blocking(self, chip_select, bytes_to_write):\n\"\"\"\n Write a list of bytes to the SPI device.\n\n :param chip_select: chip select pin\n\n :param bytes_to_write: A list of bytes to write. This must\n be in the form of a list.\n\n \"\"\"\n\n if not self.spi_enabled:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'spi_write_blocking: SPI interface is not enabled.')\n\n if type(bytes_to_write) is not list:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError('spi_write_blocking: bytes_to_write must be a list.')\n\n command = [PrivateConstants.SPI_WRITE_BLOCKING, chip_select, len(bytes_to_write)]\n\n for data in bytes_to_write:\n command.append(data)\n\n self._send_command(command)\n\n # def set_pin_mode_one_wire(self, pin):\n # \"\"\"\n # Initialize the one wire serial bus.\n #\n # :param pin: Data pin connected to the OneWire device\n # \"\"\"\n # if self.reported_features & PrivateConstants.ONEWIRE_FEATURE:\n # self.onewire_enabled = True\n # command = [PrivateConstants.ONE_WIRE_INIT, pin]\n # self._send_command(command)\n # else:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError(f'The OneWire feature is disabled in the server.')\n #\n # def onewire_reset(self, callback=None):\n # \"\"\"\n # Reset the onewire device\n #\n # :param callback: required function to report reset result\n #\n # callback returns a list:\n # [ReportType = 14, Report Subtype = 25, reset result byte,\n # timestamp]\n # \"\"\"\n # if not self.onewire_enabled:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError(f'onewire_reset: OneWire interface is not enabled.')\n # if not callback:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('onewire_reset: A Callback must be specified')\n #\n # self.onewire_callback = callback\n #\n # command = [PrivateConstants.ONE_WIRE_RESET]\n # self._send_command(command)\n #\n # def onewire_select(self, device_address):\n # \"\"\"\n # Select a device based on its address\n # :param device_address: A bytearray of 8 bytes\n # \"\"\"\n # if not self.onewire_enabled:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError(f'onewire_select: OneWire interface is not enabled.')\n #\n # if type(device_address) is not list:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('onewire_select: device address must be an array of 8 '\n # 'bytes.')\n #\n # if len(device_address) != 8:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('onewire_select: device address must be an array of 8 '\n # 'bytes.')\n # command = [PrivateConstants.ONE_WIRE_SELECT]\n # for data in device_address:\n # command.append(data)\n # self._send_command(command)\n #\n # def onewire_skip(self):\n # \"\"\"\n # Skip the device selection. This only works if you have a\n # single device, but you can avoid searching and use this to\n # immediately access your device.\n # \"\"\"\n # if not self.onewire_enabled:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError(f'onewire_skip: OneWire interface is not enabled.')\n #\n # command = [PrivateConstants.ONE_WIRE_SKIP]\n # self._send_command(command)\n #\n # def onewire_write(self, data, power=0):\n # \"\"\"\n # Write a byte to the onewire device. If 'power' is one\n # then the wire is held high at the end for\n # parasitically powered devices. You\n # are responsible for eventually de-powering it by calling\n # another read or write.\n #\n # :param data: byte to write.\n # :param power: power control (see above)\n # \"\"\"\n # if not self.onewire_enabled:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError(f'onewire_write: OneWire interface is not enabled.')\n # if 0 < data < 255:\n # command = [PrivateConstants.ONE_WIRE_WRITE, data, power]\n # self._send_command(command)\n # else:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('onewire_write: Data must be no larger than 255')\n #\n # def onewire_read(self, callback=None):\n # \"\"\"\n # Read a byte from the onewire device\n # :param callback: required function to report onewire data as a\n # result of read command\n #\n #\n # callback returns a data list:\n # [ONEWIRE_REPORT, ONEWIRE_READ=29, data byte, time-stamp]\n #\n # ONEWIRE_REPORT = 14\n # \"\"\"\n # if not self.onewire_enabled:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError(f'onewire_read: OneWire interface is not enabled.')\n #\n # if not callback:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('onewire_read A Callback must be specified')\n #\n # self.onewire_callback = callback\n #\n # command = [PrivateConstants.ONE_WIRE_READ]\n # self._send_command(command)\n # time.sleep(.2)\n #\n # def onewire_reset_search(self):\n # \"\"\"\n # Begin a new search. The next use of search will begin at the first device\n # \"\"\"\n #\n # if not self.onewire_enabled:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError(f'onewire_reset_search: OneWire interface is not '\n # f'enabled.')\n # else:\n # command = [PrivateConstants.ONE_WIRE_RESET_SEARCH]\n # self._send_command(command)\n #\n # def onewire_search(self, callback=None):\n # \"\"\"\n # Search for the next device. The device address will returned in the callback.\n # If a device is found, the 8 byte address is contained in the callback.\n # If no more devices are found, the address returned contains all elements set\n # to 0xff.\n #\n # :param callback: required function to report a onewire device address\n #\n # callback returns a data list:\n # [ONEWIRE_REPORT, ONEWIRE_SEARCH=31, 8 byte address, time-stamp]\n #\n # ONEWIRE_REPORT = 14\n # \"\"\"\n # if not self.onewire_enabled:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError(f'onewire_search: OneWire interface is not enabled.')\n #\n # if not callback:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('onewire_read A Callback must be specified')\n #\n # self.onewire_callback = callback\n #\n # command = [PrivateConstants.ONE_WIRE_SEARCH]\n # self._send_command(command)\n #\n # def onewire_crc8(self, address_list, callback=None):\n # \"\"\"\n # Compute a CRC check on an array of data.\n # :param address_list:\n #\n # :param callback: required function to report a onewire device address\n #\n # callback returns a data list:\n # [ONEWIRE_REPORT, ONEWIRE_CRC8=32, CRC, time-stamp]\n #\n # ONEWIRE_REPORT = 14\n #\n # \"\"\"\n #\n # if not self.onewire_enabled:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError(f'onewire_crc8: OneWire interface is not enabled.')\n #\n # if not callback:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('onewire_crc8 A Callback must be specified')\n #\n # if type(address_list) is not list:\n # if self.shutdown_on_exception:\n # self.shutdown()\n # raise RuntimeError('onewire_crc8: address list must be a list.')\n #\n # self.onewire_callback = callback\n #\n # address_length = len(address_list)\n #\n # command = [PrivateConstants.ONE_WIRE_CRC8, address_length - 1]\n #\n # for data in address_list:\n # command.append(data)\n #\n # self._send_command(command)\n\n def r4_hard_reset(self):\n\"\"\"\n Place the r4 into hard reset\n \"\"\"\n command = [PrivateConstants.RESET, 1]\n self._send_command(command)\n time.sleep(.5)\n command = [PrivateConstants.BOARD_HARD_RESET, 1]\n self._send_command(command)\n\n def enable_scroll_message(self, message, scroll_speed=50):\n\"\"\"\n\n :param message: Message with maximum length of 25\n :param scroll_speed: in milliseconds (maximum of 255)\n \"\"\"\n if len(message) > 25:\n raise RuntimeError(\"Scroll message size is maximum of 25 characters.\")\n\n if scroll_speed > 255:\n raise RuntimeError(\"Scroll speed maximum of 255 milliseconds.\")\n\n message = message.encode()\n command = [PrivateConstants.SCROLL_MESSAGE_ON, len(message), scroll_speed]\n for x in message:\n command.append(x)\n self._send_command(command)\n\n def disable_scroll_message(self):\n\"\"\"\n Turn off a scrolling message\n \"\"\"\n\n command = [PrivateConstants.SCROLL_MESSAGE_OFF]\n self._send_command(command)\n\n'''\n report message handlers\n '''\n\n def _analog_message(self, data):\n\"\"\"\n This is a private message handler method.\n It is a message handler for analog messages.\n\n :param data: message data\n\n \"\"\"\n pin = data[0]\n value = (data[1] << 8) + data[2]\n # set the current value in the pin structure\n time_stamp = time.time()\n # self.digital_pins[pin].event_time = time_stamp\n if self.analog_callbacks[pin]:\n message = [PrivateConstants.ANALOG_REPORT, pin, value, time_stamp]\n try:\n self.analog_callbacks[pin](message)\n except KeyError:\n pass\n\n def _dht_report(self, data):\n\"\"\"\n This is the dht report handler method.\n\n :param data: data[0] = report error return\n No Errors = 0\n\n Checksum Error = 1\n\n Timeout Error = 2\n\n Invalid Value = 999\n\n data[1] = pin number\n\n data[2] = dht type 11 or 22\n\n data[3] = humidity positivity flag\n\n data[4] = temperature positivity value\n\n data[5] = humidity integer\n\n data[6] = humidity fractional value\n\n data[7] = temperature integer\n\n data[8] = temperature fractional value\n\n\n \"\"\"\n if data[0]: # DHT_ERROR\n # error report\n # data[0] = report sub type, data[1] = pin, data[2] = error message\n if self.dht_callbacks[data[1]]:\n # Callback 0=DHT REPORT, DHT_ERROR, PIN, Time\n message = [PrivateConstants.DHT_REPORT, data[0], data[1], data[2],\n time.time()]\n try:\n self.dht_callbacks[data[1]](message)\n except KeyError:\n pass\n else:\n # got valid data DHT_DATA\n f_humidity = float(data[5] + data[6] / 100)\n if data[3]:\n f_humidity *= -1.0\n f_temperature = float(data[7] + data[8] / 100)\n if data[4]:\n f_temperature *= -1.0\n message = [PrivateConstants.DHT_REPORT, data[0], data[1], data[2],\n f_humidity, f_temperature, time.time()]\n\n try:\n self.dht_callbacks[data[1]](message)\n except KeyError:\n pass\n\n def _digital_message(self, data):\n\"\"\"\n This is a private message handler method.\n It is a message handler for Digital Messages.\n\n :param data: digital message\n\n \"\"\"\n pin = data[0]\n value = data[1]\n\n time_stamp = time.time()\n if self.digital_callbacks[pin]:\n message = [PrivateConstants.DIGITAL_REPORT, pin, value, time_stamp]\n self.digital_callbacks[pin](message)\n\n def _firmware_message(self, data):\n\"\"\"\n Telemetrix4Arduino firmware version message\n\n :param data: data[0] = major number, data[1] = minor number.\n\n data[2] = patch number\n \"\"\"\n\n self.firmware_version = [data[0], data[1], data[2]]\n\n def _i2c_read_report(self, data):\n\"\"\"\n Execute callback for i2c reads.\n\n :param data: [I2C_READ_REPORT, i2c_port, number of bytes read, address, register, bytes read..., time-stamp]\n \"\"\"\n\n # we receive [# data bytes, address, register, data bytes]\n # number of bytes of data returned\n\n # data[0] = number of bytes\n # data[1] = i2c_port\n # data[2] = number of bytes returned\n # data[3] = address\n # data[4] = register\n # data[5] ... all the data bytes\n\n cb_list = [PrivateConstants.I2C_READ_REPORT, data[0], data[1]] + data[2:]\n cb_list.append(time.time())\n\n if cb_list[1]:\n self.i2c_callback2(cb_list)\n else:\n self.i2c_callback(cb_list)\n\n def _i2c_too_few(self, data):\n\"\"\"\n I2c reports too few bytes received\n\n :param data: data[0] = device address\n \"\"\"\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(\n f'i2c too few bytes received from i2c port {data[0]} i2c address {data[1]}')\n\n def _i2c_too_many(self, data):\n\"\"\"\n I2c reports too few bytes received\n\n :param data: data[0] = device address\n \"\"\"\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(\n f'i2c too many bytes received from i2c port {data[0]} i2c address {data[1]}')\n\n def _i_am_here(self, data):\n\"\"\"\n Reply to are_u_there message\n :param data: arduino id\n \"\"\"\n self.reported_arduino_id = data[0]\n\n def _spi_report(self, report):\n\n cb_list = [PrivateConstants.SPI_REPORT, report[0]] + report[1:]\n\n cb_list.append(time.time())\n\n self.spi_callback(cb_list)\n\n def _onewire_report(self, report):\n cb_list = [PrivateConstants.ONE_WIRE_REPORT, report[0]] + report[1:]\n cb_list.append(time.time())\n self.onewire_callback(cb_list)\n\n def _report_debug_data(self, data):\n\"\"\"\n Print debug data sent from Arduino\n :param data: data[0] is a byte followed by 2\n bytes that comprise an integer\n :return:\n \"\"\"\n value = (data[1] << 8) + data[2]\n print(f'DEBUG ID: {data[0]} Value: {value}')\n\n def _report_loop_data(self, data):\n\"\"\"\n Print data that was looped back\n :param data: byte of loop back data\n :return:\n \"\"\"\n if self.loop_back_callback:\n self.loop_back_callback(data)\n\n def _send_command(self, command):\n\"\"\"\n This is a private utility method.\n\n\n :param command: command data in the form of a list\n\n \"\"\"\n # the length of the list is added at the head\n command.insert(0, len(command))\n send_message = bytes(command)\n\n if self.serial_port:\n try:\n self.serial_port.write(send_message)\n except SerialException:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError('write fail in _send_command')\n elif self.transport_address:\n self.sock.sendall(send_message)\n else:\n raise RuntimeError('No serial port or ip address set.')\n\n def _servo_unavailable(self, report):\n\"\"\"\n Message if no servos are available for use.\n :param report: pin number\n \"\"\"\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(\n f'Servo Attach For Pin {report[0]} Failed: No Available Servos')\n\n def _sonar_distance_report(self, report):\n\"\"\"\n\n :param report: data[0] = trigger pin, data[1] and data[2] = distance\n\n callback report format: [PrivateConstants.SONAR_DISTANCE, trigger_pin, distance_value, time_stamp]\n \"\"\"\n\n # get callback from pin number\n cb = self.sonar_callbacks[report[0]]\n\n # build report data\n cb_list = [PrivateConstants.SONAR_DISTANCE, report[0],\n ((report[1] << 8) + report[2]), time.time()]\n\n cb(cb_list)\n\n def _stepper_distance_to_go_report(self, report):\n return # for now\n # \"\"\"\n # Report stepper distance to go.\n #\n # :param report: data[0] = motor_id, data[1] = steps MSB, data[2] = steps byte 1,\n # data[3] = steps bytes 2, data[4] = steps LSB\n #\n # callback report format: [PrivateConstants.STEPPER_DISTANCE_TO_GO, motor_id\n # steps, time_stamp]\n # \"\"\"\n #\n # # get callback\n # cb = self.stepper_info_list[report[0]]['distance_to_go_callback']\n #\n # # isolate the steps bytes and covert list to bytes\n # steps = bytes(report[1:])\n #\n # # get value from steps\n # num_steps = int.from_bytes(steps, byteorder='big', signed=True)\n #\n # cb_list = [PrivateConstants.STEPPER_DISTANCE_TO_GO, report[0], num_steps,\n # time.time()]\n #\n # cb(cb_list)\n #\n def _stepper_target_position_report(self, report):\n return # for now\n # \"\"\"\n # Report stepper target position to go.\n #\n # :param report: data[0] = motor_id, data[1] = target position MSB,\n # data[2] = target position byte MSB+1\n # data[3] = target position byte MSB+2\n # data[4] = target position LSB\n #\n # callback report format: [PrivateConstants.STEPPER_TARGET_POSITION, motor_id\n # target_position, time_stamp]\n # \"\"\"\n #\n # # get callback\n # cb = self.stepper_info_list[report[0]]['target_position_callback']\n #\n # # isolate the steps bytes and covert list to bytes\n # target = bytes(report[1:])\n #\n # # get value from steps\n # target_position = int.from_bytes(target, byteorder='big', signed=True)\n #\n # cb_list = [PrivateConstants.STEPPER_TARGET_POSITION, report[0], target_position,\n # time.time()]\n #\n # cb(cb_list)\n #\n def _stepper_current_position_report(self, report):\n return # for now\n # \"\"\"\n # Report stepper current position.\n #\n # :param report: data[0] = motor_id, data[1] = current position MSB,\n # data[2] = current position byte MSB+1\n # data[3] = current position byte MSB+2\n # data[4] = current position LSB\n #\n # callback report format: [PrivateConstants.STEPPER_CURRENT_POSITION, motor_id\n # current_position, time_stamp]\n # \"\"\"\n #\n # # get callback\n # cb = self.stepper_info_list[report[0]]['current_position_callback']\n #\n # # isolate the steps bytes and covert list to bytes\n # position = bytes(report[1:])\n #\n # # get value from steps\n # current_position = int.from_bytes(position, byteorder='big', signed=True)\n #\n # cb_list = [PrivateConstants.STEPPER_CURRENT_POSITION, report[0], current_position,\n # time.time()]\n #\n # cb(cb_list)\n #\n def _stepper_is_running_report(self, report):\n return # for now\n # \"\"\"\n # Report if the motor is currently running\n #\n # :param report: data[0] = motor_id, True if motor is running or False if it is not.\n #\n # callback report format: [18, motor_id,\n # running_state, time_stamp]\n # \"\"\"\n #\n # # get callback\n # cb = self.stepper_info_list[report[0]]['is_running_callback']\n #\n # cb_list = [PrivateConstants.STEPPER_RUNNING_REPORT, report[0], time.time()]\n #\n # cb(cb_list)\n #\n def _stepper_run_complete_report(self, report):\n return # for now\n # \"\"\"\n # The motor completed it motion\n #\n # :param report: data[0] = motor_id\n #\n # callback report format: [PrivateConstants.STEPPER_RUN_COMPLETE_REPORT, motor_id,\n # time_stamp]\n # \"\"\"\n #\n # # get callback\n # cb = self.stepper_info_list[report[0]]['motion_complete_callback']\n #\n # cb_list = [PrivateConstants.STEPPER_RUN_COMPLETE_REPORT, report[0],\n # time.time()]\n #\n # cb(cb_list)\n\n def _features_report(self, report):\n self.reported_features = report[0]\n\n def _run_threads(self):\n self.run_event.set()\n\n def _is_running(self):\n return self.run_event.is_set()\n\n def _stop_threads(self):\n self.run_event.clear()\n\n def _reporter(self):\n\"\"\"\n This is the reporter thread. It continuously pulls data from\n the deque. When a full message is detected, that message is\n processed.\n \"\"\"\n self.run_event.wait()\n\n while self._is_running() and not self.shutdown_flag:\n if len(self.the_deque):\n # response_data will be populated with the received data for the report\n response_data = []\n packet_length = self.the_deque.popleft()\n # print(f'packet_length {packet_length}')\n if packet_length:\n # get all the data for the report and place it into response_data\n for i in range(packet_length):\n while not len(self.the_deque):\n time.sleep(self.sleep_tune)\n data = self.the_deque.popleft()\n response_data.append(data)\n\n # print(f'response_data {response_data}')\n\n # get the report type and look up its dispatch method\n # here we pop the report type off of response_data\n report_type = response_data.pop(0)\n # print(f' reported type {report_type}')\n\n # retrieve the report handler from the dispatch table\n dispatch_entry = self.report_dispatch.get(report_type)\n\n # if there is additional data for the report,\n # it will be contained in response_data\n # noinspection PyArgumentList\n dispatch_entry(response_data)\n continue\n else:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(\n 'A report with a packet length of zero was received.')\n else:\n time.sleep(self.sleep_tune)\n\n def _serial_receiver(self):\n\"\"\"\n Thread to continuously check for incoming data.\n When a byte comes in, place it onto the deque.\n \"\"\"\n self.run_event.wait()\n\n # Don't start this thread if using a tcp/ip transport\n if self.transport_address:\n return\n\n while self._is_running() and not self.shutdown_flag:\n # we can get an OSError: [Errno9] Bad file descriptor when shutting down\n # just ignore it\n try:\n if self.serial_port.inWaiting():\n c = self.serial_port.read()\n self.the_deque.append(ord(c))\n # print(ord(c))\n else:\n time.sleep(self.sleep_tune)\n # continue\n except OSError:\n pass\n\n def _tcp_receiver(self):\n\"\"\"\n Thread to continuously check for incoming data.\n When a byte comes in, place it onto the deque.\n \"\"\"\n self.run_event.wait()\n\n # Start this thread only if transport_address is set\n\n if self.transport_address:\n\n while self._is_running() and not self.shutdown_flag:\n try:\n payload = self.sock.recv(1)\n self.the_deque.append(ord(payload))\n except Exception:\n pass\n else:\n return\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.__init__","title":"__init__(com_port=None, arduino_instance_id=1, arduino_wait=1, sleep_tune=1e-06, shutdown_on_exception=True, hard_reset_on_shutdown=True, transport_address=None, ip_port=31336, transport_type=0)
","text":":param com_port: e.g. COM3 or /dev/ttyACM0. Only use if you wish to bypass auto com port detection.
:param arduino_instance_id: Match with the value installed on the arduino-telemetrix sketch.
:param arduino_wait: Amount of time to wait for an Arduino to fully reset itself.
:param sleep_tune: A tuning parameter (typically not changed by user)
:param shutdown_on_exception: call shutdown before raising a RunTimeError exception, or receiving a KeyboardInterrupt exception
:param hard_reset_on_shutdown: reset the board on shutdown
:param transport_address: ip address of tcp/ip connected device.
:param ip_port: ip port of tcp/ip connected device
:param transport_type: 0 = WiFI 1 = USBSerial 2 = BLE
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def __init__(self, com_port=None, arduino_instance_id=1,\n arduino_wait=1, sleep_tune=0.000001,\n shutdown_on_exception=True, hard_reset_on_shutdown=True,\n transport_address=None, ip_port=31336, transport_type=0):\n\n\"\"\"\n\n :param com_port: e.g. COM3 or /dev/ttyACM0.\n Only use if you wish to bypass auto com port\n detection.\n\n :param arduino_instance_id: Match with the value installed on the\n arduino-telemetrix sketch.\n\n :param arduino_wait: Amount of time to wait for an Arduino to\n fully reset itself.\n\n :param sleep_tune: A tuning parameter (typically not changed by user)\n\n :param shutdown_on_exception: call shutdown before raising\n a RunTimeError exception, or\n receiving a KeyboardInterrupt exception\n\n :param hard_reset_on_shutdown: reset the board on shutdown\n\n :param transport_address: ip address of tcp/ip connected device.\n\n :param ip_port: ip port of tcp/ip connected device\n\n :param transport_type: 0 = WiFI\n 1 = USBSerial\n 2 = BLE\n\n\n \"\"\"\n\n # initialize threading parent\n threading.Thread.__init__(self)\n\n # create the threads and set them as daemons so\n # that they stop when the program is closed\n\n # create a thread to interpret received serial data\n self.the_reporter_thread = threading.Thread(target=self._reporter)\n self.the_reporter_thread.daemon = True\n\n self.transport_address = transport_address\n self.ip_port = ip_port\n\n if transport_type not in [0, 1, 2]:\n raise RuntimeError(\"Valid transport_type value is 0, 1, or 2\")\n\n self.transport_type = transport_type\n\n if transport_type == 0:\n if not transport_address:\n raise RuntimeError(\"An IP address must be specified.\")\n\n if not self.transport_address:\n self.the_data_receive_thread = threading.Thread(target=self._serial_receiver)\n else:\n self.the_data_receive_thread = threading.Thread(target=self._tcp_receiver)\n\n self.the_data_receive_thread.daemon = True\n\n # flag to allow the reporter and receive threads to run.\n self.run_event = threading.Event()\n\n # check to make sure that Python interpreter is version 3.7 or greater\n python_version = sys.version_info\n if python_version[0] >= 3:\n if python_version[1] >= 7:\n pass\n else:\n raise RuntimeError(\"ERROR: Python 3.7 or greater is \"\n \"required for use of this program.\")\n\n # save input parameters as instance variables\n self.com_port = com_port\n self.arduino_instance_id = arduino_instance_id\n self.arduino_wait = arduino_wait\n self.sleep_tune = sleep_tune\n self.shutdown_on_exception = shutdown_on_exception\n self.hard_reset_on_shutdown = hard_reset_on_shutdown\n\n # create a deque to receive and process data from the arduino\n self.the_deque = deque()\n\n # The report_dispatch dictionary is used to process\n # incoming report messages by looking up the report message\n # and executing its associated processing method.\n\n self.report_dispatch = {}\n\n # To add a command to the command dispatch table, append here.\n self.report_dispatch.update(\n {PrivateConstants.LOOP_COMMAND: self._report_loop_data})\n self.report_dispatch.update(\n {PrivateConstants.DEBUG_PRINT: self._report_debug_data})\n self.report_dispatch.update(\n {PrivateConstants.DIGITAL_REPORT: self._digital_message})\n self.report_dispatch.update(\n {PrivateConstants.ANALOG_REPORT: self._analog_message})\n self.report_dispatch.update(\n {PrivateConstants.FIRMWARE_REPORT: self._firmware_message})\n self.report_dispatch.update({PrivateConstants.I_AM_HERE_REPORT: self._i_am_here})\n self.report_dispatch.update(\n {PrivateConstants.SERVO_UNAVAILABLE: self._servo_unavailable})\n self.report_dispatch.update(\n {PrivateConstants.I2C_READ_REPORT: self._i2c_read_report})\n self.report_dispatch.update(\n {PrivateConstants.I2C_TOO_FEW_BYTES_RCVD: self._i2c_too_few})\n self.report_dispatch.update(\n {PrivateConstants.I2C_TOO_MANY_BYTES_RCVD: self._i2c_too_many})\n self.report_dispatch.update(\n {PrivateConstants.SONAR_DISTANCE: self._sonar_distance_report})\n self.report_dispatch.update({PrivateConstants.DHT_REPORT: self._dht_report})\n self.report_dispatch.update(\n {PrivateConstants.SPI_REPORT: self._spi_report})\n self.report_dispatch.update(\n {PrivateConstants.ONE_WIRE_REPORT: self._onewire_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_DISTANCE_TO_GO:\n self._stepper_distance_to_go_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_TARGET_POSITION:\n self._stepper_target_position_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_CURRENT_POSITION:\n self._stepper_current_position_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_RUNNING_REPORT:\n self._stepper_is_running_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_RUN_COMPLETE_REPORT:\n self._stepper_run_complete_report})\n\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_DISTANCE_TO_GO:\n self._stepper_distance_to_go_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_TARGET_POSITION:\n self._stepper_target_position_report})\n self.report_dispatch.update(\n {PrivateConstants.FEATURES:\n self._features_report})\n\n # dictionaries to store the callbacks for each pin\n self.analog_callbacks = {}\n\n self.digital_callbacks = {}\n\n self.i2c_callback = None\n self.i2c_callback2 = None\n\n self.i2c_1_active = False\n self.i2c_2_active = False\n\n self.spi_callback = None\n\n self.onewire_callback = None\n\n self.cs_pins_enabled = []\n\n # the trigger pin will be the key to retrieve\n # the callback for a specific HC-SR04\n self.sonar_callbacks = {}\n\n self.sonar_count = 0\n\n self.dht_callbacks = {}\n\n self.dht_count = 0\n\n # serial port in use\n self.serial_port = None\n\n # socket for tcp/ip communications\n self.sock = None\n\n # flag to indicate we are in shutdown mode\n self.shutdown_flag = False\n\n # debug loopback callback method\n self.loop_back_callback = None\n\n # flag to indicate the start of a new report\n # self.new_report_start = True\n\n # firmware version to be stored here\n self.firmware_version = []\n\n # reported arduino instance id\n self.reported_arduino_id = []\n\n # reported features\n self.reported_features = 0\n\n # flag to indicate if i2c was previously enabled\n self.i2c_enabled = False\n\n # flag to indicate if spi is initialized\n self.spi_enabled = False\n\n # flag to indicate if onewire is initialized\n self.onewire_enabled = False\n\n # stepper motor variables\n\n # updated when a new motor is added\n # self.next_stepper_assigned = 0\n #\n # # valid list of stepper motor interface types\n # self.valid_stepper_interfaces = [1, 2, 3, 4, 6, 8]\n #\n # # maximum number of steppers supported\n # self.max_number_of_steppers = 4\n #\n # # number of steppers created - not to exceed the maximum\n # self.number_of_steppers = 0\n #\n # # dictionary to hold stepper motor information\n # self.stepper_info = {'instance': False, 'is_running': None,\n # 'maximum_speed': 1, 'speed': 0, 'acceleration': 0,\n # 'distance_to_go_callback': None,\n # 'target_position_callback': None,\n # 'current_position_callback': None,\n # 'is_running_callback': None,\n # 'motion_complete_callback': None,\n # 'acceleration_callback': None}\n #\n # # build a list of stepper motor info items\n # self.stepper_info_list = []\n # # a list of dictionaries to hold stepper information\n # for motor in range(self.max_number_of_steppers):\n # self.stepper_info_list.append(self.stepper_info)\n\n self.the_reporter_thread.start()\n self.the_data_receive_thread.start()\n\n print(f\"telemetrix_uno_r4_wifi: Version\"\n f\" {PrivateConstants.TELEMETRIX_VERSION}\\n\\n\"\n f\"Copyright (c) 2023 Alan Yorinks All Rights Reserved.\\n\")\n\n # using the serial link\n if not self.transport_address:\n if not self.com_port:\n # user did not specify a com_port\n try:\n self._find_arduino()\n except KeyboardInterrupt:\n if self.shutdown_on_exception:\n self.shutdown()\n else:\n # com_port specified - set com_port and baud rate\n try:\n self._manual_open()\n except KeyboardInterrupt:\n if self.shutdown_on_exception:\n self.shutdown()\n\n if self.serial_port:\n print(\n f\"Arduino compatible device found and connected to {self.serial_port.port}\")\n\n self.serial_port.reset_input_buffer()\n self.serial_port.reset_output_buffer()\n self.disable_scroll_message()\n\n # no com_port found - raise a runtime exception\n else:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError('No Arduino Found or User Aborted Program')\n else:\n self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n self.sock.connect((self.transport_address, self.ip_port))\n print(f'Successfully connected to: {self.transport_address}:{self.ip_port}')\n\n # allow the threads to run\n self._run_threads()\n print(f'Waiting for Arduino to reset')\n print(f'Reset Complete')\n\n # get telemetrix firmware version and print it\n print('\\nRetrieving Telemetrix4UnoR4WiFi firmware ID...')\n self._get_firmware_version()\n if not self.firmware_version:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'Telemetrix4UnoR4WiFi firmware version')\n\n else:\n\n print(f'Telemetrix4UnoR4WiFi firmware version: {self.firmware_version[0]}.'\n f'{self.firmware_version[1]}.{self.firmware_version[2]}')\n command = [PrivateConstants.ENABLE_ALL_REPORTS]\n self._send_command(command)\n\n # get the features list\n command = [PrivateConstants.GET_FEATURES]\n self._send_command(command)\n time.sleep(.2)\n\n # Have the server reset its data structures\n command = [PrivateConstants.RESET]\n self._send_command(command)\n time.sleep(.2)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.analog_write","title":"analog_write(pin, value)
","text":"Set the specified pin to the specified value.
:param pin: arduino pin number
:param value: pin value (maximum 16 bits)
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def analog_write(self, pin, value):\n\"\"\"\n Set the specified pin to the specified value.\n\n :param pin: arduino pin number\n\n :param value: pin value (maximum 16 bits)\n\n \"\"\"\n value_msb = value >> 8\n value_lsb = value & 0xff\n command = [PrivateConstants.ANALOG_WRITE, pin, value_msb, value_lsb]\n self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.digital_write","title":"digital_write(pin, value)
","text":"Set the specified pin to the specified value.
:param pin: arduino pin number
:param value: pin value (1 or 0)
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def digital_write(self, pin, value):\n\"\"\"\n Set the specified pin to the specified value.\n\n :param pin: arduino pin number\n\n :param value: pin value (1 or 0)\n\n \"\"\"\n\n command = [PrivateConstants.DIGITAL_WRITE, pin, value]\n self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.disable_all_reporting","title":"disable_all_reporting()
","text":"Disable reporting for all digital and analog input pins
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def disable_all_reporting(self):\n\"\"\"\n Disable reporting for all digital and analog input pins\n \"\"\"\n command = [PrivateConstants.MODIFY_REPORTING,\n PrivateConstants.REPORTING_DISABLE_ALL, 0]\n self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.disable_analog_reporting","title":"disable_analog_reporting(pin)
","text":"Disables analog reporting for a single analog pin.
:param pin: Analog pin number. For example for A0, the number is 0.
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def disable_analog_reporting(self, pin):\n\"\"\"\n Disables analog reporting for a single analog pin.\n\n :param pin: Analog pin number. For example for A0, the number is 0.\n\n \"\"\"\n command = [PrivateConstants.MODIFY_REPORTING,\n PrivateConstants.REPORTING_ANALOG_DISABLE, pin]\n self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.disable_digital_reporting","title":"disable_digital_reporting(pin)
","text":"Disables digital reporting for a single digital input.
:param pin: Pin number.
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def disable_digital_reporting(self, pin):\n\"\"\"\n Disables digital reporting for a single digital input.\n\n :param pin: Pin number.\n\n \"\"\"\n command = [PrivateConstants.MODIFY_REPORTING,\n PrivateConstants.REPORTING_DIGITAL_DISABLE, pin]\n self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.disable_scroll_message","title":"disable_scroll_message()
","text":"Turn off a scrolling message
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def disable_scroll_message(self):\n\"\"\"\n Turn off a scrolling message\n \"\"\"\n\n command = [PrivateConstants.SCROLL_MESSAGE_OFF]\n self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.enable_analog_reporting","title":"enable_analog_reporting(pin)
","text":"Enables analog reporting for the specified pin.
:param pin: Analog pin number. For example for A0, the number is 0.
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def enable_analog_reporting(self, pin):\n\"\"\"\n Enables analog reporting for the specified pin.\n\n :param pin: Analog pin number. For example for A0, the number is 0.\n\n\n \"\"\"\n command = [PrivateConstants.MODIFY_REPORTING,\n PrivateConstants.REPORTING_ANALOG_ENABLE, pin]\n self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.enable_digital_reporting","title":"enable_digital_reporting(pin)
","text":"Enable reporting on the specified digital pin.
:param pin: Pin number.
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def enable_digital_reporting(self, pin):\n\"\"\"\n Enable reporting on the specified digital pin.\n\n :param pin: Pin number.\n \"\"\"\n\n command = [PrivateConstants.MODIFY_REPORTING,\n PrivateConstants.REPORTING_DIGITAL_ENABLE, pin]\n self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.enable_scroll_message","title":"enable_scroll_message(message, scroll_speed=50)
","text":":param message: Message with maximum length of 25 :param scroll_speed: in milliseconds (maximum of 255)
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def enable_scroll_message(self, message, scroll_speed=50):\n\"\"\"\n\n :param message: Message with maximum length of 25\n :param scroll_speed: in milliseconds (maximum of 255)\n \"\"\"\n if len(message) > 25:\n raise RuntimeError(\"Scroll message size is maximum of 25 characters.\")\n\n if scroll_speed > 255:\n raise RuntimeError(\"Scroll speed maximum of 255 milliseconds.\")\n\n message = message.encode()\n command = [PrivateConstants.SCROLL_MESSAGE_ON, len(message), scroll_speed]\n for x in message:\n command.append(x)\n self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.i2c_read","title":"i2c_read(address, register, number_of_bytes, callback=None, i2c_port=0, write_register=True)
","text":"Read the specified number of bytes from the specified register for the i2c device.
:param address: i2c device address
:param register: i2c register (or None if no register selection is needed)
:param number_of_bytes: number of bytes to be read
:param callback: Required callback function to report i2c data as a result of read command
:param i2c_port: 0 = default, 1 = secondary
:param write_register: If True, the register is written before read Else, the write is suppressed
callback returns a data list:
[I2C_READ_REPORT, address, register, count of data bytes, data bytes, time-stamp]
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def i2c_read(self, address, register, number_of_bytes,\n callback=None, i2c_port=0,\n write_register=True):\n\"\"\"\n Read the specified number of bytes from the\n specified register for the i2c device.\n\n\n :param address: i2c device address\n\n :param register: i2c register (or None if no register\n selection is needed)\n\n :param number_of_bytes: number of bytes to be read\n\n :param callback: Required callback function to report\n i2c data as a result of read command\n\n :param i2c_port: 0 = default, 1 = secondary\n\n :param write_register: If True, the register is written\n before read\n Else, the write is suppressed\n\n\n callback returns a data list:\n\n [I2C_READ_REPORT, address, register, count of data bytes,\n data bytes, time-stamp]\n\n \"\"\"\n\n self._i2c_read_request(address, register, number_of_bytes,\n callback=callback, i2c_port=i2c_port,\n write_register=write_register)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.i2c_read_restart_transmission","title":"i2c_read_restart_transmission(address, register, number_of_bytes, callback=None, i2c_port=0, write_register=True)
","text":"Read the specified number of bytes from the specified register for the i2c device. This restarts the transmission after the read. It is required for some i2c devices such as the MMA8452Q accelerometer.
:param address: i2c device address
:param register: i2c register (or None if no register selection is needed)
:param number_of_bytes: number of bytes to be read
:param callback: Required callback function to report i2c data as a result of read command
:param i2c_port: 0 = default 1 = secondary
:param write_register: If True, the register is written before read Else, the write is suppressed
callback returns a data list:
[I2C_READ_REPORT, address, register, count of data bytes, data bytes, time-stamp]
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def i2c_read_restart_transmission(self, address, register,\n number_of_bytes,\n callback=None, i2c_port=0,\n write_register=True):\n\"\"\"\n Read the specified number of bytes from the specified\n register for the i2c device. This restarts the transmission\n after the read. It is required for some i2c devices such as the MMA8452Q\n accelerometer.\n\n\n :param address: i2c device address\n\n :param register: i2c register (or None if no register\n selection is needed)\n\n :param number_of_bytes: number of bytes to be read\n\n :param callback: Required callback function to report i2c\n data as a result of read command\n\n :param i2c_port: 0 = default 1 = secondary\n\n :param write_register: If True, the register is written before read\n Else, the write is suppressed\n\n\n\n callback returns a data list:\n\n [I2C_READ_REPORT, address, register, count of data bytes,\n data bytes, time-stamp]\n\n \"\"\"\n\n self._i2c_read_request(address, register, number_of_bytes,\n stop_transmission=False,\n callback=callback, i2c_port=i2c_port,\n write_register=write_register)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.i2c_write","title":"i2c_write(address, args, i2c_port=0)
","text":"Write data to an i2c device.
:param address: i2c device address
:param i2c_port: 0= port 1, 1 = port 2
:param args: A variable number of bytes to be sent to the device passed in as a list
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def i2c_write(self, address, args, i2c_port=0):\n\"\"\"\n Write data to an i2c device.\n\n :param address: i2c device address\n\n :param i2c_port: 0= port 1, 1 = port 2\n\n :param args: A variable number of bytes to be sent to the device\n passed in as a list\n\n \"\"\"\n if not i2c_port:\n if not self.i2c_1_active:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(\n 'I2C Write: set_pin_mode i2c never called for i2c port 1.')\n\n if i2c_port:\n if not self.i2c_2_active:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(\n 'I2C Write: set_pin_mode i2c never called for i2c port 2.')\n\n command = [PrivateConstants.I2C_WRITE, len(args), address, i2c_port]\n\n for item in args:\n command.append(item)\n\n self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.loop_back","title":"loop_back(start_character, callback=None)
","text":"This is a debugging method to send a character to the Arduino device, and have the device loop it back.
:param start_character: The character to loop back. It should be an integer.
:param callback: Looped back character will appear in the callback method
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def loop_back(self, start_character, callback=None):\n\"\"\"\n This is a debugging method to send a character to the\n Arduino device, and have the device loop it back.\n\n :param start_character: The character to loop back. It should be\n an integer.\n\n :param callback: Looped back character will appear in the callback method\n\n \"\"\"\n command = [PrivateConstants.LOOP_COMMAND, ord(start_character)]\n self.loop_back_callback = callback\n self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.r4_hard_reset","title":"r4_hard_reset()
","text":"Place the r4 into hard reset
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def r4_hard_reset(self):\n\"\"\"\n Place the r4 into hard reset\n \"\"\"\n command = [PrivateConstants.RESET, 1]\n self._send_command(command)\n time.sleep(.5)\n command = [PrivateConstants.BOARD_HARD_RESET, 1]\n self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.servo_detach","title":"servo_detach(pin_number)
","text":"Detach a servo for reuse
:param pin_number: attached pin
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def servo_detach(self, pin_number):\n\"\"\"\n Detach a servo for reuse\n\n :param pin_number: attached pin\n\n \"\"\"\n command = [PrivateConstants.SERVO_DETACH, pin_number]\n self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.servo_write","title":"servo_write(pin_number, angle)
","text":"Set a servo attached to a pin to a given angle.
:param pin_number: pin
:param angle: angle (0-180)
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def servo_write(self, pin_number, angle):\n\"\"\"\n\n Set a servo attached to a pin to a given angle.\n\n :param pin_number: pin\n\n :param angle: angle (0-180)\n\n \"\"\"\n command = [PrivateConstants.SERVO_WRITE, pin_number, angle]\n self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.set_analog_scan_interval","title":"set_analog_scan_interval(interval)
","text":"Set the analog scanning interval.
:param interval: value of 0 - 255 - milliseconds
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def set_analog_scan_interval(self, interval):\n\"\"\"\n Set the analog scanning interval.\n\n :param interval: value of 0 - 255 - milliseconds\n \"\"\"\n\n if 0 <= interval <= 255:\n command = [PrivateConstants.SET_ANALOG_SCANNING_INTERVAL, interval]\n self._send_command(command)\n else:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError('Analog interval must be between 0 and 255')\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.set_pin_mode_analog_input","title":"set_pin_mode_analog_input(pin_number, differential=0, callback=None)
","text":"Set a pin as an analog input.
:param pin_number: arduino pin number
:param differential: difference in previous to current value before report will be generated
:param callback: callback function
callback returns a data list:
[pin_type, pin_number, pin_value, raw_time_stamp]
The pin_type for analog input pins = 3
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def set_pin_mode_analog_input(self, pin_number, differential=0, callback=None):\n\"\"\"\n Set a pin as an analog input.\n\n :param pin_number: arduino pin number\n\n :param differential: difference in previous to current value before\n report will be generated\n\n :param callback: callback function\n\n\n callback returns a data list:\n\n [pin_type, pin_number, pin_value, raw_time_stamp]\n\n The pin_type for analog input pins = 3\n\n \"\"\"\n self._set_pin_mode(pin_number, PrivateConstants.AT_ANALOG, differential,\n callback)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.set_pin_mode_analog_output","title":"set_pin_mode_analog_output(pin_number)
","text":"Set a pin as a pwm (analog output) pin.
:param pin_number:arduino pin number
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def set_pin_mode_analog_output(self, pin_number):\n\"\"\"\n Set a pin as a pwm (analog output) pin.\n\n :param pin_number:arduino pin number\n\n \"\"\"\n self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.set_pin_mode_dht","title":"set_pin_mode_dht(pin, callback=None, dht_type=22)
","text":":param pin: connection pin
:param callback: callback function
:param dht_type: either 22 for DHT22 or 11 for DHT11
Error Callback: [DHT REPORT Type, DHT_ERROR_NUMBER, PIN, DHT_TYPE, Time]
Valid Data Callback: DHT REPORT Type, DHT_DATA=, PIN, DHT_TYPE, Humidity, Temperature, Time]
DHT_REPORT_TYPE = 12
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def set_pin_mode_dht(self, pin, callback=None, dht_type=22):\n\"\"\"\n\n :param pin: connection pin\n\n :param callback: callback function\n\n :param dht_type: either 22 for DHT22 or 11 for DHT11\n\n Error Callback: [DHT REPORT Type, DHT_ERROR_NUMBER, PIN, DHT_TYPE, Time]\n\n Valid Data Callback: DHT REPORT Type, DHT_DATA=, PIN, DHT_TYPE, Humidity,\n Temperature,\n Time]\n\n DHT_REPORT_TYPE = 12\n \"\"\"\n if self.reported_features & PrivateConstants.DHT_FEATURE:\n if not callback:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError('set_pin_mode_dht: A Callback must be specified')\n\n if self.dht_count < PrivateConstants.MAX_DHTS - 1:\n self.dht_callbacks[pin] = callback\n self.dht_count += 1\n\n if dht_type != 22 and dht_type != 11:\n dht_type = 22\n\n command = [PrivateConstants.DHT_NEW, pin, dht_type]\n self._send_command(command)\n else:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(\n f'Maximum Number Of DHTs Exceeded - set_pin_mode_dht fails for pin {pin}')\n else:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'The DHT feature is disabled in the server.')\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.set_pin_mode_digital_input","title":"set_pin_mode_digital_input(pin_number, callback=None)
","text":"Set a pin as a digital input.
:param pin_number: arduino pin number
:param callback: callback function
callback returns a data list:
[pin_type, pin_number, pin_value, raw_time_stamp]
The pin_type for all digital input pins = 2
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def set_pin_mode_digital_input(self, pin_number, callback=None):\n\"\"\"\n Set a pin as a digital input.\n\n :param pin_number: arduino pin number\n\n :param callback: callback function\n\n\n callback returns a data list:\n\n [pin_type, pin_number, pin_value, raw_time_stamp]\n\n The pin_type for all digital input pins = 2\n\n \"\"\"\n self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT, callback=callback)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.set_pin_mode_digital_input_pullup","title":"set_pin_mode_digital_input_pullup(pin_number, callback=None)
","text":"Set a pin as a digital input with pullup enabled.
:param pin_number: arduino pin number
:param callback: callback function
callback returns a data list:
[pin_type, pin_number, pin_value, raw_time_stamp]
The pin_type for all digital input pins = 2
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def set_pin_mode_digital_input_pullup(self, pin_number, callback=None):\n\"\"\"\n Set a pin as a digital input with pullup enabled.\n\n :param pin_number: arduino pin number\n\n :param callback: callback function\n\n\n callback returns a data list:\n\n [pin_type, pin_number, pin_value, raw_time_stamp]\n\n The pin_type for all digital input pins = 2\n \"\"\"\n self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT_PULLUP,\n callback=callback)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.set_pin_mode_digital_output","title":"set_pin_mode_digital_output(pin_number)
","text":"Set a pin as a digital output pin.
:param pin_number: arduino pin number
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def set_pin_mode_digital_output(self, pin_number):\n\"\"\"\n Set a pin as a digital output pin.\n\n :param pin_number: arduino pin number\n \"\"\"\n\n self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.set_pin_mode_i2c","title":"set_pin_mode_i2c(i2c_port=0)
","text":"Establish the standard Arduino i2c pins for i2c utilization.
:param i2c_port: 0 = i2c1, 1 = i2c2
API.\n\n See i2c_read, or i2c_read_restart_transmission.\n
Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def set_pin_mode_i2c(self, i2c_port=0):\n\"\"\"\n Establish the standard Arduino i2c pins for i2c utilization.\n\n :param i2c_port: 0 = i2c1, 1 = i2c2\n\n NOTES: 1. THIS METHOD MUST BE CALLED BEFORE ANY I2C REQUEST IS MADE\n 2. Callbacks are set within the individual i2c read methods of this\n API.\n\n See i2c_read, or i2c_read_restart_transmission.\n\n \"\"\"\n # test for i2c port 2\n if i2c_port:\n # if not previously activated set it to activated\n # and the send a begin message for this port\n if not self.i2c_2_active:\n self.i2c_2_active = True\n else:\n return\n # port 1\n else:\n if not self.i2c_1_active:\n self.i2c_1_active = True\n else:\n return\n\n command = [PrivateConstants.I2C_BEGIN, i2c_port]\n self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.set_pin_mode_servo","title":"set_pin_mode_servo(pin_number, min_pulse=544, max_pulse=2400)
","text":"Attach a pin to a servo motor
:param pin_number: pin
:param min_pulse: minimum pulse width
:param max_pulse: maximum pulse width
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def set_pin_mode_servo(self, pin_number, min_pulse=544, max_pulse=2400):\n\"\"\"\n\n Attach a pin to a servo motor\n\n :param pin_number: pin\n\n :param min_pulse: minimum pulse width\n\n :param max_pulse: maximum pulse width\n\n \"\"\"\n if self.reported_features & PrivateConstants.SERVO_FEATURE:\n\n minv = (min_pulse).to_bytes(2, byteorder=\"big\")\n maxv = (max_pulse).to_bytes(2, byteorder=\"big\")\n\n command = [PrivateConstants.SERVO_ATTACH, pin_number,\n minv[0], minv[1], maxv[0], maxv[1]]\n self._send_command(command)\n else:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'The SERVO feature is disabled in the server.')\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.set_pin_mode_sonar","title":"set_pin_mode_sonar(trigger_pin, echo_pin, callback=None)
","text":":param trigger_pin:
:param echo_pin:
:param callback: callback
callback data: [PrivateConstants.SONAR_DISTANCE, trigger_pin, distance_value, time_stamp]
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def set_pin_mode_sonar(self, trigger_pin, echo_pin,\n callback=None):\n\"\"\"\n\n :param trigger_pin:\n\n :param echo_pin:\n\n :param callback: callback\n\n callback data: [PrivateConstants.SONAR_DISTANCE, trigger_pin, distance_value, time_stamp]\n\n \"\"\"\n if self.reported_features & PrivateConstants.SONAR_FEATURE:\n\n if not callback:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError('set_pin_mode_sonar: A Callback must be specified')\n\n if self.sonar_count < PrivateConstants.MAX_SONARS - 1:\n self.sonar_callbacks[trigger_pin] = callback\n self.sonar_count += 1\n\n command = [PrivateConstants.SONAR_NEW, trigger_pin, echo_pin]\n self._send_command(command)\n else:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(\n f'Maximum Number Of Sonars Exceeded - set_pin_mode_sonar fails for pin {trigger_pin}')\n else:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'The SONAR feature is disabled in the server.')\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.set_pin_mode_spi","title":"set_pin_mode_spi(chip_select_list=None)
","text":"Specify the list of chip select pins.
Standard Arduino MISO, MOSI and CLK pins are used for the board in use.
Chip Select is any digital output capable pin.
:param chip_select_list: this is a list of pins to be used for chip select. The pins will be configured as output, and set to high ready to be used for chip select. NOTE: You must specify the chips select pins here!
command message: [command, [cs pins...]]
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def set_pin_mode_spi(self, chip_select_list=None):\n\"\"\"\n Specify the list of chip select pins.\n\n Standard Arduino MISO, MOSI and CLK pins are used for the board in use.\n\n Chip Select is any digital output capable pin.\n\n :param chip_select_list: this is a list of pins to be used for chip select.\n The pins will be configured as output, and set to high\n ready to be used for chip select.\n NOTE: You must specify the chips select pins here!\n\n\n command message: [command, [cs pins...]]\n \"\"\"\n\n if self.reported_features & PrivateConstants.SPI_FEATURE:\n if type(chip_select_list) != list:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError('chip_select_list must be in the form of a list')\n if not chip_select_list:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError('Chip select pins were not specified')\n\n self.spi_enabled = True\n\n command = [PrivateConstants.SPI_INIT, len(chip_select_list)]\n\n for pin in chip_select_list:\n command.append(pin)\n self.cs_pins_enabled.append(pin)\n self._send_command(command)\n else:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'The SPI feature is disabled in the server.')\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.shutdown","title":"shutdown()
","text":"This method attempts an orderly shutdown If any exceptions are thrown, they are ignored.
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def shutdown(self):\n\"\"\"\n This method attempts an orderly shutdown\n If any exceptions are thrown, they are ignored.\n \"\"\"\n self.shutdown_flag = True\n\n self._stop_threads()\n\n try:\n command = [PrivateConstants.STOP_ALL_REPORTS]\n self._send_command(command)\n time.sleep(.5)\n\n if self.hard_reset_on_shutdown:\n self.r4_hard_reset()\n\n if self.transport_address:\n try:\n self.sock.shutdown(socket.SHUT_RDWR)\n self.sock.close()\n except Exception:\n pass\n else:\n try:\n self.serial_port.reset_input_buffer()\n self.serial_port.reset_output_buffer()\n\n self.serial_port.close()\n\n except (RuntimeError, SerialException, OSError):\n # ignore error on shutdown\n pass\n except Exception:\n # raise RuntimeError('Shutdown failed - could not send stop streaming\n # message')\n pass\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.sonar_disable","title":"sonar_disable()
","text":"Disable sonar scanning for all sonar sensors
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def sonar_disable(self):\n\"\"\"\n Disable sonar scanning for all sonar sensors\n \"\"\"\n command = [PrivateConstants.SONAR_DISABLE]\n self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.sonar_enable","title":"sonar_enable()
","text":"Enable sonar scanning for all sonar sensors
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def sonar_enable(self):\n\"\"\"\n Enable sonar scanning for all sonar sensors\n \"\"\"\n command = [PrivateConstants.SONAR_ENABLE]\n self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.spi_cs_control","title":"spi_cs_control(chip_select_pin, select)
","text":"Control an SPI chip select line :param chip_select_pin: pin connected to CS
:param select: 0=select, 1=deselect
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def spi_cs_control(self, chip_select_pin, select):\n\"\"\"\n Control an SPI chip select line\n :param chip_select_pin: pin connected to CS\n\n :param select: 0=select, 1=deselect\n \"\"\"\n if not self.spi_enabled:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'spi_cs_control: SPI interface is not enabled.')\n\n if chip_select_pin not in self.cs_pins_enabled:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'spi_cs_control: chip select pin never enabled.')\n command = [PrivateConstants.SPI_CS_CONTROL, chip_select_pin, select]\n self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.spi_read_blocking","title":"spi_read_blocking(chip_select, register_selection, number_of_bytes_to_read, call_back=None)
","text":"Read the specified number of bytes from the specified SPI port and call the callback function with the reported data.
:param chip_select: chip select pin
:param register_selection: Register to be selected for read.
:param number_of_bytes_to_read: Number of bytes to read
:param call_back: Required callback function to report spi data as a result of read command
callback returns a data list: [SPI_READ_REPORT, chip select pin, SPI Register, count of data bytes read, data bytes, time-stamp]
SPI_READ_REPORT = 13
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def spi_read_blocking(self, chip_select, register_selection, number_of_bytes_to_read,\n call_back=None):\n\"\"\"\n Read the specified number of bytes from the specified SPI port and\n call the callback function with the reported data.\n\n :param chip_select: chip select pin\n\n :param register_selection: Register to be selected for read.\n\n :param number_of_bytes_to_read: Number of bytes to read\n\n :param call_back: Required callback function to report spi data as a\n result of read command\n\n\n callback returns a data list:\n [SPI_READ_REPORT, chip select pin, SPI Register, count of data bytes read,\n data bytes, time-stamp]\n\n SPI_READ_REPORT = 13\n\n \"\"\"\n\n if not self.spi_enabled:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'spi_read_blocking: SPI interface is not enabled.')\n\n if not call_back:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError('spi_read_blocking: A Callback must be specified')\n\n self.spi_callback = call_back\n\n command = [PrivateConstants.SPI_READ_BLOCKING, chip_select,\n number_of_bytes_to_read,\n register_selection]\n\n self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.spi_set_format","title":"spi_set_format(clock_divisor, bit_order, data_mode)
","text":"Configure how the SPI serializes and de-serializes data on the wire.
See Arduino SPI reference materials for details.
:param clock_divisor: 1 - 255
:param bit_order:
LSBFIRST = 0\n\n MSBFIRST = 1 (default)\n
:param data_mode:
SPI_MODE0 = 0x00 (default)\n\n SPI_MODE1 = 1\n\n SPI_MODE2 = 2\n\n SPI_MODE3 = 3\n
Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def spi_set_format(self, clock_divisor, bit_order, data_mode):\n\"\"\"\n Configure how the SPI serializes and de-serializes data on the wire.\n\n See Arduino SPI reference materials for details.\n\n :param clock_divisor: 1 - 255\n\n :param bit_order:\n\n LSBFIRST = 0\n\n MSBFIRST = 1 (default)\n\n :param data_mode:\n\n SPI_MODE0 = 0x00 (default)\n\n SPI_MODE1 = 1\n\n SPI_MODE2 = 2\n\n SPI_MODE3 = 3\n\n \"\"\"\n\n if not self.spi_enabled:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'spi_set_format: SPI interface is not enabled.')\n\n if not 0 < clock_divisor <= 255:\n raise RuntimeError(f'spi_set_format: illegal clock divisor selected.')\n if bit_order not in [0, 1]:\n raise RuntimeError(f'spi_set_format: illegal bit_order selected.')\n if data_mode not in [0, 1, 2, 3]:\n raise RuntimeError(f'spi_set_format: illegal data_order selected.')\n\n command = [PrivateConstants.SPI_SET_FORMAT, clock_divisor, bit_order,\n data_mode]\n self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.spi_write_blocking","title":"spi_write_blocking(chip_select, bytes_to_write)
","text":"Write a list of bytes to the SPI device.
:param chip_select: chip select pin
:param bytes_to_write: A list of bytes to write. This must be in the form of a list.
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def spi_write_blocking(self, chip_select, bytes_to_write):\n\"\"\"\n Write a list of bytes to the SPI device.\n\n :param chip_select: chip select pin\n\n :param bytes_to_write: A list of bytes to write. This must\n be in the form of a list.\n\n \"\"\"\n\n if not self.spi_enabled:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError(f'spi_write_blocking: SPI interface is not enabled.')\n\n if type(bytes_to_write) is not list:\n if self.shutdown_on_exception:\n self.shutdown()\n raise RuntimeError('spi_write_blocking: bytes_to_write must be a list.')\n\n command = [PrivateConstants.SPI_WRITE_BLOCKING, chip_select, len(bytes_to_write)]\n\n for data in bytes_to_write:\n command.append(data)\n\n self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/","title":"telemetrix_uno_r4_wifi_aio","text":"Copyright (c) 2023 Alan Yorinks All rights reserved.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 as published by the Free Software Foundation; either or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio","title":"TelemetrixUnoR4WiFiAio
","text":"This class exposes and implements the TelemetrixUnoR4WifiAio API. It includes the public API methods as well as a set of private methods. This is an asyncio API.
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
class TelemetrixUnoR4WiFiAio:\n\"\"\"\n This class exposes and implements the TelemetrixUnoR4WifiAio API.\n It includes the public API methods as well as\n a set of private methods. This is an asyncio API.\n\n \"\"\"\n\n # noinspection PyPep8,PyPep8\n def __init__(self, com_port=None,\n arduino_instance_id=1, arduino_wait=1,\n sleep_tune=0.0001, autostart=True,\n loop=None, shutdown_on_exception=True,\n close_loop_on_shutdown=True, hard_reset_on_shutdown=True,\n transport_address=None, ip_port=31336, transport_type=0,\n ble_device_name='Telemetrix4UnoR4 BLE'):\n\n\"\"\"\n If you have a single Arduino connected to your computer,\n then you may accept all the default values.\n\n Otherwise, specify a unique arduino_instance id for each board in use.\n\n :param com_port: e.g. COM3 or /dev/ttyACM0.\n\n :param arduino_instance_id: Must match value in the Telemetrix4Arduino sketch\n\n :param arduino_wait: Amount of time to wait for an Arduino to\n fully reset itself.\n\n :param sleep_tune: A tuning parameter (typically not changed by user)\n\n :param autostart: If you wish to call the start method within\n your application, then set this to False.\n\n :param loop: optional user provided event loop\n\n :param shutdown_on_exception: call shutdown before raising\n a RunTimeError exception, or\n receiving a KeyboardInterrupt exception\n\n :param close_loop_on_shutdown: stop and close the event loop loop\n when a shutdown is called or a serial\n error occurs\n\n :param hard_reset_on_shutdown: reset the board on shutdown\n\n :param transport_address: ip address of tcp/ip connected device.\n\n :param ip_port: ip port of tcp/ip connected device\n\n :param transport_type: 0 = WiFi\n 1 = SerialUSB\n 2 = BLE\n\n :param ble_device_name: name of Arduino UNO R4 WIFI BLE device.\n It must match that of Telemetrix4UnoR4BLE.ino\n\n \"\"\"\n # check to make sure that Python interpreter is version 3.8.3 or greater\n python_version = sys.version_info\n if python_version[0] >= 3:\n if python_version[1] >= 8:\n if python_version[2] >= 3:\n pass\n else:\n raise RuntimeError(\"ERROR: Python 3.7 or greater is \"\n \"required for use of this program.\")\n\n # save input parameters\n self.com_port = com_port\n self.arduino_instance_id = arduino_instance_id\n self.arduino_wait = arduino_wait\n self.sleep_tune = sleep_tune\n self.autostart = autostart\n self.hard_reset_on_shutdown = hard_reset_on_shutdown\n\n self.transport_address = transport_address\n self.ip_port = ip_port\n if transport_type not in [0, 1, 2]:\n raise RuntimeError('Invalid transport type')\n self.transport_type = transport_type\n self.firmware_version = None\n # if tcp, this variable is set to the connected socket\n self.sock = None\n\n self.ble_device_name = ble_device_name\n\n # instance of telemetrix_aio_ble\n self.ble_instance = None\n\n # set the event loop\n if loop is None:\n self.loop = asyncio.get_event_loop()\n else:\n self.loop = loop\n\n self.shutdown_on_exception = shutdown_on_exception\n self.close_loop_on_shutdown = close_loop_on_shutdown\n\n # dictionaries to store the callbacks for each pin\n self.analog_callbacks = {}\n\n self.digital_callbacks = {}\n\n self.i2c_callback = None\n self.i2c_callback2 = None\n\n self.i2c_1_active = False\n self.i2c_2_active = False\n\n self.spi_callback = None\n\n self.onewire_callback = None\n\n # debug loopback callback method\n self.loop_back_callback = None\n\n # the trigger pin will be the key to retrieve\n # the callback for a specific HC-SR04\n self.sonar_callbacks = {}\n\n self.sonar_count = 0\n\n self.dht_callbacks = {}\n\n self.dht_count = 0\n\n # serial port in use\n self.serial_port = None\n\n # generic asyncio task holder\n self.the_task = None\n\n # flag to indicate we are in shutdown mode\n self.shutdown_flag = False\n\n self.report_dispatch = {}\n\n # reported features\n self.reported_features = 0\n\n # To add a command to the command dispatch table, append here.\n self.report_dispatch.update(\n {PrivateConstants.LOOP_COMMAND: self._report_loop_data})\n self.report_dispatch.update(\n {PrivateConstants.DEBUG_PRINT: self._report_debug_data})\n self.report_dispatch.update(\n {PrivateConstants.DIGITAL_REPORT: self._digital_message})\n self.report_dispatch.update(\n {PrivateConstants.ANALOG_REPORT: self._analog_message})\n self.report_dispatch.update(\n {PrivateConstants.SERVO_UNAVAILABLE: self._servo_unavailable})\n self.report_dispatch.update(\n {PrivateConstants.I2C_READ_REPORT: self._i2c_read_report})\n self.report_dispatch.update(\n {PrivateConstants.I2C_TOO_FEW_BYTES_RCVD: self._i2c_too_few})\n self.report_dispatch.update(\n {PrivateConstants.I2C_TOO_MANY_BYTES_RCVD: self._i2c_too_many})\n self.report_dispatch.update(\n {PrivateConstants.SONAR_DISTANCE: self._sonar_distance_report})\n self.report_dispatch.update({PrivateConstants.DHT_REPORT: self._dht_report})\n self.report_dispatch.update(\n {PrivateConstants.SPI_REPORT: self._spi_report})\n self.report_dispatch.update(\n {PrivateConstants.ONE_WIRE_REPORT: self._onewire_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_DISTANCE_TO_GO:\n self._stepper_distance_to_go_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_TARGET_POSITION:\n self._stepper_target_position_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_CURRENT_POSITION:\n self._stepper_current_position_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_RUNNING_REPORT:\n self._stepper_is_running_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_RUN_COMPLETE_REPORT:\n self._stepper_run_complete_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_DISTANCE_TO_GO:\n self._stepper_distance_to_go_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_TARGET_POSITION:\n self._stepper_target_position_report})\n self.report_dispatch.update(\n {PrivateConstants.FEATURES:\n self._features_report})\n\n # dictionaries to store the callbacks for each pin\n self.analog_callbacks = {}\n\n self.digital_callbacks = {}\n\n self.i2c_callback = None\n self.i2c_callback2 = None\n\n self.i2c_1_active = False\n self.i2c_2_active = False\n\n self.spi_callback = None\n\n self.onewire_callback = None\n\n self.cs_pins_enabled = []\n\n # flag to indicate if spi is initialized\n self.spi_enabled = False\n\n # flag to indicate if onewire is initialized\n self.onewire_enabled = False\n\n # the trigger pin will be the key to retrieve\n # the callback for a specific HC-SR04\n self.sonar_callbacks = {}\n\n self.sonar_count = 0\n\n self.dht_callbacks = {}\n\n # # stepper motor variables\n #\n # # updated when a new motor is added\n # self.next_stepper_assigned = 0\n #\n # # valid list of stepper motor interface types\n # self.valid_stepper_interfaces = [1, 2, 3, 4, 6, 8]\n #\n # # maximum number of steppers supported\n # self.max_number_of_steppers = 4\n #\n # # number of steppers created - not to exceed the maximum\n # self.number_of_steppers = 0\n #\n # # dictionary to hold stepper motor information\n # self.stepper_info = {'instance': False, 'is_running': None,\n # 'maximum_speed': 1, 'speed': 0, 'acceleration': 0,\n # 'distance_to_go_callback': None,\n # 'target_position_callback': None,\n # 'current_position_callback': None,\n # 'is_running_callback': None,\n # 'motion_complete_callback': None,\n # 'acceleration_callback': None}\n #\n # # build a list of stepper motor info items\n # self.stepper_info_list = []\n # # a list of dictionaries to hold stepper information\n # for motor in range(self.max_number_of_steppers):\n # self.stepper_info_list.append(self.stepper_info)\n\n print(f'telemetrix_uno_r4_wifi_aio Version:'\n f' {PrivateConstants.TELEMETRIX_VERSION}')\n print(f'Copyright (c) 2023 Alan Yorinks All rights reserved.\\n')\n\n if autostart:\n self.loop.run_until_complete(self.start_aio())\n\n async def start_aio(self):\n\"\"\"\n This method may be called directly, if the autostart\n parameter in __init__ is set to false.\n\n This method instantiates the serial interface and then performs auto pin\n discovery if using a serial interface, or creates and connects to\n a TCP/IP enabled device running StandardFirmataWiFi.\n\n Use this method if you wish to start TelemetrixAIO manually from\n an asyncio function.\n \"\"\"\n\n if self.transport_type == PrivateConstants.SERIAL_TRANSPORT:\n if not self.com_port:\n # user did not specify a com_port\n try:\n await self._find_arduino()\n except KeyboardInterrupt:\n if self.shutdown_on_exception:\n await self.shutdown()\n else:\n # com_port specified - set com_port and baud rate\n try:\n await self._manual_open()\n except KeyboardInterrupt:\n if self.shutdown_on_exception:\n await self.shutdown()\n\n if self.com_port:\n print(f'Telemetrix4UnoR4WIFI found and connected to {self.com_port}')\n\n # no com_port found - raise a runtime exception\n else:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('No Arduino Found or User Aborted Program')\n await self.disable_scroll_message()\n # using tcp/ip\n elif self.transport_type == PrivateConstants.WIFI_TRANSPORT:\n self.sock = TelemetrixAioSocket(self.transport_address, self.ip_port, self.loop)\n await self.sock.start()\n else: # ble\n self.ble_instance = TelemetrixAioBle(self.ble_device_name, self._ble_report_dispatcher)\n await self.ble_instance.connect()\n\n # get arduino firmware version and print it\n firmware_version = await self._get_firmware_version()\n if not firmware_version:\n print('*** Firmware Version retrieval timed out. ***')\n print('\\nDo you have Arduino connectivity and do you have the ')\n print('Telemetrix4UnoR4 sketch uploaded to the board and are connected')\n print('to the correct serial port.\\n')\n print('To see a list of serial ports, type: '\n '\"list_serial_ports\" in your console.')\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError\n else:\n\n print(f'Telemetrix4UnoR4 Version Number: {firmware_version[2]}.'\n f'{firmware_version[3]}.{firmware_version[4]}')\n # start the command dispatcher loop\n command = [PrivateConstants.ENABLE_ALL_REPORTS]\n await self._send_command(command)\n if not self.loop:\n self.loop = asyncio.get_event_loop()\n self.the_task = self.loop.create_task(self._arduino_report_dispatcher())\n\n # get the features list\n command = [PrivateConstants.GET_FEATURES]\n await self._send_command(command)\n await asyncio.sleep(.5)\n\n # Have the server reset its data structures\n command = [PrivateConstants.RESET]\n await self._send_command(command)\n await asyncio.sleep(.1)\n\n async def get_event_loop(self):\n\"\"\"\n Return the currently active asyncio event loop\n\n :return: Active event loop\n\n \"\"\"\n return self.loop\n\n async def _find_arduino(self):\n\"\"\"\n This method will search all potential serial ports for an Arduino\n containing a sketch that has a matching arduino_instance_id as\n specified in the input parameters of this class.\n\n This is used explicitly with the FirmataExpress sketch.\n \"\"\"\n\n # a list of serial ports to be checked\n serial_ports = []\n\n print('Opening all potential serial ports...')\n the_ports_list = list_ports.comports()\n for port in the_ports_list:\n if port.pid is None:\n continue\n print('\\nChecking {}'.format(port.device))\n try:\n self.serial_port = TelemetrixAioSerial(port.device, 115200,\n telemetrix_aio_instance=self,\n close_loop_on_error=self.close_loop_on_shutdown)\n except SerialException:\n continue\n # create a list of serial ports that we opened\n serial_ports.append(self.serial_port)\n\n # display to the user\n print('\\t' + port.device)\n\n # clear out any possible data in the input buffer\n await self.serial_port.reset_input_buffer()\n\n # wait for arduino to reset\n print('\\nWaiting {} seconds(arduino_wait) for Arduino devices to '\n 'reset...'.format(self.arduino_wait))\n await asyncio.sleep(self.arduino_wait)\n\n print('\\nSearching for an Arduino configured with an arduino_instance = ',\n self.arduino_instance_id)\n\n for serial_port in serial_ports:\n self.serial_port = serial_port\n\n command = [PrivateConstants.ARE_U_THERE]\n await self._send_command(command)\n # provide time for the reply\n await asyncio.sleep(.1)\n\n i_am_here = await self.serial_port.read(3)\n\n if not i_am_here:\n continue\n\n # got an I am here message - is it the correct ID?\n if i_am_here[2] == self.arduino_instance_id:\n self.com_port = serial_port.com_port\n return\n\n async def _manual_open(self):\n\"\"\"\n Com port was specified by the user - try to open up that port\n\n \"\"\"\n # if port is not found, a serial exception will be thrown\n print('Opening {} ...'.format(self.com_port))\n self.serial_port = TelemetrixAioSerial(self.com_port, 115200,\n telemetrix_aio_instance=self,\n close_loop_on_error=self.close_loop_on_shutdown)\n\n print('Waiting {} seconds for the Arduino To Reset.'\n .format(self.arduino_wait))\n await asyncio.sleep(self.arduino_wait)\n command = [PrivateConstants.ARE_U_THERE]\n await self._send_command(command)\n # provide time for the reply\n await asyncio.sleep(.1)\n\n print(f'Searching for correct arduino_instance_id: {self.arduino_instance_id}')\n i_am_here = await self.serial_port.read(3)\n\n if not i_am_here:\n print(f'ERROR: correct arduino_instance_id not found')\n\n print('Correct arduino_instance_id found')\n\n async def _get_firmware_version(self):\n\"\"\"\n This method retrieves the Arduino4Telemetrix firmware version\n\n :returns: Firmata firmware version\n \"\"\"\n self.firmware_version = None\n command = [PrivateConstants.GET_FIRMWARE_VERSION]\n await self._send_command(command)\n # provide time for the reply\n await asyncio.sleep(.3)\n if self.transport_type == PrivateConstants.SERIAL_TRANSPORT:\n self.firmware_version = await self.serial_port.read(5)\n elif self.transport_type == PrivateConstants.WIFI_TRANSPORT:\n self.firmware_version = list(await self.sock.read(5))\n else:\n pass\n return self.firmware_version\n\n async def analog_write(self, pin, value):\n\"\"\"\n Set the specified pin to the specified value.\n\n :param pin: arduino pin number\n\n :param value: pin value (maximum 16 bits)\n\n \"\"\"\n value_msb = value >> 8\n value_lsb = value & 0xff\n command = [PrivateConstants.ANALOG_WRITE, pin, value_msb, value_lsb]\n await self._send_command(command)\n\n async def digital_write(self, pin, value):\n\"\"\"\n Set the specified pin to the specified value.\n\n :param pin: arduino pin number\n\n :param value: pin value (1 or 0)\n\n \"\"\"\n command = [PrivateConstants.DIGITAL_WRITE, pin, value]\n await self._send_command(command)\n\n async def i2c_read(self, address, register, number_of_bytes,\n callback, i2c_port=0,\n write_register=True):\n\"\"\"\n Read the specified number of bytes from the specified register for\n the i2c device.\n\n\n :param address: i2c device address\n\n :param register: i2c register (or None if no register selection is needed)\n\n :param number_of_bytes: number of bytes to be read\n\n :param callback: Required callback function to report i2c data as a\n result of read command\n\n :param i2c_port: select the default port (0) or secondary port (1)\n\n :param write_register: If True, the register is written\n before read\n Else, the write is suppressed\n\n\n callback returns a data list:\n\n [I2C_READ_REPORT, address, register, count of data bytes,\n data bytes, time-stamp]\n\n \"\"\"\n if not callback:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('i2c_read: A Callback must be specified')\n\n await self._i2c_read_request(address, register, number_of_bytes,\n callback=callback, i2c_port=i2c_port,\n write_register=write_register)\n\n async def i2c_read_restart_transmission(self, address, register,\n number_of_bytes,\n callback, i2c_port=0,\n write_register=True):\n\"\"\"\n Read the specified number of bytes from the specified register for\n the i2c device. This restarts the transmission after the read. It is\n required for some i2c devices such as the MMA8452Q accelerometer.\n\n\n :param address: i2c device address\n\n :param register: i2c register (or None if no register\n selection is needed)\n\n :param number_of_bytes: number of bytes to be read\n\n :param callback: Required callback function to report i2c data as a\n result of read command\n\n :param i2c_port: select the default port (0) or secondary port (1)\n\n :param write_register: If True, the register is written\n before read\n Else, the write is suppressed\n\n callback returns a data list:\n\n [I2C_READ_REPORT, address, register, count of data bytes,\n data bytes, time-stamp]\n\n \"\"\"\n if not callback:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(\n 'i2c_read_restart_transmission: A Callback must be specified')\n\n await self._i2c_read_request(address, register, number_of_bytes,\n stop_transmission=False,\n callback=callback, i2c_port=i2c_port,\n write_register=write_register)\n\n async def _i2c_read_request(self, address, register, number_of_bytes,\n stop_transmission=True, callback=None,\n i2c_port=0, write_register=True):\n\"\"\"\n This method requests the read of an i2c device. Results are retrieved\n via callback.\n\n :param address: i2c device address\n\n :param register: register number (or None if no register selection is needed)\n\n :param number_of_bytes: number of bytes expected to be returned\n\n :param stop_transmission: stop transmission after read\n\n :param callback: Required callback function to report i2c data as a\n result of read command.\n\n :param i2c_port: select the default port (0) or secondary port (1)\n\n :param write_register: If True, the register is written\n before read\n Else, the write is suppressed\n\n \"\"\"\n if not i2c_port:\n if not self.i2c_1_active:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(\n 'I2C Read: set_pin_mode i2c never called for i2c port 1.')\n\n if i2c_port:\n if not self.i2c_2_active:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(\n 'I2C Read: set_pin_mode i2c never called for i2c port 2.')\n\n if not callback:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('I2C Read: A callback function must be specified.')\n\n if not i2c_port:\n self.i2c_callback = callback\n else:\n self.i2c_callback2 = callback\n\n if not register:\n register = 0\n\n if write_register:\n write_register = 1\n else:\n write_register = 0\n\n # message contains:\n # 1. address\n # 2. register\n # 3. number of bytes\n # 4. restart_transmission - True or False\n # 5. i2c port\n # 6. suppress write flag\n\n command = [PrivateConstants.I2C_READ, address, register, number_of_bytes,\n stop_transmission, i2c_port, write_register]\n await self._send_command(command)\n\n async def i2c_write(self, address, args, i2c_port=0):\n\"\"\"\n Write data to an i2c device.\n\n :param address: i2c device address\n\n :param i2c_port: 0= port 1, 1 = port 2\n\n :param args: A variable number of bytes to be sent to the device\n passed in as a list\n\n \"\"\"\n if not i2c_port:\n if not self.i2c_1_active:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(\n 'I2C Write: set_pin_mode i2c never called for i2c port 1.')\n\n if i2c_port:\n if not self.i2c_2_active:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(\n 'I2C Write: set_pin_mode i2c never called for i2c port 2.')\n\n command = [PrivateConstants.I2C_WRITE, len(args), address, i2c_port]\n\n for item in args:\n command.append(item)\n\n await self._send_command(command)\n\n async def loop_back(self, start_character, callback):\n\"\"\"\n This is a debugging method to send a character to the\n Arduino device, and have the device loop it back.\n\n :param start_character: The character to loop back. It should be\n an integer.\n\n :param callback: Looped back character will appear in the callback method\n\n \"\"\"\n\n if not callback:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('loop_back: A callback function must be specified.')\n command = [PrivateConstants.LOOP_COMMAND, ord(start_character)]\n self.loop_back_callback = callback\n await self._send_command(command)\n\n async def set_analog_scan_interval(self, interval):\n\"\"\"\n Set the analog scanning interval.\n\n :param interval: value of 0 - 255 - milliseconds\n \"\"\"\n\n if 0 <= interval <= 255:\n command = [PrivateConstants.SET_ANALOG_SCANNING_INTERVAL, interval]\n await self._send_command(command)\n else:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('Analog interval must be between 0 and 255')\n\n async def set_pin_mode_analog_input(self, pin_number, differential=0, callback=None):\n\"\"\"\n Set a pin as an analog input.\n\n :param pin_number: arduino pin number\n\n :param callback: async callback function\n\n :param differential: difference in previous to current value before\n report will be generated\n\n callback returns a data list:\n\n [pin_type, pin_number, pin_value, raw_time_stamp]\n\n The pin_type for analog input pins = 3\n\n \"\"\"\n\n if not callback:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(\n 'set_pin_mode_analog_input: A callback function must be specified.')\n\n await self._set_pin_mode(pin_number, PrivateConstants.AT_ANALOG,\n differential, callback=callback)\n\n async def set_pin_mode_analog_output(self, pin_number):\n\"\"\"\n\n Set a pin as a pwm (analog output) pin.\n\n :param pin_number:arduino pin number\n\n \"\"\"\n\n await self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT, differential=0,\n callback=None)\n\n async def set_pin_mode_digital_input(self, pin_number, callback):\n\"\"\"\n Set a pin as a digital input.\n\n :param pin_number: arduino pin number\n\n :param callback: async callback function\n\n callback returns a data list:\n\n [pin_type, pin_number, pin_value, raw_time_stamp]\n\n The pin_type for all digital input pins = 2\n\n \"\"\"\n await self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT, differential=0,\n callback=callback)\n\n async def set_pin_mode_digital_input_pullup(self, pin_number, callback):\n\"\"\"\n Set a pin as a digital input with pullup enabled.\n\n :param pin_number: arduino pin number\n\n :param callback: async callback function\n\n callback returns a data list:\n\n [pin_type, pin_number, pin_value, raw_time_stamp]\n\n The pin_type for all digital input pins = 2\n\n \"\"\"\n if not callback:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(\n 'set_pin_mode_digital_input_pullup: A callback function must be specified.')\n\n await self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT_PULLUP,\n differential=0, callback=callback)\n\n async def set_pin_mode_digital_output(self, pin_number):\n\"\"\"\n Set a pin as a digital output pin.\n\n :param pin_number: arduino pin number\n \"\"\"\n\n await self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT, differential=0,\n callback=None)\n\n # noinspection PyIncorrectDocstring\n async def set_pin_mode_i2c(self, i2c_port=0):\n\"\"\"\n Establish the standard Arduino i2c pins for i2c utilization.\n\n :param i2c_port: 0 = i2c1, 1 = i2c2\n\n NOTES: 1. THIS METHOD MUST BE CALLED BEFORE ANY I2C REQUEST IS MADE\n 2. Callbacks are set within the individual i2c read methods of this\n API.\n\n See i2c_read, or i2c_read_restart_transmission.\n\n \"\"\"\n # test for i2c port 2\n if i2c_port:\n # if not previously activated set it to activated\n # and the send a begin message for this port\n if not self.i2c_2_active:\n self.i2c_2_active = True\n else:\n return\n # port 1\n else:\n if not self.i2c_1_active:\n self.i2c_1_active = True\n else:\n return\n\n command = [PrivateConstants.I2C_BEGIN, i2c_port]\n await self._send_command(command)\n\n async def set_pin_mode_dht(self, pin, callback=None, dht_type=22):\n\"\"\"\n\n :param pin: connection pin\n\n :param callback: callback function\n\n :param dht_type: either 22 for DHT22 or 11 for DHT11\n\n Error Callback: [DHT REPORT Type, DHT_ERROR_NUMBER, PIN, DHT_TYPE, Time]\n\n Valid Data Callback: DHT REPORT Type, DHT_DATA=, PIN, DHT_TYPE, Humidity,\n Temperature,\n Time]\n\n \"\"\"\n if self.reported_features & PrivateConstants.DHT_FEATURE:\n\n if not callback:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('set_pin_mode_dht: A Callback must be specified')\n\n if self.dht_count < PrivateConstants.MAX_DHTS - 1:\n self.dht_callbacks[pin] = callback\n self.dht_count += 1\n\n if dht_type != 22 and dht_type != 11:\n dht_type = 22\n\n command = [PrivateConstants.DHT_NEW, pin, dht_type]\n await self._send_command(command)\n else:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(\n f'Maximum Number Of DHTs Exceeded - set_pin_mode_dht fails for pin {pin}')\n\n else:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(f'The DHT feature is disabled in the server.')\n\n async def set_pin_mode_servo(self, pin_number, min_pulse=544, max_pulse=2400):\n\"\"\"\n\n Attach a pin to a servo motor\n\n :param pin_number: pin\n\n :param min_pulse: minimum pulse width\n\n :param max_pulse: maximum pulse width\n\n \"\"\"\n if self.reported_features & PrivateConstants.SERVO_FEATURE:\n\n minv = (min_pulse).to_bytes(2, byteorder=\"big\")\n maxv = (max_pulse).to_bytes(2, byteorder=\"big\")\n\n command = [PrivateConstants.SERVO_ATTACH, pin_number,\n minv[0], minv[1], maxv[0], maxv[1]]\n await self._send_command(command)\n else:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(f'The SERVO feature is disabled in the server.')\n\n async def set_pin_mode_sonar(self, trigger_pin, echo_pin,\n callback):\n\"\"\"\n\n :param trigger_pin:\n\n :param echo_pin:\n\n :param callback: callback\n\n \"\"\"\n if self.reported_features & PrivateConstants.SONAR_FEATURE:\n\n if not callback:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('set_pin_mode_sonar: A Callback must be specified')\n\n if self.sonar_count < PrivateConstants.MAX_SONARS - 1:\n self.sonar_callbacks[trigger_pin] = callback\n self.sonar_count += 1\n\n command = [PrivateConstants.SONAR_NEW, trigger_pin, echo_pin]\n await self._send_command(command)\n else:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(\n f'Maximum Number Of Sonars Exceeded - set_pin_mode_sonar fails for pin {trigger_pin}')\n else:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(f'The SONAR feature is disabled in the server.')\n\n async def set_pin_mode_spi(self, chip_select_list=None):\n\"\"\"\n Specify the list of chip select pins.\n\n Standard Arduino MISO, MOSI and CLK pins are used for the board in use.\n\n Chip Select is any digital output capable pin.\n\n :param chip_select_list: this is a list of pins to be used for chip select.\n The pins will be configured as output, and set to high\n ready to be used for chip select.\n NOTE: You must specify the chips select pins here!\n\n\n command message: [command, number of cs pins, [cs pins...]]\n \"\"\"\n if self.reported_features & PrivateConstants.SPI_FEATURE:\n\n if type(chip_select_list) != list:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('chip_select_list must be in the form of a list')\n if not chip_select_list:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('Chip select pins were not specified')\n\n self.spi_enabled = True\n\n command = [PrivateConstants.SPI_INIT, len(chip_select_list)]\n\n for pin in chip_select_list:\n command.append(pin)\n self.cs_pins_enabled.append(pin)\n await self._send_command(command)\n else:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(f'The SPI feature is disabled in the server.')\n\n # async def set_pin_mode_stepper(self, interface=1, pin1=2, pin2=3, pin3=4,\n # pin4=5, enable=True):\n # \"\"\"\n # Stepper motor support is implemented as a proxy for the\n # the AccelStepper library for the Arduino.\n #\n # This feature is compatible with the TB6600 Motor Driver\n #\n # Note: It may not work for other driver types!\n #\n # https://github.com/waspinator/AccelStepper\n #\n # Instantiate a stepper motor.\n #\n # Initialize the interface and pins for a stepper motor.\n #\n # :param interface: Motor Interface Type:\n #\n # 1 = Stepper Driver, 2 driver pins required\n #\n # 2 = FULL2WIRE 2 wire stepper, 2 motor pins required\n #\n # 3 = FULL3WIRE 3 wire stepper, such as HDD spindle,\n # 3 motor pins required\n #\n # 4 = FULL4WIRE, 4 wire full stepper, 4 motor pins\n # required\n #\n # 6 = HALF3WIRE, 3 wire half stepper, such as HDD spindle,\n # 3 motor pins required\n #\n # 8 = HALF4WIRE, 4 wire half stepper, 4 motor pins required\n #\n # :param pin1: Arduino digital pin number for motor pin 1\n #\n # :param pin2: Arduino digital pin number for motor pin 2\n #\n # :param pin3: Arduino digital pin number for motor pin 3\n #\n # :param pin4: Arduino digital pin number for motor pin 4\n #\n # :param enable: If this is true, the output pins at construction time.\n #\n # :return: Motor Reference number\n # \"\"\"\n # if self.reported_features & PrivateConstants.STEPPERS_FEATURE:\n #\n # if self.number_of_steppers == self.max_number_of_steppers:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('Maximum number of steppers has already been assigned')\n #\n # if interface not in self.valid_stepper_interfaces:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('Invalid stepper interface')\n #\n # self.number_of_steppers += 1\n #\n # motor_id = self.next_stepper_assigned\n # self.next_stepper_assigned += 1\n # self.stepper_info_list[motor_id]['instance'] = True\n #\n # # build message and send message to server\n # command = [PrivateConstants.SET_PIN_MODE_STEPPER, motor_id, interface, pin1,\n # pin2, pin3, pin4, enable]\n # await self._send_command(command)\n #\n # # return motor id\n # return motor_id\n # else:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError(f'The Stepper feature is disabled in the server.')\n\n async def sonar_disable(self):\n\"\"\"\n Disable sonar scanning for all sonar sensors\n \"\"\"\n command = [PrivateConstants.SONAR_DISABLE]\n await self._send_command(command)\n\n async def sonar_enable(self):\n\"\"\"\n Enable sonar scanning for all sonar sensors\n \"\"\"\n command = [PrivateConstants.SONAR_ENABLE]\n await self._send_command(command)\n\n async def spi_cs_control(self, chip_select_pin, select):\n\"\"\"\n Control an SPI chip select line\n :param chip_select_pin: pin connected to CS\n\n :param select: 0=select, 1=deselect\n \"\"\"\n if not self.spi_enabled:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(f'spi_cs_control: SPI interface is not enabled.')\n\n if chip_select_pin not in self.cs_pins_enabled:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(f'spi_cs_control: chip select pin never enabled.')\n command = [PrivateConstants.SPI_CS_CONTROL, chip_select_pin, select]\n await self._send_command(command)\n\n async def spi_read_blocking(self, chip_select, register_selection,\n number_of_bytes_to_read,\n call_back=None):\n\"\"\"\n Read the specified number of bytes from the specified SPI port and\n call the callback function with the reported data.\n\n :param chip_select: chip select pin\n\n :param register_selection: Register to be selected for read.\n\n :param number_of_bytes_to_read: Number of bytes to read\n\n :param call_back: Required callback function to report spi data as a\n result of read command\n\n\n callback returns a data list:\n [SPI_READ_REPORT, chip select pin, SPI Register, count of data bytes read,\n data bytes, time-stamp]\n SPI_READ_REPORT = 13\n\n \"\"\"\n\n if not self.spi_enabled:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(f'spi_read_blocking: SPI interface is not enabled.')\n\n if not call_back:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('spi_read_blocking: A Callback must be specified')\n\n self.spi_callback = call_back\n\n command = [PrivateConstants.SPI_READ_BLOCKING, chip_select,\n number_of_bytes_to_read,\n register_selection]\n\n await self._send_command(command)\n\n async def spi_set_format(self, clock_divisor, bit_order, data_mode):\n\"\"\"\n Configure how the SPI serializes and de-serializes data on the wire.\n\n See Arduino SPI reference materials for details.\n\n :param clock_divisor: 1 - 255\n\n :param bit_order:\n\n LSBFIRST = 0\n\n MSBFIRST = 1 (default)\n\n :param data_mode:\n\n SPI_MODE0 = 0x00 (default)\n\n SPI_MODE1 = 1\n\n SPI_MODE2 = 2\n\n SPI_MODE3 = 3\n\n \"\"\"\n\n if not self.spi_enabled:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(f'spi_set_format: SPI interface is not enabled.')\n\n if not 0 < clock_divisor <= 255:\n raise RuntimeError(f'spi_set_format: illegal clock divisor selected.')\n if bit_order not in [0, 1]:\n raise RuntimeError(f'spi_set_format: illegal bit_order selected.')\n if data_mode not in [0, 1, 2, 3]:\n raise RuntimeError(f'spi_set_format: illegal data_order selected.')\n\n command = [PrivateConstants.SPI_SET_FORMAT, clock_divisor, bit_order,\n data_mode]\n await self._send_command(command)\n\n async def spi_write_blocking(self, chip_select, bytes_to_write):\n\"\"\"\n Write a list of bytes to the SPI device.\n\n :param chip_select: chip select pin\n\n :param bytes_to_write: A list of bytes to write. This must\n be in the form of a list.\n\n \"\"\"\n\n if not self.spi_enabled:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(f'spi_write_blocking: SPI interface is not enabled.')\n\n if type(bytes_to_write) is not list:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('spi_write_blocking: bytes_to_write must be a list.')\n\n command = [PrivateConstants.SPI_WRITE_BLOCKING, chip_select, len(bytes_to_write)]\n\n for data in bytes_to_write:\n command.append(data)\n\n await self._send_command(command)\n\n # async def set_pin_mode_one_wire(self, pin):\n # \"\"\"\n # Initialize the one wire serial bus.\n #\n # :param pin: Data pin connected to the OneWire device\n # \"\"\"\n # self.onewire_enabled = True\n # command = [PrivateConstants.ONE_WIRE_INIT, pin]\n # await self._send_command(command)\n #\n # async def onewire_reset(self, callback=None):\n # \"\"\"\n # Reset the onewire device\n #\n # :param callback: required function to report reset result\n #\n # callback returns a list:\n # [ReportType = 14, Report Subtype = 25, reset result byte,\n # timestamp]\n # \"\"\"\n # if not self.onewire_enabled:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError(f'onewire_reset: OneWire interface is not enabled.')\n # if not callback:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('onewire_reset: A Callback must be specified')\n #\n # self.onewire_callback = callback\n #\n # command = [PrivateConstants.ONE_WIRE_RESET]\n # await self._send_command(command)\n #\n # async def onewire_select(self, device_address):\n # \"\"\"\n # Select a device based on its address\n # :param device_address: A bytearray of 8 bytes\n # \"\"\"\n # if not self.onewire_enabled:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError(f'onewire_select: OneWire interface is not enabled.')\n #\n # if type(device_address) is not list:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('onewire_select: device address must be an array of 8 '\n # 'bytes.')\n #\n # if len(device_address) != 8:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('onewire_select: device address must be an array of 8 '\n # 'bytes.')\n # command = [PrivateConstants.ONE_WIRE_SELECT]\n # for data in device_address:\n # command.append(data)\n # await self._send_command(command)\n #\n # async def onewire_skip(self):\n # \"\"\"\n # Skip the device selection. This only works if you have a\n # single device, but you can avoid searching and use this to\n # immediately access your device.\n # \"\"\"\n # if not self.onewire_enabled:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError(f'onewire_skip: OneWire interface is not enabled.')\n #\n # command = [PrivateConstants.ONE_WIRE_SKIP]\n # await self._send_command(command)\n #\n # async def onewire_write(self, data, power=0):\n # \"\"\"\n # Write a byte to the onewire device. If 'power' is one\n # then the wire is held high at the end for\n # parasitically powered devices. You\n # are responsible for eventually de-powering it by calling\n # another read or write.\n #\n # :param data: byte to write.\n # :param power: power control (see above)\n # \"\"\"\n # if not self.onewire_enabled:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError(f'onewire_write: OneWire interface is not enabled.')\n # if 0 < data < 255:\n # command = [PrivateConstants.ONE_WIRE_WRITE, data, power]\n # await self._send_command(command)\n # else:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('onewire_write: Data must be no larger than 255')\n #\n # async def onewire_read(self, callback=None):\n # \"\"\"\n # Read a byte from the onewire device\n # :param callback: required function to report onewire data as a\n # result of read command\n #\n #\n # callback returns a data list:\n # [ONEWIRE_REPORT, ONEWIRE_READ=29, data byte, time-stamp]\n #\n # ONEWIRE_REPORT = 14\n # \"\"\"\n # if not self.onewire_enabled:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError(f'onewire_read: OneWire interface is not enabled.')\n #\n # if not callback:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('onewire_read A Callback must be specified')\n #\n # self.onewire_callback = callback\n #\n # command = [PrivateConstants.ONE_WIRE_READ]\n # await self._send_command(command)\n # await asynio.sleep(.2)\n #\n # async def onewire_reset_search(self):\n # \"\"\"\n # Begin a new search. The next use of search will begin at the first device\n # \"\"\"\n #\n # if not self.onewire_enabled:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError(f'onewire_reset_search: OneWire interface is not '\n # f'enabled.')\n # else:\n # command = [PrivateConstants.ONE_WIRE_RESET_SEARCH]\n # await self._send_command(command)\n #\n # async def onewire_search(self, callback=None):\n # \"\"\"\n # Search for the next device. The device address will returned in the callback.\n # If a device is found, the 8 byte address is contained in the callback.\n # If no more devices are found, the address returned contains all elements set\n # to 0xff.\n #\n # :param callback: required function to report a onewire device address\n #\n # callback returns a data list:\n # [ONEWIRE_REPORT, ONEWIRE_SEARCH=31, 8 byte address, time-stamp]\n #\n # ONEWIRE_REPORT = 14\n # \"\"\"\n # if not self.onewire_enabled:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError(f'onewire_search: OneWire interface is not enabled.')\n #\n # if not callback:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('onewire_read A Callback must be specified')\n #\n # self.onewire_callback = callback\n #\n # command = [PrivateConstants.ONE_WIRE_SEARCH]\n # await self._send_command(command)\n #\n # async def onewire_crc8(self, address_list, callback=None):\n # \"\"\"\n # Compute a CRC check on an array of data.\n # :param address_list:\n #\n # :param callback: required function to report a onewire device address\n #\n # callback returns a data list:\n # [ONEWIRE_REPORT, ONEWIRE_CRC8=32, CRC, time-stamp]\n #\n # ONEWIRE_REPORT = 14\n #\n # \"\"\"\n #\n # if not self.onewire_enabled:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError(f'onewire_crc8: OneWire interface is not enabled.')\n #\n # if not callback:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('onewire_crc8 A Callback must be specified')\n #\n # if type(address_list) is not list:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('onewire_crc8: address list must be a list.')\n #\n # self.onewire_callback = callback\n #\n # address_length = len(address_list)\n #\n # command = [PrivateConstants.ONE_WIRE_CRC8, address_length - 1]\n #\n # for data in address_list:\n # command.append(data)\n #\n # await self._send_command(command)\n\n async def _set_pin_mode(self, pin_number, pin_state, differential, callback):\n\"\"\"\n A private method to set the various pin modes.\n\n :param pin_number: arduino pin number\n\n :param pin_state: INPUT/OUTPUT/ANALOG/PWM/PULLUP - for SERVO use\n servo_config()\n For DHT use: set_pin_mode_dht\n\n :param differential: for analog inputs - threshold\n value to be achieved for report to\n be generated\n\n :param callback: A reference to an async call back function to be\n called when pin data value changes\n\n \"\"\"\n if not callback and pin_state != PrivateConstants.AT_OUTPUT:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('_set_pin_mode: A Callback must be specified')\n else:\n if pin_state == PrivateConstants.AT_INPUT:\n command = [PrivateConstants.SET_PIN_MODE, pin_number,\n PrivateConstants.AT_INPUT, 1]\n self.digital_callbacks[pin_number] = callback\n elif pin_state == PrivateConstants.AT_INPUT_PULLUP:\n command = [PrivateConstants.SET_PIN_MODE, pin_number,\n PrivateConstants.AT_INPUT_PULLUP, 1]\n self.digital_callbacks[pin_number] = callback\n elif pin_state == PrivateConstants.AT_ANALOG:\n command = [PrivateConstants.SET_PIN_MODE, pin_number,\n PrivateConstants.AT_ANALOG,\n differential >> 8, differential & 0xff, 1]\n self.analog_callbacks[pin_number] = callback\n elif pin_state == PrivateConstants.AT_OUTPUT:\n command = [PrivateConstants.SET_PIN_MODE, pin_number,\n PrivateConstants.AT_OUTPUT, 1]\n else:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('Unknown pin state')\n\n if command:\n await self._send_command(command)\n\n await asyncio.sleep(.05)\n\n async def servo_detach(self, pin_number):\n\"\"\"\n Detach a servo for reuse\n :param pin_number: attached pin\n \"\"\"\n command = [PrivateConstants.SERVO_DETACH, pin_number]\n await self._send_command(command)\n\n async def servo_write(self, pin_number, angle):\n\"\"\"\n\n Set a servo attached to a pin to a given angle.\n\n :param pin_number: pin\n\n :param angle: angle (0-180)\n\n \"\"\"\n command = [PrivateConstants.SERVO_WRITE, pin_number, angle]\n await self._send_command(command)\n\n # async def stepper_move_to(self, motor_id, position):\n # \"\"\"\n # Set an absolution target position. If position is positive, the movement is\n # clockwise, else it is counter-clockwise.\n #\n # The run() function (below) will try to move the motor (at most one step per call)\n # from the current position to the target position set by the most\n # recent call to this function. Caution: moveTo() also recalculates the\n # speed for the next step.\n # If you are trying to use constant speed movements, you should call setSpeed()\n # after calling moveTo().\n #\n # :param motor_id: motor id: 0 - 3\n #\n # :param position: target position. Maximum value is 32 bits.\n # \"\"\"\n #\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_move_to: Invalid motor_id.')\n #\n # if position < 0:\n # polarity = 1\n # else:\n # polarity = 0\n # position = abs(position)\n #\n # position_bytes = list(position.to_bytes(4, 'big', signed=True))\n #\n # command = [PrivateConstants.STEPPER_MOVE_TO, motor_id]\n # for value in position_bytes:\n # command.append(value)\n # command.append(polarity)\n #\n # await self._send_command(command)\n #\n # async def stepper_move(self, motor_id, relative_position):\n # \"\"\"\n # Set the target position relative to the current position.\n #\n # :param motor_id: motor id: 0 - 3\n #\n # :param relative_position: The desired position relative to the current\n # position. Negative is anticlockwise from\n # the current position. Maximum value is 32 bits.\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_move: Invalid motor_id.')\n #\n # if relative_position < 0:\n # polarity = 1\n # else:\n # polarity = 0\n # position = abs(relative_position)\n #\n # position_bytes = list(position.to_bytes(4, 'big', signed=True))\n #\n # command = [PrivateConstants.STEPPER_MOVE, motor_id]\n # for value in position_bytes:\n # command.append(value)\n # command.append(polarity)\n # await self._send_command(command)\n #\n # async def stepper_run(self, motor_id, completion_callback=None):\n # \"\"\"\n # This method steps the selected motor based on the current speed.\n #\n # Once called, the server will continuously attempt to step the motor.\n #\n # :param motor_id: 0 - 3\n #\n # :param completion_callback: call back function to receive motion complete\n # notification\n #\n # callback returns a data list:\n #\n # [report_type, motor_id, raw_time_stamp]\n #\n # The report_type = 19\n # \"\"\"\n # if not completion_callback:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_run: A motion complete callback must be '\n # 'specified.')\n #\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_run: Invalid motor_id.')\n #\n # self.stepper_info_list[motor_id]['motion_complete_callback'] = completion_callback\n # command = [PrivateConstants.STEPPER_RUN, motor_id]\n # await self._send_command(command)\n #\n # async def stepper_run_speed(self, motor_id):\n # \"\"\"\n # This method steps the selected motor based at a constant speed as set by the most\n # recent call to stepper_set_max_speed(). The motor will run continuously.\n #\n # Once called, the server will continuously attempt to step the motor.\n #\n # :param motor_id: 0 - 3\n #\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_run_speed: Invalid motor_id.')\n #\n # command = [PrivateConstants.STEPPER_RUN_SPEED, motor_id]\n # await self._send_command(command)\n #\n # async def stepper_set_max_speed(self, motor_id, max_speed):\n # \"\"\"\n # Sets the maximum permitted speed. The stepper_run() function will accelerate\n # up to the speed set by this function.\n #\n # Caution: the maximum speed achievable depends on your processor and clock speed.\n # The default maxSpeed is 1 step per second.\n #\n # Caution: Speeds that exceed the maximum speed supported by the processor may\n # result in non-linear accelerations and decelerations.\n #\n # :param motor_id: 0 - 3\n #\n # :param max_speed: 1 - 1000\n # \"\"\"\n #\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_set_max_speed: Invalid motor_id.')\n #\n # if not 1 < max_speed <= 1000:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_set_max_speed: Speed range is 1 - 1000.')\n #\n # self.stepper_info_list[motor_id]['max_speed'] = max_speed\n # max_speed_msb = (max_speed & 0xff00) >> 8\n # max_speed_lsb = max_speed & 0xff\n #\n # command = [PrivateConstants.STEPPER_SET_MAX_SPEED, motor_id, max_speed_msb,\n # max_speed_lsb]\n # await self._send_command(command)\n #\n # async def stepper_get_max_speed(self, motor_id):\n # \"\"\"\n # Returns the maximum speed configured for this stepper\n # that was previously set by stepper_set_max_speed()\n #\n # Value is stored in the client, so no callback is required.\n #\n # :param motor_id: 0 - 3\n #\n # :return: The currently configured maximum speed.\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_max_speed: Invalid motor_id.')\n #\n # return self.stepper_info_list[motor_id]['max_speed']\n #\n # async def stepper_set_acceleration(self, motor_id, acceleration):\n # \"\"\"\n # Sets the acceleration/deceleration rate.\n #\n # :param motor_id: 0 - 3\n #\n # :param acceleration: The desired acceleration in steps per second\n # per second. Must be > 0.0. This is an\n # expensive call since it requires a square\n # root to be calculated on the server.\n # Dont call more often than needed.\n #\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_set_acceleration: Invalid motor_id.')\n #\n # if not 1 < acceleration <= 1000:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_set_acceleration: Acceleration range is 1 - '\n # '1000.')\n #\n # self.stepper_info_list[motor_id]['acceleration'] = acceleration\n #\n # max_accel_msb = acceleration >> 8\n # max_accel_lsb = acceleration & 0xff\n #\n # command = [PrivateConstants.STEPPER_SET_ACCELERATION, motor_id, max_accel_msb,\n # max_accel_lsb]\n # await self._send_command(command)\n #\n # async def stepper_set_speed(self, motor_id, speed):\n # \"\"\"\n # Sets the desired constant speed for use with stepper_run_speed().\n #\n # :param motor_id: 0 - 3\n #\n # :param speed: 0 - 1000 The desired constant speed in steps per\n # second. Positive is clockwise. Speeds of more than 1000 steps per\n # second are unreliable. Speed accuracy depends on the Arduino\n # crystal. Jitter depends on how frequently you call the\n # stepper_run_speed() method.\n # The speed will be limited by the current value of\n # stepper_set_max_speed().\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_set_speed: Invalid motor_id.')\n #\n # if not 0 < speed <= 1000:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_set_speed: Speed range is 0 - '\n # '1000.')\n #\n # self.stepper_info_list[motor_id]['speed'] = speed\n #\n # speed_msb = speed >> 8\n # speed_lsb = speed & 0xff\n #\n # command = [PrivateConstants.STEPPER_SET_SPEED, motor_id, speed_msb, speed_lsb]\n # await self._send_command(command)\n #\n # async def stepper_get_speed(self, motor_id):\n # \"\"\"\n # Returns the most recently set speed.\n # that was previously set by stepper_set_speed();\n #\n # Value is stored in the client, so no callback is required.\n #\n # :param motor_id: 0 - 3\n #\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_get_speed: Invalid motor_id.')\n #\n # return self.stepper_info_list[motor_id]['speed']\n #\n # async def stepper_get_distance_to_go(self, motor_id, distance_to_go_callback):\n # \"\"\"\n # Request the distance from the current position to the target position\n # from the server.\n #\n # :param motor_id: 0 - 3\n #\n # :param distance_to_go_callback: required callback function to receive report\n #\n # :return: The distance to go is returned via the callback as a list:\n #\n # [REPORT_TYPE=15, motor_id, distance in steps, time_stamp]\n #\n # A positive distance is clockwise from the current position.\n #\n # \"\"\"\n # if not distance_to_go_callback:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_get_distance_to_go Read: A callback function must be specified.')\n #\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_get_distance_to_go: Invalid motor_id.')\n # self.stepper_info_list[motor_id][\n # 'distance_to_go_callback'] = distance_to_go_callback\n # command = [PrivateConstants.STEPPER_GET_DISTANCE_TO_GO, motor_id]\n # await self._send_command(command)\n #\n # async def stepper_get_target_position(self, motor_id, target_callback):\n # \"\"\"\n # Request the most recently set target position from the server.\n #\n # :param motor_id: 0 - 3\n #\n # :param target_callback: required callback function to receive report\n #\n # :return: The distance to go is returned via the callback as a list:\n #\n # [REPORT_TYPE=16, motor_id, target position in steps, time_stamp]\n #\n # Positive is clockwise from the 0 position.\n #\n # \"\"\"\n # if not target_callback:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError(\n # 'stepper_get_target_position Read: A callback function must be specified.')\n #\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_get_target_position: Invalid motor_id.')\n #\n # self.stepper_info_list[motor_id][\n # 'target_position_callback'] = target_callback\n #\n # command = [PrivateConstants.STEPPER_GET_TARGET_POSITION, motor_id]\n # await self._send_command(command)\n #\n # async def stepper_get_current_position(self, motor_id, current_position_callback):\n # \"\"\"\n # Request the current motor position from the server.\n #\n # :param motor_id: 0 - 3\n #\n # :param current_position_callback: required callback function to receive report\n #\n # :return: The current motor position returned via the callback as a list:\n #\n # [REPORT_TYPE=17, motor_id, current position in steps, time_stamp]\n #\n # Positive is clockwise from the 0 position.\n # \"\"\"\n # if not current_position_callback:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError(\n # 'stepper_get_current_position Read: A callback function must be specified.')\n #\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_get_current_position: Invalid motor_id.')\n #\n # self.stepper_info_list[motor_id]['current_position_callback'] = current_position_callback\n #\n # command = [PrivateConstants.STEPPER_GET_CURRENT_POSITION, motor_id]\n # await self._send_command(command)\n #\n # async def stepper_set_current_position(self, motor_id, position):\n # \"\"\"\n # Resets the current position of the motor, so that wherever the motor\n # happens to be right now is considered to be the new 0 position. Useful\n # for setting a zero position on a stepper after an initial hardware\n # positioning move.\n #\n # Has the side effect of setting the current motor speed to 0.\n #\n # :param motor_id: 0 - 3\n #\n # :param position: Position in steps. This is a 32 bit value\n # \"\"\"\n #\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_set_current_position: Invalid motor_id.')\n # position_bytes = list(position.to_bytes(4, 'big', signed=True))\n #\n # command = [PrivateConstants.STEPPER_SET_CURRENT_POSITION, motor_id]\n # for value in position_bytes:\n # command.append(value)\n # await self._send_command(command)\n #\n # async def stepper_run_speed_to_position(self, motor_id, completion_callback=None):\n # \"\"\"\n # Runs the motor at the currently selected speed until the target position is\n # reached.\n #\n # Does not implement accelerations.\n #\n # :param motor_id: 0 - 3\n #\n # :param completion_callback: call back function to receive motion complete\n # notification\n #\n # callback returns a data list:\n #\n # [report_type, motor_id, raw_time_stamp]\n #\n # The report_type = 19\n # \"\"\"\n # if not completion_callback:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_run_speed_to_position: A motion complete '\n # 'callback must be '\n # 'specified.')\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_run_speed_to_position: Invalid motor_id.')\n #\n # self.stepper_info_list[motor_id]['motion_complete_callback'] = completion_callback\n # command = [PrivateConstants.STEPPER_RUN_SPEED_TO_POSITION, motor_id]\n # await self._send_command(command)\n #\n # async def stepper_stop(self, motor_id):\n # \"\"\"\n # Sets a new target position that causes the stepper\n # to stop as quickly as possible, using the current speed and\n # acceleration parameters.\n #\n # :param motor_id: 0 - 3\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_stop: Invalid motor_id.')\n #\n # command = [PrivateConstants.STEPPER_STOP, motor_id]\n # await self._send_command(command)\n #\n # async def stepper_disable_outputs(self, motor_id):\n # \"\"\"\n # Disable motor pin outputs by setting them all LOW.\n #\n # Depending on the design of your electronics this may turn off\n # the power to the motor coils, saving power.\n #\n # This is useful to support Arduino low power modes: disable the outputs\n # during sleep and then re-enable with enableOutputs() before stepping\n # again.\n #\n # If the enable Pin is defined, sets it to OUTPUT mode and clears\n # the pin to disabled.\n #\n # :param motor_id: 0 - 3\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_disable_outputs: Invalid motor_id.')\n #\n # command = [PrivateConstants.STEPPER_DISABLE_OUTPUTS, motor_id]\n # await self._send_command(command)\n #\n # async def stepper_enable_outputs(self, motor_id):\n # \"\"\"\n # Enable motor pin outputs by setting the motor pins to OUTPUT\n # mode.\n #\n # If the enable Pin is defined, sets it to OUTPUT mode and sets\n # the pin to enabled.\n #\n # :param motor_id: 0 - 3\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_enable_outputs: Invalid motor_id.')\n #\n # command = [PrivateConstants.STEPPER_ENABLE_OUTPUTS, motor_id]\n # await self._send_command(command)\n #\n # async def stepper_set_min_pulse_width(self, motor_id, minimum_width):\n # \"\"\"\n # Sets the minimum pulse width allowed by the stepper driver.\n #\n # The minimum practical pulse width is approximately 20 microseconds.\n #\n # Times less than 20 microseconds will usually result in 20 microseconds or so.\n #\n # :param motor_id: 0 -3\n #\n # :param minimum_width: A 16 bit unsigned value expressed in microseconds.\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_set_min_pulse_width: Invalid motor_id.')\n #\n # if not 0 < minimum_width <= 0xff:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_set_min_pulse_width: Pulse width range = '\n # '0-0xffff.')\n #\n # width_msb = minimum_width >> 8\n # width_lsb = minimum_width & 0xff\n #\n # command = [PrivateConstants.STEPPER_SET_MINIMUM_PULSE_WIDTH, motor_id, width_msb,\n # width_lsb]\n # await self._send_command(command)\n #\n # async def stepper_set_enable_pin(self, motor_id, pin=0xff):\n # \"\"\"\n # Sets the enable pin number for stepper drivers.\n # 0xFF indicates unused (default).\n #\n # Otherwise, if a pin is set, the pin will be turned on when\n # enableOutputs() is called and switched off when disableOutputs()\n # is called.\n #\n # :param motor_id: 0 - 4\n # :param pin: 0-0xff\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_set_enable_pin: Invalid motor_id.')\n #\n # if not 0 < pin <= 0xff:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_set_enable_pin: Pulse width range = '\n # '0-0xff.')\n # command = [PrivateConstants.STEPPER_SET_ENABLE_PIN, motor_id, pin]\n #\n # await self._send_command(command)\n #\n # async def stepper_set_3_pins_inverted(self, motor_id, direction=False, step=False,\n # enable=False):\n # \"\"\"\n # Sets the inversion for stepper driver pins.\n #\n # :param motor_id: 0 - 3\n #\n # :param direction: True=inverted or False\n #\n # :param step: True=inverted or False\n #\n # :param enable: True=inverted or False\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_set_3_pins_inverted: Invalid motor_id.')\n #\n # command = [PrivateConstants.STEPPER_SET_3_PINS_INVERTED, motor_id, direction,\n # step, enable]\n #\n # await self._send_command(command)\n #\n # async def stepper_set_4_pins_inverted(self, motor_id, pin1_invert=False,\n # pin2_invert=False,\n # pin3_invert=False, pin4_invert=False, enable=False):\n # \"\"\"\n # Sets the inversion for 2, 3 and 4 wire stepper pins\n #\n # :param motor_id: 0 - 3\n #\n # :param pin1_invert: True=inverted or False\n #\n # :param pin2_invert: True=inverted or False\n #\n # :param pin3_invert: True=inverted or False\n #\n # :param pin4_invert: True=inverted or False\n #\n # :param enable: True=inverted or False\n # \"\"\"\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_set_4_pins_inverted: Invalid motor_id.')\n #\n # command = [PrivateConstants.STEPPER_SET_4_PINS_INVERTED, motor_id, pin1_invert,\n # pin2_invert, pin3_invert, pin4_invert, enable]\n #\n # await self._send_command(command)\n #\n # async def stepper_is_running(self, motor_id, callback):\n # \"\"\"\n # Checks to see if the motor is currently running to a target.\n #\n # Callback return True if the speed is not zero or not at the target position.\n #\n # :param motor_id: 0-4\n #\n # :param callback: required callback function to receive report\n #\n # :return: The current running state returned via the callback as a list:\n #\n # [REPORT_TYPE=18, motor_id, True or False for running state, time_stamp]\n # \"\"\"\n # if not callback:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError(\n # 'stepper_is_running: A callback function must be specified.')\n #\n # if not self.stepper_info_list[motor_id]['instance']:\n # if self.shutdown_on_exception:\n # await self.shutdown()\n # raise RuntimeError('stepper_is_running: Invalid motor_id.')\n #\n # self.stepper_info_list[motor_id]['is_running_callback'] = callback\n #\n # command = [PrivateConstants.STEPPER_IS_RUNNING, motor_id]\n # await self._send_command(command)\n\n async def shutdown(self):\n\"\"\"\n This method attempts an orderly shutdown\n If any exceptions are thrown, they are ignored.\n\n \"\"\"\n self.shutdown_flag = True\n\n if self.hard_reset_on_shutdown:\n await self.r4_hard_reset()\n # stop all reporting - both analog and digital\n try:\n if self.serial_port:\n command = [PrivateConstants.STOP_ALL_REPORTS]\n await self._send_command(command)\n\n await asyncio.sleep(.5)\n\n await self.serial_port.reset_input_buffer()\n await self.serial_port.close()\n if self.close_loop_on_shutdown:\n self.loop.stop()\n elif self.sock:\n command = [PrivateConstants.STOP_ALL_REPORTS]\n await self._send_command(command)\n self.the_task.cancel()\n await asyncio.sleep(.5)\n if self.close_loop_on_shutdown:\n self.loop.stop()\n except (RuntimeError, SerialException):\n pass\n\n async def r4_hard_reset(self):\n\"\"\"\n Place the r4 into hard reset\n \"\"\"\n command = [PrivateConstants.BOARD_HARD_RESET, 1]\n await self._send_command(command)\n\n async def disable_all_reporting(self):\n\"\"\"\n Disable reporting for all digital and analog input pins\n \"\"\"\n command = [PrivateConstants.MODIFY_REPORTING,\n PrivateConstants.REPORTING_DISABLE_ALL, 0]\n await self._send_command(command)\n\n async def disable_analog_reporting(self, pin):\n\"\"\"\n Disables analog reporting for a single analog pin.\n\n :param pin: Analog pin number. For example for A0, the number is 0.\n\n \"\"\"\n command = [PrivateConstants.MODIFY_REPORTING,\n PrivateConstants.REPORTING_ANALOG_DISABLE, pin]\n await self._send_command(command)\n\n async def disable_digital_reporting(self, pin):\n\"\"\"\n Disables digital reporting for a single digital pin\n\n\n :param pin: pin number\n\n \"\"\"\n command = [PrivateConstants.MODIFY_REPORTING,\n PrivateConstants.REPORTING_DIGITAL_DISABLE, pin]\n await self._send_command(command)\n\n async def enable_analog_reporting(self, pin):\n\"\"\"\n Enables analog reporting for the specified pin.\n\n :param pin: Analog pin number. For example for A0, the number is 0.\n\n\n \"\"\"\n command = [PrivateConstants.MODIFY_REPORTING,\n PrivateConstants.REPORTING_ANALOG_ENABLE, pin]\n await self._send_command(command)\n\n async def enable_digital_reporting(self, pin):\n\"\"\"\n Enable reporting on the specified digital pin.\n\n :param pin: Pin number.\n \"\"\"\n\n command = [PrivateConstants.MODIFY_REPORTING,\n PrivateConstants.REPORTING_DIGITAL_ENABLE, pin]\n await self._send_command(command)\n\n async def enable_scroll_message(self, message, scroll_speed=50):\n\"\"\"\n\n :param message: Message with maximum length of 25\n :param scroll_speed: in milliseconds (maximum of 255)\n \"\"\"\n if len(message) > 25:\n raise RuntimeError(\"Scroll message size is maximum of 25 characters.\")\n\n if scroll_speed > 255:\n raise RuntimeError(\"Scroll speed maximum of 255 milliseconds.\")\n\n message = message.encode()\n command = [PrivateConstants.SCROLL_MESSAGE_ON, len(message), scroll_speed]\n for x in message:\n command.append(x)\n await self._send_command(command)\n\n async def disable_scroll_message(self):\n\"\"\"\n Turn off a scrolling message\n \"\"\"\n\n command = [PrivateConstants.SCROLL_MESSAGE_OFF]\n await self._send_command(command)\n\n async def _arduino_report_dispatcher(self):\n\"\"\"\n This is a private method.\n It continually accepts and interprets data coming from Telemetrix4Arduino,and then\n dispatches the correct handler to process the data.\n\n It first receives the length of the packet, and then reads in the rest of the\n packet. A packet consists of a length, report identifier and then the report data.\n Using the report identifier, the report handler is fetched from report_dispatch.\n\n :returns: This method never returns\n \"\"\"\n\n while True:\n if self.shutdown_flag:\n break\n try:\n if not self.transport_address:\n packet_length = await self.serial_port.read()\n else:\n\n packet_length = ord(await self.sock.read())\n except TypeError:\n continue\n\n # get the rest of the packet\n if not self.transport_address:\n packet = await self.serial_port.read(packet_length)\n else:\n packet = list(await self.sock.read(packet_length))\n if len(packet) != packet_length:\n continue\n # print(f'packet.len() {}')\n # await asyncio.sleep(.1)\n\n report = packet[0]\n # print(report)\n # handle all other messages by looking them up in the\n # command dictionary\n\n await self.report_dispatch[report](packet[1:])\n await asyncio.sleep(self.sleep_tune)\n\n async def _ble_report_dispatcher(self, sender=None, data=None):\n\"\"\"\n This is a private method called by the incoming data notifier\n\n Using the report identifier, the report handler is fetched from report_dispatch.\n\n :param sender: BLE sender ID\n :param data: data received over the ble link\n\n \"\"\"\n self.the_sender = sender\n data = list(data)\n report = data[1]\n\n if report == 5: # get firmware data reply\n self.firmware_version = list(data)\n print()\n # noinspection PyArgumentList\n else:\n await self.report_dispatch[report](data[2:])\n\n'''\n Report message handlers\n '''\n\n async def _report_loop_data(self, data):\n\"\"\"\n Print data that was looped back\n\n :param data: byte of loop back data\n \"\"\"\n if self.loop_back_callback:\n await self.loop_back_callback(data)\n\n async def _spi_report(self, report):\n report = list(report)\n cb_list = [PrivateConstants.SPI_REPORT, report[0]] + report[1:]\n\n cb_list.append(time.time())\n\n await self.spi_callback(cb_list)\n\n async def _onewire_report(self, report):\n report = list(report)\n\n cb_list = [PrivateConstants.ONE_WIRE_REPORT, report[0]] + report[1:]\n cb_list.append(time.time())\n await self.onewire_callback(cb_list)\n\n async def _report_debug_data(self, data):\n\"\"\"\n Print debug data sent from Arduino\n\n :param data: data[0] is a byte followed by 2\n bytes that comprise an integer\n \"\"\"\n value = (data[1] << 8) + data[2]\n print(f'DEBUG ID: {data[0]} Value: {value}')\n\n async def _analog_message(self, data):\n\"\"\"\n This is a private message handler method.\n It is a message handler for analog messages.\n\n :param data: message data\n\n \"\"\"\n pin = data[0]\n value = (data[1] << 8) + data[2]\n\n time_stamp = time.time()\n\n # append pin number, pin value, and pin type to return value and return as a list\n message = [PrivateConstants.AT_ANALOG, pin, value, time_stamp]\n\n await self.analog_callbacks[pin](message)\n\n async def _dht_report(self, data):\n\"\"\"\n This is a private message handler for dht reports\n\n :param data: data[0] = report error return\n No Errors = 0\n\n Checksum Error = 1\n\n Timeout Error = 2\n\n Invalid Value = 999\n\n data[1] = pin number\n\n data[2] = dht type 11 or 22\n\n data[3] = humidity positivity flag\n\n data[4] = temperature positivity value\n\n data[5] = humidity integer\n\n data[6] = humidity fractional value\n\n data[7] = temperature integer\n\n data[8] = temperature fractional value\n \"\"\"\n data = list(data)\n if data[0]: # DHT_ERROR\n # error report\n # data[0] = report sub type, data[1] = pin, data[2] = error message\n if self.dht_callbacks[data[1]]:\n # Callback 0=DHT REPORT, DHT_ERROR, PIN, Time\n message = [PrivateConstants.DHT_REPORT, data[0], data[1], data[2],\n time.time()]\n await self.dht_callbacks[data[1]](message)\n else:\n # got valid data DHT_DATA\n f_humidity = float(data[5] + data[6] / 100)\n if data[3]:\n f_humidity *= -1.0\n f_temperature = float(data[7] + data[8] / 100)\n if data[4]:\n f_temperature *= -1.0\n message = [PrivateConstants.DHT_REPORT, data[0], data[1], data[2],\n f_humidity, f_temperature, time.time()]\n\n await self.dht_callbacks[data[1]](message)\n\n async def _digital_message(self, data):\n\"\"\"\n This is a private message handler method.\n It is a message handler for Digital Messages.\n\n :param data: digital message\n\n \"\"\"\n pin = data[0]\n value = data[1]\n\n time_stamp = time.time()\n if self.digital_callbacks[pin]:\n message = [PrivateConstants.DIGITAL_REPORT, pin, value, time_stamp]\n await self.digital_callbacks[pin](message)\n\n async def _servo_unavailable(self, report):\n\"\"\"\n Message if no servos are available for use.\n\n :param report: pin number\n \"\"\"\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(\n f'Servo Attach For Pin {report[0]} Failed: No Available Servos')\n\n async def _i2c_read_report(self, data):\n\"\"\"\n Execute callback for i2c reads.\n\n :param data: [I2C_READ_REPORT, i2c_port, number of bytes read, address, register, bytes read..., time-stamp]\n \"\"\"\n\n # we receive [# data bytes, address, register, data bytes]\n # number of bytes of data returned\n\n # data[0] = number of bytes\n # data[1] = i2c_port\n # data[2] = number of bytes returned\n # data[3] = address\n # data[4] = register\n # data[5] ... all the data bytes\n data = list(data)\n cb_list = [PrivateConstants.I2C_READ_REPORT, data[0], data[1]] + data[2:]\n cb_list.append(time.time())\n\n if cb_list[1]:\n await self.i2c_callback2(cb_list)\n else:\n await self.i2c_callback(cb_list)\n\n async def _i2c_too_few(self, data):\n\"\"\"\n I2c reports too few bytes received\n\n :param data: data[0] = device address\n \"\"\"\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(\n f'i2c too few bytes received from i2c port {data[0]} i2c address {data[1]}')\n\n async def _i2c_too_many(self, data):\n\"\"\"\n I2c reports too few bytes received\n\n :param data: data[0] = device address\n \"\"\"\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(\n f'i2c too many bytes received from i2c port {data[0]} i2c address {data[1]}')\n\n async def _sonar_distance_report(self, report):\n\"\"\"\n\n :param report: data[0] = trigger pin, data[1] and data[2] = distance\n\n callback report format: [PrivateConstants.SONAR_DISTANCE, trigger_pin, distance_value, time_stamp]\n \"\"\"\n report = list(report)\n # get callback from pin number\n cb = self.sonar_callbacks[report[0]]\n\n # build report data\n cb_list = [PrivateConstants.SONAR_DISTANCE, report[0],\n ((report[1] << 8) + report[2]), time.time()]\n\n await cb(cb_list)\n\n async def _stepper_distance_to_go_report(self, report):\n return # for now\n # \"\"\"\n # Report stepper distance to go.\n #\n # :param report: data[0] = motor_id, data[1] = steps MSB, data[2] = steps byte 1,\n # data[3] = steps bytes 2, data[4] = steps LSB\n #\n # callback report format: [PrivateConstants.STEPPER_DISTANCE_TO_GO, motor_id\n # steps, time_stamp]\n # \"\"\"\n # report = list(report)\n # # get callback\n # cb = self.stepper_info_list[report[0]]['distance_to_go_callback']\n #\n # # isolate the steps bytes and covert list to bytes\n # steps = bytes(report[1:])\n #\n # # get value from steps\n # num_steps = int.from_bytes(steps, byteorder='big', signed=True)\n #\n # cb_list = [PrivateConstants.STEPPER_DISTANCE_TO_GO, report[0], num_steps,\n # time.time()]\n #\n # await cb(cb_list)\n #\n\n async def _stepper_target_position_report(self, report):\n return # for now\n # \"\"\"\n # Report stepper target position to go.\n #\n # :param report: data[0] = motor_id, data[1] = target position MSB,\n # data[2] = target position byte MSB+1\n # data[3] = target position byte MSB+2\n # data[4] = target position LSB\n #\n # callback report format: [PrivateConstants.STEPPER_TARGET_POSITION, motor_id\n # target_position, time_stamp]\n # \"\"\"\n # report = list(report)\n # # get callback\n # cb = self.stepper_info_list[report[0]]['target_position_callback']\n #\n # # isolate the steps bytes and covert list to bytes\n # target = bytes(report[1:])\n #\n # # get value from steps\n # target_position = int.from_bytes(target, byteorder='big', signed=True)\n #\n # cb_list = [PrivateConstants.STEPPER_TARGET_POSITION, report[0], target_position,\n # time.time()]\n #\n # await cb(cb_list)\n #\n\n async def _stepper_current_position_report(self, report):\n return # for now\n # \"\"\"\n # Report stepper current position.\n #\n # :param report: data[0] = motor_id, data[1] = current position MSB,\n # data[2] = current position byte MSB+1\n # data[3] = current position byte MSB+2\n # data[4] = current position LSB\n #\n # callback report format: [PrivateConstants.STEPPER_CURRENT_POSITION, motor_id\n # current_position, time_stamp]\n # \"\"\"\n # report = list(report)\n\n # # get callback\n # cb = self.stepper_info_list[report[0]]['current_position_callback']\n #\n # # isolate the steps bytes and covert list to bytes\n # position = bytes(report[1:])\n #\n # # get value from steps\n # current_position = int.from_bytes(position, byteorder='big', signed=True)\n #\n # cb_list = [PrivateConstants.STEPPER_CURRENT_POSITION, report[0], current_position,\n # time.time()]\n #\n # await cb(cb_list)\n #\n\n async def _stepper_is_running_report(self, report):\n return # for now\n # \"\"\"\n # Report if the motor is currently running\n #\n # :param report: data[0] = motor_id, True if motor is running or False if it is not.\n #\n # callback report format: [18, motor_id,\n # running_state, time_stamp]\n # \"\"\"\n # report = list(report)\n\n # # get callback\n # cb = self.stepper_info_list[report[0]]['is_running_callback']\n #\n # cb_list = [PrivateConstants.STEPPER_RUNNING_REPORT, report[0], time.time()]\n #\n # await cb(cb_list)\n #\n\n async def _stepper_run_complete_report(self, report):\n return # for now\n # \"\"\"\n # The motor completed it motion\n #\n # :param report: data[0] = motor_id\n #\n # callback report format: [PrivateConstants.STEPPER_RUN_COMPLETE_REPORT, motor_id,\n # time_stamp]\n # \"\"\"\n # report = list(report)\n # # get callback\n # cb = self.stepper_info_list[report[0]]['motion_complete_callback']\n #\n # cb_list = [PrivateConstants.STEPPER_RUN_COMPLETE_REPORT, report[0],\n # time.time()]\n #\n # await cb(cb_list)\n\n async def _features_report(self, report):\n self.reported_features = report[0]\n\n async def _send_command(self, command):\n\"\"\"\n This is a private utility method.\n\n\n :param command: command data in the form of a list\n\n :returns: number of bytes sent\n \"\"\"\n # the length of the list is added at the head\n # the length of the list is added at the head\n command.insert(0, len(command))\n send_message = bytes(command)\n\n if self.transport_type == 1:\n try:\n await self.serial_port.write(send_message)\n except SerialException:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('write fail in _send_command')\n elif self.transport_type == 0:\n await self.sock.write(send_message)\n else:\n await self.ble_instance.write(send_message)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.__init__","title":"__init__(com_port=None, arduino_instance_id=1, arduino_wait=1, sleep_tune=0.0001, autostart=True, loop=None, shutdown_on_exception=True, close_loop_on_shutdown=True, hard_reset_on_shutdown=True, transport_address=None, ip_port=31336, transport_type=0, ble_device_name='Telemetrix4UnoR4 BLE')
","text":"If you have a single Arduino connected to your computer, then you may accept all the default values.
Otherwise, specify a unique arduino_instance id for each board in use.
:param com_port: e.g. COM3 or /dev/ttyACM0.
:param arduino_instance_id: Must match value in the Telemetrix4Arduino sketch
:param arduino_wait: Amount of time to wait for an Arduino to fully reset itself.
:param sleep_tune: A tuning parameter (typically not changed by user)
:param autostart: If you wish to call the start method within your application, then set this to False.
:param loop: optional user provided event loop
:param shutdown_on_exception: call shutdown before raising a RunTimeError exception, or receiving a KeyboardInterrupt exception
:param close_loop_on_shutdown: stop and close the event loop loop when a shutdown is called or a serial error occurs
:param hard_reset_on_shutdown: reset the board on shutdown
:param transport_address: ip address of tcp/ip connected device.
:param ip_port: ip port of tcp/ip connected device
:param transport_type: 0 = WiFi 1 = SerialUSB 2 = BLE
:param ble_device_name: name of Arduino UNO R4 WIFI BLE device. It must match that of Telemetrix4UnoR4BLE.ino
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
def __init__(self, com_port=None,\n arduino_instance_id=1, arduino_wait=1,\n sleep_tune=0.0001, autostart=True,\n loop=None, shutdown_on_exception=True,\n close_loop_on_shutdown=True, hard_reset_on_shutdown=True,\n transport_address=None, ip_port=31336, transport_type=0,\n ble_device_name='Telemetrix4UnoR4 BLE'):\n\n\"\"\"\n If you have a single Arduino connected to your computer,\n then you may accept all the default values.\n\n Otherwise, specify a unique arduino_instance id for each board in use.\n\n :param com_port: e.g. COM3 or /dev/ttyACM0.\n\n :param arduino_instance_id: Must match value in the Telemetrix4Arduino sketch\n\n :param arduino_wait: Amount of time to wait for an Arduino to\n fully reset itself.\n\n :param sleep_tune: A tuning parameter (typically not changed by user)\n\n :param autostart: If you wish to call the start method within\n your application, then set this to False.\n\n :param loop: optional user provided event loop\n\n :param shutdown_on_exception: call shutdown before raising\n a RunTimeError exception, or\n receiving a KeyboardInterrupt exception\n\n :param close_loop_on_shutdown: stop and close the event loop loop\n when a shutdown is called or a serial\n error occurs\n\n :param hard_reset_on_shutdown: reset the board on shutdown\n\n :param transport_address: ip address of tcp/ip connected device.\n\n :param ip_port: ip port of tcp/ip connected device\n\n :param transport_type: 0 = WiFi\n 1 = SerialUSB\n 2 = BLE\n\n :param ble_device_name: name of Arduino UNO R4 WIFI BLE device.\n It must match that of Telemetrix4UnoR4BLE.ino\n\n \"\"\"\n # check to make sure that Python interpreter is version 3.8.3 or greater\n python_version = sys.version_info\n if python_version[0] >= 3:\n if python_version[1] >= 8:\n if python_version[2] >= 3:\n pass\n else:\n raise RuntimeError(\"ERROR: Python 3.7 or greater is \"\n \"required for use of this program.\")\n\n # save input parameters\n self.com_port = com_port\n self.arduino_instance_id = arduino_instance_id\n self.arduino_wait = arduino_wait\n self.sleep_tune = sleep_tune\n self.autostart = autostart\n self.hard_reset_on_shutdown = hard_reset_on_shutdown\n\n self.transport_address = transport_address\n self.ip_port = ip_port\n if transport_type not in [0, 1, 2]:\n raise RuntimeError('Invalid transport type')\n self.transport_type = transport_type\n self.firmware_version = None\n # if tcp, this variable is set to the connected socket\n self.sock = None\n\n self.ble_device_name = ble_device_name\n\n # instance of telemetrix_aio_ble\n self.ble_instance = None\n\n # set the event loop\n if loop is None:\n self.loop = asyncio.get_event_loop()\n else:\n self.loop = loop\n\n self.shutdown_on_exception = shutdown_on_exception\n self.close_loop_on_shutdown = close_loop_on_shutdown\n\n # dictionaries to store the callbacks for each pin\n self.analog_callbacks = {}\n\n self.digital_callbacks = {}\n\n self.i2c_callback = None\n self.i2c_callback2 = None\n\n self.i2c_1_active = False\n self.i2c_2_active = False\n\n self.spi_callback = None\n\n self.onewire_callback = None\n\n # debug loopback callback method\n self.loop_back_callback = None\n\n # the trigger pin will be the key to retrieve\n # the callback for a specific HC-SR04\n self.sonar_callbacks = {}\n\n self.sonar_count = 0\n\n self.dht_callbacks = {}\n\n self.dht_count = 0\n\n # serial port in use\n self.serial_port = None\n\n # generic asyncio task holder\n self.the_task = None\n\n # flag to indicate we are in shutdown mode\n self.shutdown_flag = False\n\n self.report_dispatch = {}\n\n # reported features\n self.reported_features = 0\n\n # To add a command to the command dispatch table, append here.\n self.report_dispatch.update(\n {PrivateConstants.LOOP_COMMAND: self._report_loop_data})\n self.report_dispatch.update(\n {PrivateConstants.DEBUG_PRINT: self._report_debug_data})\n self.report_dispatch.update(\n {PrivateConstants.DIGITAL_REPORT: self._digital_message})\n self.report_dispatch.update(\n {PrivateConstants.ANALOG_REPORT: self._analog_message})\n self.report_dispatch.update(\n {PrivateConstants.SERVO_UNAVAILABLE: self._servo_unavailable})\n self.report_dispatch.update(\n {PrivateConstants.I2C_READ_REPORT: self._i2c_read_report})\n self.report_dispatch.update(\n {PrivateConstants.I2C_TOO_FEW_BYTES_RCVD: self._i2c_too_few})\n self.report_dispatch.update(\n {PrivateConstants.I2C_TOO_MANY_BYTES_RCVD: self._i2c_too_many})\n self.report_dispatch.update(\n {PrivateConstants.SONAR_DISTANCE: self._sonar_distance_report})\n self.report_dispatch.update({PrivateConstants.DHT_REPORT: self._dht_report})\n self.report_dispatch.update(\n {PrivateConstants.SPI_REPORT: self._spi_report})\n self.report_dispatch.update(\n {PrivateConstants.ONE_WIRE_REPORT: self._onewire_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_DISTANCE_TO_GO:\n self._stepper_distance_to_go_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_TARGET_POSITION:\n self._stepper_target_position_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_CURRENT_POSITION:\n self._stepper_current_position_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_RUNNING_REPORT:\n self._stepper_is_running_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_RUN_COMPLETE_REPORT:\n self._stepper_run_complete_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_DISTANCE_TO_GO:\n self._stepper_distance_to_go_report})\n self.report_dispatch.update(\n {PrivateConstants.STEPPER_TARGET_POSITION:\n self._stepper_target_position_report})\n self.report_dispatch.update(\n {PrivateConstants.FEATURES:\n self._features_report})\n\n # dictionaries to store the callbacks for each pin\n self.analog_callbacks = {}\n\n self.digital_callbacks = {}\n\n self.i2c_callback = None\n self.i2c_callback2 = None\n\n self.i2c_1_active = False\n self.i2c_2_active = False\n\n self.spi_callback = None\n\n self.onewire_callback = None\n\n self.cs_pins_enabled = []\n\n # flag to indicate if spi is initialized\n self.spi_enabled = False\n\n # flag to indicate if onewire is initialized\n self.onewire_enabled = False\n\n # the trigger pin will be the key to retrieve\n # the callback for a specific HC-SR04\n self.sonar_callbacks = {}\n\n self.sonar_count = 0\n\n self.dht_callbacks = {}\n\n # # stepper motor variables\n #\n # # updated when a new motor is added\n # self.next_stepper_assigned = 0\n #\n # # valid list of stepper motor interface types\n # self.valid_stepper_interfaces = [1, 2, 3, 4, 6, 8]\n #\n # # maximum number of steppers supported\n # self.max_number_of_steppers = 4\n #\n # # number of steppers created - not to exceed the maximum\n # self.number_of_steppers = 0\n #\n # # dictionary to hold stepper motor information\n # self.stepper_info = {'instance': False, 'is_running': None,\n # 'maximum_speed': 1, 'speed': 0, 'acceleration': 0,\n # 'distance_to_go_callback': None,\n # 'target_position_callback': None,\n # 'current_position_callback': None,\n # 'is_running_callback': None,\n # 'motion_complete_callback': None,\n # 'acceleration_callback': None}\n #\n # # build a list of stepper motor info items\n # self.stepper_info_list = []\n # # a list of dictionaries to hold stepper information\n # for motor in range(self.max_number_of_steppers):\n # self.stepper_info_list.append(self.stepper_info)\n\n print(f'telemetrix_uno_r4_wifi_aio Version:'\n f' {PrivateConstants.TELEMETRIX_VERSION}')\n print(f'Copyright (c) 2023 Alan Yorinks All rights reserved.\\n')\n\n if autostart:\n self.loop.run_until_complete(self.start_aio())\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.analog_write","title":"analog_write(pin, value)
async
","text":"Set the specified pin to the specified value.
:param pin: arduino pin number
:param value: pin value (maximum 16 bits)
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def analog_write(self, pin, value):\n\"\"\"\n Set the specified pin to the specified value.\n\n :param pin: arduino pin number\n\n :param value: pin value (maximum 16 bits)\n\n \"\"\"\n value_msb = value >> 8\n value_lsb = value & 0xff\n command = [PrivateConstants.ANALOG_WRITE, pin, value_msb, value_lsb]\n await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.digital_write","title":"digital_write(pin, value)
async
","text":"Set the specified pin to the specified value.
:param pin: arduino pin number
:param value: pin value (1 or 0)
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def digital_write(self, pin, value):\n\"\"\"\n Set the specified pin to the specified value.\n\n :param pin: arduino pin number\n\n :param value: pin value (1 or 0)\n\n \"\"\"\n command = [PrivateConstants.DIGITAL_WRITE, pin, value]\n await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.disable_all_reporting","title":"disable_all_reporting()
async
","text":"Disable reporting for all digital and analog input pins
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def disable_all_reporting(self):\n\"\"\"\n Disable reporting for all digital and analog input pins\n \"\"\"\n command = [PrivateConstants.MODIFY_REPORTING,\n PrivateConstants.REPORTING_DISABLE_ALL, 0]\n await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.disable_analog_reporting","title":"disable_analog_reporting(pin)
async
","text":"Disables analog reporting for a single analog pin.
:param pin: Analog pin number. For example for A0, the number is 0.
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def disable_analog_reporting(self, pin):\n\"\"\"\n Disables analog reporting for a single analog pin.\n\n :param pin: Analog pin number. For example for A0, the number is 0.\n\n \"\"\"\n command = [PrivateConstants.MODIFY_REPORTING,\n PrivateConstants.REPORTING_ANALOG_DISABLE, pin]\n await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.disable_digital_reporting","title":"disable_digital_reporting(pin)
async
","text":"Disables digital reporting for a single digital pin
:param pin: pin number
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def disable_digital_reporting(self, pin):\n\"\"\"\n Disables digital reporting for a single digital pin\n\n\n :param pin: pin number\n\n \"\"\"\n command = [PrivateConstants.MODIFY_REPORTING,\n PrivateConstants.REPORTING_DIGITAL_DISABLE, pin]\n await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.disable_scroll_message","title":"disable_scroll_message()
async
","text":"Turn off a scrolling message
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def disable_scroll_message(self):\n\"\"\"\n Turn off a scrolling message\n \"\"\"\n\n command = [PrivateConstants.SCROLL_MESSAGE_OFF]\n await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.enable_analog_reporting","title":"enable_analog_reporting(pin)
async
","text":"Enables analog reporting for the specified pin.
:param pin: Analog pin number. For example for A0, the number is 0.
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def enable_analog_reporting(self, pin):\n\"\"\"\n Enables analog reporting for the specified pin.\n\n :param pin: Analog pin number. For example for A0, the number is 0.\n\n\n \"\"\"\n command = [PrivateConstants.MODIFY_REPORTING,\n PrivateConstants.REPORTING_ANALOG_ENABLE, pin]\n await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.enable_digital_reporting","title":"enable_digital_reporting(pin)
async
","text":"Enable reporting on the specified digital pin.
:param pin: Pin number.
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def enable_digital_reporting(self, pin):\n\"\"\"\n Enable reporting on the specified digital pin.\n\n :param pin: Pin number.\n \"\"\"\n\n command = [PrivateConstants.MODIFY_REPORTING,\n PrivateConstants.REPORTING_DIGITAL_ENABLE, pin]\n await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.enable_scroll_message","title":"enable_scroll_message(message, scroll_speed=50)
async
","text":":param message: Message with maximum length of 25 :param scroll_speed: in milliseconds (maximum of 255)
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def enable_scroll_message(self, message, scroll_speed=50):\n\"\"\"\n\n :param message: Message with maximum length of 25\n :param scroll_speed: in milliseconds (maximum of 255)\n \"\"\"\n if len(message) > 25:\n raise RuntimeError(\"Scroll message size is maximum of 25 characters.\")\n\n if scroll_speed > 255:\n raise RuntimeError(\"Scroll speed maximum of 255 milliseconds.\")\n\n message = message.encode()\n command = [PrivateConstants.SCROLL_MESSAGE_ON, len(message), scroll_speed]\n for x in message:\n command.append(x)\n await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.get_event_loop","title":"get_event_loop()
async
","text":"Return the currently active asyncio event loop
:return: Active event loop
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def get_event_loop(self):\n\"\"\"\n Return the currently active asyncio event loop\n\n :return: Active event loop\n\n \"\"\"\n return self.loop\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.i2c_read","title":"i2c_read(address, register, number_of_bytes, callback, i2c_port=0, write_register=True)
async
","text":"Read the specified number of bytes from the specified register for the i2c device.
:param address: i2c device address
:param register: i2c register (or None if no register selection is needed)
:param number_of_bytes: number of bytes to be read
:param callback: Required callback function to report i2c data as a result of read command
:param i2c_port: select the default port (0) or secondary port (1)
:param write_register: If True, the register is written before read Else, the write is suppressed
callback returns a data list:
[I2C_READ_REPORT, address, register, count of data bytes, data bytes, time-stamp]
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def i2c_read(self, address, register, number_of_bytes,\n callback, i2c_port=0,\n write_register=True):\n\"\"\"\n Read the specified number of bytes from the specified register for\n the i2c device.\n\n\n :param address: i2c device address\n\n :param register: i2c register (or None if no register selection is needed)\n\n :param number_of_bytes: number of bytes to be read\n\n :param callback: Required callback function to report i2c data as a\n result of read command\n\n :param i2c_port: select the default port (0) or secondary port (1)\n\n :param write_register: If True, the register is written\n before read\n Else, the write is suppressed\n\n\n callback returns a data list:\n\n [I2C_READ_REPORT, address, register, count of data bytes,\n data bytes, time-stamp]\n\n \"\"\"\n if not callback:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('i2c_read: A Callback must be specified')\n\n await self._i2c_read_request(address, register, number_of_bytes,\n callback=callback, i2c_port=i2c_port,\n write_register=write_register)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.i2c_read_restart_transmission","title":"i2c_read_restart_transmission(address, register, number_of_bytes, callback, i2c_port=0, write_register=True)
async
","text":"Read the specified number of bytes from the specified register for the i2c device. This restarts the transmission after the read. It is required for some i2c devices such as the MMA8452Q accelerometer.
:param address: i2c device address
:param register: i2c register (or None if no register selection is needed)
:param number_of_bytes: number of bytes to be read
:param callback: Required callback function to report i2c data as a result of read command
:param i2c_port: select the default port (0) or secondary port (1)
:param write_register: If True, the register is written before read Else, the write is suppressed
callback returns a data list:
[I2C_READ_REPORT, address, register, count of data bytes, data bytes, time-stamp]
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def i2c_read_restart_transmission(self, address, register,\n number_of_bytes,\n callback, i2c_port=0,\n write_register=True):\n\"\"\"\n Read the specified number of bytes from the specified register for\n the i2c device. This restarts the transmission after the read. It is\n required for some i2c devices such as the MMA8452Q accelerometer.\n\n\n :param address: i2c device address\n\n :param register: i2c register (or None if no register\n selection is needed)\n\n :param number_of_bytes: number of bytes to be read\n\n :param callback: Required callback function to report i2c data as a\n result of read command\n\n :param i2c_port: select the default port (0) or secondary port (1)\n\n :param write_register: If True, the register is written\n before read\n Else, the write is suppressed\n\n callback returns a data list:\n\n [I2C_READ_REPORT, address, register, count of data bytes,\n data bytes, time-stamp]\n\n \"\"\"\n if not callback:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(\n 'i2c_read_restart_transmission: A Callback must be specified')\n\n await self._i2c_read_request(address, register, number_of_bytes,\n stop_transmission=False,\n callback=callback, i2c_port=i2c_port,\n write_register=write_register)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.i2c_write","title":"i2c_write(address, args, i2c_port=0)
async
","text":"Write data to an i2c device.
:param address: i2c device address
:param i2c_port: 0= port 1, 1 = port 2
:param args: A variable number of bytes to be sent to the device passed in as a list
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def i2c_write(self, address, args, i2c_port=0):\n\"\"\"\n Write data to an i2c device.\n\n :param address: i2c device address\n\n :param i2c_port: 0= port 1, 1 = port 2\n\n :param args: A variable number of bytes to be sent to the device\n passed in as a list\n\n \"\"\"\n if not i2c_port:\n if not self.i2c_1_active:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(\n 'I2C Write: set_pin_mode i2c never called for i2c port 1.')\n\n if i2c_port:\n if not self.i2c_2_active:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(\n 'I2C Write: set_pin_mode i2c never called for i2c port 2.')\n\n command = [PrivateConstants.I2C_WRITE, len(args), address, i2c_port]\n\n for item in args:\n command.append(item)\n\n await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.loop_back","title":"loop_back(start_character, callback)
async
","text":"This is a debugging method to send a character to the Arduino device, and have the device loop it back.
:param start_character: The character to loop back. It should be an integer.
:param callback: Looped back character will appear in the callback method
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def loop_back(self, start_character, callback):\n\"\"\"\n This is a debugging method to send a character to the\n Arduino device, and have the device loop it back.\n\n :param start_character: The character to loop back. It should be\n an integer.\n\n :param callback: Looped back character will appear in the callback method\n\n \"\"\"\n\n if not callback:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('loop_back: A callback function must be specified.')\n command = [PrivateConstants.LOOP_COMMAND, ord(start_character)]\n self.loop_back_callback = callback\n await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.r4_hard_reset","title":"r4_hard_reset()
async
","text":"Place the r4 into hard reset
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def r4_hard_reset(self):\n\"\"\"\n Place the r4 into hard reset\n \"\"\"\n command = [PrivateConstants.BOARD_HARD_RESET, 1]\n await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.servo_detach","title":"servo_detach(pin_number)
async
","text":"Detach a servo for reuse :param pin_number: attached pin
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def servo_detach(self, pin_number):\n\"\"\"\n Detach a servo for reuse\n :param pin_number: attached pin\n \"\"\"\n command = [PrivateConstants.SERVO_DETACH, pin_number]\n await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.servo_write","title":"servo_write(pin_number, angle)
async
","text":"Set a servo attached to a pin to a given angle.
:param pin_number: pin
:param angle: angle (0-180)
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def servo_write(self, pin_number, angle):\n\"\"\"\n\n Set a servo attached to a pin to a given angle.\n\n :param pin_number: pin\n\n :param angle: angle (0-180)\n\n \"\"\"\n command = [PrivateConstants.SERVO_WRITE, pin_number, angle]\n await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.set_analog_scan_interval","title":"set_analog_scan_interval(interval)
async
","text":"Set the analog scanning interval.
:param interval: value of 0 - 255 - milliseconds
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def set_analog_scan_interval(self, interval):\n\"\"\"\n Set the analog scanning interval.\n\n :param interval: value of 0 - 255 - milliseconds\n \"\"\"\n\n if 0 <= interval <= 255:\n command = [PrivateConstants.SET_ANALOG_SCANNING_INTERVAL, interval]\n await self._send_command(command)\n else:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('Analog interval must be between 0 and 255')\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.set_pin_mode_analog_input","title":"set_pin_mode_analog_input(pin_number, differential=0, callback=None)
async
","text":"Set a pin as an analog input.
:param pin_number: arduino pin number
:param callback: async callback function
:param differential: difference in previous to current value before report will be generated
callback returns a data list:
[pin_type, pin_number, pin_value, raw_time_stamp]
The pin_type for analog input pins = 3
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def set_pin_mode_analog_input(self, pin_number, differential=0, callback=None):\n\"\"\"\n Set a pin as an analog input.\n\n :param pin_number: arduino pin number\n\n :param callback: async callback function\n\n :param differential: difference in previous to current value before\n report will be generated\n\n callback returns a data list:\n\n [pin_type, pin_number, pin_value, raw_time_stamp]\n\n The pin_type for analog input pins = 3\n\n \"\"\"\n\n if not callback:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(\n 'set_pin_mode_analog_input: A callback function must be specified.')\n\n await self._set_pin_mode(pin_number, PrivateConstants.AT_ANALOG,\n differential, callback=callback)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.set_pin_mode_analog_output","title":"set_pin_mode_analog_output(pin_number)
async
","text":"Set a pin as a pwm (analog output) pin.
:param pin_number:arduino pin number
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def set_pin_mode_analog_output(self, pin_number):\n\"\"\"\n\n Set a pin as a pwm (analog output) pin.\n\n :param pin_number:arduino pin number\n\n \"\"\"\n\n await self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT, differential=0,\n callback=None)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.set_pin_mode_dht","title":"set_pin_mode_dht(pin, callback=None, dht_type=22)
async
","text":":param pin: connection pin
:param callback: callback function
:param dht_type: either 22 for DHT22 or 11 for DHT11
Error Callback: [DHT REPORT Type, DHT_ERROR_NUMBER, PIN, DHT_TYPE, Time]
Valid Data Callback: DHT REPORT Type, DHT_DATA=, PIN, DHT_TYPE, Humidity, Temperature, Time]
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def set_pin_mode_dht(self, pin, callback=None, dht_type=22):\n\"\"\"\n\n :param pin: connection pin\n\n :param callback: callback function\n\n :param dht_type: either 22 for DHT22 or 11 for DHT11\n\n Error Callback: [DHT REPORT Type, DHT_ERROR_NUMBER, PIN, DHT_TYPE, Time]\n\n Valid Data Callback: DHT REPORT Type, DHT_DATA=, PIN, DHT_TYPE, Humidity,\n Temperature,\n Time]\n\n \"\"\"\n if self.reported_features & PrivateConstants.DHT_FEATURE:\n\n if not callback:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('set_pin_mode_dht: A Callback must be specified')\n\n if self.dht_count < PrivateConstants.MAX_DHTS - 1:\n self.dht_callbacks[pin] = callback\n self.dht_count += 1\n\n if dht_type != 22 and dht_type != 11:\n dht_type = 22\n\n command = [PrivateConstants.DHT_NEW, pin, dht_type]\n await self._send_command(command)\n else:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(\n f'Maximum Number Of DHTs Exceeded - set_pin_mode_dht fails for pin {pin}')\n\n else:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(f'The DHT feature is disabled in the server.')\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.set_pin_mode_digital_input","title":"set_pin_mode_digital_input(pin_number, callback)
async
","text":"Set a pin as a digital input.
:param pin_number: arduino pin number
:param callback: async callback function
callback returns a data list:
[pin_type, pin_number, pin_value, raw_time_stamp]
The pin_type for all digital input pins = 2
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def set_pin_mode_digital_input(self, pin_number, callback):\n\"\"\"\n Set a pin as a digital input.\n\n :param pin_number: arduino pin number\n\n :param callback: async callback function\n\n callback returns a data list:\n\n [pin_type, pin_number, pin_value, raw_time_stamp]\n\n The pin_type for all digital input pins = 2\n\n \"\"\"\n await self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT, differential=0,\n callback=callback)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.set_pin_mode_digital_input_pullup","title":"set_pin_mode_digital_input_pullup(pin_number, callback)
async
","text":"Set a pin as a digital input with pullup enabled.
:param pin_number: arduino pin number
:param callback: async callback function
callback returns a data list:
[pin_type, pin_number, pin_value, raw_time_stamp]
The pin_type for all digital input pins = 2
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def set_pin_mode_digital_input_pullup(self, pin_number, callback):\n\"\"\"\n Set a pin as a digital input with pullup enabled.\n\n :param pin_number: arduino pin number\n\n :param callback: async callback function\n\n callback returns a data list:\n\n [pin_type, pin_number, pin_value, raw_time_stamp]\n\n The pin_type for all digital input pins = 2\n\n \"\"\"\n if not callback:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(\n 'set_pin_mode_digital_input_pullup: A callback function must be specified.')\n\n await self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT_PULLUP,\n differential=0, callback=callback)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.set_pin_mode_digital_output","title":"set_pin_mode_digital_output(pin_number)
async
","text":"Set a pin as a digital output pin.
:param pin_number: arduino pin number
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def set_pin_mode_digital_output(self, pin_number):\n\"\"\"\n Set a pin as a digital output pin.\n\n :param pin_number: arduino pin number\n \"\"\"\n\n await self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT, differential=0,\n callback=None)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.set_pin_mode_i2c","title":"set_pin_mode_i2c(i2c_port=0)
async
","text":"Establish the standard Arduino i2c pins for i2c utilization.
:param i2c_port: 0 = i2c1, 1 = i2c2
API.\n\n See i2c_read, or i2c_read_restart_transmission.\n
Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def set_pin_mode_i2c(self, i2c_port=0):\n\"\"\"\n Establish the standard Arduino i2c pins for i2c utilization.\n\n :param i2c_port: 0 = i2c1, 1 = i2c2\n\n NOTES: 1. THIS METHOD MUST BE CALLED BEFORE ANY I2C REQUEST IS MADE\n 2. Callbacks are set within the individual i2c read methods of this\n API.\n\n See i2c_read, or i2c_read_restart_transmission.\n\n \"\"\"\n # test for i2c port 2\n if i2c_port:\n # if not previously activated set it to activated\n # and the send a begin message for this port\n if not self.i2c_2_active:\n self.i2c_2_active = True\n else:\n return\n # port 1\n else:\n if not self.i2c_1_active:\n self.i2c_1_active = True\n else:\n return\n\n command = [PrivateConstants.I2C_BEGIN, i2c_port]\n await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.set_pin_mode_servo","title":"set_pin_mode_servo(pin_number, min_pulse=544, max_pulse=2400)
async
","text":"Attach a pin to a servo motor
:param pin_number: pin
:param min_pulse: minimum pulse width
:param max_pulse: maximum pulse width
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def set_pin_mode_servo(self, pin_number, min_pulse=544, max_pulse=2400):\n\"\"\"\n\n Attach a pin to a servo motor\n\n :param pin_number: pin\n\n :param min_pulse: minimum pulse width\n\n :param max_pulse: maximum pulse width\n\n \"\"\"\n if self.reported_features & PrivateConstants.SERVO_FEATURE:\n\n minv = (min_pulse).to_bytes(2, byteorder=\"big\")\n maxv = (max_pulse).to_bytes(2, byteorder=\"big\")\n\n command = [PrivateConstants.SERVO_ATTACH, pin_number,\n minv[0], minv[1], maxv[0], maxv[1]]\n await self._send_command(command)\n else:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(f'The SERVO feature is disabled in the server.')\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.set_pin_mode_sonar","title":"set_pin_mode_sonar(trigger_pin, echo_pin, callback)
async
","text":":param trigger_pin:
:param echo_pin:
:param callback: callback
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def set_pin_mode_sonar(self, trigger_pin, echo_pin,\n callback):\n\"\"\"\n\n :param trigger_pin:\n\n :param echo_pin:\n\n :param callback: callback\n\n \"\"\"\n if self.reported_features & PrivateConstants.SONAR_FEATURE:\n\n if not callback:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('set_pin_mode_sonar: A Callback must be specified')\n\n if self.sonar_count < PrivateConstants.MAX_SONARS - 1:\n self.sonar_callbacks[trigger_pin] = callback\n self.sonar_count += 1\n\n command = [PrivateConstants.SONAR_NEW, trigger_pin, echo_pin]\n await self._send_command(command)\n else:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(\n f'Maximum Number Of Sonars Exceeded - set_pin_mode_sonar fails for pin {trigger_pin}')\n else:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(f'The SONAR feature is disabled in the server.')\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.set_pin_mode_spi","title":"set_pin_mode_spi(chip_select_list=None)
async
","text":"Specify the list of chip select pins.
Standard Arduino MISO, MOSI and CLK pins are used for the board in use.
Chip Select is any digital output capable pin.
:param chip_select_list: this is a list of pins to be used for chip select. The pins will be configured as output, and set to high ready to be used for chip select. NOTE: You must specify the chips select pins here!
command message: [command, number of cs pins, [cs pins...]]
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def set_pin_mode_spi(self, chip_select_list=None):\n\"\"\"\n Specify the list of chip select pins.\n\n Standard Arduino MISO, MOSI and CLK pins are used for the board in use.\n\n Chip Select is any digital output capable pin.\n\n :param chip_select_list: this is a list of pins to be used for chip select.\n The pins will be configured as output, and set to high\n ready to be used for chip select.\n NOTE: You must specify the chips select pins here!\n\n\n command message: [command, number of cs pins, [cs pins...]]\n \"\"\"\n if self.reported_features & PrivateConstants.SPI_FEATURE:\n\n if type(chip_select_list) != list:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('chip_select_list must be in the form of a list')\n if not chip_select_list:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('Chip select pins were not specified')\n\n self.spi_enabled = True\n\n command = [PrivateConstants.SPI_INIT, len(chip_select_list)]\n\n for pin in chip_select_list:\n command.append(pin)\n self.cs_pins_enabled.append(pin)\n await self._send_command(command)\n else:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(f'The SPI feature is disabled in the server.')\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.shutdown","title":"shutdown()
async
","text":"This method attempts an orderly shutdown If any exceptions are thrown, they are ignored.
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def shutdown(self):\n\"\"\"\n This method attempts an orderly shutdown\n If any exceptions are thrown, they are ignored.\n\n \"\"\"\n self.shutdown_flag = True\n\n if self.hard_reset_on_shutdown:\n await self.r4_hard_reset()\n # stop all reporting - both analog and digital\n try:\n if self.serial_port:\n command = [PrivateConstants.STOP_ALL_REPORTS]\n await self._send_command(command)\n\n await asyncio.sleep(.5)\n\n await self.serial_port.reset_input_buffer()\n await self.serial_port.close()\n if self.close_loop_on_shutdown:\n self.loop.stop()\n elif self.sock:\n command = [PrivateConstants.STOP_ALL_REPORTS]\n await self._send_command(command)\n self.the_task.cancel()\n await asyncio.sleep(.5)\n if self.close_loop_on_shutdown:\n self.loop.stop()\n except (RuntimeError, SerialException):\n pass\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.sonar_disable","title":"sonar_disable()
async
","text":"Disable sonar scanning for all sonar sensors
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def sonar_disable(self):\n\"\"\"\n Disable sonar scanning for all sonar sensors\n \"\"\"\n command = [PrivateConstants.SONAR_DISABLE]\n await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.sonar_enable","title":"sonar_enable()
async
","text":"Enable sonar scanning for all sonar sensors
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def sonar_enable(self):\n\"\"\"\n Enable sonar scanning for all sonar sensors\n \"\"\"\n command = [PrivateConstants.SONAR_ENABLE]\n await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.spi_cs_control","title":"spi_cs_control(chip_select_pin, select)
async
","text":"Control an SPI chip select line :param chip_select_pin: pin connected to CS
:param select: 0=select, 1=deselect
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def spi_cs_control(self, chip_select_pin, select):\n\"\"\"\n Control an SPI chip select line\n :param chip_select_pin: pin connected to CS\n\n :param select: 0=select, 1=deselect\n \"\"\"\n if not self.spi_enabled:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(f'spi_cs_control: SPI interface is not enabled.')\n\n if chip_select_pin not in self.cs_pins_enabled:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(f'spi_cs_control: chip select pin never enabled.')\n command = [PrivateConstants.SPI_CS_CONTROL, chip_select_pin, select]\n await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.spi_read_blocking","title":"spi_read_blocking(chip_select, register_selection, number_of_bytes_to_read, call_back=None)
async
","text":"Read the specified number of bytes from the specified SPI port and call the callback function with the reported data.
:param chip_select: chip select pin
:param register_selection: Register to be selected for read.
:param number_of_bytes_to_read: Number of bytes to read
:param call_back: Required callback function to report spi data as a result of read command
callback returns a data list[SPI_READ_REPORT, chip select pin, SPI Register, count of data bytes read, data bytes, time-stamp]
SPI_READ_REPORT = 13
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def spi_read_blocking(self, chip_select, register_selection,\n number_of_bytes_to_read,\n call_back=None):\n\"\"\"\n Read the specified number of bytes from the specified SPI port and\n call the callback function with the reported data.\n\n :param chip_select: chip select pin\n\n :param register_selection: Register to be selected for read.\n\n :param number_of_bytes_to_read: Number of bytes to read\n\n :param call_back: Required callback function to report spi data as a\n result of read command\n\n\n callback returns a data list:\n [SPI_READ_REPORT, chip select pin, SPI Register, count of data bytes read,\n data bytes, time-stamp]\n SPI_READ_REPORT = 13\n\n \"\"\"\n\n if not self.spi_enabled:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(f'spi_read_blocking: SPI interface is not enabled.')\n\n if not call_back:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('spi_read_blocking: A Callback must be specified')\n\n self.spi_callback = call_back\n\n command = [PrivateConstants.SPI_READ_BLOCKING, chip_select,\n number_of_bytes_to_read,\n register_selection]\n\n await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.spi_set_format","title":"spi_set_format(clock_divisor, bit_order, data_mode)
async
","text":"Configure how the SPI serializes and de-serializes data on the wire.
See Arduino SPI reference materials for details.
:param clock_divisor: 1 - 255
:param bit_order:
LSBFIRST = 0\n\n MSBFIRST = 1 (default)\n
:param data_mode:
SPI_MODE0 = 0x00 (default)\n\n SPI_MODE1 = 1\n\n SPI_MODE2 = 2\n\n SPI_MODE3 = 3\n
Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def spi_set_format(self, clock_divisor, bit_order, data_mode):\n\"\"\"\n Configure how the SPI serializes and de-serializes data on the wire.\n\n See Arduino SPI reference materials for details.\n\n :param clock_divisor: 1 - 255\n\n :param bit_order:\n\n LSBFIRST = 0\n\n MSBFIRST = 1 (default)\n\n :param data_mode:\n\n SPI_MODE0 = 0x00 (default)\n\n SPI_MODE1 = 1\n\n SPI_MODE2 = 2\n\n SPI_MODE3 = 3\n\n \"\"\"\n\n if not self.spi_enabled:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(f'spi_set_format: SPI interface is not enabled.')\n\n if not 0 < clock_divisor <= 255:\n raise RuntimeError(f'spi_set_format: illegal clock divisor selected.')\n if bit_order not in [0, 1]:\n raise RuntimeError(f'spi_set_format: illegal bit_order selected.')\n if data_mode not in [0, 1, 2, 3]:\n raise RuntimeError(f'spi_set_format: illegal data_order selected.')\n\n command = [PrivateConstants.SPI_SET_FORMAT, clock_divisor, bit_order,\n data_mode]\n await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.spi_write_blocking","title":"spi_write_blocking(chip_select, bytes_to_write)
async
","text":"Write a list of bytes to the SPI device.
:param chip_select: chip select pin
:param bytes_to_write: A list of bytes to write. This must be in the form of a list.
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def spi_write_blocking(self, chip_select, bytes_to_write):\n\"\"\"\n Write a list of bytes to the SPI device.\n\n :param chip_select: chip select pin\n\n :param bytes_to_write: A list of bytes to write. This must\n be in the form of a list.\n\n \"\"\"\n\n if not self.spi_enabled:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError(f'spi_write_blocking: SPI interface is not enabled.')\n\n if type(bytes_to_write) is not list:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('spi_write_blocking: bytes_to_write must be a list.')\n\n command = [PrivateConstants.SPI_WRITE_BLOCKING, chip_select, len(bytes_to_write)]\n\n for data in bytes_to_write:\n command.append(data)\n\n await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.start_aio","title":"start_aio()
async
","text":"This method may be called directly, if the autostart parameter in init is set to false.
This method instantiates the serial interface and then performs auto pin discovery if using a serial interface, or creates and connects to a TCP/IP enabled device running StandardFirmataWiFi.
Use this method if you wish to start TelemetrixAIO manually from an asyncio function.
Source code intelemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def start_aio(self):\n\"\"\"\n This method may be called directly, if the autostart\n parameter in __init__ is set to false.\n\n This method instantiates the serial interface and then performs auto pin\n discovery if using a serial interface, or creates and connects to\n a TCP/IP enabled device running StandardFirmataWiFi.\n\n Use this method if you wish to start TelemetrixAIO manually from\n an asyncio function.\n \"\"\"\n\n if self.transport_type == PrivateConstants.SERIAL_TRANSPORT:\n if not self.com_port:\n # user did not specify a com_port\n try:\n await self._find_arduino()\n except KeyboardInterrupt:\n if self.shutdown_on_exception:\n await self.shutdown()\n else:\n # com_port specified - set com_port and baud rate\n try:\n await self._manual_open()\n except KeyboardInterrupt:\n if self.shutdown_on_exception:\n await self.shutdown()\n\n if self.com_port:\n print(f'Telemetrix4UnoR4WIFI found and connected to {self.com_port}')\n\n # no com_port found - raise a runtime exception\n else:\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError('No Arduino Found or User Aborted Program')\n await self.disable_scroll_message()\n # using tcp/ip\n elif self.transport_type == PrivateConstants.WIFI_TRANSPORT:\n self.sock = TelemetrixAioSocket(self.transport_address, self.ip_port, self.loop)\n await self.sock.start()\n else: # ble\n self.ble_instance = TelemetrixAioBle(self.ble_device_name, self._ble_report_dispatcher)\n await self.ble_instance.connect()\n\n # get arduino firmware version and print it\n firmware_version = await self._get_firmware_version()\n if not firmware_version:\n print('*** Firmware Version retrieval timed out. ***')\n print('\\nDo you have Arduino connectivity and do you have the ')\n print('Telemetrix4UnoR4 sketch uploaded to the board and are connected')\n print('to the correct serial port.\\n')\n print('To see a list of serial ports, type: '\n '\"list_serial_ports\" in your console.')\n if self.shutdown_on_exception:\n await self.shutdown()\n raise RuntimeError\n else:\n\n print(f'Telemetrix4UnoR4 Version Number: {firmware_version[2]}.'\n f'{firmware_version[3]}.{firmware_version[4]}')\n # start the command dispatcher loop\n command = [PrivateConstants.ENABLE_ALL_REPORTS]\n await self._send_command(command)\n if not self.loop:\n self.loop = asyncio.get_event_loop()\n self.the_task = self.loop.create_task(self._arduino_report_dispatcher())\n\n # get the features list\n command = [PrivateConstants.GET_FEATURES]\n await self._send_command(command)\n await asyncio.sleep(.5)\n\n # Have the server reset its data structures\n command = [PrivateConstants.RESET]\n await self._send_command(command)\n await asyncio.sleep(.1)\n
"},{"location":"template_ble/","title":"BLE AIO","text":"Here, we need to instantiate the class passing in two parameters. We need to pass in auto_start=False. This is because we are using the Bleak BLE library, and this allows for a clean shutdown. We also need to pass in transport_type=2, which enables the BLE transport.
Lastly, we need to manually start the asyncio portion of the API by calling board.start_aio() in our main function.
\nimport sys\nimport asyncio\n\n# IMPORT THE API\nfrom telemetrix_uno_r4.wifi.telemetrix_uno_r4_wifi_aio import telemetrix_uno_r4_wifi_aio\n\n# An async method for running your application.\n# We pass in the instance of the API created below .\nasync def my_app(my_board):\n # THIS NEXT LINE MUST BE ADDED HERE\n await my_board.start_aio()\n\n # Your Application code\n\n# get the event loop\nloop = asyncio.new_event_loop()\nasyncio.set_event_loop(loop)\n\n# instantiate telemetrix_aio\n\nboard = telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio(autostart=False,\n transport_type=2)\n\ntry:\n # start the main function\n loop.run_until_complete(my_app(board))\nexcept KeyboardInterrupt:\n try:\n loop.run_until_complete(board.shutdown())\n except:\n pass\n sys.exit(0)\n\n
Copyright (C) 2023 Alan Yorinks. All Rights Reserved.
"},{"location":"template_minima_aio/","title":"Minima AIO","text":"\nimport sys\nimport asyncio\n\n# IMPORT THE API\nfrom telemetrix_uno_r4.minima.telemetrix_uno_r4_minima_aio import telemetrix_uno_r4_minima_aio\n\n# An async method for running your application.\n# We pass in the instance of the API created below .\nasync def my_app(the_board):\n # Your Application code\n\n# get the event loop\nloop = asyncio.new_event_loop()\nasyncio.set_event_loop(loop)\n\n# instantiate telemetrix_aio\nboard = telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio()\n\ntry:\n # start the main function\n loop.run_until_complete(my_app(board))\nexcept KeyboardInterrupt:\n try:\n loop.run_until_complete(board.shutdown())\n except:\n pass\n sys.exit(0)\n\n
"},{"location":"template_minima_threaded/","title":"Minima Threaded","text":"import sys\nimport time\n\n# IMPORT THE API\nfrom telemetrix_uno_r4.minima.telemetrix_uno_r4_minima import telemetrix_uno_r4_minima\n\"\"\"\n\n# INSTANTIATE THE API CLASS\nboard = telemetrix_uno_r4_minima.TelemetrixUnoR4Minima()\n\ntry:\n # WRITE YOUR APPLICATION HERE\nexcept:\n board.shutdown()\n\n\n\n\n
Copyright (C) 2023 Alan Yorinks. All Rights Reserved.
"},{"location":"template_usb_serial_aio/","title":"USBSerial AIO","text":"Here, we need to instantiate the class passing in a transport_type of 1. This parameter value enables the serial transport.
\nimport sys\nimport asyncio\n\n# IMPORT THE API\nfrom telemetrix_uno_r4.wifi.telemetrix_uno_r4_wifi_aio import telemetrix_uno_r4_wifi_aio\n\n# An async method for running your application.\n# We pass in the instance of the API created below .\nasync def my_app(the_board):\n # Your Application code\n\n# get the event loop\nloop = asyncio.new_event_loop()\nasyncio.set_event_loop(loop)\n\n# instantiate telemetrix_aio\nboard = telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio(transport_type=1)\n\ntry:\n # start the main function\n loop.run_until_complete(my_app(board))\nexcept KeyboardInterrupt:\n try:\n loop.run_until_complete(board.shutdown())\n except:\n pass\n sys.exit(0)\n\n
Copyright (C) 2023 Alan Yorinks. All Rights Reserved.
"},{"location":"template_usb_serial_threaded/","title":"USBSerial Threaded","text":"Here, we need to instantiate the class passing in a transport_type of 1. This enables the serial transport.
import sys\nimport time\n\n# IMPORT THE API\nfrom telemetrix_uno_r4.wifi.telemetrix_uno_r4_wifi import telemetrix_uno_r4_wifi\n\n# INSTANTIATE THE API CLASS\nboard = telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi(transport_type=1)\ntry:\n # WRITE YOUR APPLICATION HERE\nexcept:\n board.shutdown()\n\n\n\n\n
Copyright (C) 2023 Alan Yorinks. All Rights Reserved.
"},{"location":"template_wifi_aio/","title":"WIFI AIO","text":"Here, we need to instantiate the class passing in the IP address assigned by your router. This parameter enables the WIFI transport.
\nimport sys\nimport asyncio\n\n# IMPORT THE API\nfrom telemetrix_uno_r4.wifi.telemetrix_uno_r4_wifi_aio import telemetrix_uno_r4_wifi_aio\n\n# An async method for running your application.\n# We pass in the instance of the API created below .\nasync def my_app(the_board):\n # Your Application code\n\n# get the event loop\nloop = asyncio.new_event_loop()\nasyncio.set_event_loop(loop)\n\n# instantiate telemetrix_aio\n# Make sure to edit the transport address assigned by your router.\nboard = telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio(\n transport_address='192.168.2.118')\n\ntry:\n # start the main function\n loop.run_until_complete(my_app(board))\nexcept KeyboardInterrupt:\n try:\n loop.run_until_complete(board.shutdown())\n except:\n pass\n sys.exit(0)\n\n
Copyright (C) 2023 Alan Yorinks. All Rights Reserved.
"},{"location":"template_wifi_threaded/","title":"WIFI Threaded","text":"Here, we need to instantiate the class passing in the IP address assigned by your router. This parameter enables the WIFI transport.
import sys\nimport time\n\n# IMPORT THE API\nfrom telemetrix_uno_r4.wifi.telemetrix_uno_r4_wifi import telemetrix_uno_r4_wifi\n\n# INSTANTIATE THE API CLASS\n# Make sure to edit the transport address assigned by your router.\n\nboard = telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi(transport_address='192.168.2.118')\ntry:\n # WRITE YOUR APPLICATION HERE\nexcept:\n board.shutdown()\n\n\n\n\n
Copyright (C) 2023 Alan Yorinks. All Rights Reserved.
"},{"location":"venv/","title":"Create A Python Virtual Environment","text":"When using Telemetrix, it is highly recommended that you work within a Python virtual environment.
A virtual environment isolates your project from other projects. Packages installed into a virtual environment are confined to your current project and will not affect or change packages used by other projects. Please refer to this article or the Python documentation.
If you are using the latest version of Ubuntu and Debian Linux, you are required to use a virtual environment.
Copyright (C) 2023 Alan Yorinks. All Rights Reserved.
"}]} \ No newline at end of file diff --git a/server_config/index.html b/server_config/index.html new file mode 100644 index 0000000..a2c2e6f --- /dev/null +++ b/server_config/index.html @@ -0,0 +1,1361 @@ + + + + + + + + + + + + + + + + + + + + + +The Minima requires no configuration.
+By default, when you power up the Arduino, the sketch is identified by the message +"Telemetrix BLE" scrolling across the display. This message will be extinguished once a +client application connects.
+You may disable the power on scrolling by commenting out the line that says
+#define ENABLE_STARTING_BANNER 1
+
+The client API method, enable_scroll_message, which allows you to create and scroll your +own message +across the display, still functions even if you disable the starting banner.
+The ble_name string is the name the BLE client will search for to connect. You may +change the default value, but if you do, you must also set the +ble_device_name parameter in the __init__ method when you +instantiate telemetrix_uno_r4_wifi_aio.
+By default, when you power up the Arduino, the sketch is identified by the message +"USBSerial" scrolling across the display. This message will be extinguished once a +client application connects.
+You may disable the power on scrolling by commenting out the line that says
+#define ENABLE_STARTING_BANNER 1
+
+The client API method, enable_scroll_message, allows you to create and scroll your +own message +across the display, and it still functions even if you disable the starting banner.
+Edit the sketch and place your router's SSID between the quotes.
+Edit the sketch and place your router's PASSWORD between the quotes.
+If the starting banner is enabled, and you forget to set SSID and PASSWORD in the sketch, +a series of question marks will scroll across the screen.
+Once you have a valid SSID and PASSWORD configured, the IP address assigned by the +router will be displayed.
+You may disable the power on scrolling by commenting out the line that says
+#define ENABLE_STARTING_BANNER 1
+
+The client API method, enable_scroll_message, allows you to create and scroll your +own message +across the display, and it still functions even if you disable the starting banner.
+
+Copyright (C) 2023 Alan Yorinks. All Rights Reserved.
Open the Arduino IDE and click on the library icon.
+ +In the search box, type Telemetrix4UnoR4, and when the library is found, click INSTALL.
+ +You will be prompted to install all of the dependencies. Select INSTALL ALL.
+ +Follow the instructions on this link +to make sure that you have the correct version of +the radio firmware installed and to install the Beta version of the ArduinoBLE library.
+
+Copyright (C) 2023 Alan Yorinks. All Rights Reserved.
Select File from the Arduino IDE main menu and then select Examples.
+Next, select TelemetrixUnoR4 from the example selections.
+ +There are four servers to choose from:
+Arduino UNO R4 Minima
+Arduino UNO R4 WIFI
+
+Copyright (C) 2023 Alan Yorinks. All Rights Reserved.
Copyright (c) 2023 Alan Yorinks All rights reserved.
+This program is free software; you can redistribute it and/or +modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +Version 3 as published by the Free Software Foundation; either +or (at your option) any later version. +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details.
+You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ + + +TelemetrixUnoR4Minima
+
+
+
+ Bases: threading.Thread
This class exposes and implements the telemetrix API. +It uses threading to accommodate concurrency. +It includes the public API methods as well as +a set of private methods.
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
35 + 36 + 37 + 38 + 39 + 40 + 41 + 42 + 43 + 44 + 45 + 46 + 47 + 48 + 49 + 50 + 51 + 52 + 53 + 54 + 55 + 56 + 57 + 58 + 59 + 60 + 61 + 62 + 63 + 64 + 65 + 66 + 67 + 68 + 69 + 70 + 71 + 72 + 73 + 74 + 75 + 76 + 77 + 78 + 79 + 80 + 81 + 82 + 83 + 84 + 85 + 86 + 87 + 88 + 89 + 90 + 91 + 92 + 93 + 94 + 95 + 96 + 97 + 98 + 99 + 100 + 101 + 102 + 103 + 104 + 105 + 106 + 107 + 108 + 109 + 110 + 111 + 112 + 113 + 114 + 115 + 116 + 117 + 118 + 119 + 120 + 121 + 122 + 123 + 124 + 125 + 126 + 127 + 128 + 129 + 130 + 131 + 132 + 133 + 134 + 135 + 136 + 137 + 138 + 139 + 140 + 141 + 142 + 143 + 144 + 145 + 146 + 147 + 148 + 149 + 150 + 151 + 152 + 153 + 154 + 155 + 156 + 157 + 158 + 159 + 160 + 161 + 162 + 163 + 164 + 165 + 166 + 167 + 168 + 169 + 170 + 171 + 172 + 173 + 174 + 175 + 176 + 177 + 178 + 179 + 180 + 181 + 182 + 183 + 184 + 185 + 186 + 187 + 188 + 189 + 190 + 191 + 192 + 193 + 194 + 195 + 196 + 197 + 198 + 199 + 200 + 201 + 202 + 203 + 204 + 205 + 206 + 207 + 208 + 209 + 210 + 211 + 212 + 213 + 214 + 215 + 216 + 217 + 218 + 219 + 220 + 221 + 222 + 223 + 224 + 225 + 226 + 227 + 228 + 229 + 230 + 231 + 232 + 233 + 234 + 235 + 236 + 237 + 238 + 239 + 240 + 241 + 242 + 243 + 244 + 245 + 246 + 247 + 248 + 249 + 250 + 251 + 252 + 253 + 254 + 255 + 256 + 257 + 258 + 259 + 260 + 261 + 262 + 263 + 264 + 265 + 266 + 267 + 268 + 269 + 270 + 271 + 272 + 273 + 274 + 275 + 276 + 277 + 278 + 279 + 280 + 281 + 282 + 283 + 284 + 285 + 286 + 287 + 288 + 289 + 290 + 291 + 292 + 293 + 294 + 295 + 296 + 297 + 298 + 299 + 300 + 301 + 302 + 303 + 304 + 305 + 306 + 307 + 308 + 309 + 310 + 311 + 312 + 313 + 314 + 315 + 316 + 317 + 318 + 319 + 320 + 321 + 322 + 323 + 324 + 325 + 326 + 327 + 328 + 329 + 330 + 331 + 332 + 333 + 334 + 335 + 336 + 337 + 338 + 339 + 340 + 341 + 342 + 343 + 344 + 345 + 346 + 347 + 348 + 349 + 350 + 351 + 352 + 353 + 354 + 355 + 356 + 357 + 358 + 359 + 360 + 361 + 362 + 363 + 364 + 365 + 366 + 367 + 368 + 369 + 370 + 371 + 372 + 373 + 374 + 375 + 376 + 377 + 378 + 379 + 380 + 381 + 382 + 383 + 384 + 385 + 386 + 387 + 388 + 389 + 390 + 391 + 392 + 393 + 394 + 395 + 396 + 397 + 398 + 399 + 400 + 401 + 402 + 403 + 404 + 405 + 406 + 407 + 408 + 409 + 410 + 411 + 412 + 413 + 414 + 415 + 416 + 417 + 418 + 419 + 420 + 421 + 422 + 423 + 424 + 425 + 426 + 427 + 428 + 429 + 430 + 431 + 432 + 433 + 434 + 435 + 436 + 437 + 438 + 439 + 440 + 441 + 442 + 443 + 444 + 445 + 446 + 447 + 448 + 449 + 450 + 451 + 452 + 453 + 454 + 455 + 456 + 457 + 458 + 459 + 460 + 461 + 462 + 463 + 464 + 465 + 466 + 467 + 468 + 469 + 470 + 471 + 472 + 473 + 474 + 475 + 476 + 477 + 478 + 479 + 480 + 481 + 482 + 483 + 484 + 485 + 486 + 487 + 488 + 489 + 490 + 491 + 492 + 493 + 494 + 495 + 496 + 497 + 498 + 499 + 500 + 501 + 502 + 503 + 504 + 505 + 506 + 507 + 508 + 509 + 510 + 511 + 512 + 513 + 514 + 515 + 516 + 517 + 518 + 519 + 520 + 521 + 522 + 523 + 524 + 525 + 526 + 527 + 528 + 529 + 530 + 531 + 532 + 533 + 534 + 535 + 536 + 537 + 538 + 539 + 540 + 541 + 542 + 543 + 544 + 545 + 546 + 547 + 548 + 549 + 550 + 551 + 552 + 553 + 554 + 555 + 556 + 557 + 558 + 559 + 560 + 561 + 562 + 563 + 564 + 565 + 566 + 567 + 568 + 569 + 570 + 571 + 572 + 573 + 574 + 575 + 576 + 577 + 578 + 579 + 580 + 581 + 582 + 583 + 584 + 585 + 586 + 587 + 588 + 589 + 590 + 591 + 592 + 593 + 594 + 595 + 596 + 597 + 598 + 599 + 600 + 601 + 602 + 603 + 604 + 605 + 606 + 607 + 608 + 609 + 610 + 611 + 612 + 613 + 614 + 615 + 616 + 617 + 618 + 619 + 620 + 621 + 622 + 623 + 624 + 625 + 626 + 627 + 628 + 629 + 630 + 631 + 632 + 633 + 634 + 635 + 636 + 637 + 638 + 639 + 640 + 641 + 642 + 643 + 644 + 645 + 646 + 647 + 648 + 649 + 650 + 651 + 652 + 653 + 654 + 655 + 656 + 657 + 658 + 659 + 660 + 661 + 662 + 663 + 664 + 665 + 666 + 667 + 668 + 669 + 670 + 671 + 672 + 673 + 674 + 675 + 676 + 677 + 678 + 679 + 680 + 681 + 682 + 683 + 684 + 685 + 686 + 687 + 688 + 689 + 690 + 691 + 692 + 693 + 694 + 695 + 696 + 697 + 698 + 699 + 700 + 701 + 702 + 703 + 704 + 705 + 706 + 707 + 708 + 709 + 710 + 711 + 712 + 713 + 714 + 715 + 716 + 717 + 718 + 719 + 720 + 721 + 722 + 723 + 724 + 725 + 726 + 727 + 728 + 729 + 730 + 731 + 732 + 733 + 734 + 735 + 736 + 737 + 738 + 739 + 740 + 741 + 742 + 743 + 744 + 745 + 746 + 747 + 748 + 749 + 750 + 751 + 752 + 753 + 754 + 755 + 756 + 757 + 758 + 759 + 760 + 761 + 762 + 763 + 764 + 765 + 766 + 767 + 768 + 769 + 770 + 771 + 772 + 773 + 774 + 775 + 776 + 777 + 778 + 779 + 780 + 781 + 782 + 783 + 784 + 785 + 786 + 787 + 788 + 789 + 790 + 791 + 792 + 793 + 794 + 795 + 796 + 797 + 798 + 799 + 800 + 801 + 802 + 803 + 804 + 805 + 806 + 807 + 808 + 809 + 810 + 811 + 812 + 813 + 814 + 815 + 816 + 817 + 818 + 819 + 820 + 821 + 822 + 823 + 824 + 825 + 826 + 827 + 828 + 829 + 830 + 831 + 832 + 833 + 834 + 835 + 836 + 837 + 838 + 839 + 840 + 841 + 842 + 843 + 844 + 845 + 846 + 847 + 848 + 849 + 850 + 851 + 852 + 853 + 854 + 855 + 856 + 857 + 858 + 859 + 860 + 861 + 862 + 863 + 864 + 865 + 866 + 867 + 868 + 869 + 870 + 871 + 872 + 873 + 874 + 875 + 876 + 877 + 878 + 879 + 880 + 881 + 882 + 883 + 884 + 885 + 886 + 887 + 888 + 889 + 890 + 891 + 892 + 893 + 894 + 895 + 896 + 897 + 898 + 899 + 900 + 901 + 902 + 903 + 904 + 905 + 906 + 907 + 908 + 909 + 910 + 911 + 912 + 913 + 914 + 915 + 916 + 917 + 918 + 919 + 920 + 921 + 922 + 923 + 924 + 925 + 926 + 927 + 928 + 929 + 930 + 931 + 932 + 933 + 934 + 935 + 936 + 937 + 938 + 939 + 940 + 941 + 942 + 943 + 944 + 945 + 946 + 947 + 948 + 949 + 950 + 951 + 952 + 953 + 954 + 955 + 956 + 957 + 958 + 959 + 960 + 961 + 962 + 963 + 964 + 965 + 966 + 967 + 968 + 969 + 970 + 971 + 972 + 973 + 974 + 975 + 976 + 977 + 978 + 979 + 980 + 981 + 982 + 983 + 984 + 985 + 986 + 987 + 988 + 989 + 990 + 991 + 992 + 993 + 994 + 995 + 996 + 997 + 998 + 999 +1000 +1001 +1002 +1003 +1004 +1005 +1006 +1007 +1008 +1009 +1010 +1011 +1012 +1013 +1014 +1015 +1016 +1017 +1018 +1019 +1020 +1021 +1022 +1023 +1024 +1025 +1026 +1027 +1028 +1029 +1030 +1031 +1032 +1033 +1034 +1035 +1036 +1037 +1038 +1039 +1040 +1041 +1042 +1043 +1044 +1045 +1046 +1047 +1048 +1049 +1050 +1051 +1052 +1053 +1054 +1055 +1056 +1057 +1058 +1059 +1060 +1061 +1062 +1063 +1064 +1065 +1066 +1067 +1068 +1069 +1070 +1071 +1072 +1073 +1074 +1075 +1076 +1077 +1078 +1079 +1080 +1081 +1082 +1083 +1084 +1085 +1086 +1087 +1088 +1089 +1090 +1091 +1092 +1093 +1094 +1095 +1096 +1097 +1098 +1099 +1100 +1101 +1102 +1103 +1104 +1105 +1106 +1107 +1108 +1109 +1110 +1111 +1112 +1113 +1114 +1115 +1116 +1117 +1118 +1119 +1120 +1121 +1122 +1123 +1124 +1125 +1126 +1127 +1128 +1129 +1130 +1131 +1132 +1133 +1134 +1135 +1136 +1137 +1138 +1139 +1140 +1141 +1142 +1143 +1144 +1145 +1146 +1147 +1148 +1149 +1150 +1151 +1152 +1153 +1154 +1155 +1156 +1157 +1158 +1159 +1160 +1161 +1162 +1163 +1164 +1165 +1166 +1167 +1168 +1169 +1170 +1171 +1172 +1173 +1174 +1175 +1176 +1177 +1178 +1179 +1180 +1181 +1182 +1183 +1184 +1185 +1186 +1187 +1188 +1189 +1190 +1191 +1192 +1193 +1194 +1195 +1196 +1197 +1198 +1199 +1200 +1201 +1202 +1203 +1204 +1205 +1206 +1207 +1208 +1209 +1210 +1211 +1212 +1213 +1214 +1215 +1216 +1217 +1218 +1219 +1220 +1221 +1222 +1223 +1224 +1225 +1226 +1227 +1228 +1229 +1230 +1231 +1232 +1233 +1234 +1235 +1236 +1237 +1238 +1239 +1240 +1241 +1242 +1243 +1244 +1245 +1246 +1247 +1248 +1249 +1250 +1251 +1252 +1253 +1254 +1255 +1256 +1257 +1258 +1259 +1260 +1261 +1262 +1263 +1264 +1265 +1266 +1267 +1268 +1269 +1270 +1271 +1272 +1273 +1274 +1275 +1276 +1277 +1278 +1279 +1280 +1281 +1282 +1283 +1284 +1285 +1286 +1287 +1288 +1289 +1290 +1291 +1292 +1293 +1294 +1295 +1296 +1297 +1298 +1299 +1300 +1301 +1302 +1303 +1304 +1305 +1306 +1307 +1308 +1309 +1310 +1311 +1312 +1313 +1314 +1315 +1316 +1317 +1318 +1319 +1320 +1321 +1322 +1323 +1324 +1325 +1326 +1327 +1328 +1329 +1330 +1331 +1332 +1333 +1334 +1335 +1336 +1337 +1338 +1339 +1340 +1341 +1342 +1343 +1344 +1345 +1346 +1347 +1348 +1349 +1350 +1351 +1352 +1353 +1354 +1355 +1356 +1357 +1358 +1359 +1360 +1361 +1362 +1363 +1364 +1365 +1366 +1367 +1368 +1369 +1370 +1371 +1372 +1373 +1374 +1375 +1376 +1377 +1378 +1379 +1380 +1381 +1382 +1383 +1384 +1385 +1386 +1387 +1388 +1389 +1390 +1391 +1392 +1393 +1394 +1395 +1396 +1397 +1398 +1399 +1400 +1401 +1402 +1403 +1404 +1405 +1406 +1407 +1408 +1409 +1410 +1411 +1412 +1413 +1414 +1415 +1416 +1417 +1418 +1419 +1420 +1421 +1422 +1423 +1424 +1425 +1426 +1427 +1428 +1429 +1430 +1431 +1432 +1433 +1434 +1435 +1436 +1437 +1438 +1439 +1440 +1441 +1442 +1443 +1444 +1445 +1446 +1447 +1448 +1449 +1450 +1451 +1452 +1453 +1454 +1455 +1456 +1457 +1458 +1459 +1460 +1461 +1462 +1463 +1464 +1465 +1466 +1467 +1468 +1469 +1470 +1471 +1472 +1473 +1474 +1475 +1476 +1477 +1478 +1479 +1480 +1481 +1482 +1483 +1484 +1485 +1486 +1487 +1488 +1489 +1490 +1491 +1492 +1493 +1494 +1495 +1496 +1497 +1498 +1499 +1500 +1501 +1502 +1503 +1504 +1505 +1506 +1507 +1508 +1509 +1510 +1511 +1512 +1513 +1514 +1515 +1516 +1517 +1518 +1519 +1520 +1521 +1522 +1523 +1524 +1525 +1526 +1527 +1528 +1529 +1530 +1531 +1532 +1533 +1534 +1535 +1536 +1537 +1538 +1539 +1540 +1541 +1542 +1543 +1544 +1545 +1546 +1547 +1548 +1549 +1550 +1551 +1552 +1553 +1554 +1555 +1556 +1557 +1558 +1559 +1560 +1561 +1562 +1563 +1564 +1565 +1566 +1567 +1568 +1569 +1570 +1571 +1572 +1573 +1574 +1575 +1576 +1577 +1578 +1579 +1580 +1581 +1582 +1583 +1584 +1585 +1586 +1587 +1588 +1589 +1590 +1591 +1592 +1593 +1594 +1595 +1596 +1597 +1598 +1599 +1600 +1601 +1602 +1603 +1604 +1605 +1606 +1607 +1608 +1609 +1610 +1611 +1612 +1613 +1614 +1615 +1616 +1617 +1618 +1619 +1620 +1621 +1622 +1623 +1624 +1625 +1626 +1627 +1628 +1629 +1630 +1631 +1632 +1633 +1634 +1635 +1636 +1637 +1638 +1639 +1640 +1641 +1642 +1643 +1644 +1645 +1646 +1647 +1648 +1649 +1650 +1651 +1652 +1653 +1654 +1655 +1656 +1657 +1658 +1659 +1660 +1661 +1662 +1663 +1664 +1665 +1666 +1667 +1668 +1669 +1670 +1671 +1672 +1673 +1674 +1675 +1676 +1677 +1678 +1679 +1680 +1681 +1682 +1683 +1684 +1685 +1686 +1687 +1688 +1689 +1690 +1691 +1692 +1693 +1694 +1695 +1696 +1697 +1698 +1699 +1700 +1701 +1702 +1703 +1704 +1705 +1706 +1707 +1708 +1709 +1710 +1711 +1712 +1713 +1714 +1715 +1716 +1717 +1718 +1719 +1720 +1721 +1722 +1723 +1724 +1725 +1726 +1727 +1728 +1729 +1730 +1731 +1732 +1733 +1734 +1735 +1736 +1737 +1738 +1739 +1740 +1741 +1742 +1743 +1744 +1745 +1746 +1747 +1748 +1749 +1750 +1751 +1752 +1753 +1754 +1755 +1756 +1757 +1758 +1759 +1760 +1761 +1762 +1763 +1764 +1765 +1766 +1767 +1768 +1769 +1770 +1771 +1772 +1773 +1774 +1775 +1776 +1777 +1778 +1779 +1780 +1781 +1782 +1783 +1784 +1785 +1786 +1787 +1788 +1789 +1790 +1791 +1792 +1793 +1794 +1795 +1796 +1797 +1798 +1799 +1800 +1801 +1802 +1803 +1804 +1805 +1806 +1807 +1808 +1809 +1810 +1811 +1812 +1813 +1814 +1815 +1816 +1817 +1818 +1819 +1820 +1821 +1822 +1823 +1824 +1825 +1826 +1827 +1828 +1829 +1830 +1831 +1832 +1833 +1834 +1835 +1836 +1837 +1838 +1839 +1840 +1841 +1842 +1843 +1844 +1845 +1846 +1847 +1848 +1849 +1850 +1851 +1852 +1853 +1854 +1855 +1856 +1857 +1858 +1859 +1860 +1861 +1862 +1863 +1864 +1865 +1866 +1867 +1868 +1869 +1870 +1871 +1872 +1873 +1874 +1875 +1876 +1877 +1878 +1879 +1880 +1881 +1882 +1883 +1884 +1885 +1886 +1887 +1888 +1889 +1890 +1891 +1892 +1893 +1894 +1895 +1896 +1897 +1898 +1899 +1900 +1901 +1902 +1903 +1904 +1905 +1906 +1907 +1908 +1909 +1910 +1911 +1912 +1913 +1914 +1915 +1916 +1917 +1918 +1919 +1920 +1921 +1922 +1923 +1924 +1925 +1926 +1927 +1928 +1929 +1930 +1931 +1932 +1933 +1934 +1935 +1936 +1937 +1938 +1939 +1940 +1941 +1942 +1943 +1944 +1945 +1946 +1947 +1948 +1949 +1950 +1951 +1952 +1953 +1954 +1955 +1956 +1957 +1958 +1959 +1960 +1961 +1962 +1963 +1964 +1965 +1966 +1967 +1968 +1969 +1970 +1971 +1972 +1973 +1974 +1975 +1976 +1977 +1978 +1979 +1980 +1981 +1982 +1983 +1984 +1985 +1986 +1987 +1988 +1989 +1990 +1991 +1992 +1993 +1994 +1995 +1996 +1997 +1998 +1999 +2000 +2001 +2002 +2003 +2004 +2005 +2006 +2007 +2008 +2009 +2010 +2011 +2012 +2013 +2014 +2015 +2016 +2017 +2018 +2019 +2020 +2021 +2022 +2023 +2024 +2025 +2026 +2027 +2028 +2029 +2030 +2031 +2032 +2033 +2034 +2035 +2036 +2037 +2038 +2039 +2040 +2041 +2042 +2043 +2044 +2045 +2046 +2047 +2048 +2049 +2050 +2051 +2052 +2053 +2054 +2055 +2056 +2057 +2058 +2059 +2060 +2061 +2062 +2063 +2064 +2065 +2066 +2067 +2068 +2069 +2070 +2071 +2072 +2073 +2074 +2075 +2076 +2077 +2078 +2079 +2080 +2081 +2082 +2083 +2084 +2085 +2086 +2087 +2088 +2089 +2090 +2091 +2092 +2093 +2094 +2095 +2096 +2097 +2098 +2099 +2100 +2101 +2102 +2103 +2104 +2105 +2106 +2107 +2108 +2109 +2110 +2111 +2112 +2113 +2114 +2115 +2116 +2117 +2118 +2119 +2120 +2121 +2122 +2123 +2124 +2125 +2126 +2127 +2128 +2129 +2130 +2131 +2132 +2133 +2134 +2135 +2136 +2137 +2138 +2139 +2140 +2141 +2142 +2143 +2144 +2145 +2146 +2147 +2148 +2149 +2150 +2151 +2152 +2153 +2154 +2155 +2156 +2157 +2158 +2159 +2160 +2161 +2162 +2163 +2164 +2165 +2166 +2167 +2168 +2169 +2170 +2171 +2172 +2173 +2174 +2175 +2176 +2177 +2178 +2179 +2180 +2181 +2182 +2183 +2184 +2185 +2186 +2187 +2188 +2189 +2190 +2191 +2192 +2193 +2194 +2195 +2196 +2197 +2198 +2199 +2200 +2201 +2202 +2203 +2204 +2205 +2206 +2207 +2208 +2209 +2210 +2211 +2212 +2213 +2214 +2215 +2216 +2217 +2218 +2219 +2220 +2221 +2222 +2223 +2224 +2225 +2226 +2227 +2228 +2229 +2230 +2231 +2232 +2233 +2234 +2235 +2236 +2237 +2238 +2239 +2240 +2241 +2242 +2243 +2244 +2245 +2246 +2247 +2248 +2249 +2250 +2251 +2252 +2253 +2254 +2255 +2256 +2257 +2258 +2259 +2260 +2261 +2262 +2263 +2264 +2265 +2266 +2267 +2268 +2269 +2270 +2271 +2272 +2273 +2274 +2275 +2276 +2277 +2278 +2279 +2280 +2281 +2282 +2283 +2284 +2285 +2286 +2287 +2288 +2289 +2290 +2291 +2292 +2293 +2294 +2295 +2296 +2297 +2298 +2299 +2300 +2301 +2302 +2303 +2304 +2305 +2306 +2307 +2308 +2309 +2310 +2311 +2312 +2313 +2314 +2315 +2316 +2317 +2318 +2319 +2320 +2321 +2322 +2323 +2324 +2325 +2326 +2327 +2328 +2329 +2330 +2331 +2332 +2333 +2334 +2335 +2336 +2337 +2338 +2339 +2340 +2341 +2342 +2343 +2344 +2345 +2346 +2347 +2348 +2349 +2350 +2351 +2352 +2353 +2354 +2355 +2356 +2357 +2358 +2359 +2360 +2361 +2362 +2363 +2364 +2365 +2366 +2367 +2368 +2369 +2370 +2371 +2372 +2373 +2374 +2375 +2376 +2377 +2378 +2379 +2380 +2381 +2382 +2383 +2384 +2385 +2386 +2387 +2388 +2389 +2390 +2391 +2392 +2393 +2394 +2395 +2396 +2397 +2398 +2399 +2400 +2401 +2402 +2403 +2404 +2405 +2406 +2407 +2408 +2409 +2410 +2411 +2412 +2413 +2414 +2415 +2416 +2417 +2418 +2419 +2420 +2421 +2422 +2423 +2424 +2425 +2426 +2427 +2428 +2429 +2430 +2431 +2432 +2433 +2434 +2435 +2436 +2437 +2438 +2439 +2440 +2441 +2442 +2443 +2444 +2445 +2446 +2447 +2448 +2449 +2450 +2451 +2452 +2453 +2454 +2455 +2456 +2457 +2458 +2459 +2460 +2461 +2462 +2463 +2464 +2465 +2466 +2467 +2468 +2469 +2470 +2471 +2472 +2473 +2474 +2475 +2476 +2477 +2478 +2479 +2480 +2481 +2482 +2483 +2484 +2485 +2486 +2487 +2488 +2489 +2490 +2491 +2492 +2493 +2494 +2495 +2496 +2497 +2498 +2499 +2500 +2501 +2502 +2503 +2504 +2505 +2506 +2507 +2508 +2509 +2510 +2511 +2512 +2513 +2514 +2515 +2516 +2517 +2518 +2519 +2520 +2521 +2522 +2523 +2524 +2525 +2526 +2527 +2528 +2529 +2530 +2531 +2532 +2533 +2534 +2535 +2536 +2537 +2538 +2539 +2540 +2541 +2542 +2543 +2544 +2545 +2546 +2547 +2548 +2549 +2550 +2551 +2552 +2553 |
|
__init__(com_port=None, arduino_instance_id=1, arduino_wait=1, sleep_tune=1e-06, shutdown_on_exception=True, hard_reset_on_shutdown=True)
+
+:param com_port: e.g. COM3 or /dev/ttyACM0. + Only use if you wish to bypass auto com port + detection.
+:param arduino_instance_id: Match with the value installed on the + arduino-telemetrix sketch.
+:param arduino_wait: Amount of time to wait for an Arduino to + fully reset itself.
+:param sleep_tune: A tuning parameter (typically not changed by user)
+:param shutdown_on_exception: call shutdown before raising + a RunTimeError exception, or + receiving a KeyboardInterrupt exception
+:param hard_reset_on_shutdown: reset the board on shutdown
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
45 + 46 + 47 + 48 + 49 + 50 + 51 + 52 + 53 + 54 + 55 + 56 + 57 + 58 + 59 + 60 + 61 + 62 + 63 + 64 + 65 + 66 + 67 + 68 + 69 + 70 + 71 + 72 + 73 + 74 + 75 + 76 + 77 + 78 + 79 + 80 + 81 + 82 + 83 + 84 + 85 + 86 + 87 + 88 + 89 + 90 + 91 + 92 + 93 + 94 + 95 + 96 + 97 + 98 + 99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +131 +132 +133 +134 +135 +136 +137 +138 +139 +140 +141 +142 +143 +144 +145 +146 +147 +148 +149 +150 +151 +152 +153 +154 +155 +156 +157 +158 +159 +160 +161 +162 +163 +164 +165 +166 +167 +168 +169 +170 +171 +172 +173 +174 +175 +176 +177 +178 +179 +180 +181 +182 +183 +184 +185 +186 +187 +188 +189 +190 +191 +192 +193 +194 +195 +196 +197 +198 +199 +200 +201 +202 +203 +204 +205 +206 +207 +208 +209 +210 +211 +212 +213 +214 +215 +216 +217 +218 +219 +220 +221 +222 +223 +224 +225 +226 +227 +228 +229 +230 +231 +232 +233 +234 +235 +236 +237 +238 +239 +240 +241 +242 +243 +244 +245 +246 +247 +248 +249 +250 +251 +252 +253 +254 +255 +256 +257 +258 +259 +260 +261 +262 +263 +264 +265 +266 +267 +268 +269 +270 +271 +272 +273 +274 +275 +276 +277 +278 +279 +280 +281 +282 +283 +284 +285 +286 +287 +288 +289 +290 +291 +292 +293 +294 +295 +296 +297 +298 +299 +300 +301 +302 +303 +304 +305 +306 +307 +308 +309 +310 +311 +312 +313 +314 +315 +316 |
|
analog_write(pin, value)
+
+Set the specified pin to the specified value.
+:param pin: arduino pin number
+:param value: pin value (maximum 16 bits)
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
412 +413 +414 +415 +416 +417 +418 +419 +420 +421 +422 +423 +424 |
|
digital_write(pin, value)
+
+Set the specified pin to the specified value.
+:param pin: arduino pin number
+:param value: pin value (1 or 0)
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
426 +427 +428 +429 +430 +431 +432 +433 +434 +435 +436 +437 |
|
disable_all_reporting()
+
+Disable reporting for all digital and analog input pins
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
439 +440 +441 +442 +443 +444 +445 |
|
disable_analog_reporting(pin)
+
+Disables analog reporting for a single analog pin.
+:param pin: Analog pin number. For example for A0, the number is 0.
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
447 +448 +449 +450 +451 +452 +453 +454 +455 +456 |
|
disable_digital_reporting(pin)
+
+Disables digital reporting for a single digital input.
+:param pin: Pin number.
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
458 +459 +460 +461 +462 +463 +464 +465 +466 +467 |
|
enable_analog_reporting(pin)
+
+Enables analog reporting for the specified pin.
+:param pin: Analog pin number. For example for A0, the number is 0.
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
469 +470 +471 +472 +473 +474 +475 +476 +477 +478 +479 |
|
enable_digital_reporting(pin)
+
+Enable reporting on the specified digital pin.
+:param pin: Pin number.
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
481 +482 +483 +484 +485 +486 +487 +488 +489 +490 |
|
i2c_read(address, register, number_of_bytes, callback=None, i2c_port=0, write_register=True)
+
+Read the specified number of bytes from the + specified register for the i2c device.
+:param address: i2c device address
+:param register: i2c register (or None if no register + selection is needed)
+:param number_of_bytes: number of bytes to be read
+:param callback: Required callback function to report + i2c data as a result of read command
+:param i2c_port: 0 = default, 1 = secondary
+:param write_register: If True, the register is written + before read + Else, the write is suppressed
+callback returns a data list:
+[I2C_READ_REPORT, address, register, count of data bytes, + data bytes, time-stamp]
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
513 +514 +515 +516 +517 +518 +519 +520 +521 +522 +523 +524 +525 +526 +527 +528 +529 +530 +531 +532 +533 +534 +535 +536 +537 +538 +539 +540 +541 +542 +543 +544 +545 +546 +547 |
|
i2c_read_restart_transmission(address, register, number_of_bytes, callback=None, i2c_port=0, write_register=True)
+
+Read the specified number of bytes from the specified + register for the i2c device. This restarts the transmission + after the read. It is required for some i2c devices such as the MMA8452Q + accelerometer.
+:param address: i2c device address
+:param register: i2c register (or None if no register + selection is needed)
+:param number_of_bytes: number of bytes to be read
+:param callback: Required callback function to report i2c + data as a result of read command
+:param i2c_port: 0 = default 1 = secondary
+:param write_register: If True, the register is written before read + Else, the write is suppressed
+callback returns a data list:
+[I2C_READ_REPORT, address, register, count of data bytes, + data bytes, time-stamp]
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
549 +550 +551 +552 +553 +554 +555 +556 +557 +558 +559 +560 +561 +562 +563 +564 +565 +566 +567 +568 +569 +570 +571 +572 +573 +574 +575 +576 +577 +578 +579 +580 +581 +582 +583 +584 +585 +586 +587 |
|
i2c_write(address, args, i2c_port=0)
+
+Write data to an i2c device.
+:param address: i2c device address
+:param i2c_port: 0= port 1, 1 = port 2
+:param args: A variable number of bytes to be sent to the device + passed in as a list
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
655 +656 +657 +658 +659 +660 +661 +662 +663 +664 +665 +666 +667 +668 +669 +670 +671 +672 +673 +674 +675 +676 +677 +678 +679 +680 +681 +682 +683 +684 +685 +686 |
|
loop_back(start_character, callback=None)
+
+This is a debugging method to send a character to the +Arduino device, and have the device loop it back.
+:param start_character: The character to loop back. It should be + an integer.
+:param callback: Looped back character will appear in the callback method
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
688 +689 +690 +691 +692 +693 +694 +695 +696 +697 +698 +699 +700 +701 |
|
r4_hard_reset()
+
+Place the r4 into hard reset
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
2100 +2101 +2102 +2103 +2104 +2105 +2106 +2107 +2108 |
|
servo_detach(pin_number)
+
+Detach a servo for reuse
+:param pin_number: attached pin
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
1057 +1058 +1059 +1060 +1061 +1062 +1063 +1064 +1065 |
|
servo_write(pin_number, angle)
+
+Set a servo attached to a pin to a given angle.
+:param pin_number: pin
+:param angle: angle (0-180)
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
1044 +1045 +1046 +1047 +1048 +1049 +1050 +1051 +1052 +1053 +1054 +1055 |
|
set_analog_scan_interval(interval)
+
+Set the analog scanning interval.
+:param interval: value of 0 - 255 - milliseconds
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
703 +704 +705 +706 +707 +708 +709 +710 +711 +712 +713 +714 +715 +716 |
|
set_pin_mode_analog_input(pin_number, differential=0, callback=None)
+
+Set a pin as an analog input.
+:param pin_number: arduino pin number
+:param differential: difference in previous to current value before + report will be generated
+:param callback: callback function
+callback returns a data list:
+[pin_type, pin_number, pin_value, raw_time_stamp]
+The pin_type for analog input pins = 3
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
727 +728 +729 +730 +731 +732 +733 +734 +735 +736 +737 +738 +739 +740 +741 +742 +743 +744 +745 +746 +747 |
|
set_pin_mode_analog_output(pin_number)
+
+Set a pin as a pwm (analog output) pin.
+:param pin_number:arduino pin number
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
718 +719 +720 +721 +722 +723 +724 +725 |
|
set_pin_mode_dht(pin, callback=None, dht_type=22)
+
+:param pin: connection pin
+:param callback: callback function
+:param dht_type: either 22 for DHT22 or 11 for DHT11
+Error Callback: [DHT REPORT Type, DHT_ERROR_NUMBER, PIN, DHT_TYPE, Time]
+Valid Data Callback: DHT REPORT Type, DHT_DATA=, PIN, DHT_TYPE, Humidity, +Temperature, +Time]
+DHT_REPORT_TYPE = 12
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
825 +826 +827 +828 +829 +830 +831 +832 +833 +834 +835 +836 +837 +838 +839 +840 +841 +842 +843 +844 +845 +846 +847 +848 +849 +850 +851 +852 +853 +854 +855 +856 +857 +858 +859 +860 +861 +862 +863 +864 +865 |
|
set_pin_mode_digital_input(pin_number, callback=None)
+
+Set a pin as a digital input.
+:param pin_number: arduino pin number
+:param callback: callback function
+callback returns a data list:
+[pin_type, pin_number, pin_value, raw_time_stamp]
+The pin_type for all digital input pins = 2
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
749 +750 +751 +752 +753 +754 +755 +756 +757 +758 +759 +760 +761 +762 +763 +764 +765 |
|
set_pin_mode_digital_input_pullup(pin_number, callback=None)
+
+Set a pin as a digital input with pullup enabled.
+:param pin_number: arduino pin number
+:param callback: callback function
+callback returns a data list:
+[pin_type, pin_number, pin_value, raw_time_stamp]
+The pin_type for all digital input pins = 2
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
767 +768 +769 +770 +771 +772 +773 +774 +775 +776 +777 +778 +779 +780 +781 +782 +783 |
|
set_pin_mode_digital_output(pin_number)
+
+Set a pin as a digital output pin.
+:param pin_number: arduino pin number
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
785 +786 +787 +788 +789 +790 +791 +792 |
|
set_pin_mode_i2c(i2c_port=0)
+
+Establish the standard Arduino i2c pins for i2c utilization.
+:param i2c_port: 0 = i2c1, 1 = i2c2
+ + API.
+
+ See i2c_read, or i2c_read_restart_transmission.
+
+
+ telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
794 +795 +796 +797 +798 +799 +800 +801 +802 +803 +804 +805 +806 +807 +808 +809 +810 +811 +812 +813 +814 +815 +816 +817 +818 +819 +820 +821 +822 +823 |
|
set_pin_mode_servo(pin_number, min_pulse=544, max_pulse=2400)
+
+Attach a pin to a servo motor
+:param pin_number: pin
+:param min_pulse: minimum pulse width
+:param max_pulse: maximum pulse width
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
868 +869 +870 +871 +872 +873 +874 +875 +876 +877 +878 +879 +880 +881 +882 +883 +884 +885 +886 +887 +888 +889 +890 +891 |
|
set_pin_mode_sonar(trigger_pin, echo_pin, callback=None)
+
+:param trigger_pin:
+:param echo_pin:
+:param callback: callback
+callback data: [PrivateConstants.SONAR_DISTANCE, trigger_pin, distance_value, time_stamp]
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
893 +894 +895 +896 +897 +898 +899 +900 +901 +902 +903 +904 +905 +906 +907 +908 +909 +910 +911 +912 +913 +914 +915 +916 +917 +918 +919 +920 +921 +922 +923 +924 +925 +926 +927 |
|
set_pin_mode_spi(chip_select_list=None)
+
+Specify the list of chip select pins.
+Standard Arduino MISO, MOSI and CLK pins are used for the board in use.
+Chip Select is any digital output capable pin.
+:param chip_select_list: this is a list of pins to be used for chip select. + The pins will be configured as output, and set to high + ready to be used for chip select. + NOTE: You must specify the chips select pins here!
+command message: [command, [cs pins...]]
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
929 +930 +931 +932 +933 +934 +935 +936 +937 +938 +939 +940 +941 +942 +943 +944 +945 +946 +947 +948 +949 +950 +951 +952 +953 +954 +955 +956 +957 +958 +959 +960 +961 +962 +963 +964 +965 +966 +967 |
|
shutdown()
+
+This method attempts an orderly shutdown +If any exceptions are thrown, they are ignored.
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
1712 +1713 +1714 +1715 +1716 +1717 +1718 +1719 +1720 +1721 +1722 +1723 +1724 +1725 +1726 +1727 +1728 +1729 +1730 +1731 +1732 +1733 +1734 +1735 +1736 +1737 +1738 +1739 +1740 +1741 |
|
sonar_disable()
+
+Disable sonar scanning for all sonar sensors
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
1743 +1744 +1745 +1746 +1747 +1748 |
|
sonar_enable()
+
+Enable sonar scanning for all sonar sensors
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
1750 +1751 +1752 +1753 +1754 +1755 |
|
spi_cs_control(chip_select_pin, select)
+
+Control an SPI chip select line +:param chip_select_pin: pin connected to CS
+:param select: 0=select, 1=deselect
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
1757 +1758 +1759 +1760 +1761 +1762 +1763 +1764 +1765 +1766 +1767 +1768 +1769 +1770 +1771 +1772 +1773 +1774 |
|
spi_read_blocking(chip_select, register_selection, number_of_bytes_to_read, call_back=None)
+
+Read the specified number of bytes from the specified SPI port and +call the callback function with the reported data.
+:param chip_select: chip select pin
+:param register_selection: Register to be selected for read.
+:param number_of_bytes_to_read: Number of bytes to read
+:param call_back: Required callback function to report spi data as a + result of read command
+callback returns a data list: +[SPI_READ_REPORT, chip select pin, SPI Register, count of data bytes read, +data bytes, time-stamp]
+SPI_READ_REPORT = 13
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
1776 +1777 +1778 +1779 +1780 +1781 +1782 +1783 +1784 +1785 +1786 +1787 +1788 +1789 +1790 +1791 +1792 +1793 +1794 +1795 +1796 +1797 +1798 +1799 +1800 +1801 +1802 +1803 +1804 +1805 +1806 +1807 +1808 +1809 +1810 +1811 +1812 +1813 +1814 +1815 +1816 |
|
spi_set_format(clock_divisor, bit_order, data_mode)
+
+Configure how the SPI serializes and de-serializes data on the wire.
+See Arduino SPI reference materials for details.
+:param clock_divisor: 1 - 255
+:param bit_order:
+ LSBFIRST = 0
+
+ MSBFIRST = 1 (default)
+
+:param data_mode:
+ SPI_MODE0 = 0x00 (default)
+
+ SPI_MODE1 = 1
+
+ SPI_MODE2 = 2
+
+ SPI_MODE3 = 3
+
+
+ telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
1818 +1819 +1820 +1821 +1822 +1823 +1824 +1825 +1826 +1827 +1828 +1829 +1830 +1831 +1832 +1833 +1834 +1835 +1836 +1837 +1838 +1839 +1840 +1841 +1842 +1843 +1844 +1845 +1846 +1847 +1848 +1849 +1850 +1851 +1852 +1853 +1854 +1855 +1856 +1857 +1858 |
|
spi_write_blocking(chip_select, bytes_to_write)
+
+Write a list of bytes to the SPI device.
+:param chip_select: chip select pin
+:param bytes_to_write: A list of bytes to write. This must + be in the form of a list.
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
1860 +1861 +1862 +1863 +1864 +1865 +1866 +1867 +1868 +1869 +1870 +1871 +1872 +1873 +1874 +1875 +1876 +1877 +1878 +1879 +1880 +1881 +1882 +1883 +1884 +1885 +1886 |
|
Copyright (c) 2023 Alan Yorinks All rights reserved.
+This program is free software; you can redistribute it and/or +modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +Version 3 as published by the Free Software Foundation; either +or (at your option) any later version. +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details.
+You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ + + +TelemetrixUnoR4MinimaAio
+
+
+This class exposes and implements the TelemetrixAIO API. +It includes the public API methods as well as +a set of private methods. This is an asyncio API.
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
33 + 34 + 35 + 36 + 37 + 38 + 39 + 40 + 41 + 42 + 43 + 44 + 45 + 46 + 47 + 48 + 49 + 50 + 51 + 52 + 53 + 54 + 55 + 56 + 57 + 58 + 59 + 60 + 61 + 62 + 63 + 64 + 65 + 66 + 67 + 68 + 69 + 70 + 71 + 72 + 73 + 74 + 75 + 76 + 77 + 78 + 79 + 80 + 81 + 82 + 83 + 84 + 85 + 86 + 87 + 88 + 89 + 90 + 91 + 92 + 93 + 94 + 95 + 96 + 97 + 98 + 99 + 100 + 101 + 102 + 103 + 104 + 105 + 106 + 107 + 108 + 109 + 110 + 111 + 112 + 113 + 114 + 115 + 116 + 117 + 118 + 119 + 120 + 121 + 122 + 123 + 124 + 125 + 126 + 127 + 128 + 129 + 130 + 131 + 132 + 133 + 134 + 135 + 136 + 137 + 138 + 139 + 140 + 141 + 142 + 143 + 144 + 145 + 146 + 147 + 148 + 149 + 150 + 151 + 152 + 153 + 154 + 155 + 156 + 157 + 158 + 159 + 160 + 161 + 162 + 163 + 164 + 165 + 166 + 167 + 168 + 169 + 170 + 171 + 172 + 173 + 174 + 175 + 176 + 177 + 178 + 179 + 180 + 181 + 182 + 183 + 184 + 185 + 186 + 187 + 188 + 189 + 190 + 191 + 192 + 193 + 194 + 195 + 196 + 197 + 198 + 199 + 200 + 201 + 202 + 203 + 204 + 205 + 206 + 207 + 208 + 209 + 210 + 211 + 212 + 213 + 214 + 215 + 216 + 217 + 218 + 219 + 220 + 221 + 222 + 223 + 224 + 225 + 226 + 227 + 228 + 229 + 230 + 231 + 232 + 233 + 234 + 235 + 236 + 237 + 238 + 239 + 240 + 241 + 242 + 243 + 244 + 245 + 246 + 247 + 248 + 249 + 250 + 251 + 252 + 253 + 254 + 255 + 256 + 257 + 258 + 259 + 260 + 261 + 262 + 263 + 264 + 265 + 266 + 267 + 268 + 269 + 270 + 271 + 272 + 273 + 274 + 275 + 276 + 277 + 278 + 279 + 280 + 281 + 282 + 283 + 284 + 285 + 286 + 287 + 288 + 289 + 290 + 291 + 292 + 293 + 294 + 295 + 296 + 297 + 298 + 299 + 300 + 301 + 302 + 303 + 304 + 305 + 306 + 307 + 308 + 309 + 310 + 311 + 312 + 313 + 314 + 315 + 316 + 317 + 318 + 319 + 320 + 321 + 322 + 323 + 324 + 325 + 326 + 327 + 328 + 329 + 330 + 331 + 332 + 333 + 334 + 335 + 336 + 337 + 338 + 339 + 340 + 341 + 342 + 343 + 344 + 345 + 346 + 347 + 348 + 349 + 350 + 351 + 352 + 353 + 354 + 355 + 356 + 357 + 358 + 359 + 360 + 361 + 362 + 363 + 364 + 365 + 366 + 367 + 368 + 369 + 370 + 371 + 372 + 373 + 374 + 375 + 376 + 377 + 378 + 379 + 380 + 381 + 382 + 383 + 384 + 385 + 386 + 387 + 388 + 389 + 390 + 391 + 392 + 393 + 394 + 395 + 396 + 397 + 398 + 399 + 400 + 401 + 402 + 403 + 404 + 405 + 406 + 407 + 408 + 409 + 410 + 411 + 412 + 413 + 414 + 415 + 416 + 417 + 418 + 419 + 420 + 421 + 422 + 423 + 424 + 425 + 426 + 427 + 428 + 429 + 430 + 431 + 432 + 433 + 434 + 435 + 436 + 437 + 438 + 439 + 440 + 441 + 442 + 443 + 444 + 445 + 446 + 447 + 448 + 449 + 450 + 451 + 452 + 453 + 454 + 455 + 456 + 457 + 458 + 459 + 460 + 461 + 462 + 463 + 464 + 465 + 466 + 467 + 468 + 469 + 470 + 471 + 472 + 473 + 474 + 475 + 476 + 477 + 478 + 479 + 480 + 481 + 482 + 483 + 484 + 485 + 486 + 487 + 488 + 489 + 490 + 491 + 492 + 493 + 494 + 495 + 496 + 497 + 498 + 499 + 500 + 501 + 502 + 503 + 504 + 505 + 506 + 507 + 508 + 509 + 510 + 511 + 512 + 513 + 514 + 515 + 516 + 517 + 518 + 519 + 520 + 521 + 522 + 523 + 524 + 525 + 526 + 527 + 528 + 529 + 530 + 531 + 532 + 533 + 534 + 535 + 536 + 537 + 538 + 539 + 540 + 541 + 542 + 543 + 544 + 545 + 546 + 547 + 548 + 549 + 550 + 551 + 552 + 553 + 554 + 555 + 556 + 557 + 558 + 559 + 560 + 561 + 562 + 563 + 564 + 565 + 566 + 567 + 568 + 569 + 570 + 571 + 572 + 573 + 574 + 575 + 576 + 577 + 578 + 579 + 580 + 581 + 582 + 583 + 584 + 585 + 586 + 587 + 588 + 589 + 590 + 591 + 592 + 593 + 594 + 595 + 596 + 597 + 598 + 599 + 600 + 601 + 602 + 603 + 604 + 605 + 606 + 607 + 608 + 609 + 610 + 611 + 612 + 613 + 614 + 615 + 616 + 617 + 618 + 619 + 620 + 621 + 622 + 623 + 624 + 625 + 626 + 627 + 628 + 629 + 630 + 631 + 632 + 633 + 634 + 635 + 636 + 637 + 638 + 639 + 640 + 641 + 642 + 643 + 644 + 645 + 646 + 647 + 648 + 649 + 650 + 651 + 652 + 653 + 654 + 655 + 656 + 657 + 658 + 659 + 660 + 661 + 662 + 663 + 664 + 665 + 666 + 667 + 668 + 669 + 670 + 671 + 672 + 673 + 674 + 675 + 676 + 677 + 678 + 679 + 680 + 681 + 682 + 683 + 684 + 685 + 686 + 687 + 688 + 689 + 690 + 691 + 692 + 693 + 694 + 695 + 696 + 697 + 698 + 699 + 700 + 701 + 702 + 703 + 704 + 705 + 706 + 707 + 708 + 709 + 710 + 711 + 712 + 713 + 714 + 715 + 716 + 717 + 718 + 719 + 720 + 721 + 722 + 723 + 724 + 725 + 726 + 727 + 728 + 729 + 730 + 731 + 732 + 733 + 734 + 735 + 736 + 737 + 738 + 739 + 740 + 741 + 742 + 743 + 744 + 745 + 746 + 747 + 748 + 749 + 750 + 751 + 752 + 753 + 754 + 755 + 756 + 757 + 758 + 759 + 760 + 761 + 762 + 763 + 764 + 765 + 766 + 767 + 768 + 769 + 770 + 771 + 772 + 773 + 774 + 775 + 776 + 777 + 778 + 779 + 780 + 781 + 782 + 783 + 784 + 785 + 786 + 787 + 788 + 789 + 790 + 791 + 792 + 793 + 794 + 795 + 796 + 797 + 798 + 799 + 800 + 801 + 802 + 803 + 804 + 805 + 806 + 807 + 808 + 809 + 810 + 811 + 812 + 813 + 814 + 815 + 816 + 817 + 818 + 819 + 820 + 821 + 822 + 823 + 824 + 825 + 826 + 827 + 828 + 829 + 830 + 831 + 832 + 833 + 834 + 835 + 836 + 837 + 838 + 839 + 840 + 841 + 842 + 843 + 844 + 845 + 846 + 847 + 848 + 849 + 850 + 851 + 852 + 853 + 854 + 855 + 856 + 857 + 858 + 859 + 860 + 861 + 862 + 863 + 864 + 865 + 866 + 867 + 868 + 869 + 870 + 871 + 872 + 873 + 874 + 875 + 876 + 877 + 878 + 879 + 880 + 881 + 882 + 883 + 884 + 885 + 886 + 887 + 888 + 889 + 890 + 891 + 892 + 893 + 894 + 895 + 896 + 897 + 898 + 899 + 900 + 901 + 902 + 903 + 904 + 905 + 906 + 907 + 908 + 909 + 910 + 911 + 912 + 913 + 914 + 915 + 916 + 917 + 918 + 919 + 920 + 921 + 922 + 923 + 924 + 925 + 926 + 927 + 928 + 929 + 930 + 931 + 932 + 933 + 934 + 935 + 936 + 937 + 938 + 939 + 940 + 941 + 942 + 943 + 944 + 945 + 946 + 947 + 948 + 949 + 950 + 951 + 952 + 953 + 954 + 955 + 956 + 957 + 958 + 959 + 960 + 961 + 962 + 963 + 964 + 965 + 966 + 967 + 968 + 969 + 970 + 971 + 972 + 973 + 974 + 975 + 976 + 977 + 978 + 979 + 980 + 981 + 982 + 983 + 984 + 985 + 986 + 987 + 988 + 989 + 990 + 991 + 992 + 993 + 994 + 995 + 996 + 997 + 998 + 999 +1000 +1001 +1002 +1003 +1004 +1005 +1006 +1007 +1008 +1009 +1010 +1011 +1012 +1013 +1014 +1015 +1016 +1017 +1018 +1019 +1020 +1021 +1022 +1023 +1024 +1025 +1026 +1027 +1028 +1029 +1030 +1031 +1032 +1033 +1034 +1035 +1036 +1037 +1038 +1039 +1040 +1041 +1042 +1043 +1044 +1045 +1046 +1047 +1048 +1049 +1050 +1051 +1052 +1053 +1054 +1055 +1056 +1057 +1058 +1059 +1060 +1061 +1062 +1063 +1064 +1065 +1066 +1067 +1068 +1069 +1070 +1071 +1072 +1073 +1074 +1075 +1076 +1077 +1078 +1079 +1080 +1081 +1082 +1083 +1084 +1085 +1086 +1087 +1088 +1089 +1090 +1091 +1092 +1093 +1094 +1095 +1096 +1097 +1098 +1099 +1100 +1101 +1102 +1103 +1104 +1105 +1106 +1107 +1108 +1109 +1110 +1111 +1112 +1113 +1114 +1115 +1116 +1117 +1118 +1119 +1120 +1121 +1122 +1123 +1124 +1125 +1126 +1127 +1128 +1129 +1130 +1131 +1132 +1133 +1134 +1135 +1136 +1137 +1138 +1139 +1140 +1141 +1142 +1143 +1144 +1145 +1146 +1147 +1148 +1149 +1150 +1151 +1152 +1153 +1154 +1155 +1156 +1157 +1158 +1159 +1160 +1161 +1162 +1163 +1164 +1165 +1166 +1167 +1168 +1169 +1170 +1171 +1172 +1173 +1174 +1175 +1176 +1177 +1178 +1179 +1180 +1181 +1182 +1183 +1184 +1185 +1186 +1187 +1188 +1189 +1190 +1191 +1192 +1193 +1194 +1195 +1196 +1197 +1198 +1199 +1200 +1201 +1202 +1203 +1204 +1205 +1206 +1207 +1208 +1209 +1210 +1211 +1212 +1213 +1214 +1215 +1216 +1217 +1218 +1219 +1220 +1221 +1222 +1223 +1224 +1225 +1226 +1227 +1228 +1229 +1230 +1231 +1232 +1233 +1234 +1235 +1236 +1237 +1238 +1239 +1240 +1241 +1242 +1243 +1244 +1245 +1246 +1247 +1248 +1249 +1250 +1251 +1252 +1253 +1254 +1255 +1256 +1257 +1258 +1259 +1260 +1261 +1262 +1263 +1264 +1265 +1266 +1267 +1268 +1269 +1270 +1271 +1272 +1273 +1274 +1275 +1276 +1277 +1278 +1279 +1280 +1281 +1282 +1283 +1284 +1285 +1286 +1287 +1288 +1289 +1290 +1291 +1292 +1293 +1294 +1295 +1296 +1297 +1298 +1299 +1300 +1301 +1302 +1303 +1304 +1305 +1306 +1307 +1308 +1309 +1310 +1311 +1312 +1313 +1314 +1315 +1316 +1317 +1318 +1319 +1320 +1321 +1322 +1323 +1324 +1325 +1326 +1327 +1328 +1329 +1330 +1331 +1332 +1333 +1334 +1335 +1336 +1337 +1338 +1339 +1340 +1341 +1342 +1343 +1344 +1345 +1346 +1347 +1348 +1349 +1350 +1351 +1352 +1353 +1354 +1355 +1356 +1357 +1358 +1359 +1360 +1361 +1362 +1363 +1364 +1365 +1366 +1367 +1368 +1369 +1370 +1371 +1372 +1373 +1374 +1375 +1376 +1377 +1378 +1379 +1380 +1381 +1382 +1383 +1384 +1385 +1386 +1387 +1388 +1389 +1390 +1391 +1392 +1393 +1394 +1395 +1396 +1397 +1398 +1399 +1400 +1401 +1402 +1403 +1404 +1405 +1406 +1407 +1408 +1409 +1410 +1411 +1412 +1413 +1414 +1415 +1416 +1417 +1418 +1419 +1420 +1421 +1422 +1423 +1424 +1425 +1426 +1427 +1428 +1429 +1430 +1431 +1432 +1433 +1434 +1435 +1436 +1437 +1438 +1439 +1440 +1441 +1442 +1443 +1444 +1445 +1446 +1447 +1448 +1449 +1450 +1451 +1452 +1453 +1454 +1455 +1456 +1457 +1458 +1459 +1460 +1461 +1462 +1463 +1464 +1465 +1466 +1467 +1468 +1469 +1470 +1471 +1472 +1473 +1474 +1475 +1476 +1477 +1478 +1479 +1480 +1481 +1482 +1483 +1484 +1485 +1486 +1487 +1488 +1489 +1490 +1491 +1492 +1493 +1494 +1495 +1496 +1497 +1498 +1499 +1500 +1501 +1502 +1503 +1504 +1505 +1506 +1507 +1508 +1509 +1510 +1511 +1512 +1513 +1514 +1515 +1516 +1517 +1518 +1519 +1520 +1521 +1522 +1523 +1524 +1525 +1526 +1527 +1528 +1529 +1530 +1531 +1532 +1533 +1534 +1535 +1536 +1537 +1538 +1539 +1540 +1541 +1542 +1543 +1544 +1545 +1546 +1547 +1548 +1549 +1550 +1551 +1552 +1553 +1554 +1555 +1556 +1557 +1558 +1559 +1560 +1561 +1562 +1563 +1564 +1565 +1566 +1567 +1568 +1569 +1570 +1571 +1572 +1573 +1574 +1575 +1576 +1577 +1578 +1579 +1580 +1581 +1582 +1583 +1584 +1585 +1586 +1587 +1588 +1589 +1590 +1591 +1592 +1593 +1594 +1595 +1596 +1597 +1598 +1599 +1600 +1601 +1602 +1603 +1604 +1605 +1606 +1607 +1608 +1609 +1610 +1611 +1612 +1613 +1614 +1615 +1616 +1617 +1618 +1619 +1620 +1621 +1622 +1623 +1624 +1625 +1626 +1627 +1628 +1629 +1630 +1631 +1632 +1633 +1634 +1635 +1636 +1637 +1638 +1639 +1640 +1641 +1642 +1643 +1644 +1645 +1646 +1647 +1648 +1649 +1650 +1651 +1652 +1653 +1654 +1655 +1656 +1657 +1658 +1659 +1660 +1661 +1662 +1663 +1664 +1665 +1666 +1667 +1668 +1669 +1670 +1671 +1672 +1673 +1674 +1675 +1676 +1677 +1678 +1679 +1680 +1681 +1682 +1683 +1684 +1685 +1686 +1687 +1688 +1689 +1690 +1691 +1692 +1693 +1694 +1695 +1696 +1697 +1698 +1699 +1700 +1701 +1702 +1703 +1704 +1705 +1706 +1707 +1708 +1709 +1710 +1711 +1712 +1713 +1714 +1715 +1716 +1717 +1718 +1719 +1720 +1721 +1722 +1723 +1724 +1725 +1726 +1727 +1728 +1729 +1730 +1731 +1732 +1733 +1734 +1735 +1736 +1737 +1738 +1739 +1740 +1741 +1742 +1743 +1744 +1745 +1746 +1747 +1748 +1749 +1750 +1751 +1752 +1753 +1754 +1755 +1756 +1757 +1758 +1759 +1760 +1761 +1762 +1763 +1764 +1765 +1766 +1767 +1768 +1769 +1770 +1771 +1772 +1773 +1774 +1775 +1776 +1777 +1778 +1779 +1780 +1781 +1782 +1783 +1784 +1785 +1786 +1787 +1788 +1789 +1790 +1791 +1792 +1793 +1794 +1795 +1796 +1797 +1798 +1799 +1800 +1801 +1802 +1803 +1804 +1805 +1806 +1807 +1808 +1809 +1810 +1811 +1812 +1813 +1814 +1815 +1816 +1817 +1818 +1819 +1820 +1821 +1822 +1823 +1824 +1825 +1826 +1827 +1828 +1829 +1830 +1831 +1832 +1833 +1834 +1835 +1836 +1837 +1838 +1839 +1840 +1841 +1842 +1843 +1844 +1845 +1846 +1847 +1848 +1849 +1850 +1851 +1852 +1853 +1854 +1855 +1856 +1857 +1858 +1859 +1860 +1861 +1862 +1863 +1864 +1865 +1866 +1867 +1868 +1869 +1870 +1871 +1872 +1873 +1874 +1875 +1876 +1877 +1878 +1879 +1880 +1881 +1882 +1883 +1884 +1885 +1886 +1887 +1888 +1889 +1890 +1891 +1892 +1893 +1894 +1895 +1896 +1897 +1898 +1899 +1900 +1901 +1902 +1903 +1904 +1905 +1906 +1907 +1908 +1909 +1910 +1911 +1912 +1913 +1914 +1915 +1916 +1917 +1918 +1919 +1920 +1921 +1922 +1923 +1924 +1925 +1926 +1927 +1928 +1929 +1930 +1931 +1932 +1933 +1934 +1935 +1936 +1937 +1938 +1939 +1940 +1941 +1942 +1943 +1944 +1945 +1946 +1947 +1948 +1949 +1950 +1951 +1952 +1953 +1954 +1955 +1956 +1957 +1958 +1959 +1960 +1961 +1962 +1963 +1964 +1965 +1966 +1967 +1968 +1969 +1970 +1971 +1972 +1973 +1974 +1975 +1976 +1977 +1978 +1979 +1980 +1981 +1982 +1983 +1984 +1985 +1986 +1987 +1988 +1989 +1990 +1991 +1992 +1993 +1994 +1995 +1996 +1997 +1998 +1999 +2000 +2001 +2002 +2003 +2004 +2005 +2006 +2007 +2008 +2009 +2010 +2011 +2012 +2013 +2014 +2015 +2016 +2017 +2018 +2019 +2020 +2021 +2022 +2023 +2024 +2025 +2026 +2027 +2028 +2029 +2030 +2031 +2032 +2033 +2034 +2035 +2036 +2037 +2038 +2039 +2040 +2041 +2042 +2043 +2044 +2045 +2046 +2047 +2048 +2049 +2050 +2051 +2052 +2053 +2054 +2055 +2056 +2057 +2058 +2059 +2060 +2061 +2062 +2063 +2064 +2065 +2066 +2067 +2068 +2069 +2070 +2071 +2072 +2073 +2074 +2075 +2076 +2077 +2078 +2079 +2080 +2081 +2082 +2083 +2084 +2085 +2086 +2087 +2088 +2089 +2090 +2091 +2092 +2093 +2094 +2095 +2096 +2097 +2098 +2099 +2100 +2101 +2102 +2103 +2104 +2105 +2106 +2107 +2108 +2109 +2110 +2111 +2112 +2113 +2114 +2115 +2116 +2117 +2118 +2119 +2120 +2121 +2122 +2123 +2124 +2125 +2126 +2127 +2128 +2129 +2130 +2131 +2132 +2133 +2134 +2135 +2136 +2137 +2138 +2139 +2140 +2141 +2142 +2143 +2144 +2145 +2146 +2147 +2148 +2149 +2150 +2151 +2152 +2153 +2154 +2155 +2156 +2157 +2158 +2159 +2160 +2161 +2162 +2163 +2164 +2165 +2166 +2167 +2168 +2169 +2170 +2171 +2172 +2173 +2174 +2175 +2176 +2177 +2178 +2179 +2180 +2181 +2182 +2183 +2184 +2185 +2186 +2187 +2188 +2189 +2190 +2191 +2192 +2193 +2194 +2195 +2196 +2197 +2198 +2199 +2200 +2201 +2202 +2203 +2204 +2205 +2206 +2207 +2208 +2209 +2210 +2211 +2212 +2213 +2214 +2215 +2216 +2217 +2218 +2219 +2220 +2221 +2222 +2223 +2224 +2225 +2226 +2227 +2228 +2229 +2230 +2231 +2232 +2233 +2234 +2235 +2236 +2237 +2238 +2239 +2240 +2241 +2242 +2243 +2244 +2245 +2246 +2247 +2248 +2249 +2250 +2251 +2252 +2253 +2254 +2255 +2256 +2257 +2258 +2259 +2260 +2261 +2262 +2263 +2264 +2265 +2266 +2267 +2268 +2269 +2270 +2271 +2272 +2273 +2274 +2275 +2276 +2277 +2278 +2279 +2280 +2281 +2282 +2283 +2284 +2285 +2286 +2287 +2288 +2289 +2290 +2291 +2292 +2293 +2294 +2295 +2296 +2297 +2298 +2299 +2300 +2301 +2302 +2303 +2304 +2305 +2306 +2307 +2308 +2309 +2310 +2311 +2312 +2313 +2314 +2315 +2316 +2317 +2318 +2319 +2320 +2321 +2322 +2323 +2324 +2325 +2326 +2327 +2328 +2329 +2330 +2331 +2332 +2333 +2334 +2335 +2336 +2337 +2338 +2339 +2340 +2341 +2342 +2343 +2344 +2345 +2346 +2347 +2348 +2349 +2350 +2351 +2352 +2353 +2354 +2355 +2356 +2357 +2358 +2359 +2360 +2361 +2362 +2363 +2364 +2365 +2366 +2367 +2368 +2369 +2370 +2371 +2372 +2373 +2374 +2375 +2376 +2377 +2378 +2379 +2380 +2381 +2382 +2383 +2384 +2385 +2386 +2387 +2388 +2389 +2390 +2391 +2392 +2393 +2394 +2395 +2396 +2397 +2398 +2399 +2400 +2401 +2402 +2403 +2404 +2405 +2406 +2407 +2408 +2409 +2410 +2411 +2412 +2413 +2414 +2415 +2416 +2417 +2418 +2419 +2420 +2421 +2422 +2423 +2424 +2425 +2426 +2427 +2428 +2429 +2430 +2431 +2432 +2433 +2434 +2435 +2436 +2437 +2438 +2439 +2440 +2441 +2442 +2443 +2444 +2445 +2446 +2447 +2448 +2449 +2450 +2451 +2452 +2453 +2454 +2455 +2456 +2457 +2458 +2459 +2460 +2461 +2462 +2463 +2464 +2465 +2466 +2467 +2468 +2469 +2470 +2471 +2472 +2473 +2474 +2475 +2476 +2477 +2478 +2479 +2480 +2481 +2482 +2483 +2484 +2485 +2486 +2487 +2488 +2489 +2490 +2491 +2492 +2493 +2494 +2495 +2496 +2497 +2498 +2499 +2500 |
|
__init__(com_port=None, arduino_instance_id=1, arduino_wait=1, sleep_tune=0.0001, autostart=True, loop=None, shutdown_on_exception=True, close_loop_on_shutdown=True, hard_reset_on_shutdown=True)
+
+If you have a single Arduino connected to your computer, + then you may accept all the default values.
+Otherwise, specify a unique arduino_instance id for each board in use.
+:param com_port: e.g. COM3 or /dev/ttyACM0.
+:param arduino_instance_id: Must match value in the Telemetrix4Arduino sketch
+:param arduino_wait: Amount of time to wait for an Arduino to + fully reset itself.
+:param sleep_tune: A tuning parameter (typically not changed by user)
+:param autostart: If you wish to call the start method within + your application, then set this to False.
+:param loop: optional user provided event loop
+:param shutdown_on_exception: call shutdown before raising + a RunTimeError exception, or + receiving a KeyboardInterrupt exception
+:param close_loop_on_shutdown: stop and close the event loop loop + when a shutdown is called or a serial + error occurs
+:param hard_reset_on_shutdown: reset the board on shutdown
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
42 + 43 + 44 + 45 + 46 + 47 + 48 + 49 + 50 + 51 + 52 + 53 + 54 + 55 + 56 + 57 + 58 + 59 + 60 + 61 + 62 + 63 + 64 + 65 + 66 + 67 + 68 + 69 + 70 + 71 + 72 + 73 + 74 + 75 + 76 + 77 + 78 + 79 + 80 + 81 + 82 + 83 + 84 + 85 + 86 + 87 + 88 + 89 + 90 + 91 + 92 + 93 + 94 + 95 + 96 + 97 + 98 + 99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +131 +132 +133 +134 +135 +136 +137 +138 +139 +140 +141 +142 +143 +144 +145 +146 +147 +148 +149 +150 +151 +152 +153 +154 +155 +156 +157 +158 +159 +160 +161 +162 +163 +164 +165 +166 +167 +168 +169 +170 +171 +172 +173 +174 +175 +176 +177 +178 +179 +180 +181 +182 +183 +184 +185 +186 +187 +188 +189 +190 +191 +192 +193 +194 +195 +196 +197 +198 +199 +200 +201 +202 +203 +204 +205 +206 +207 +208 +209 +210 +211 +212 +213 +214 +215 +216 +217 +218 +219 +220 +221 +222 +223 +224 +225 +226 +227 +228 +229 +230 +231 +232 +233 +234 +235 +236 +237 +238 +239 +240 +241 +242 +243 +244 +245 +246 +247 +248 +249 +250 +251 +252 +253 +254 +255 +256 +257 +258 +259 +260 +261 +262 +263 |
|
analog_write(pin, value)
+
+
+ async
+
+
+Set the specified pin to the specified value.
+:param pin: arduino pin number
+:param value: pin value (maximum 16 bits)
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
443 +444 +445 +446 +447 +448 +449 +450 +451 +452 +453 +454 +455 |
|
digital_write(pin, value)
+
+
+ async
+
+
+Set the specified pin to the specified value.
+:param pin: arduino pin number
+:param value: pin value (1 or 0)
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
457 +458 +459 +460 +461 +462 +463 +464 +465 +466 +467 |
|
disable_all_reporting()
+
+
+ async
+
+
+Disable reporting for all digital and analog input pins
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
2078 +2079 +2080 +2081 +2082 +2083 +2084 |
|
disable_analog_reporting(pin)
+
+
+ async
+
+
+Disables analog reporting for a single analog pin.
+:param pin: Analog pin number. For example for A0, the number is 0.
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
2086 +2087 +2088 +2089 +2090 +2091 +2092 +2093 +2094 +2095 |
|
disable_digital_reporting(pin)
+
+
+ async
+
+
+Disables digital reporting for a single digital pin
+:param pin: pin number
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
2097 +2098 +2099 +2100 +2101 +2102 +2103 +2104 +2105 +2106 +2107 |
|
enable_analog_reporting(pin)
+
+
+ async
+
+
+Enables analog reporting for the specified pin.
+:param pin: Analog pin number. For example for A0, the number is 0.
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
2109 +2110 +2111 +2112 +2113 +2114 +2115 +2116 +2117 +2118 +2119 |
|
enable_digital_reporting(pin)
+
+
+ async
+
+
+Enable reporting on the specified digital pin.
+:param pin: Pin number.
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
2121 +2122 +2123 +2124 +2125 +2126 +2127 +2128 +2129 +2130 |
|
get_event_loop()
+
+
+ async
+
+
+Return the currently active asyncio event loop
+:return: Active event loop
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
334 +335 +336 +337 +338 +339 +340 +341 |
|
i2c_read(address, register, number_of_bytes, callback, i2c_port=0, write_register=True)
+
+
+ async
+
+
+Read the specified number of bytes from the specified register for +the i2c device.
+:param address: i2c device address
+:param register: i2c register (or None if no register selection is needed)
+:param number_of_bytes: number of bytes to be read
+:param callback: Required callback function to report i2c data as a + result of read command
+:param i2c_port: select the default port (0) or secondary port (1)
+:param write_register: If True, the register is written + before read + Else, the write is suppressed
+callback returns a data list:
+[I2C_READ_REPORT, address, register, count of data bytes, + data bytes, time-stamp]
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
469 +470 +471 +472 +473 +474 +475 +476 +477 +478 +479 +480 +481 +482 +483 +484 +485 +486 +487 +488 +489 +490 +491 +492 +493 +494 +495 +496 +497 +498 +499 +500 +501 +502 +503 +504 +505 +506 |
|
i2c_read_restart_transmission(address, register, number_of_bytes, callback, i2c_port=0, write_register=True)
+
+
+ async
+
+
+Read the specified number of bytes from the specified register for +the i2c device. This restarts the transmission after the read. It is +required for some i2c devices such as the MMA8452Q accelerometer.
+:param address: i2c device address
+:param register: i2c register (or None if no register + selection is needed)
+:param number_of_bytes: number of bytes to be read
+:param callback: Required callback function to report i2c data as a + result of read command
+:param i2c_port: select the default port (0) or secondary port (1)
+:param write_register: If True, the register is written + before read + Else, the write is suppressed
+callback returns a data list:
+[I2C_READ_REPORT, address, register, count of data bytes, + data bytes, time-stamp]
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
508 +509 +510 +511 +512 +513 +514 +515 +516 +517 +518 +519 +520 +521 +522 +523 +524 +525 +526 +527 +528 +529 +530 +531 +532 +533 +534 +535 +536 +537 +538 +539 +540 +541 +542 +543 +544 +545 +546 +547 +548 +549 |
|
i2c_write(address, args, i2c_port=0)
+
+
+ async
+
+
+Write data to an i2c device.
+:param address: i2c device address
+:param i2c_port: 0= port 1, 1 = port 2
+:param args: A variable number of bytes to be sent to the device + passed in as a list
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
620 +621 +622 +623 +624 +625 +626 +627 +628 +629 +630 +631 +632 +633 +634 +635 +636 +637 +638 +639 +640 +641 +642 +643 +644 +645 +646 +647 +648 +649 +650 +651 |
|
loop_back(start_character, callback)
+
+
+ async
+
+
+This is a debugging method to send a character to the +Arduino device, and have the device loop it back.
+:param start_character: The character to loop back. It should be + an integer.
+:param callback: Looped back character will appear in the callback method
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
653 +654 +655 +656 +657 +658 +659 +660 +661 +662 +663 +664 +665 +666 +667 +668 +669 +670 +671 |
|
r4_hard_reset()
+
+
+ async
+
+
+Place the r4 into hard reset
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
2071 +2072 +2073 +2074 +2075 +2076 |
|
servo_detach(pin_number)
+
+
+ async
+
+
+Detach a servo for reuse +:param pin_number: attached pin
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
1430 +1431 +1432 +1433 +1434 +1435 +1436 |
|
servo_write(pin_number, angle)
+
+
+ async
+
+
+Set a servo attached to a pin to a given angle.
+:param pin_number: pin
+:param angle: angle (0-180)
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
1438 +1439 +1440 +1441 +1442 +1443 +1444 +1445 +1446 +1447 +1448 +1449 |
|
set_analog_scan_interval(interval)
+
+
+ async
+
+
+Set the analog scanning interval.
+:param interval: value of 0 - 255 - milliseconds
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
673 +674 +675 +676 +677 +678 +679 +680 +681 +682 +683 +684 +685 +686 |
|
set_pin_mode_analog_input(pin_number, differential=0, callback=None)
+
+
+ async
+
+
+Set a pin as an analog input.
+:param pin_number: arduino pin number
+:param callback: async callback function
+:param differential: difference in previous to current value before + report will be generated
+callback returns a data list:
+[pin_type, pin_number, pin_value, raw_time_stamp]
+The pin_type for analog input pins = 3
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
688 +689 +690 +691 +692 +693 +694 +695 +696 +697 +698 +699 +700 +701 +702 +703 +704 +705 +706 +707 +708 +709 +710 +711 +712 +713 +714 |
|
set_pin_mode_analog_output(pin_number)
+
+
+ async
+
+
+Set a pin as a pwm (analog output) pin.
+:param pin_number:arduino pin number
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
716 +717 +718 +719 +720 +721 +722 +723 +724 +725 +726 |
|
set_pin_mode_dht(pin, callback=None, dht_type=22)
+
+
+ async
+
+
+:param pin: connection pin
+:param callback: callback function
+:param dht_type: either 22 for DHT22 or 11 for DHT11
+Error Callback: [DHT REPORT Type, DHT_ERROR_NUMBER, PIN, DHT_TYPE, Time]
+Valid Data Callback: DHT REPORT Type, DHT_DATA=, PIN, DHT_TYPE, Humidity, +Temperature, +Time]
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
812 +813 +814 +815 +816 +817 +818 +819 +820 +821 +822 +823 +824 +825 +826 +827 +828 +829 +830 +831 +832 +833 +834 +835 +836 +837 +838 +839 +840 +841 +842 +843 +844 +845 +846 +847 +848 +849 +850 +851 +852 +853 |
|
set_pin_mode_digital_input(pin_number, callback)
+
+
+ async
+
+
+Set a pin as a digital input.
+:param pin_number: arduino pin number
+:param callback: async callback function
+callback returns a data list:
+[pin_type, pin_number, pin_value, raw_time_stamp]
+The pin_type for all digital input pins = 2
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
728 +729 +730 +731 +732 +733 +734 +735 +736 +737 +738 +739 +740 +741 +742 +743 +744 |
|
set_pin_mode_digital_input_pullup(pin_number, callback)
+
+
+ async
+
+
+Set a pin as a digital input with pullup enabled.
+:param pin_number: arduino pin number
+:param callback: async callback function
+callback returns a data list:
+[pin_type, pin_number, pin_value, raw_time_stamp]
+The pin_type for all digital input pins = 2
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
746 +747 +748 +749 +750 +751 +752 +753 +754 +755 +756 +757 +758 +759 +760 +761 +762 +763 +764 +765 +766 +767 +768 |
|
set_pin_mode_digital_output(pin_number)
+
+
+ async
+
+
+Set a pin as a digital output pin.
+:param pin_number: arduino pin number
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
770 +771 +772 +773 +774 +775 +776 +777 +778 |
|
set_pin_mode_i2c(i2c_port=0)
+
+
+ async
+
+
+Establish the standard Arduino i2c pins for i2c utilization.
+:param i2c_port: 0 = i2c1, 1 = i2c2
+ + API.
+
+ See i2c_read, or i2c_read_restart_transmission.
+
+
+ telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
781 +782 +783 +784 +785 +786 +787 +788 +789 +790 +791 +792 +793 +794 +795 +796 +797 +798 +799 +800 +801 +802 +803 +804 +805 +806 +807 +808 +809 +810 |
|
set_pin_mode_servo(pin_number, min_pulse=544, max_pulse=2400)
+
+
+ async
+
+
+Attach a pin to a servo motor
+:param pin_number: pin
+:param min_pulse: minimum pulse width
+:param max_pulse: maximum pulse width
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
855 +856 +857 +858 +859 +860 +861 +862 +863 +864 +865 +866 +867 +868 +869 +870 +871 +872 +873 +874 +875 +876 +877 +878 |
|
set_pin_mode_sonar(trigger_pin, echo_pin, callback)
+
+
+ async
+
+
+:param trigger_pin:
+:param echo_pin:
+:param callback: callback
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
880 +881 +882 +883 +884 +885 +886 +887 +888 +889 +890 +891 +892 +893 +894 +895 +896 +897 +898 +899 +900 +901 +902 +903 +904 +905 +906 +907 +908 +909 +910 +911 +912 |
|
set_pin_mode_spi(chip_select_list=None)
+
+
+ async
+
+
+Specify the list of chip select pins.
+Standard Arduino MISO, MOSI and CLK pins are used for the board in use.
+Chip Select is any digital output capable pin.
+:param chip_select_list: this is a list of pins to be used for chip select. + The pins will be configured as output, and set to high + ready to be used for chip select. + NOTE: You must specify the chips select pins here!
+command message: [command, number of cs pins, [cs pins...]]
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
914 +915 +916 +917 +918 +919 +920 +921 +922 +923 +924 +925 +926 +927 +928 +929 +930 +931 +932 +933 +934 +935 +936 +937 +938 +939 +940 +941 +942 +943 +944 +945 +946 +947 +948 +949 +950 +951 +952 |
|
shutdown()
+
+
+ async
+
+
+This method attempts an orderly shutdown +If any exceptions are thrown, they are ignored.
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
2047 +2048 +2049 +2050 +2051 +2052 +2053 +2054 +2055 +2056 +2057 +2058 +2059 +2060 +2061 +2062 +2063 +2064 +2065 +2066 +2067 +2068 +2069 |
|
sonar_disable()
+
+
+ async
+
+
+Disable sonar scanning for all sonar sensors
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
1029 +1030 +1031 +1032 +1033 +1034 |
|
sonar_enable()
+
+
+ async
+
+
+Enable sonar scanning for all sonar sensors
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
1036 +1037 +1038 +1039 +1040 +1041 |
|
spi_cs_control(chip_select_pin, select)
+
+
+ async
+
+
+Control an SPI chip select line +:param chip_select_pin: pin connected to CS
+:param select: 0=select, 1=deselect
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
1043 +1044 +1045 +1046 +1047 +1048 +1049 +1050 +1051 +1052 +1053 +1054 +1055 +1056 +1057 +1058 +1059 +1060 |
|
spi_read_blocking(chip_select, register_selection, number_of_bytes_to_read, call_back=None)
+
+
+ async
+
+
+Read the specified number of bytes from the specified SPI port and +call the callback function with the reported data.
+:param chip_select: chip select pin
+:param register_selection: Register to be selected for read.
+:param number_of_bytes_to_read: Number of bytes to read
+:param call_back: Required callback function to report spi data as a + result of read command
+ +[SPI_READ_REPORT, chip select pin, SPI Register, count of data bytes read, + data bytes, time-stamp]
+SPI_READ_REPORT = 13
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
1062 +1063 +1064 +1065 +1066 +1067 +1068 +1069 +1070 +1071 +1072 +1073 +1074 +1075 +1076 +1077 +1078 +1079 +1080 +1081 +1082 +1083 +1084 +1085 +1086 +1087 +1088 +1089 +1090 +1091 +1092 +1093 +1094 +1095 +1096 +1097 +1098 +1099 +1100 +1101 +1102 |
|
spi_set_format(clock_divisor, bit_order, data_mode)
+
+
+ async
+
+
+Configure how the SPI serializes and de-serializes data on the wire.
+See Arduino SPI reference materials for details.
+:param clock_divisor: 1 - 255
+:param bit_order:
+ LSBFIRST = 0
+
+ MSBFIRST = 1 (default)
+
+:param data_mode:
+ SPI_MODE0 = 0x00 (default)
+
+ SPI_MODE1 = 1
+
+ SPI_MODE2 = 2
+
+ SPI_MODE3 = 3
+
+
+ telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
1104 +1105 +1106 +1107 +1108 +1109 +1110 +1111 +1112 +1113 +1114 +1115 +1116 +1117 +1118 +1119 +1120 +1121 +1122 +1123 +1124 +1125 +1126 +1127 +1128 +1129 +1130 +1131 +1132 +1133 +1134 +1135 +1136 +1137 +1138 +1139 +1140 +1141 +1142 +1143 +1144 |
|
spi_write_blocking(chip_select, bytes_to_write)
+
+
+ async
+
+
+Write a list of bytes to the SPI device.
+:param chip_select: chip select pin
+:param bytes_to_write: A list of bytes to write. This must + be in the form of a list.
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
1146 +1147 +1148 +1149 +1150 +1151 +1152 +1153 +1154 +1155 +1156 +1157 +1158 +1159 +1160 +1161 +1162 +1163 +1164 +1165 +1166 +1167 +1168 +1169 +1170 +1171 +1172 |
|
start_aio()
+
+
+ async
+
+
+This method may be called directly, if the autostart +parameter in init is set to false.
+This method instantiates the serial interface and then performs auto pin +discovery if using a serial interface, or creates and connects to +a TCP/IP enabled device running StandardFirmataWiFi.
+Use this method if you wish to start TelemetrixAIO manually from +an asyncio function.
+ +telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
265 +266 +267 +268 +269 +270 +271 +272 +273 +274 +275 +276 +277 +278 +279 +280 +281 +282 +283 +284 +285 +286 +287 +288 +289 +290 +291 +292 +293 +294 +295 +296 +297 +298 +299 +300 +301 +302 +303 +304 +305 +306 +307 +308 +309 +310 +311 +312 +313 +314 +315 +316 +317 +318 +319 +320 +321 +322 +323 +324 +325 +326 +327 +328 +329 +330 +331 +332 |
|
Copyright (c) 2023 Alan Yorinks All rights reserved.
+This program is free software; you can redistribute it and/or +modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +Version 3 as published by the Free Software Foundation; either +or (at your option) any later version. +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details.
+You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ + + +TelemetrixUnoR4WiFi
+
+
+
+ Bases: threading.Thread
This class exposes and implements the telemetrix API. +It uses threading to accommodate concurrency. +It includes the public API methods as well as +a set of private methods.
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
35 + 36 + 37 + 38 + 39 + 40 + 41 + 42 + 43 + 44 + 45 + 46 + 47 + 48 + 49 + 50 + 51 + 52 + 53 + 54 + 55 + 56 + 57 + 58 + 59 + 60 + 61 + 62 + 63 + 64 + 65 + 66 + 67 + 68 + 69 + 70 + 71 + 72 + 73 + 74 + 75 + 76 + 77 + 78 + 79 + 80 + 81 + 82 + 83 + 84 + 85 + 86 + 87 + 88 + 89 + 90 + 91 + 92 + 93 + 94 + 95 + 96 + 97 + 98 + 99 + 100 + 101 + 102 + 103 + 104 + 105 + 106 + 107 + 108 + 109 + 110 + 111 + 112 + 113 + 114 + 115 + 116 + 117 + 118 + 119 + 120 + 121 + 122 + 123 + 124 + 125 + 126 + 127 + 128 + 129 + 130 + 131 + 132 + 133 + 134 + 135 + 136 + 137 + 138 + 139 + 140 + 141 + 142 + 143 + 144 + 145 + 146 + 147 + 148 + 149 + 150 + 151 + 152 + 153 + 154 + 155 + 156 + 157 + 158 + 159 + 160 + 161 + 162 + 163 + 164 + 165 + 166 + 167 + 168 + 169 + 170 + 171 + 172 + 173 + 174 + 175 + 176 + 177 + 178 + 179 + 180 + 181 + 182 + 183 + 184 + 185 + 186 + 187 + 188 + 189 + 190 + 191 + 192 + 193 + 194 + 195 + 196 + 197 + 198 + 199 + 200 + 201 + 202 + 203 + 204 + 205 + 206 + 207 + 208 + 209 + 210 + 211 + 212 + 213 + 214 + 215 + 216 + 217 + 218 + 219 + 220 + 221 + 222 + 223 + 224 + 225 + 226 + 227 + 228 + 229 + 230 + 231 + 232 + 233 + 234 + 235 + 236 + 237 + 238 + 239 + 240 + 241 + 242 + 243 + 244 + 245 + 246 + 247 + 248 + 249 + 250 + 251 + 252 + 253 + 254 + 255 + 256 + 257 + 258 + 259 + 260 + 261 + 262 + 263 + 264 + 265 + 266 + 267 + 268 + 269 + 270 + 271 + 272 + 273 + 274 + 275 + 276 + 277 + 278 + 279 + 280 + 281 + 282 + 283 + 284 + 285 + 286 + 287 + 288 + 289 + 290 + 291 + 292 + 293 + 294 + 295 + 296 + 297 + 298 + 299 + 300 + 301 + 302 + 303 + 304 + 305 + 306 + 307 + 308 + 309 + 310 + 311 + 312 + 313 + 314 + 315 + 316 + 317 + 318 + 319 + 320 + 321 + 322 + 323 + 324 + 325 + 326 + 327 + 328 + 329 + 330 + 331 + 332 + 333 + 334 + 335 + 336 + 337 + 338 + 339 + 340 + 341 + 342 + 343 + 344 + 345 + 346 + 347 + 348 + 349 + 350 + 351 + 352 + 353 + 354 + 355 + 356 + 357 + 358 + 359 + 360 + 361 + 362 + 363 + 364 + 365 + 366 + 367 + 368 + 369 + 370 + 371 + 372 + 373 + 374 + 375 + 376 + 377 + 378 + 379 + 380 + 381 + 382 + 383 + 384 + 385 + 386 + 387 + 388 + 389 + 390 + 391 + 392 + 393 + 394 + 395 + 396 + 397 + 398 + 399 + 400 + 401 + 402 + 403 + 404 + 405 + 406 + 407 + 408 + 409 + 410 + 411 + 412 + 413 + 414 + 415 + 416 + 417 + 418 + 419 + 420 + 421 + 422 + 423 + 424 + 425 + 426 + 427 + 428 + 429 + 430 + 431 + 432 + 433 + 434 + 435 + 436 + 437 + 438 + 439 + 440 + 441 + 442 + 443 + 444 + 445 + 446 + 447 + 448 + 449 + 450 + 451 + 452 + 453 + 454 + 455 + 456 + 457 + 458 + 459 + 460 + 461 + 462 + 463 + 464 + 465 + 466 + 467 + 468 + 469 + 470 + 471 + 472 + 473 + 474 + 475 + 476 + 477 + 478 + 479 + 480 + 481 + 482 + 483 + 484 + 485 + 486 + 487 + 488 + 489 + 490 + 491 + 492 + 493 + 494 + 495 + 496 + 497 + 498 + 499 + 500 + 501 + 502 + 503 + 504 + 505 + 506 + 507 + 508 + 509 + 510 + 511 + 512 + 513 + 514 + 515 + 516 + 517 + 518 + 519 + 520 + 521 + 522 + 523 + 524 + 525 + 526 + 527 + 528 + 529 + 530 + 531 + 532 + 533 + 534 + 535 + 536 + 537 + 538 + 539 + 540 + 541 + 542 + 543 + 544 + 545 + 546 + 547 + 548 + 549 + 550 + 551 + 552 + 553 + 554 + 555 + 556 + 557 + 558 + 559 + 560 + 561 + 562 + 563 + 564 + 565 + 566 + 567 + 568 + 569 + 570 + 571 + 572 + 573 + 574 + 575 + 576 + 577 + 578 + 579 + 580 + 581 + 582 + 583 + 584 + 585 + 586 + 587 + 588 + 589 + 590 + 591 + 592 + 593 + 594 + 595 + 596 + 597 + 598 + 599 + 600 + 601 + 602 + 603 + 604 + 605 + 606 + 607 + 608 + 609 + 610 + 611 + 612 + 613 + 614 + 615 + 616 + 617 + 618 + 619 + 620 + 621 + 622 + 623 + 624 + 625 + 626 + 627 + 628 + 629 + 630 + 631 + 632 + 633 + 634 + 635 + 636 + 637 + 638 + 639 + 640 + 641 + 642 + 643 + 644 + 645 + 646 + 647 + 648 + 649 + 650 + 651 + 652 + 653 + 654 + 655 + 656 + 657 + 658 + 659 + 660 + 661 + 662 + 663 + 664 + 665 + 666 + 667 + 668 + 669 + 670 + 671 + 672 + 673 + 674 + 675 + 676 + 677 + 678 + 679 + 680 + 681 + 682 + 683 + 684 + 685 + 686 + 687 + 688 + 689 + 690 + 691 + 692 + 693 + 694 + 695 + 696 + 697 + 698 + 699 + 700 + 701 + 702 + 703 + 704 + 705 + 706 + 707 + 708 + 709 + 710 + 711 + 712 + 713 + 714 + 715 + 716 + 717 + 718 + 719 + 720 + 721 + 722 + 723 + 724 + 725 + 726 + 727 + 728 + 729 + 730 + 731 + 732 + 733 + 734 + 735 + 736 + 737 + 738 + 739 + 740 + 741 + 742 + 743 + 744 + 745 + 746 + 747 + 748 + 749 + 750 + 751 + 752 + 753 + 754 + 755 + 756 + 757 + 758 + 759 + 760 + 761 + 762 + 763 + 764 + 765 + 766 + 767 + 768 + 769 + 770 + 771 + 772 + 773 + 774 + 775 + 776 + 777 + 778 + 779 + 780 + 781 + 782 + 783 + 784 + 785 + 786 + 787 + 788 + 789 + 790 + 791 + 792 + 793 + 794 + 795 + 796 + 797 + 798 + 799 + 800 + 801 + 802 + 803 + 804 + 805 + 806 + 807 + 808 + 809 + 810 + 811 + 812 + 813 + 814 + 815 + 816 + 817 + 818 + 819 + 820 + 821 + 822 + 823 + 824 + 825 + 826 + 827 + 828 + 829 + 830 + 831 + 832 + 833 + 834 + 835 + 836 + 837 + 838 + 839 + 840 + 841 + 842 + 843 + 844 + 845 + 846 + 847 + 848 + 849 + 850 + 851 + 852 + 853 + 854 + 855 + 856 + 857 + 858 + 859 + 860 + 861 + 862 + 863 + 864 + 865 + 866 + 867 + 868 + 869 + 870 + 871 + 872 + 873 + 874 + 875 + 876 + 877 + 878 + 879 + 880 + 881 + 882 + 883 + 884 + 885 + 886 + 887 + 888 + 889 + 890 + 891 + 892 + 893 + 894 + 895 + 896 + 897 + 898 + 899 + 900 + 901 + 902 + 903 + 904 + 905 + 906 + 907 + 908 + 909 + 910 + 911 + 912 + 913 + 914 + 915 + 916 + 917 + 918 + 919 + 920 + 921 + 922 + 923 + 924 + 925 + 926 + 927 + 928 + 929 + 930 + 931 + 932 + 933 + 934 + 935 + 936 + 937 + 938 + 939 + 940 + 941 + 942 + 943 + 944 + 945 + 946 + 947 + 948 + 949 + 950 + 951 + 952 + 953 + 954 + 955 + 956 + 957 + 958 + 959 + 960 + 961 + 962 + 963 + 964 + 965 + 966 + 967 + 968 + 969 + 970 + 971 + 972 + 973 + 974 + 975 + 976 + 977 + 978 + 979 + 980 + 981 + 982 + 983 + 984 + 985 + 986 + 987 + 988 + 989 + 990 + 991 + 992 + 993 + 994 + 995 + 996 + 997 + 998 + 999 +1000 +1001 +1002 +1003 +1004 +1005 +1006 +1007 +1008 +1009 +1010 +1011 +1012 +1013 +1014 +1015 +1016 +1017 +1018 +1019 +1020 +1021 +1022 +1023 +1024 +1025 +1026 +1027 +1028 +1029 +1030 +1031 +1032 +1033 +1034 +1035 +1036 +1037 +1038 +1039 +1040 +1041 +1042 +1043 +1044 +1045 +1046 +1047 +1048 +1049 +1050 +1051 +1052 +1053 +1054 +1055 +1056 +1057 +1058 +1059 +1060 +1061 +1062 +1063 +1064 +1065 +1066 +1067 +1068 +1069 +1070 +1071 +1072 +1073 +1074 +1075 +1076 +1077 +1078 +1079 +1080 +1081 +1082 +1083 +1084 +1085 +1086 +1087 +1088 +1089 +1090 +1091 +1092 +1093 +1094 +1095 +1096 +1097 +1098 +1099 +1100 +1101 +1102 +1103 +1104 +1105 +1106 +1107 +1108 +1109 +1110 +1111 +1112 +1113 +1114 +1115 +1116 +1117 +1118 +1119 +1120 +1121 +1122 +1123 +1124 +1125 +1126 +1127 +1128 +1129 +1130 +1131 +1132 +1133 +1134 +1135 +1136 +1137 +1138 +1139 +1140 +1141 +1142 +1143 +1144 +1145 +1146 +1147 +1148 +1149 +1150 +1151 +1152 +1153 +1154 +1155 +1156 +1157 +1158 +1159 +1160 +1161 +1162 +1163 +1164 +1165 +1166 +1167 +1168 +1169 +1170 +1171 +1172 +1173 +1174 +1175 +1176 +1177 +1178 +1179 +1180 +1181 +1182 +1183 +1184 +1185 +1186 +1187 +1188 +1189 +1190 +1191 +1192 +1193 +1194 +1195 +1196 +1197 +1198 +1199 +1200 +1201 +1202 +1203 +1204 +1205 +1206 +1207 +1208 +1209 +1210 +1211 +1212 +1213 +1214 +1215 +1216 +1217 +1218 +1219 +1220 +1221 +1222 +1223 +1224 +1225 +1226 +1227 +1228 +1229 +1230 +1231 +1232 +1233 +1234 +1235 +1236 +1237 +1238 +1239 +1240 +1241 +1242 +1243 +1244 +1245 +1246 +1247 +1248 +1249 +1250 +1251 +1252 +1253 +1254 +1255 +1256 +1257 +1258 +1259 +1260 +1261 +1262 +1263 +1264 +1265 +1266 +1267 +1268 +1269 +1270 +1271 +1272 +1273 +1274 +1275 +1276 +1277 +1278 +1279 +1280 +1281 +1282 +1283 +1284 +1285 +1286 +1287 +1288 +1289 +1290 +1291 +1292 +1293 +1294 +1295 +1296 +1297 +1298 +1299 +1300 +1301 +1302 +1303 +1304 +1305 +1306 +1307 +1308 +1309 +1310 +1311 +1312 +1313 +1314 +1315 +1316 +1317 +1318 +1319 +1320 +1321 +1322 +1323 +1324 +1325 +1326 +1327 +1328 +1329 +1330 +1331 +1332 +1333 +1334 +1335 +1336 +1337 +1338 +1339 +1340 +1341 +1342 +1343 +1344 +1345 +1346 +1347 +1348 +1349 +1350 +1351 +1352 +1353 +1354 +1355 +1356 +1357 +1358 +1359 +1360 +1361 +1362 +1363 +1364 +1365 +1366 +1367 +1368 +1369 +1370 +1371 +1372 +1373 +1374 +1375 +1376 +1377 +1378 +1379 +1380 +1381 +1382 +1383 +1384 +1385 +1386 +1387 +1388 +1389 +1390 +1391 +1392 +1393 +1394 +1395 +1396 +1397 +1398 +1399 +1400 +1401 +1402 +1403 +1404 +1405 +1406 +1407 +1408 +1409 +1410 +1411 +1412 +1413 +1414 +1415 +1416 +1417 +1418 +1419 +1420 +1421 +1422 +1423 +1424 +1425 +1426 +1427 +1428 +1429 +1430 +1431 +1432 +1433 +1434 +1435 +1436 +1437 +1438 +1439 +1440 +1441 +1442 +1443 +1444 +1445 +1446 +1447 +1448 +1449 +1450 +1451 +1452 +1453 +1454 +1455 +1456 +1457 +1458 +1459 +1460 +1461 +1462 +1463 +1464 +1465 +1466 +1467 +1468 +1469 +1470 +1471 +1472 +1473 +1474 +1475 +1476 +1477 +1478 +1479 +1480 +1481 +1482 +1483 +1484 +1485 +1486 +1487 +1488 +1489 +1490 +1491 +1492 +1493 +1494 +1495 +1496 +1497 +1498 +1499 +1500 +1501 +1502 +1503 +1504 +1505 +1506 +1507 +1508 +1509 +1510 +1511 +1512 +1513 +1514 +1515 +1516 +1517 +1518 +1519 +1520 +1521 +1522 +1523 +1524 +1525 +1526 +1527 +1528 +1529 +1530 +1531 +1532 +1533 +1534 +1535 +1536 +1537 +1538 +1539 +1540 +1541 +1542 +1543 +1544 +1545 +1546 +1547 +1548 +1549 +1550 +1551 +1552 +1553 +1554 +1555 +1556 +1557 +1558 +1559 +1560 +1561 +1562 +1563 +1564 +1565 +1566 +1567 +1568 +1569 +1570 +1571 +1572 +1573 +1574 +1575 +1576 +1577 +1578 +1579 +1580 +1581 +1582 +1583 +1584 +1585 +1586 +1587 +1588 +1589 +1590 +1591 +1592 +1593 +1594 +1595 +1596 +1597 +1598 +1599 +1600 +1601 +1602 +1603 +1604 +1605 +1606 +1607 +1608 +1609 +1610 +1611 +1612 +1613 +1614 +1615 +1616 +1617 +1618 +1619 +1620 +1621 +1622 +1623 +1624 +1625 +1626 +1627 +1628 +1629 +1630 +1631 +1632 +1633 +1634 +1635 +1636 +1637 +1638 +1639 +1640 +1641 +1642 +1643 +1644 +1645 +1646 +1647 +1648 +1649 +1650 +1651 +1652 +1653 +1654 +1655 +1656 +1657 +1658 +1659 +1660 +1661 +1662 +1663 +1664 +1665 +1666 +1667 +1668 +1669 +1670 +1671 +1672 +1673 +1674 +1675 +1676 +1677 +1678 +1679 +1680 +1681 +1682 +1683 +1684 +1685 +1686 +1687 +1688 +1689 +1690 +1691 +1692 +1693 +1694 +1695 +1696 +1697 +1698 +1699 +1700 +1701 +1702 +1703 +1704 +1705 +1706 +1707 +1708 +1709 +1710 +1711 +1712 +1713 +1714 +1715 +1716 +1717 +1718 +1719 +1720 +1721 +1722 +1723 +1724 +1725 +1726 +1727 +1728 +1729 +1730 +1731 +1732 +1733 +1734 +1735 +1736 +1737 +1738 +1739 +1740 +1741 +1742 +1743 +1744 +1745 +1746 +1747 +1748 +1749 +1750 +1751 +1752 +1753 +1754 +1755 +1756 +1757 +1758 +1759 +1760 +1761 +1762 +1763 +1764 +1765 +1766 +1767 +1768 +1769 +1770 +1771 +1772 +1773 +1774 +1775 +1776 +1777 +1778 +1779 +1780 +1781 +1782 +1783 +1784 +1785 +1786 +1787 +1788 +1789 +1790 +1791 +1792 +1793 +1794 +1795 +1796 +1797 +1798 +1799 +1800 +1801 +1802 +1803 +1804 +1805 +1806 +1807 +1808 +1809 +1810 +1811 +1812 +1813 +1814 +1815 +1816 +1817 +1818 +1819 +1820 +1821 +1822 +1823 +1824 +1825 +1826 +1827 +1828 +1829 +1830 +1831 +1832 +1833 +1834 +1835 +1836 +1837 +1838 +1839 +1840 +1841 +1842 +1843 +1844 +1845 +1846 +1847 +1848 +1849 +1850 +1851 +1852 +1853 +1854 +1855 +1856 +1857 +1858 +1859 +1860 +1861 +1862 +1863 +1864 +1865 +1866 +1867 +1868 +1869 +1870 +1871 +1872 +1873 +1874 +1875 +1876 +1877 +1878 +1879 +1880 +1881 +1882 +1883 +1884 +1885 +1886 +1887 +1888 +1889 +1890 +1891 +1892 +1893 +1894 +1895 +1896 +1897 +1898 +1899 +1900 +1901 +1902 +1903 +1904 +1905 +1906 +1907 +1908 +1909 +1910 +1911 +1912 +1913 +1914 +1915 +1916 +1917 +1918 +1919 +1920 +1921 +1922 +1923 +1924 +1925 +1926 +1927 +1928 +1929 +1930 +1931 +1932 +1933 +1934 +1935 +1936 +1937 +1938 +1939 +1940 +1941 +1942 +1943 +1944 +1945 +1946 +1947 +1948 +1949 +1950 +1951 +1952 +1953 +1954 +1955 +1956 +1957 +1958 +1959 +1960 +1961 +1962 +1963 +1964 +1965 +1966 +1967 +1968 +1969 +1970 +1971 +1972 +1973 +1974 +1975 +1976 +1977 +1978 +1979 +1980 +1981 +1982 +1983 +1984 +1985 +1986 +1987 +1988 +1989 +1990 +1991 +1992 +1993 +1994 +1995 +1996 +1997 +1998 +1999 +2000 +2001 +2002 +2003 +2004 +2005 +2006 +2007 +2008 +2009 +2010 +2011 +2012 +2013 +2014 +2015 +2016 +2017 +2018 +2019 +2020 +2021 +2022 +2023 +2024 +2025 +2026 +2027 +2028 +2029 +2030 +2031 +2032 +2033 +2034 +2035 +2036 +2037 +2038 +2039 +2040 +2041 +2042 +2043 +2044 +2045 +2046 +2047 +2048 +2049 +2050 +2051 +2052 +2053 +2054 +2055 +2056 +2057 +2058 +2059 +2060 +2061 +2062 +2063 +2064 +2065 +2066 +2067 +2068 +2069 +2070 +2071 +2072 +2073 +2074 +2075 +2076 +2077 +2078 +2079 +2080 +2081 +2082 +2083 +2084 +2085 +2086 +2087 +2088 +2089 +2090 +2091 +2092 +2093 +2094 +2095 +2096 +2097 +2098 +2099 +2100 +2101 +2102 +2103 +2104 +2105 +2106 +2107 +2108 +2109 +2110 +2111 +2112 +2113 +2114 +2115 +2116 +2117 +2118 +2119 +2120 +2121 +2122 +2123 +2124 +2125 +2126 +2127 +2128 +2129 +2130 +2131 +2132 +2133 +2134 +2135 +2136 +2137 +2138 +2139 +2140 +2141 +2142 +2143 +2144 +2145 +2146 +2147 +2148 +2149 +2150 +2151 +2152 +2153 +2154 +2155 +2156 +2157 +2158 +2159 +2160 +2161 +2162 +2163 +2164 +2165 +2166 +2167 +2168 +2169 +2170 +2171 +2172 +2173 +2174 +2175 +2176 +2177 +2178 +2179 +2180 +2181 +2182 +2183 +2184 +2185 +2186 +2187 +2188 +2189 +2190 +2191 +2192 +2193 +2194 +2195 +2196 +2197 +2198 +2199 +2200 +2201 +2202 +2203 +2204 +2205 +2206 +2207 +2208 +2209 +2210 +2211 +2212 +2213 +2214 +2215 +2216 +2217 +2218 +2219 +2220 +2221 +2222 +2223 +2224 +2225 +2226 +2227 +2228 +2229 +2230 +2231 +2232 +2233 +2234 +2235 +2236 +2237 +2238 +2239 +2240 +2241 +2242 +2243 +2244 +2245 +2246 +2247 +2248 +2249 +2250 +2251 +2252 +2253 +2254 +2255 +2256 +2257 +2258 +2259 +2260 +2261 +2262 +2263 +2264 +2265 +2266 +2267 +2268 +2269 +2270 +2271 +2272 +2273 +2274 +2275 +2276 +2277 +2278 +2279 +2280 +2281 +2282 +2283 +2284 +2285 +2286 +2287 +2288 +2289 +2290 +2291 +2292 +2293 +2294 +2295 +2296 +2297 +2298 +2299 +2300 +2301 +2302 +2303 +2304 +2305 +2306 +2307 +2308 +2309 +2310 +2311 +2312 +2313 +2314 +2315 +2316 +2317 +2318 +2319 +2320 +2321 +2322 +2323 +2324 +2325 +2326 +2327 +2328 +2329 +2330 +2331 +2332 +2333 +2334 +2335 +2336 +2337 +2338 +2339 +2340 +2341 +2342 +2343 +2344 +2345 +2346 +2347 +2348 +2349 +2350 +2351 +2352 +2353 +2354 +2355 +2356 +2357 +2358 +2359 +2360 +2361 +2362 +2363 +2364 +2365 +2366 +2367 +2368 +2369 +2370 +2371 +2372 +2373 +2374 +2375 +2376 +2377 +2378 +2379 +2380 +2381 +2382 +2383 +2384 +2385 +2386 +2387 +2388 +2389 +2390 +2391 +2392 +2393 +2394 +2395 +2396 +2397 +2398 +2399 +2400 +2401 +2402 +2403 +2404 +2405 +2406 +2407 +2408 +2409 +2410 +2411 +2412 +2413 +2414 +2415 +2416 +2417 +2418 +2419 +2420 +2421 +2422 +2423 +2424 +2425 +2426 +2427 +2428 +2429 +2430 +2431 +2432 +2433 +2434 +2435 +2436 +2437 +2438 +2439 +2440 +2441 +2442 +2443 +2444 +2445 +2446 +2447 +2448 +2449 +2450 +2451 +2452 +2453 +2454 +2455 +2456 +2457 +2458 +2459 +2460 +2461 +2462 +2463 +2464 +2465 +2466 +2467 +2468 +2469 +2470 +2471 +2472 +2473 +2474 +2475 +2476 +2477 +2478 +2479 +2480 +2481 +2482 +2483 +2484 +2485 +2486 +2487 +2488 +2489 +2490 +2491 +2492 +2493 +2494 +2495 +2496 +2497 +2498 +2499 +2500 +2501 +2502 +2503 +2504 +2505 +2506 +2507 +2508 +2509 +2510 +2511 +2512 +2513 +2514 +2515 +2516 +2517 +2518 +2519 +2520 +2521 +2522 +2523 +2524 +2525 +2526 +2527 +2528 +2529 +2530 +2531 +2532 +2533 +2534 +2535 +2536 +2537 +2538 +2539 +2540 +2541 +2542 +2543 +2544 +2545 +2546 +2547 +2548 +2549 +2550 +2551 +2552 +2553 +2554 +2555 +2556 +2557 +2558 +2559 +2560 +2561 +2562 +2563 +2564 +2565 +2566 +2567 +2568 +2569 +2570 +2571 +2572 +2573 +2574 +2575 +2576 +2577 +2578 +2579 +2580 +2581 +2582 +2583 +2584 +2585 +2586 +2587 +2588 +2589 +2590 +2591 +2592 +2593 +2594 +2595 +2596 +2597 +2598 +2599 +2600 +2601 +2602 +2603 +2604 +2605 +2606 +2607 +2608 +2609 +2610 +2611 +2612 +2613 +2614 +2615 +2616 +2617 +2618 +2619 +2620 +2621 +2622 +2623 +2624 +2625 +2626 +2627 +2628 +2629 +2630 +2631 +2632 +2633 +2634 +2635 +2636 +2637 +2638 +2639 +2640 +2641 +2642 +2643 +2644 +2645 |
|
__init__(com_port=None, arduino_instance_id=1, arduino_wait=1, sleep_tune=1e-06, shutdown_on_exception=True, hard_reset_on_shutdown=True, transport_address=None, ip_port=31336, transport_type=0)
+
+:param com_port: e.g. COM3 or /dev/ttyACM0. + Only use if you wish to bypass auto com port + detection.
+:param arduino_instance_id: Match with the value installed on the + arduino-telemetrix sketch.
+:param arduino_wait: Amount of time to wait for an Arduino to + fully reset itself.
+:param sleep_tune: A tuning parameter (typically not changed by user)
+:param shutdown_on_exception: call shutdown before raising + a RunTimeError exception, or + receiving a KeyboardInterrupt exception
+:param hard_reset_on_shutdown: reset the board on shutdown
+:param transport_address: ip address of tcp/ip connected device.
+:param ip_port: ip port of tcp/ip connected device
+:param transport_type: 0 = WiFI + 1 = USBSerial + 2 = BLE
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
45 + 46 + 47 + 48 + 49 + 50 + 51 + 52 + 53 + 54 + 55 + 56 + 57 + 58 + 59 + 60 + 61 + 62 + 63 + 64 + 65 + 66 + 67 + 68 + 69 + 70 + 71 + 72 + 73 + 74 + 75 + 76 + 77 + 78 + 79 + 80 + 81 + 82 + 83 + 84 + 85 + 86 + 87 + 88 + 89 + 90 + 91 + 92 + 93 + 94 + 95 + 96 + 97 + 98 + 99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +131 +132 +133 +134 +135 +136 +137 +138 +139 +140 +141 +142 +143 +144 +145 +146 +147 +148 +149 +150 +151 +152 +153 +154 +155 +156 +157 +158 +159 +160 +161 +162 +163 +164 +165 +166 +167 +168 +169 +170 +171 +172 +173 +174 +175 +176 +177 +178 +179 +180 +181 +182 +183 +184 +185 +186 +187 +188 +189 +190 +191 +192 +193 +194 +195 +196 +197 +198 +199 +200 +201 +202 +203 +204 +205 +206 +207 +208 +209 +210 +211 +212 +213 +214 +215 +216 +217 +218 +219 +220 +221 +222 +223 +224 +225 +226 +227 +228 +229 +230 +231 +232 +233 +234 +235 +236 +237 +238 +239 +240 +241 +242 +243 +244 +245 +246 +247 +248 +249 +250 +251 +252 +253 +254 +255 +256 +257 +258 +259 +260 +261 +262 +263 +264 +265 +266 +267 +268 +269 +270 +271 +272 +273 +274 +275 +276 +277 +278 +279 +280 +281 +282 +283 +284 +285 +286 +287 +288 +289 +290 +291 +292 +293 +294 +295 +296 +297 +298 +299 +300 +301 +302 +303 +304 +305 +306 +307 +308 +309 +310 +311 +312 +313 +314 +315 +316 +317 +318 +319 +320 +321 +322 +323 +324 +325 +326 +327 +328 +329 +330 +331 +332 +333 +334 +335 +336 +337 +338 +339 +340 +341 +342 +343 +344 +345 +346 +347 +348 +349 +350 +351 +352 |
|
analog_write(pin, value)
+
+Set the specified pin to the specified value.
+:param pin: arduino pin number
+:param value: pin value (maximum 16 bits)
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
448 +449 +450 +451 +452 +453 +454 +455 +456 +457 +458 +459 +460 |
|
digital_write(pin, value)
+
+Set the specified pin to the specified value.
+:param pin: arduino pin number
+:param value: pin value (1 or 0)
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
462 +463 +464 +465 +466 +467 +468 +469 +470 +471 +472 +473 |
|
disable_all_reporting()
+
+Disable reporting for all digital and analog input pins
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
475 +476 +477 +478 +479 +480 +481 |
|
disable_analog_reporting(pin)
+
+Disables analog reporting for a single analog pin.
+:param pin: Analog pin number. For example for A0, the number is 0.
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
483 +484 +485 +486 +487 +488 +489 +490 +491 +492 |
|
disable_digital_reporting(pin)
+
+Disables digital reporting for a single digital input.
+:param pin: Pin number.
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
494 +495 +496 +497 +498 +499 +500 +501 +502 +503 |
|
disable_scroll_message()
+
+Turn off a scrolling message
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
2172 +2173 +2174 +2175 +2176 +2177 +2178 |
|
enable_analog_reporting(pin)
+
+Enables analog reporting for the specified pin.
+:param pin: Analog pin number. For example for A0, the number is 0.
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
505 +506 +507 +508 +509 +510 +511 +512 +513 +514 +515 |
|
enable_digital_reporting(pin)
+
+Enable reporting on the specified digital pin.
+:param pin: Pin number.
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
517 +518 +519 +520 +521 +522 +523 +524 +525 +526 |
|
enable_scroll_message(message, scroll_speed=50)
+
+:param message: Message with maximum length of 25 +:param scroll_speed: in milliseconds (maximum of 255)
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
2154 +2155 +2156 +2157 +2158 +2159 +2160 +2161 +2162 +2163 +2164 +2165 +2166 +2167 +2168 +2169 +2170 |
|
i2c_read(address, register, number_of_bytes, callback=None, i2c_port=0, write_register=True)
+
+Read the specified number of bytes from the + specified register for the i2c device.
+:param address: i2c device address
+:param register: i2c register (or None if no register + selection is needed)
+:param number_of_bytes: number of bytes to be read
+:param callback: Required callback function to report + i2c data as a result of read command
+:param i2c_port: 0 = default, 1 = secondary
+:param write_register: If True, the register is written + before read + Else, the write is suppressed
+callback returns a data list:
+[I2C_READ_REPORT, address, register, count of data bytes, + data bytes, time-stamp]
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
549 +550 +551 +552 +553 +554 +555 +556 +557 +558 +559 +560 +561 +562 +563 +564 +565 +566 +567 +568 +569 +570 +571 +572 +573 +574 +575 +576 +577 +578 +579 +580 +581 +582 +583 |
|
i2c_read_restart_transmission(address, register, number_of_bytes, callback=None, i2c_port=0, write_register=True)
+
+Read the specified number of bytes from the specified + register for the i2c device. This restarts the transmission + after the read. It is required for some i2c devices such as the MMA8452Q + accelerometer.
+:param address: i2c device address
+:param register: i2c register (or None if no register + selection is needed)
+:param number_of_bytes: number of bytes to be read
+:param callback: Required callback function to report i2c + data as a result of read command
+:param i2c_port: 0 = default 1 = secondary
+:param write_register: If True, the register is written before read + Else, the write is suppressed
+callback returns a data list:
+[I2C_READ_REPORT, address, register, count of data bytes, + data bytes, time-stamp]
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
585 +586 +587 +588 +589 +590 +591 +592 +593 +594 +595 +596 +597 +598 +599 +600 +601 +602 +603 +604 +605 +606 +607 +608 +609 +610 +611 +612 +613 +614 +615 +616 +617 +618 +619 +620 +621 +622 +623 |
|
i2c_write(address, args, i2c_port=0)
+
+Write data to an i2c device.
+:param address: i2c device address
+:param i2c_port: 0= port 1, 1 = port 2
+:param args: A variable number of bytes to be sent to the device + passed in as a list
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
691 +692 +693 +694 +695 +696 +697 +698 +699 +700 +701 +702 +703 +704 +705 +706 +707 +708 +709 +710 +711 +712 +713 +714 +715 +716 +717 +718 +719 +720 +721 +722 |
|
loop_back(start_character, callback=None)
+
+This is a debugging method to send a character to the +Arduino device, and have the device loop it back.
+:param start_character: The character to loop back. It should be + an integer.
+:param callback: Looped back character will appear in the callback method
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
724 +725 +726 +727 +728 +729 +730 +731 +732 +733 +734 +735 +736 +737 |
|
r4_hard_reset()
+
+Place the r4 into hard reset
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
2144 +2145 +2146 +2147 +2148 +2149 +2150 +2151 +2152 |
|
servo_detach(pin_number)
+
+Detach a servo for reuse
+:param pin_number: attached pin
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
1093 +1094 +1095 +1096 +1097 +1098 +1099 +1100 +1101 |
|
servo_write(pin_number, angle)
+
+Set a servo attached to a pin to a given angle.
+:param pin_number: pin
+:param angle: angle (0-180)
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
1080 +1081 +1082 +1083 +1084 +1085 +1086 +1087 +1088 +1089 +1090 +1091 |
|
set_analog_scan_interval(interval)
+
+Set the analog scanning interval.
+:param interval: value of 0 - 255 - milliseconds
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
739 +740 +741 +742 +743 +744 +745 +746 +747 +748 +749 +750 +751 +752 |
|
set_pin_mode_analog_input(pin_number, differential=0, callback=None)
+
+Set a pin as an analog input.
+:param pin_number: arduino pin number
+:param differential: difference in previous to current value before + report will be generated
+:param callback: callback function
+callback returns a data list:
+[pin_type, pin_number, pin_value, raw_time_stamp]
+The pin_type for analog input pins = 3
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
763 +764 +765 +766 +767 +768 +769 +770 +771 +772 +773 +774 +775 +776 +777 +778 +779 +780 +781 +782 +783 |
|
set_pin_mode_analog_output(pin_number)
+
+Set a pin as a pwm (analog output) pin.
+:param pin_number:arduino pin number
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
754 +755 +756 +757 +758 +759 +760 +761 |
|
set_pin_mode_dht(pin, callback=None, dht_type=22)
+
+:param pin: connection pin
+:param callback: callback function
+:param dht_type: either 22 for DHT22 or 11 for DHT11
+Error Callback: [DHT REPORT Type, DHT_ERROR_NUMBER, PIN, DHT_TYPE, Time]
+Valid Data Callback: DHT REPORT Type, DHT_DATA=, PIN, DHT_TYPE, Humidity, +Temperature, +Time]
+DHT_REPORT_TYPE = 12
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
861 +862 +863 +864 +865 +866 +867 +868 +869 +870 +871 +872 +873 +874 +875 +876 +877 +878 +879 +880 +881 +882 +883 +884 +885 +886 +887 +888 +889 +890 +891 +892 +893 +894 +895 +896 +897 +898 +899 +900 +901 |
|
set_pin_mode_digital_input(pin_number, callback=None)
+
+Set a pin as a digital input.
+:param pin_number: arduino pin number
+:param callback: callback function
+callback returns a data list:
+[pin_type, pin_number, pin_value, raw_time_stamp]
+The pin_type for all digital input pins = 2
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
785 +786 +787 +788 +789 +790 +791 +792 +793 +794 +795 +796 +797 +798 +799 +800 +801 |
|
set_pin_mode_digital_input_pullup(pin_number, callback=None)
+
+Set a pin as a digital input with pullup enabled.
+:param pin_number: arduino pin number
+:param callback: callback function
+callback returns a data list:
+[pin_type, pin_number, pin_value, raw_time_stamp]
+The pin_type for all digital input pins = 2
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
803 +804 +805 +806 +807 +808 +809 +810 +811 +812 +813 +814 +815 +816 +817 +818 +819 |
|
set_pin_mode_digital_output(pin_number)
+
+Set a pin as a digital output pin.
+:param pin_number: arduino pin number
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
821 +822 +823 +824 +825 +826 +827 +828 |
|
set_pin_mode_i2c(i2c_port=0)
+
+Establish the standard Arduino i2c pins for i2c utilization.
+:param i2c_port: 0 = i2c1, 1 = i2c2
+ + API.
+
+ See i2c_read, or i2c_read_restart_transmission.
+
+
+ telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
830 +831 +832 +833 +834 +835 +836 +837 +838 +839 +840 +841 +842 +843 +844 +845 +846 +847 +848 +849 +850 +851 +852 +853 +854 +855 +856 +857 +858 +859 |
|
set_pin_mode_servo(pin_number, min_pulse=544, max_pulse=2400)
+
+Attach a pin to a servo motor
+:param pin_number: pin
+:param min_pulse: minimum pulse width
+:param max_pulse: maximum pulse width
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
904 +905 +906 +907 +908 +909 +910 +911 +912 +913 +914 +915 +916 +917 +918 +919 +920 +921 +922 +923 +924 +925 +926 +927 |
|
set_pin_mode_sonar(trigger_pin, echo_pin, callback=None)
+
+:param trigger_pin:
+:param echo_pin:
+:param callback: callback
+callback data: [PrivateConstants.SONAR_DISTANCE, trigger_pin, distance_value, time_stamp]
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
929 +930 +931 +932 +933 +934 +935 +936 +937 +938 +939 +940 +941 +942 +943 +944 +945 +946 +947 +948 +949 +950 +951 +952 +953 +954 +955 +956 +957 +958 +959 +960 +961 +962 +963 |
|
set_pin_mode_spi(chip_select_list=None)
+
+Specify the list of chip select pins.
+Standard Arduino MISO, MOSI and CLK pins are used for the board in use.
+Chip Select is any digital output capable pin.
+:param chip_select_list: this is a list of pins to be used for chip select. + The pins will be configured as output, and set to high + ready to be used for chip select. + NOTE: You must specify the chips select pins here!
+command message: [command, [cs pins...]]
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
965 + 966 + 967 + 968 + 969 + 970 + 971 + 972 + 973 + 974 + 975 + 976 + 977 + 978 + 979 + 980 + 981 + 982 + 983 + 984 + 985 + 986 + 987 + 988 + 989 + 990 + 991 + 992 + 993 + 994 + 995 + 996 + 997 + 998 + 999 +1000 +1001 +1002 +1003 |
|
shutdown()
+
+This method attempts an orderly shutdown +If any exceptions are thrown, they are ignored.
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
1748 +1749 +1750 +1751 +1752 +1753 +1754 +1755 +1756 +1757 +1758 +1759 +1760 +1761 +1762 +1763 +1764 +1765 +1766 +1767 +1768 +1769 +1770 +1771 +1772 +1773 +1774 +1775 +1776 +1777 +1778 +1779 +1780 +1781 +1782 +1783 +1784 |
|
sonar_disable()
+
+Disable sonar scanning for all sonar sensors
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
1786 +1787 +1788 +1789 +1790 +1791 |
|
sonar_enable()
+
+Enable sonar scanning for all sonar sensors
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
1793 +1794 +1795 +1796 +1797 +1798 |
|
spi_cs_control(chip_select_pin, select)
+
+Control an SPI chip select line +:param chip_select_pin: pin connected to CS
+:param select: 0=select, 1=deselect
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
1800 +1801 +1802 +1803 +1804 +1805 +1806 +1807 +1808 +1809 +1810 +1811 +1812 +1813 +1814 +1815 +1816 +1817 |
|
spi_read_blocking(chip_select, register_selection, number_of_bytes_to_read, call_back=None)
+
+Read the specified number of bytes from the specified SPI port and +call the callback function with the reported data.
+:param chip_select: chip select pin
+:param register_selection: Register to be selected for read.
+:param number_of_bytes_to_read: Number of bytes to read
+:param call_back: Required callback function to report spi data as a + result of read command
+callback returns a data list: +[SPI_READ_REPORT, chip select pin, SPI Register, count of data bytes read, +data bytes, time-stamp]
+SPI_READ_REPORT = 13
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
1819 +1820 +1821 +1822 +1823 +1824 +1825 +1826 +1827 +1828 +1829 +1830 +1831 +1832 +1833 +1834 +1835 +1836 +1837 +1838 +1839 +1840 +1841 +1842 +1843 +1844 +1845 +1846 +1847 +1848 +1849 +1850 +1851 +1852 +1853 +1854 +1855 +1856 +1857 +1858 +1859 |
|
spi_set_format(clock_divisor, bit_order, data_mode)
+
+Configure how the SPI serializes and de-serializes data on the wire.
+See Arduino SPI reference materials for details.
+:param clock_divisor: 1 - 255
+:param bit_order:
+ LSBFIRST = 0
+
+ MSBFIRST = 1 (default)
+
+:param data_mode:
+ SPI_MODE0 = 0x00 (default)
+
+ SPI_MODE1 = 1
+
+ SPI_MODE2 = 2
+
+ SPI_MODE3 = 3
+
+
+ telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
1861 +1862 +1863 +1864 +1865 +1866 +1867 +1868 +1869 +1870 +1871 +1872 +1873 +1874 +1875 +1876 +1877 +1878 +1879 +1880 +1881 +1882 +1883 +1884 +1885 +1886 +1887 +1888 +1889 +1890 +1891 +1892 +1893 +1894 +1895 +1896 +1897 +1898 +1899 +1900 +1901 |
|
spi_write_blocking(chip_select, bytes_to_write)
+
+Write a list of bytes to the SPI device.
+:param chip_select: chip select pin
+:param bytes_to_write: A list of bytes to write. This must + be in the form of a list.
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
1903 +1904 +1905 +1906 +1907 +1908 +1909 +1910 +1911 +1912 +1913 +1914 +1915 +1916 +1917 +1918 +1919 +1920 +1921 +1922 +1923 +1924 +1925 +1926 +1927 +1928 +1929 |
|
Copyright (c) 2023 Alan Yorinks All rights reserved.
+This program is free software; you can redistribute it and/or +modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +Version 3 as published by the Free Software Foundation; either +or (at your option) any later version. +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details.
+You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ + + +TelemetrixUnoR4WiFiAio
+
+
+This class exposes and implements the TelemetrixUnoR4WifiAio API. +It includes the public API methods as well as +a set of private methods. This is an asyncio API.
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
39 + 40 + 41 + 42 + 43 + 44 + 45 + 46 + 47 + 48 + 49 + 50 + 51 + 52 + 53 + 54 + 55 + 56 + 57 + 58 + 59 + 60 + 61 + 62 + 63 + 64 + 65 + 66 + 67 + 68 + 69 + 70 + 71 + 72 + 73 + 74 + 75 + 76 + 77 + 78 + 79 + 80 + 81 + 82 + 83 + 84 + 85 + 86 + 87 + 88 + 89 + 90 + 91 + 92 + 93 + 94 + 95 + 96 + 97 + 98 + 99 + 100 + 101 + 102 + 103 + 104 + 105 + 106 + 107 + 108 + 109 + 110 + 111 + 112 + 113 + 114 + 115 + 116 + 117 + 118 + 119 + 120 + 121 + 122 + 123 + 124 + 125 + 126 + 127 + 128 + 129 + 130 + 131 + 132 + 133 + 134 + 135 + 136 + 137 + 138 + 139 + 140 + 141 + 142 + 143 + 144 + 145 + 146 + 147 + 148 + 149 + 150 + 151 + 152 + 153 + 154 + 155 + 156 + 157 + 158 + 159 + 160 + 161 + 162 + 163 + 164 + 165 + 166 + 167 + 168 + 169 + 170 + 171 + 172 + 173 + 174 + 175 + 176 + 177 + 178 + 179 + 180 + 181 + 182 + 183 + 184 + 185 + 186 + 187 + 188 + 189 + 190 + 191 + 192 + 193 + 194 + 195 + 196 + 197 + 198 + 199 + 200 + 201 + 202 + 203 + 204 + 205 + 206 + 207 + 208 + 209 + 210 + 211 + 212 + 213 + 214 + 215 + 216 + 217 + 218 + 219 + 220 + 221 + 222 + 223 + 224 + 225 + 226 + 227 + 228 + 229 + 230 + 231 + 232 + 233 + 234 + 235 + 236 + 237 + 238 + 239 + 240 + 241 + 242 + 243 + 244 + 245 + 246 + 247 + 248 + 249 + 250 + 251 + 252 + 253 + 254 + 255 + 256 + 257 + 258 + 259 + 260 + 261 + 262 + 263 + 264 + 265 + 266 + 267 + 268 + 269 + 270 + 271 + 272 + 273 + 274 + 275 + 276 + 277 + 278 + 279 + 280 + 281 + 282 + 283 + 284 + 285 + 286 + 287 + 288 + 289 + 290 + 291 + 292 + 293 + 294 + 295 + 296 + 297 + 298 + 299 + 300 + 301 + 302 + 303 + 304 + 305 + 306 + 307 + 308 + 309 + 310 + 311 + 312 + 313 + 314 + 315 + 316 + 317 + 318 + 319 + 320 + 321 + 322 + 323 + 324 + 325 + 326 + 327 + 328 + 329 + 330 + 331 + 332 + 333 + 334 + 335 + 336 + 337 + 338 + 339 + 340 + 341 + 342 + 343 + 344 + 345 + 346 + 347 + 348 + 349 + 350 + 351 + 352 + 353 + 354 + 355 + 356 + 357 + 358 + 359 + 360 + 361 + 362 + 363 + 364 + 365 + 366 + 367 + 368 + 369 + 370 + 371 + 372 + 373 + 374 + 375 + 376 + 377 + 378 + 379 + 380 + 381 + 382 + 383 + 384 + 385 + 386 + 387 + 388 + 389 + 390 + 391 + 392 + 393 + 394 + 395 + 396 + 397 + 398 + 399 + 400 + 401 + 402 + 403 + 404 + 405 + 406 + 407 + 408 + 409 + 410 + 411 + 412 + 413 + 414 + 415 + 416 + 417 + 418 + 419 + 420 + 421 + 422 + 423 + 424 + 425 + 426 + 427 + 428 + 429 + 430 + 431 + 432 + 433 + 434 + 435 + 436 + 437 + 438 + 439 + 440 + 441 + 442 + 443 + 444 + 445 + 446 + 447 + 448 + 449 + 450 + 451 + 452 + 453 + 454 + 455 + 456 + 457 + 458 + 459 + 460 + 461 + 462 + 463 + 464 + 465 + 466 + 467 + 468 + 469 + 470 + 471 + 472 + 473 + 474 + 475 + 476 + 477 + 478 + 479 + 480 + 481 + 482 + 483 + 484 + 485 + 486 + 487 + 488 + 489 + 490 + 491 + 492 + 493 + 494 + 495 + 496 + 497 + 498 + 499 + 500 + 501 + 502 + 503 + 504 + 505 + 506 + 507 + 508 + 509 + 510 + 511 + 512 + 513 + 514 + 515 + 516 + 517 + 518 + 519 + 520 + 521 + 522 + 523 + 524 + 525 + 526 + 527 + 528 + 529 + 530 + 531 + 532 + 533 + 534 + 535 + 536 + 537 + 538 + 539 + 540 + 541 + 542 + 543 + 544 + 545 + 546 + 547 + 548 + 549 + 550 + 551 + 552 + 553 + 554 + 555 + 556 + 557 + 558 + 559 + 560 + 561 + 562 + 563 + 564 + 565 + 566 + 567 + 568 + 569 + 570 + 571 + 572 + 573 + 574 + 575 + 576 + 577 + 578 + 579 + 580 + 581 + 582 + 583 + 584 + 585 + 586 + 587 + 588 + 589 + 590 + 591 + 592 + 593 + 594 + 595 + 596 + 597 + 598 + 599 + 600 + 601 + 602 + 603 + 604 + 605 + 606 + 607 + 608 + 609 + 610 + 611 + 612 + 613 + 614 + 615 + 616 + 617 + 618 + 619 + 620 + 621 + 622 + 623 + 624 + 625 + 626 + 627 + 628 + 629 + 630 + 631 + 632 + 633 + 634 + 635 + 636 + 637 + 638 + 639 + 640 + 641 + 642 + 643 + 644 + 645 + 646 + 647 + 648 + 649 + 650 + 651 + 652 + 653 + 654 + 655 + 656 + 657 + 658 + 659 + 660 + 661 + 662 + 663 + 664 + 665 + 666 + 667 + 668 + 669 + 670 + 671 + 672 + 673 + 674 + 675 + 676 + 677 + 678 + 679 + 680 + 681 + 682 + 683 + 684 + 685 + 686 + 687 + 688 + 689 + 690 + 691 + 692 + 693 + 694 + 695 + 696 + 697 + 698 + 699 + 700 + 701 + 702 + 703 + 704 + 705 + 706 + 707 + 708 + 709 + 710 + 711 + 712 + 713 + 714 + 715 + 716 + 717 + 718 + 719 + 720 + 721 + 722 + 723 + 724 + 725 + 726 + 727 + 728 + 729 + 730 + 731 + 732 + 733 + 734 + 735 + 736 + 737 + 738 + 739 + 740 + 741 + 742 + 743 + 744 + 745 + 746 + 747 + 748 + 749 + 750 + 751 + 752 + 753 + 754 + 755 + 756 + 757 + 758 + 759 + 760 + 761 + 762 + 763 + 764 + 765 + 766 + 767 + 768 + 769 + 770 + 771 + 772 + 773 + 774 + 775 + 776 + 777 + 778 + 779 + 780 + 781 + 782 + 783 + 784 + 785 + 786 + 787 + 788 + 789 + 790 + 791 + 792 + 793 + 794 + 795 + 796 + 797 + 798 + 799 + 800 + 801 + 802 + 803 + 804 + 805 + 806 + 807 + 808 + 809 + 810 + 811 + 812 + 813 + 814 + 815 + 816 + 817 + 818 + 819 + 820 + 821 + 822 + 823 + 824 + 825 + 826 + 827 + 828 + 829 + 830 + 831 + 832 + 833 + 834 + 835 + 836 + 837 + 838 + 839 + 840 + 841 + 842 + 843 + 844 + 845 + 846 + 847 + 848 + 849 + 850 + 851 + 852 + 853 + 854 + 855 + 856 + 857 + 858 + 859 + 860 + 861 + 862 + 863 + 864 + 865 + 866 + 867 + 868 + 869 + 870 + 871 + 872 + 873 + 874 + 875 + 876 + 877 + 878 + 879 + 880 + 881 + 882 + 883 + 884 + 885 + 886 + 887 + 888 + 889 + 890 + 891 + 892 + 893 + 894 + 895 + 896 + 897 + 898 + 899 + 900 + 901 + 902 + 903 + 904 + 905 + 906 + 907 + 908 + 909 + 910 + 911 + 912 + 913 + 914 + 915 + 916 + 917 + 918 + 919 + 920 + 921 + 922 + 923 + 924 + 925 + 926 + 927 + 928 + 929 + 930 + 931 + 932 + 933 + 934 + 935 + 936 + 937 + 938 + 939 + 940 + 941 + 942 + 943 + 944 + 945 + 946 + 947 + 948 + 949 + 950 + 951 + 952 + 953 + 954 + 955 + 956 + 957 + 958 + 959 + 960 + 961 + 962 + 963 + 964 + 965 + 966 + 967 + 968 + 969 + 970 + 971 + 972 + 973 + 974 + 975 + 976 + 977 + 978 + 979 + 980 + 981 + 982 + 983 + 984 + 985 + 986 + 987 + 988 + 989 + 990 + 991 + 992 + 993 + 994 + 995 + 996 + 997 + 998 + 999 +1000 +1001 +1002 +1003 +1004 +1005 +1006 +1007 +1008 +1009 +1010 +1011 +1012 +1013 +1014 +1015 +1016 +1017 +1018 +1019 +1020 +1021 +1022 +1023 +1024 +1025 +1026 +1027 +1028 +1029 +1030 +1031 +1032 +1033 +1034 +1035 +1036 +1037 +1038 +1039 +1040 +1041 +1042 +1043 +1044 +1045 +1046 +1047 +1048 +1049 +1050 +1051 +1052 +1053 +1054 +1055 +1056 +1057 +1058 +1059 +1060 +1061 +1062 +1063 +1064 +1065 +1066 +1067 +1068 +1069 +1070 +1071 +1072 +1073 +1074 +1075 +1076 +1077 +1078 +1079 +1080 +1081 +1082 +1083 +1084 +1085 +1086 +1087 +1088 +1089 +1090 +1091 +1092 +1093 +1094 +1095 +1096 +1097 +1098 +1099 +1100 +1101 +1102 +1103 +1104 +1105 +1106 +1107 +1108 +1109 +1110 +1111 +1112 +1113 +1114 +1115 +1116 +1117 +1118 +1119 +1120 +1121 +1122 +1123 +1124 +1125 +1126 +1127 +1128 +1129 +1130 +1131 +1132 +1133 +1134 +1135 +1136 +1137 +1138 +1139 +1140 +1141 +1142 +1143 +1144 +1145 +1146 +1147 +1148 +1149 +1150 +1151 +1152 +1153 +1154 +1155 +1156 +1157 +1158 +1159 +1160 +1161 +1162 +1163 +1164 +1165 +1166 +1167 +1168 +1169 +1170 +1171 +1172 +1173 +1174 +1175 +1176 +1177 +1178 +1179 +1180 +1181 +1182 +1183 +1184 +1185 +1186 +1187 +1188 +1189 +1190 +1191 +1192 +1193 +1194 +1195 +1196 +1197 +1198 +1199 +1200 +1201 +1202 +1203 +1204 +1205 +1206 +1207 +1208 +1209 +1210 +1211 +1212 +1213 +1214 +1215 +1216 +1217 +1218 +1219 +1220 +1221 +1222 +1223 +1224 +1225 +1226 +1227 +1228 +1229 +1230 +1231 +1232 +1233 +1234 +1235 +1236 +1237 +1238 +1239 +1240 +1241 +1242 +1243 +1244 +1245 +1246 +1247 +1248 +1249 +1250 +1251 +1252 +1253 +1254 +1255 +1256 +1257 +1258 +1259 +1260 +1261 +1262 +1263 +1264 +1265 +1266 +1267 +1268 +1269 +1270 +1271 +1272 +1273 +1274 +1275 +1276 +1277 +1278 +1279 +1280 +1281 +1282 +1283 +1284 +1285 +1286 +1287 +1288 +1289 +1290 +1291 +1292 +1293 +1294 +1295 +1296 +1297 +1298 +1299 +1300 +1301 +1302 +1303 +1304 +1305 +1306 +1307 +1308 +1309 +1310 +1311 +1312 +1313 +1314 +1315 +1316 +1317 +1318 +1319 +1320 +1321 +1322 +1323 +1324 +1325 +1326 +1327 +1328 +1329 +1330 +1331 +1332 +1333 +1334 +1335 +1336 +1337 +1338 +1339 +1340 +1341 +1342 +1343 +1344 +1345 +1346 +1347 +1348 +1349 +1350 +1351 +1352 +1353 +1354 +1355 +1356 +1357 +1358 +1359 +1360 +1361 +1362 +1363 +1364 +1365 +1366 +1367 +1368 +1369 +1370 +1371 +1372 +1373 +1374 +1375 +1376 +1377 +1378 +1379 +1380 +1381 +1382 +1383 +1384 +1385 +1386 +1387 +1388 +1389 +1390 +1391 +1392 +1393 +1394 +1395 +1396 +1397 +1398 +1399 +1400 +1401 +1402 +1403 +1404 +1405 +1406 +1407 +1408 +1409 +1410 +1411 +1412 +1413 +1414 +1415 +1416 +1417 +1418 +1419 +1420 +1421 +1422 +1423 +1424 +1425 +1426 +1427 +1428 +1429 +1430 +1431 +1432 +1433 +1434 +1435 +1436 +1437 +1438 +1439 +1440 +1441 +1442 +1443 +1444 +1445 +1446 +1447 +1448 +1449 +1450 +1451 +1452 +1453 +1454 +1455 +1456 +1457 +1458 +1459 +1460 +1461 +1462 +1463 +1464 +1465 +1466 +1467 +1468 +1469 +1470 +1471 +1472 +1473 +1474 +1475 +1476 +1477 +1478 +1479 +1480 +1481 +1482 +1483 +1484 +1485 +1486 +1487 +1488 +1489 +1490 +1491 +1492 +1493 +1494 +1495 +1496 +1497 +1498 +1499 +1500 +1501 +1502 +1503 +1504 +1505 +1506 +1507 +1508 +1509 +1510 +1511 +1512 +1513 +1514 +1515 +1516 +1517 +1518 +1519 +1520 +1521 +1522 +1523 +1524 +1525 +1526 +1527 +1528 +1529 +1530 +1531 +1532 +1533 +1534 +1535 +1536 +1537 +1538 +1539 +1540 +1541 +1542 +1543 +1544 +1545 +1546 +1547 +1548 +1549 +1550 +1551 +1552 +1553 +1554 +1555 +1556 +1557 +1558 +1559 +1560 +1561 +1562 +1563 +1564 +1565 +1566 +1567 +1568 +1569 +1570 +1571 +1572 +1573 +1574 +1575 +1576 +1577 +1578 +1579 +1580 +1581 +1582 +1583 +1584 +1585 +1586 +1587 +1588 +1589 +1590 +1591 +1592 +1593 +1594 +1595 +1596 +1597 +1598 +1599 +1600 +1601 +1602 +1603 +1604 +1605 +1606 +1607 +1608 +1609 +1610 +1611 +1612 +1613 +1614 +1615 +1616 +1617 +1618 +1619 +1620 +1621 +1622 +1623 +1624 +1625 +1626 +1627 +1628 +1629 +1630 +1631 +1632 +1633 +1634 +1635 +1636 +1637 +1638 +1639 +1640 +1641 +1642 +1643 +1644 +1645 +1646 +1647 +1648 +1649 +1650 +1651 +1652 +1653 +1654 +1655 +1656 +1657 +1658 +1659 +1660 +1661 +1662 +1663 +1664 +1665 +1666 +1667 +1668 +1669 +1670 +1671 +1672 +1673 +1674 +1675 +1676 +1677 +1678 +1679 +1680 +1681 +1682 +1683 +1684 +1685 +1686 +1687 +1688 +1689 +1690 +1691 +1692 +1693 +1694 +1695 +1696 +1697 +1698 +1699 +1700 +1701 +1702 +1703 +1704 +1705 +1706 +1707 +1708 +1709 +1710 +1711 +1712 +1713 +1714 +1715 +1716 +1717 +1718 +1719 +1720 +1721 +1722 +1723 +1724 +1725 +1726 +1727 +1728 +1729 +1730 +1731 +1732 +1733 +1734 +1735 +1736 +1737 +1738 +1739 +1740 +1741 +1742 +1743 +1744 +1745 +1746 +1747 +1748 +1749 +1750 +1751 +1752 +1753 +1754 +1755 +1756 +1757 +1758 +1759 +1760 +1761 +1762 +1763 +1764 +1765 +1766 +1767 +1768 +1769 +1770 +1771 +1772 +1773 +1774 +1775 +1776 +1777 +1778 +1779 +1780 +1781 +1782 +1783 +1784 +1785 +1786 +1787 +1788 +1789 +1790 +1791 +1792 +1793 +1794 +1795 +1796 +1797 +1798 +1799 +1800 +1801 +1802 +1803 +1804 +1805 +1806 +1807 +1808 +1809 +1810 +1811 +1812 +1813 +1814 +1815 +1816 +1817 +1818 +1819 +1820 +1821 +1822 +1823 +1824 +1825 +1826 +1827 +1828 +1829 +1830 +1831 +1832 +1833 +1834 +1835 +1836 +1837 +1838 +1839 +1840 +1841 +1842 +1843 +1844 +1845 +1846 +1847 +1848 +1849 +1850 +1851 +1852 +1853 +1854 +1855 +1856 +1857 +1858 +1859 +1860 +1861 +1862 +1863 +1864 +1865 +1866 +1867 +1868 +1869 +1870 +1871 +1872 +1873 +1874 +1875 +1876 +1877 +1878 +1879 +1880 +1881 +1882 +1883 +1884 +1885 +1886 +1887 +1888 +1889 +1890 +1891 +1892 +1893 +1894 +1895 +1896 +1897 +1898 +1899 +1900 +1901 +1902 +1903 +1904 +1905 +1906 +1907 +1908 +1909 +1910 +1911 +1912 +1913 +1914 +1915 +1916 +1917 +1918 +1919 +1920 +1921 +1922 +1923 +1924 +1925 +1926 +1927 +1928 +1929 +1930 +1931 +1932 +1933 +1934 +1935 +1936 +1937 +1938 +1939 +1940 +1941 +1942 +1943 +1944 +1945 +1946 +1947 +1948 +1949 +1950 +1951 +1952 +1953 +1954 +1955 +1956 +1957 +1958 +1959 +1960 +1961 +1962 +1963 +1964 +1965 +1966 +1967 +1968 +1969 +1970 +1971 +1972 +1973 +1974 +1975 +1976 +1977 +1978 +1979 +1980 +1981 +1982 +1983 +1984 +1985 +1986 +1987 +1988 +1989 +1990 +1991 +1992 +1993 +1994 +1995 +1996 +1997 +1998 +1999 +2000 +2001 +2002 +2003 +2004 +2005 +2006 +2007 +2008 +2009 +2010 +2011 +2012 +2013 +2014 +2015 +2016 +2017 +2018 +2019 +2020 +2021 +2022 +2023 +2024 +2025 +2026 +2027 +2028 +2029 +2030 +2031 +2032 +2033 +2034 +2035 +2036 +2037 +2038 +2039 +2040 +2041 +2042 +2043 +2044 +2045 +2046 +2047 +2048 +2049 +2050 +2051 +2052 +2053 +2054 +2055 +2056 +2057 +2058 +2059 +2060 +2061 +2062 +2063 +2064 +2065 +2066 +2067 +2068 +2069 +2070 +2071 +2072 +2073 +2074 +2075 +2076 +2077 +2078 +2079 +2080 +2081 +2082 +2083 +2084 +2085 +2086 +2087 +2088 +2089 +2090 +2091 +2092 +2093 +2094 +2095 +2096 +2097 +2098 +2099 +2100 +2101 +2102 +2103 +2104 +2105 +2106 +2107 +2108 +2109 +2110 +2111 +2112 +2113 +2114 +2115 +2116 +2117 +2118 +2119 +2120 +2121 +2122 +2123 +2124 +2125 +2126 +2127 +2128 +2129 +2130 +2131 +2132 +2133 +2134 +2135 +2136 +2137 +2138 +2139 +2140 +2141 +2142 +2143 +2144 +2145 +2146 +2147 +2148 +2149 +2150 +2151 +2152 +2153 +2154 +2155 +2156 +2157 +2158 +2159 +2160 +2161 +2162 +2163 +2164 +2165 +2166 +2167 +2168 +2169 +2170 +2171 +2172 +2173 +2174 +2175 +2176 +2177 +2178 +2179 +2180 +2181 +2182 +2183 +2184 +2185 +2186 +2187 +2188 +2189 +2190 +2191 +2192 +2193 +2194 +2195 +2196 +2197 +2198 +2199 +2200 +2201 +2202 +2203 +2204 +2205 +2206 +2207 +2208 +2209 +2210 +2211 +2212 +2213 +2214 +2215 +2216 +2217 +2218 +2219 +2220 +2221 +2222 +2223 +2224 +2225 +2226 +2227 +2228 +2229 +2230 +2231 +2232 +2233 +2234 +2235 +2236 +2237 +2238 +2239 +2240 +2241 +2242 +2243 +2244 +2245 +2246 +2247 +2248 +2249 +2250 +2251 +2252 +2253 +2254 +2255 +2256 +2257 +2258 +2259 +2260 +2261 +2262 +2263 +2264 +2265 +2266 +2267 +2268 +2269 +2270 +2271 +2272 +2273 +2274 +2275 +2276 +2277 +2278 +2279 +2280 +2281 +2282 +2283 +2284 +2285 +2286 +2287 +2288 +2289 +2290 +2291 +2292 +2293 +2294 +2295 +2296 +2297 +2298 +2299 +2300 +2301 +2302 +2303 +2304 +2305 +2306 +2307 +2308 +2309 +2310 +2311 +2312 +2313 +2314 +2315 +2316 +2317 +2318 +2319 +2320 +2321 +2322 +2323 +2324 +2325 +2326 +2327 +2328 +2329 +2330 +2331 +2332 +2333 +2334 +2335 +2336 +2337 +2338 +2339 +2340 +2341 +2342 +2343 +2344 +2345 +2346 +2347 +2348 +2349 +2350 +2351 +2352 +2353 +2354 +2355 +2356 +2357 +2358 +2359 +2360 +2361 +2362 +2363 +2364 +2365 +2366 +2367 +2368 +2369 +2370 +2371 +2372 +2373 +2374 +2375 +2376 +2377 +2378 +2379 +2380 +2381 +2382 +2383 +2384 +2385 +2386 +2387 +2388 +2389 +2390 +2391 +2392 +2393 +2394 +2395 +2396 +2397 +2398 +2399 +2400 +2401 +2402 +2403 +2404 +2405 +2406 +2407 +2408 +2409 +2410 +2411 +2412 +2413 +2414 +2415 +2416 +2417 +2418 +2419 +2420 +2421 +2422 +2423 +2424 +2425 +2426 +2427 +2428 +2429 +2430 +2431 +2432 +2433 +2434 +2435 +2436 +2437 +2438 +2439 +2440 +2441 +2442 +2443 +2444 +2445 +2446 +2447 +2448 +2449 +2450 +2451 +2452 +2453 +2454 +2455 +2456 +2457 +2458 +2459 +2460 +2461 +2462 +2463 +2464 +2465 +2466 +2467 +2468 +2469 +2470 +2471 +2472 +2473 +2474 +2475 +2476 +2477 +2478 +2479 +2480 +2481 +2482 +2483 +2484 +2485 +2486 +2487 +2488 +2489 +2490 +2491 +2492 +2493 +2494 +2495 +2496 +2497 +2498 +2499 +2500 +2501 +2502 +2503 +2504 +2505 +2506 +2507 +2508 +2509 +2510 +2511 +2512 +2513 +2514 +2515 +2516 +2517 +2518 +2519 +2520 +2521 +2522 +2523 +2524 +2525 +2526 +2527 +2528 +2529 +2530 +2531 +2532 +2533 +2534 +2535 +2536 +2537 +2538 +2539 +2540 +2541 +2542 +2543 +2544 +2545 +2546 +2547 +2548 +2549 +2550 +2551 +2552 +2553 +2554 +2555 +2556 +2557 +2558 +2559 +2560 +2561 +2562 +2563 +2564 +2565 +2566 +2567 +2568 +2569 +2570 +2571 +2572 +2573 +2574 +2575 +2576 +2577 +2578 +2579 +2580 +2581 +2582 +2583 +2584 +2585 +2586 +2587 +2588 +2589 +2590 +2591 +2592 +2593 +2594 +2595 +2596 +2597 +2598 +2599 +2600 +2601 +2602 +2603 +2604 +2605 +2606 +2607 +2608 +2609 +2610 +2611 +2612 +2613 +2614 +2615 +2616 +2617 +2618 +2619 +2620 +2621 +2622 +2623 +2624 +2625 +2626 +2627 +2628 +2629 |
|
__init__(com_port=None, arduino_instance_id=1, arduino_wait=1, sleep_tune=0.0001, autostart=True, loop=None, shutdown_on_exception=True, close_loop_on_shutdown=True, hard_reset_on_shutdown=True, transport_address=None, ip_port=31336, transport_type=0, ble_device_name='Telemetrix4UnoR4 BLE')
+
+If you have a single Arduino connected to your computer, + then you may accept all the default values.
+Otherwise, specify a unique arduino_instance id for each board in use.
+:param com_port: e.g. COM3 or /dev/ttyACM0.
+:param arduino_instance_id: Must match value in the Telemetrix4Arduino sketch
+:param arduino_wait: Amount of time to wait for an Arduino to + fully reset itself.
+:param sleep_tune: A tuning parameter (typically not changed by user)
+:param autostart: If you wish to call the start method within + your application, then set this to False.
+:param loop: optional user provided event loop
+:param shutdown_on_exception: call shutdown before raising + a RunTimeError exception, or + receiving a KeyboardInterrupt exception
+:param close_loop_on_shutdown: stop and close the event loop loop + when a shutdown is called or a serial + error occurs
+:param hard_reset_on_shutdown: reset the board on shutdown
+:param transport_address: ip address of tcp/ip connected device.
+:param ip_port: ip port of tcp/ip connected device
+:param transport_type: 0 = WiFi + 1 = SerialUSB + 2 = BLE
+:param ble_device_name: name of Arduino UNO R4 WIFI BLE device. + It must match that of Telemetrix4UnoR4BLE.ino
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
48 + 49 + 50 + 51 + 52 + 53 + 54 + 55 + 56 + 57 + 58 + 59 + 60 + 61 + 62 + 63 + 64 + 65 + 66 + 67 + 68 + 69 + 70 + 71 + 72 + 73 + 74 + 75 + 76 + 77 + 78 + 79 + 80 + 81 + 82 + 83 + 84 + 85 + 86 + 87 + 88 + 89 + 90 + 91 + 92 + 93 + 94 + 95 + 96 + 97 + 98 + 99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +131 +132 +133 +134 +135 +136 +137 +138 +139 +140 +141 +142 +143 +144 +145 +146 +147 +148 +149 +150 +151 +152 +153 +154 +155 +156 +157 +158 +159 +160 +161 +162 +163 +164 +165 +166 +167 +168 +169 +170 +171 +172 +173 +174 +175 +176 +177 +178 +179 +180 +181 +182 +183 +184 +185 +186 +187 +188 +189 +190 +191 +192 +193 +194 +195 +196 +197 +198 +199 +200 +201 +202 +203 +204 +205 +206 +207 +208 +209 +210 +211 +212 +213 +214 +215 +216 +217 +218 +219 +220 +221 +222 +223 +224 +225 +226 +227 +228 +229 +230 +231 +232 +233 +234 +235 +236 +237 +238 +239 +240 +241 +242 +243 +244 +245 +246 +247 +248 +249 +250 +251 +252 +253 +254 +255 +256 +257 +258 +259 +260 +261 +262 +263 +264 +265 +266 +267 +268 +269 +270 +271 +272 +273 +274 +275 +276 +277 +278 +279 +280 +281 +282 +283 +284 +285 +286 +287 +288 +289 +290 +291 +292 +293 +294 +295 +296 |
|
analog_write(pin, value)
+
+
+ async
+
+
+Set the specified pin to the specified value.
+:param pin: arduino pin number
+:param value: pin value (maximum 16 bits)
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
491 +492 +493 +494 +495 +496 +497 +498 +499 +500 +501 +502 +503 |
|
digital_write(pin, value)
+
+
+ async
+
+
+Set the specified pin to the specified value.
+:param pin: arduino pin number
+:param value: pin value (1 or 0)
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
505 +506 +507 +508 +509 +510 +511 +512 +513 +514 +515 |
|
disable_all_reporting()
+
+
+ async
+
+
+Disable reporting for all digital and analog input pins
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
2135 +2136 +2137 +2138 +2139 +2140 +2141 |
|
disable_analog_reporting(pin)
+
+
+ async
+
+
+Disables analog reporting for a single analog pin.
+:param pin: Analog pin number. For example for A0, the number is 0.
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
2143 +2144 +2145 +2146 +2147 +2148 +2149 +2150 +2151 +2152 |
|
disable_digital_reporting(pin)
+
+
+ async
+
+
+Disables digital reporting for a single digital pin
+:param pin: pin number
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
2154 +2155 +2156 +2157 +2158 +2159 +2160 +2161 +2162 +2163 +2164 |
|
disable_scroll_message()
+
+
+ async
+
+
+Turn off a scrolling message
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
2207 +2208 +2209 +2210 +2211 +2212 +2213 |
|
enable_analog_reporting(pin)
+
+
+ async
+
+
+Enables analog reporting for the specified pin.
+:param pin: Analog pin number. For example for A0, the number is 0.
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
2166 +2167 +2168 +2169 +2170 +2171 +2172 +2173 +2174 +2175 +2176 |
|
enable_digital_reporting(pin)
+
+
+ async
+
+
+Enable reporting on the specified digital pin.
+:param pin: Pin number.
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
2178 +2179 +2180 +2181 +2182 +2183 +2184 +2185 +2186 +2187 |
|
enable_scroll_message(message, scroll_speed=50)
+
+
+ async
+
+
+:param message: Message with maximum length of 25 +:param scroll_speed: in milliseconds (maximum of 255)
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
2189 +2190 +2191 +2192 +2193 +2194 +2195 +2196 +2197 +2198 +2199 +2200 +2201 +2202 +2203 +2204 +2205 |
|
get_event_loop()
+
+
+ async
+
+
+Return the currently active asyncio event loop
+:return: Active event loop
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
377 +378 +379 +380 +381 +382 +383 +384 |
|
i2c_read(address, register, number_of_bytes, callback, i2c_port=0, write_register=True)
+
+
+ async
+
+
+Read the specified number of bytes from the specified register for +the i2c device.
+:param address: i2c device address
+:param register: i2c register (or None if no register selection is needed)
+:param number_of_bytes: number of bytes to be read
+:param callback: Required callback function to report i2c data as a + result of read command
+:param i2c_port: select the default port (0) or secondary port (1)
+:param write_register: If True, the register is written + before read + Else, the write is suppressed
+callback returns a data list:
+[I2C_READ_REPORT, address, register, count of data bytes, + data bytes, time-stamp]
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
517 +518 +519 +520 +521 +522 +523 +524 +525 +526 +527 +528 +529 +530 +531 +532 +533 +534 +535 +536 +537 +538 +539 +540 +541 +542 +543 +544 +545 +546 +547 +548 +549 +550 +551 +552 +553 +554 |
|
i2c_read_restart_transmission(address, register, number_of_bytes, callback, i2c_port=0, write_register=True)
+
+
+ async
+
+
+Read the specified number of bytes from the specified register for +the i2c device. This restarts the transmission after the read. It is +required for some i2c devices such as the MMA8452Q accelerometer.
+:param address: i2c device address
+:param register: i2c register (or None if no register + selection is needed)
+:param number_of_bytes: number of bytes to be read
+:param callback: Required callback function to report i2c data as a + result of read command
+:param i2c_port: select the default port (0) or secondary port (1)
+:param write_register: If True, the register is written + before read + Else, the write is suppressed
+callback returns a data list:
+[I2C_READ_REPORT, address, register, count of data bytes, + data bytes, time-stamp]
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
556 +557 +558 +559 +560 +561 +562 +563 +564 +565 +566 +567 +568 +569 +570 +571 +572 +573 +574 +575 +576 +577 +578 +579 +580 +581 +582 +583 +584 +585 +586 +587 +588 +589 +590 +591 +592 +593 +594 +595 +596 +597 |
|
i2c_write(address, args, i2c_port=0)
+
+
+ async
+
+
+Write data to an i2c device.
+:param address: i2c device address
+:param i2c_port: 0= port 1, 1 = port 2
+:param args: A variable number of bytes to be sent to the device + passed in as a list
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
668 +669 +670 +671 +672 +673 +674 +675 +676 +677 +678 +679 +680 +681 +682 +683 +684 +685 +686 +687 +688 +689 +690 +691 +692 +693 +694 +695 +696 +697 +698 +699 |
|
loop_back(start_character, callback)
+
+
+ async
+
+
+This is a debugging method to send a character to the +Arduino device, and have the device loop it back.
+:param start_character: The character to loop back. It should be + an integer.
+:param callback: Looped back character will appear in the callback method
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
701 +702 +703 +704 +705 +706 +707 +708 +709 +710 +711 +712 +713 +714 +715 +716 +717 +718 +719 |
|
r4_hard_reset()
+
+
+ async
+
+
+Place the r4 into hard reset
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
2128 +2129 +2130 +2131 +2132 +2133 |
|
servo_detach(pin_number)
+
+
+ async
+
+
+Detach a servo for reuse +:param pin_number: attached pin
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
1479 +1480 +1481 +1482 +1483 +1484 +1485 |
|
servo_write(pin_number, angle)
+
+
+ async
+
+
+Set a servo attached to a pin to a given angle.
+:param pin_number: pin
+:param angle: angle (0-180)
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
1487 +1488 +1489 +1490 +1491 +1492 +1493 +1494 +1495 +1496 +1497 +1498 |
|
set_analog_scan_interval(interval)
+
+
+ async
+
+
+Set the analog scanning interval.
+:param interval: value of 0 - 255 - milliseconds
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
721 +722 +723 +724 +725 +726 +727 +728 +729 +730 +731 +732 +733 +734 |
|
set_pin_mode_analog_input(pin_number, differential=0, callback=None)
+
+
+ async
+
+
+Set a pin as an analog input.
+:param pin_number: arduino pin number
+:param callback: async callback function
+:param differential: difference in previous to current value before + report will be generated
+callback returns a data list:
+[pin_type, pin_number, pin_value, raw_time_stamp]
+The pin_type for analog input pins = 3
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
736 +737 +738 +739 +740 +741 +742 +743 +744 +745 +746 +747 +748 +749 +750 +751 +752 +753 +754 +755 +756 +757 +758 +759 +760 +761 +762 |
|
set_pin_mode_analog_output(pin_number)
+
+
+ async
+
+
+Set a pin as a pwm (analog output) pin.
+:param pin_number:arduino pin number
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
764 +765 +766 +767 +768 +769 +770 +771 +772 +773 +774 |
|
set_pin_mode_dht(pin, callback=None, dht_type=22)
+
+
+ async
+
+
+:param pin: connection pin
+:param callback: callback function
+:param dht_type: either 22 for DHT22 or 11 for DHT11
+Error Callback: [DHT REPORT Type, DHT_ERROR_NUMBER, PIN, DHT_TYPE, Time]
+Valid Data Callback: DHT REPORT Type, DHT_DATA=, PIN, DHT_TYPE, Humidity, +Temperature, +Time]
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
860 +861 +862 +863 +864 +865 +866 +867 +868 +869 +870 +871 +872 +873 +874 +875 +876 +877 +878 +879 +880 +881 +882 +883 +884 +885 +886 +887 +888 +889 +890 +891 +892 +893 +894 +895 +896 +897 +898 +899 +900 +901 |
|
set_pin_mode_digital_input(pin_number, callback)
+
+
+ async
+
+
+Set a pin as a digital input.
+:param pin_number: arduino pin number
+:param callback: async callback function
+callback returns a data list:
+[pin_type, pin_number, pin_value, raw_time_stamp]
+The pin_type for all digital input pins = 2
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
776 +777 +778 +779 +780 +781 +782 +783 +784 +785 +786 +787 +788 +789 +790 +791 +792 |
|
set_pin_mode_digital_input_pullup(pin_number, callback)
+
+
+ async
+
+
+Set a pin as a digital input with pullup enabled.
+:param pin_number: arduino pin number
+:param callback: async callback function
+callback returns a data list:
+[pin_type, pin_number, pin_value, raw_time_stamp]
+The pin_type for all digital input pins = 2
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
794 +795 +796 +797 +798 +799 +800 +801 +802 +803 +804 +805 +806 +807 +808 +809 +810 +811 +812 +813 +814 +815 +816 |
|
set_pin_mode_digital_output(pin_number)
+
+
+ async
+
+
+Set a pin as a digital output pin.
+:param pin_number: arduino pin number
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
818 +819 +820 +821 +822 +823 +824 +825 +826 |
|
set_pin_mode_i2c(i2c_port=0)
+
+
+ async
+
+
+Establish the standard Arduino i2c pins for i2c utilization.
+:param i2c_port: 0 = i2c1, 1 = i2c2
+ + API.
+
+ See i2c_read, or i2c_read_restart_transmission.
+
+
+ telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
829 +830 +831 +832 +833 +834 +835 +836 +837 +838 +839 +840 +841 +842 +843 +844 +845 +846 +847 +848 +849 +850 +851 +852 +853 +854 +855 +856 +857 +858 |
|
set_pin_mode_servo(pin_number, min_pulse=544, max_pulse=2400)
+
+
+ async
+
+
+Attach a pin to a servo motor
+:param pin_number: pin
+:param min_pulse: minimum pulse width
+:param max_pulse: maximum pulse width
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
903 +904 +905 +906 +907 +908 +909 +910 +911 +912 +913 +914 +915 +916 +917 +918 +919 +920 +921 +922 +923 +924 +925 +926 |
|
set_pin_mode_sonar(trigger_pin, echo_pin, callback)
+
+
+ async
+
+
+:param trigger_pin:
+:param echo_pin:
+:param callback: callback
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
928 +929 +930 +931 +932 +933 +934 +935 +936 +937 +938 +939 +940 +941 +942 +943 +944 +945 +946 +947 +948 +949 +950 +951 +952 +953 +954 +955 +956 +957 +958 +959 +960 |
|
set_pin_mode_spi(chip_select_list=None)
+
+
+ async
+
+
+Specify the list of chip select pins.
+Standard Arduino MISO, MOSI and CLK pins are used for the board in use.
+Chip Select is any digital output capable pin.
+:param chip_select_list: this is a list of pins to be used for chip select. + The pins will be configured as output, and set to high + ready to be used for chip select. + NOTE: You must specify the chips select pins here!
+command message: [command, number of cs pins, [cs pins...]]
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
962 + 963 + 964 + 965 + 966 + 967 + 968 + 969 + 970 + 971 + 972 + 973 + 974 + 975 + 976 + 977 + 978 + 979 + 980 + 981 + 982 + 983 + 984 + 985 + 986 + 987 + 988 + 989 + 990 + 991 + 992 + 993 + 994 + 995 + 996 + 997 + 998 + 999 +1000 |
|
shutdown()
+
+
+ async
+
+
+This method attempts an orderly shutdown +If any exceptions are thrown, they are ignored.
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
2096 +2097 +2098 +2099 +2100 +2101 +2102 +2103 +2104 +2105 +2106 +2107 +2108 +2109 +2110 +2111 +2112 +2113 +2114 +2115 +2116 +2117 +2118 +2119 +2120 +2121 +2122 +2123 +2124 +2125 +2126 |
|
sonar_disable()
+
+
+ async
+
+
+Disable sonar scanning for all sonar sensors
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
1077 +1078 +1079 +1080 +1081 +1082 |
|
sonar_enable()
+
+
+ async
+
+
+Enable sonar scanning for all sonar sensors
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
1084 +1085 +1086 +1087 +1088 +1089 |
|
spi_cs_control(chip_select_pin, select)
+
+
+ async
+
+
+Control an SPI chip select line +:param chip_select_pin: pin connected to CS
+:param select: 0=select, 1=deselect
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
1091 +1092 +1093 +1094 +1095 +1096 +1097 +1098 +1099 +1100 +1101 +1102 +1103 +1104 +1105 +1106 +1107 +1108 |
|
spi_read_blocking(chip_select, register_selection, number_of_bytes_to_read, call_back=None)
+
+
+ async
+
+
+Read the specified number of bytes from the specified SPI port and +call the callback function with the reported data.
+:param chip_select: chip select pin
+:param register_selection: Register to be selected for read.
+:param number_of_bytes_to_read: Number of bytes to read
+:param call_back: Required callback function to report spi data as a + result of read command
+ +[SPI_READ_REPORT, chip select pin, SPI Register, count of data bytes read, + data bytes, time-stamp]
+SPI_READ_REPORT = 13
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
1110 +1111 +1112 +1113 +1114 +1115 +1116 +1117 +1118 +1119 +1120 +1121 +1122 +1123 +1124 +1125 +1126 +1127 +1128 +1129 +1130 +1131 +1132 +1133 +1134 +1135 +1136 +1137 +1138 +1139 +1140 +1141 +1142 +1143 +1144 +1145 +1146 +1147 +1148 +1149 +1150 |
|
spi_set_format(clock_divisor, bit_order, data_mode)
+
+
+ async
+
+
+Configure how the SPI serializes and de-serializes data on the wire.
+See Arduino SPI reference materials for details.
+:param clock_divisor: 1 - 255
+:param bit_order:
+ LSBFIRST = 0
+
+ MSBFIRST = 1 (default)
+
+:param data_mode:
+ SPI_MODE0 = 0x00 (default)
+
+ SPI_MODE1 = 1
+
+ SPI_MODE2 = 2
+
+ SPI_MODE3 = 3
+
+
+ telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
1152 +1153 +1154 +1155 +1156 +1157 +1158 +1159 +1160 +1161 +1162 +1163 +1164 +1165 +1166 +1167 +1168 +1169 +1170 +1171 +1172 +1173 +1174 +1175 +1176 +1177 +1178 +1179 +1180 +1181 +1182 +1183 +1184 +1185 +1186 +1187 +1188 +1189 +1190 +1191 +1192 |
|
spi_write_blocking(chip_select, bytes_to_write)
+
+
+ async
+
+
+Write a list of bytes to the SPI device.
+:param chip_select: chip select pin
+:param bytes_to_write: A list of bytes to write. This must + be in the form of a list.
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
1194 +1195 +1196 +1197 +1198 +1199 +1200 +1201 +1202 +1203 +1204 +1205 +1206 +1207 +1208 +1209 +1210 +1211 +1212 +1213 +1214 +1215 +1216 +1217 +1218 +1219 +1220 |
|
start_aio()
+
+
+ async
+
+
+This method may be called directly, if the autostart +parameter in init is set to false.
+This method instantiates the serial interface and then performs auto pin +discovery if using a serial interface, or creates and connects to +a TCP/IP enabled device running StandardFirmataWiFi.
+Use this method if you wish to start TelemetrixAIO manually from +an asyncio function.
+ +telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
298 +299 +300 +301 +302 +303 +304 +305 +306 +307 +308 +309 +310 +311 +312 +313 +314 +315 +316 +317 +318 +319 +320 +321 +322 +323 +324 +325 +326 +327 +328 +329 +330 +331 +332 +333 +334 +335 +336 +337 +338 +339 +340 +341 +342 +343 +344 +345 +346 +347 +348 +349 +350 +351 +352 +353 +354 +355 +356 +357 +358 +359 +360 +361 +362 +363 +364 +365 +366 +367 +368 +369 +370 +371 +372 +373 +374 +375 |
|
Here, we need to instantiate the class passing in two parameters. +We need to pass in auto_start=False. This is because we are using the Bleak BLE +library, and this allows for a clean shutdown. +We also need to pass in transport_type=2, which enables the BLE transport.
+Lastly, we need to manually start the asyncio portion of the API by calling +board.start_aio() in our main function.
+
+import sys
+import asyncio
+
+# IMPORT THE API
+from telemetrix_uno_r4.wifi.telemetrix_uno_r4_wifi_aio import telemetrix_uno_r4_wifi_aio
+
+# An async method for running your application.
+# We pass in the instance of the API created below .
+async def my_app(my_board):
+ # THIS NEXT LINE MUST BE ADDED HERE
+ await my_board.start_aio()
+
+ # Your Application code
+
+# get the event loop
+loop = asyncio.new_event_loop()
+asyncio.set_event_loop(loop)
+
+# instantiate telemetrix_aio
+
+board = telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio(autostart=False,
+ transport_type=2)
+
+try:
+ # start the main function
+ loop.run_until_complete(my_app(board))
+except KeyboardInterrupt:
+ try:
+ loop.run_until_complete(board.shutdown())
+ except:
+ pass
+ sys.exit(0)
+
+
+
+
Copyright (C) 2023 Alan Yorinks. All Rights Reserved.
+ + + + + + +
+import sys
+import asyncio
+
+# IMPORT THE API
+from telemetrix_uno_r4.minima.telemetrix_uno_r4_minima_aio import telemetrix_uno_r4_minima_aio
+
+# An async method for running your application.
+# We pass in the instance of the API created below .
+async def my_app(the_board):
+ # Your Application code
+
+# get the event loop
+loop = asyncio.new_event_loop()
+asyncio.set_event_loop(loop)
+
+# instantiate telemetrix_aio
+board = telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio()
+
+try:
+ # start the main function
+ loop.run_until_complete(my_app(board))
+except KeyboardInterrupt:
+ try:
+ loop.run_until_complete(board.shutdown())
+ except:
+ pass
+ sys.exit(0)
+
+
+
+
+
+
+
+
+ import sys
+import time
+
+# IMPORT THE API
+from telemetrix_uno_r4.minima.telemetrix_uno_r4_minima import telemetrix_uno_r4_minima
+"""
+
+# INSTANTIATE THE API CLASS
+board = telemetrix_uno_r4_minima.TelemetrixUnoR4Minima()
+
+try:
+ # WRITE YOUR APPLICATION HERE
+except:
+ board.shutdown()
+
+
+
+
+
+
+
Copyright (C) 2023 Alan Yorinks. All Rights Reserved.
+ + + + + + +Here, we need to instantiate the class passing in a transport_type of 1. +This parameter value enables the serial transport.
+
+import sys
+import asyncio
+
+# IMPORT THE API
+from telemetrix_uno_r4.wifi.telemetrix_uno_r4_wifi_aio import telemetrix_uno_r4_wifi_aio
+
+# An async method for running your application.
+# We pass in the instance of the API created below .
+async def my_app(the_board):
+ # Your Application code
+
+# get the event loop
+loop = asyncio.new_event_loop()
+asyncio.set_event_loop(loop)
+
+# instantiate telemetrix_aio
+board = telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio(transport_type=1)
+
+try:
+ # start the main function
+ loop.run_until_complete(my_app(board))
+except KeyboardInterrupt:
+ try:
+ loop.run_until_complete(board.shutdown())
+ except:
+ pass
+ sys.exit(0)
+
+
+
+
Copyright (C) 2023 Alan Yorinks. All Rights Reserved.
+ + + + + + +Here, we need to instantiate the class passing in a transport_type of 1. This enables +the serial transport.
+import sys
+import time
+
+# IMPORT THE API
+from telemetrix_uno_r4.wifi.telemetrix_uno_r4_wifi import telemetrix_uno_r4_wifi
+
+# INSTANTIATE THE API CLASS
+board = telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi(transport_type=1)
+try:
+ # WRITE YOUR APPLICATION HERE
+except:
+ board.shutdown()
+
+
+
+
+
+
+
Copyright (C) 2023 Alan Yorinks. All Rights Reserved.
+ + + + + + +Here, we need to instantiate the class passing in the IP address assigned by your +router. This parameter enables the WIFI transport.
+
+import sys
+import asyncio
+
+# IMPORT THE API
+from telemetrix_uno_r4.wifi.telemetrix_uno_r4_wifi_aio import telemetrix_uno_r4_wifi_aio
+
+# An async method for running your application.
+# We pass in the instance of the API created below .
+async def my_app(the_board):
+ # Your Application code
+
+# get the event loop
+loop = asyncio.new_event_loop()
+asyncio.set_event_loop(loop)
+
+# instantiate telemetrix_aio
+# Make sure to edit the transport address assigned by your router.
+board = telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio(
+ transport_address='192.168.2.118')
+
+try:
+ # start the main function
+ loop.run_until_complete(my_app(board))
+except KeyboardInterrupt:
+ try:
+ loop.run_until_complete(board.shutdown())
+ except:
+ pass
+ sys.exit(0)
+
+
+
+
Copyright (C) 2023 Alan Yorinks. All Rights Reserved.
+ + + + + + +Here, we need to instantiate the class passing in the IP address assigned by your +router. This parameter enables the WIFI transport.
+import sys
+import time
+
+# IMPORT THE API
+from telemetrix_uno_r4.wifi.telemetrix_uno_r4_wifi import telemetrix_uno_r4_wifi
+
+# INSTANTIATE THE API CLASS
+# Make sure to edit the transport address assigned by your router.
+
+board = telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi(transport_address='192.168.2.118')
+try:
+ # WRITE YOUR APPLICATION HERE
+except:
+ board.shutdown()
+
+
+
+
+
+
+
Copyright (C) 2023 Alan Yorinks. All Rights Reserved.
+ + + + + + +When using Telemetrix, it is highly recommended that you work within a Python virtual +environment.
+A virtual environment isolates your project from other projects. +Packages installed into a virtual environment are confined to your +current project and will not affect or change packages used by other projects. +Please refer to this article +or the Python documentation.
+If you are using the latest version of Ubuntu and Debian Linux, you are +required +to use a virtual environment.
+
+Copyright (C) 2023 Alan Yorinks. All Rights Reserved.