tino / pyFirmata

Python interface for the Firmata (http://firmata.org/) protocol. It is compliant with Firmata 2.1. Any help with updating to 2.2 is welcome. The Capability Query is implemented, but the Pin State Query feature not yet.
MIT License
575 stars 193 forks source link

Analog data 14-bit not being read correctly (which is part of Firmata >= 2.0) #83

Open eejd opened 5 years ago

eejd commented 5 years ago

I have tried to read a 14-bit value from the analog pin using pyFirmata (1.1.0) and Firmata (2.5.8) on an Arduino Mega. The values appear to not be converting even the two byte (protocol 2.0) messages correctly. This is not using EXTENDED_ANALOG. I can read the values correctly from the Arduino if I use another protocol parser (example, Bonsai C# Aurduino Fermata node, C++ reference code). I am trying to locate the error in the code to submit a patch, but I am unclear on the state of the pyFirmata support for protocol >= 2.0. The _handle_analog_message assumes the 1.0 max value of 1024 and doesn't seem to be doing message interrogation necessary to support EXTENDED_ANALOG. Output of a straight value extraction (loop polling analog pin 1) shows value jumps that appear to be reading extra bits incorrectly. (I.e. values above 1.0 with the assumed 1024 integer range). Is this a known problem/restriction?

eejd commented 5 years ago

Further investigation reveals that this problem occurs only on Windows, but not on MacOS (identical Anaconda Python distributions, pyFirmata versions). The best I have been able to gather is that it's in the serial byte reading code, but I haven't determined the cause. Observing the LSB and MSB reads, they are not correct.