How to use uctypes? #15873
Replies: 5 comments 3 replies
-
I'm not too sure about your particular use case, but in general with uctypes I find the test cases for it helpful examples, look for everthing starting with |
Beta Was this translation helpful? Give feedback.
-
If you're using a Pico 2 the 32-bit shift and add of data in a 4-byte bytearray could be done using the inline assembler. Two or three instructions and lightning fast. |
Beta Was this translation helpful? Give feedback.
-
@andrewleech Thank you for the link. Unfortunately, the examples were not helpful enough. I decided to try parsing data with brute force using bit shifting. @peterhinch Thank you for your suggestion. I agree the PIO assembler builds bit arrays with amazing speed. That part of my code is working very well. My main concern is if MicroPython will be too slow to parse a 32-bit message before being interrupted by the interrupt when the next 32-bit message becomes available. I am now integrating each part of my code together, so I will soon learn if my concern is valid. |
Beta Was this translation helpful? Give feedback.
-
You probably have already seen this: code that analyzes 32 bit integer runs very fast if the Viper decorator and Viper data types are used. |
Beta Was this translation helpful? Give feedback.
-
I think there's not quite enough information to give full guidance. I can pretty much guarantee that micropython should be fast enough to "process" a 32bit value only 10 times a second, however the detail of what you're trying to process is the make or break. What I gather so far is you're sampling a bitstream (pin input?) in PIO? such that you have a 32bit buffer which is bit shifted and the new input bit placed at LSB. Whether you're using PIO or timer interrupt or pin interrupt to do this bit shift and sample possibly doesn't matter. What might matter more is the format you're getting this 32bit value into python. Is it a 4-long What are you trying to process? Is it just a bitmask you're trying and Regardless, if you ever need to loop over values to check something bit by bit then viper likely will work well for you. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Is there an example or explanation of how to use
uctypes
with a constant flow of changing bits?Example:
every 100 microseconds, bit 31 is deleted then bit 0 is appended to a 32-bit array. Then key bits are parsed from the 32-bit array.
Problem:
I am trying to use MicroPython to monitor a bitstream of incoming data to parse key bits as inputs for functions. The bitstream runs at 5000 bit/sec.
I know this would be easier to perform with c, but I want to learn how to do this with MicroPython.
Is there an example or explanation of how to use uctypes with a constant flow of changing bits?
uctypes
looks to be a perfect tool for monitoring a bitstream of data. The problem is there is very little information on how to implementuctypes
.I have reviewed the three examples in the MicroPython documentation, but these examples were not helpful.
Beta Was this translation helpful? Give feedback.
All reactions