Improving s2a_fm Performance

Recently, a couple of s2a_fm users had asked about improving s2a_fm's CPU utilization performance. Here is a quick Scratch test program that monitors 3 analog input devices and a single digital input device.

Running this program using the current s2a_fm code, typical CPU utilization is shown in this task manager screenshot:
We can see that Scratch is taking up about 1% of the CPU and that s2a_fm is consuming about 40% of the CPU.

These measurements were taken using Ubuntu 15.10 64bit running on an Intel i5-2600k with 8 GB of RAM installed.

Running the same exact Scratch program on a prototype asyncio implementation of s2a_fm,  we get the following results:

The asyncio version dramatically reduced CPU utilization by a factor of 10! In addition, there appears to be an improvement in responsiveness. For example, when changing the value of the pot, there is less stutter and lag.

Because these results are so promising, I am about to embark on developing the next generation of s2a_fm, to be called s2aio.

Here are some of the design goals for the new version:
  • All existing s2a_fm Scratch programs should be able to be run on s2aio without modification including existing language translation support.
  • Provide Arduino auto port detection. s2aio will be using pymata-aio that has this capability already implemented.
  • Auto launch of Scratch 2 after invoking s2aio. This is already working for Linux, and hopefully will be available for Windows as well.
  • Simpler installation - single command to install s2aio, and all of its dependencies (pymata-aio, pyserial, aiohttp, etc.).
  • All documentation to appear on the project's Github Wiki page. The goal here is that the documentation can be easily translated using Google Chrome's translation facilities.
Please note that s2aio will require the use of Python 3.5 and will not be compatible with Python 2.7. 

Stay tuned for further updates. 

pymata_aio v2.6
New Feature Release is Available

Keep Alive Link Detection

To detect when connectivity is lost between the Arduino and pymata_aio, a keep_alive link detection feature has been added.  When activated, a keep_alive message will be sent periodically to the Arduino. If the Arduino does not receive a keep_alive message in the prescribed time, it will reset itself.

Feature Prerequisite

To make use of this feature you will need to upload FirmataPlus, FirmataPlusRB or FirmataPlusLBT to the Arduino. You may still use StandardFirmata if you do not use this feature.

Enabling the Feature

To enable the feature when using one of the FirmataPlus sketches, simply call the keep_alive API method. This method has 2 defaulted parameters.

  • period - this parameter specifies how often the keep alive message is expected to be received by the Arduino. The default value is 1 second, but may be optionally set from 0 to 10 seconds. A value of 0 disables the feature if previously enabled. Once activated, if the Arduino does not receive a keep_alive message within a period time frame, it will reset itself.
  • margin - this parameter assures that the keep alive messages are sent more often than the value specified by period. It has a default value of .3, but may optionally be set to a value of .1 to .9. It is used in a calculation in conjunction with the period parameter to determine how often to send the keep_alive message to the Arduino. The margin parameter allows you to adjust for any propagation delays.

    The formula used is:
    KEEP_ALIVE_SEND_TIME_PERIOD = period - (period * margin)

    So, for example if you use the default values, a keep_alive message will be sent to the Arduino every .7 seconds. If you selected a period of 4 seconds with a margin of .1, then a keep_alive will be sent every 3.6 seconds. 

pymata_aio Version 2.5 Release

This release:

1. Merges in the lastest updates to the SparkFun RedBot experiment files from the Rose-Hulman Institute of Technology.
2. Fixes a bug introduced in v2.3 that prevented specifying the com port as a parameter.
3. Improved shutdown of pymata_iot. It now sends a reset to the Arduino upon exit.

pymata_aio v2.4 released

v2.3 removed from Pypi

The v2.3 release introduced a bug that rendered the library unusable for Windows users. Python 3.5 asyncio has a mechanism that allows registration of signals (SIGTERM, etc.), but this mechanism does not provide support for Windows. 

As a result, integrated control-c support has been removed from the library and is now the responsibility of the application developer to provide. Examples are provided for both pymata_core and pymata3 APIs here.

pymata_aio v2.3 
Problems on Windows

If you are having difficulties with version 2.3, I am working on a fix. My efforts to improve the Control-C handling seems to crash on windows.

I am investigating and will report back when I have a fix and release v2.4.

In the meantime, please download version 2.1 which does not exhibit this behavior. The only major difference between version 2.1 and 2.3 is the support for WiFly.

Sorry for the confusion and inconvenience.


Version 2.3 Has Been Released

NOTE: pymata_aio now requires Python 3.5

If you wish to use Python 3.4.3 use pip or github to retrieve version 1.9.

Version 2.3 Features

  • TCP/IP support was added for running the SparkFun RedBot robot with a WiFly module.
  • Improved Control-C handling.
  • FirmataPlus and FirmataPlusRB now reset the Arduino when a "send_reset" or "shutdown"  API command is executed.

Any applications developed using earlier versions of pymata_aio should be fully compatible with version 2.3 and should not require any modifications.