-
Is there a method for telemetrix to read ONLY ONE specific analog input reading upon request and only upon request? The analog callback function currently spams my python script flow and is just a massive headache to work around. Currently the way I understand how analog reading from Telemetrix works, is that I have to:
Yes, I could use 'differential' argument to stop spamming too early etc (but then I get no reading reports if analog input has seemingly not changed), maybe even build the entire script around individual callbacks per pin (less spamming from other pins, but report is still blocked by not enough differential change on the pin), How I would see the analog reading should work (maybe as an addition to the current reporting mechanism):
I have done few workarounds myself in python but some odd cases always break the callback calling and I miss some readouts. Can this be done right now? If not Just please guide me how could I achieve this right now or please find some way to implement this into the API. |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 8 replies
-
@xAht0x Thanks for the question. I will not be implementing a polling method since, in my experience, it leads to more problems than it solves. With the current method, each enabled analog input pin is polled within the Arduino sketch at 19ms per scan. This rate can be modified using the set_analog_scan_interval method. This assures that the likelihood of missing a data change is minimal. Polling the pin from the Python side is inefficient and more likely to lead to missed changes. The callback method should be as short and as simple as possible. If you wish to supply your callback code, I would be happy to see if any improvements may be made. If you want to modify Telemetrix, this article explains what is involved. If you have any questions, I would be happy to answer them. |
Beta Was this translation helpful? Give feedback.
-
Pymata4 is an older and no longer supported library that allows you to do analog_reads without specifying a callback method. This may help solve your issue. I am closing this discussion, but please ask questions anytime. |
Beta Was this translation helpful? Give feedback.
-
Hei, thanks for looking into this.
Exactly! But,
I was not implying to have polling from python side. It's just that I'm expecting analog report only when I ask for it. Not to be spammed/interrupted by all other pins I have not asked for. I was simply wondering, if it would be possible, to request for a specific analog pin read, so that Arduino calls the callback with that 19ms poll, get my result in callback, for that pin and then Arduino stops reporting - all by telemetrix. So that I wouldn't need to write filters and double check the content of the callbacks in python to suppress ever increasing callback reports that I have not requested. =============== The script runs a background task to blink an LED and then asks for certain analog pins for results. From terminal it can be seen that the read_analog gets wrong readings stored. For example, first measurement all good: Broken: Sure I could try and disable reporting after every pin result has been received, but that takes time and callback manages to be called quite a few times before I can suppress it. And yes, maybe in combination with interval I could decrease the frequency of the report, but then I have to wait on python for the callback to be called and again until correct pin is reported etc etc - just annoying. Anyway, I have few ideas for a workarounds, until then, I hope this helps to illustrate my problem and hopefully this could be solved from API side - I currently don't have much time or interest to fiddle with the source. |
Beta Was this translation helpful? Give feedback.
-
Got back to it after a while. Can play around with two callback methods:
Callbacks should be changed inside read_analog() method. Note: Because mega has 16 analog pins, not 15. A0 - A15. The checks inside Telemetrix4Arduino were non-inclusive thus excluding pin 15. Thanks for the great software, works like a charm. |
Beta Was this translation helpful? Give feedback.
-
I am glad things worked for you. Thanks for pointing out the 16 analog pins bug. I will be updating the sketch within the next couple of days. |
Beta Was this translation helpful? Give feedback.
@xAht0x Thanks for the question. I will not be implementing a polling method since, in my experience, it leads to more problems than it solves. With the current method, each enabled analog input pin is polled within the Arduino sketch at 19ms per scan. This rate can be modified using the set_analog_scan_interval method. This assures that the likelihood of missing a data change is minimal. Polling the pin from the Python side is inefficient and more likely to lead to missed changes.
The callback method should be as short and as simple as possible. If you wish to supply your callback code, I would be happy to see if any improvements may be made.
If you want to modify Telemetrix, this article …