Search found 10 matches

by MicroP_W691
Tue May 18, 2021 10:26 am
Forum: General Discussion and Questions
Topic: Why does split method behave differently in an inline if-else statement?
Replies: 4
Views: 2864

Re: Why does split method behave differently in an inline if-else statement?

Oops, I figured out the issue, user error! The object after the last comma is being assigned to the 'b' variable, which make sense based on how the line would tokenised and parsed by the interpreter. The correct implementation should be: >>> a,b = u.split('^') if ('^' in u) else (u,'') This returns ...
by MicroP_W691
Tue May 18, 2021 10:13 am
Forum: General Discussion and Questions
Topic: Why does split method behave differently in an inline if-else statement?
Replies: 4
Views: 2864

Why does split method behave differently in an inline if-else statement?

I'm a bit confused why the behaviour of the split statement is different between two use cases, and wondered what I may have overlooked? This works the way I'd expect it to: >>> u = 'm/s^2' >>> if '^' in u: a, b = u.split('^') >>> a 'm/s' >>> b '2' Now I tried to simplify this into a single statemen...
by MicroP_W691
Mon Oct 19, 2020 7:45 am
Forum: General Discussion and Questions
Topic: Inline Assembler: 'bx(lr)' raises TypeError
Replies: 5
Views: 3401

Re: Inline Assembler: 'bx(lr)' raises TypeError

Thank you, your reply helped me see where I was going wrong. I was using a comparison branch instruction instead of bl, so the link register wasn't being stored at the point where I branched off. For anyone else stumbling upon this post with the same issue, to resolve this: I was originally using th...
by MicroP_W691
Thu Oct 15, 2020 10:08 am
Forum: General Discussion and Questions
Topic: Inline Assembler: 'bx(lr)' raises TypeError
Replies: 5
Views: 3401

Re: Inline Assembler: 'bx(lr)' raises TypeError

I tried adding some random add and sub instructions between the pop({lr}) and the bx(lr) but unfortunately, this didn't make a difference. The Traceback doesn't tell me what line it failed on (reports the line where the function is called), so I only worked out it was that line by commenting out the...
by MicroP_W691
Thu Oct 15, 2020 8:10 am
Forum: General Discussion and Questions
Topic: Inline Assembler: 'bx(lr)' raises TypeError
Replies: 5
Views: 3401

Inline Assembler: 'bx(lr)' raises TypeError

Hi, not sure what I'm doing wrong here, but I've been trying to use the inline assembler to process data coming in at a high rate. I have some very basic knowledge of assembly having written a few assembly functions to speed up timing-critical sections of C-Code before on embedded platforms, but I w...
by MicroP_W691
Tue Apr 28, 2020 3:37 pm
Forum: General Discussion and Questions
Topic: Equivalent __index__ method in Micropython
Replies: 2
Views: 2008

Re: Equivalent __index__ method in Micropython

Ah ok, not a problem, thanks for the info @jimmo
by MicroP_W691
Tue Apr 28, 2020 11:38 am
Forum: General Discussion and Questions
Topic: Equivalent __index__ method in Micropython
Replies: 2
Views: 2008

Equivalent __index__ method in Micropython

In CPython, there is a class 'magic' method '__index__()' which allows the object to be used in slice notation: class Screen_Object(object): def __init__(x_pos, y_pos, index) self.x = x_pos self.y = y_pos self.screen_list_index = index def draw_object(self): #draw instructions def __index__(self): r...
by MicroP_W691
Mon Mar 16, 2020 10:06 am
Forum: General Discussion and Questions
Topic: MemoryView, uctypes.struct, array or other built-in Data Structure... Which is quickest?
Replies: 3
Views: 4632

Re: MemoryView, uctypes.struct, array or other built-in Data Structure... Which is quickest?

Thank you for both your replies @pythoncoder and @jimmo, it looks like a bytearray is going to be the best option. I I see my mistake with the memory view object and using the 'print' function (thanks @jimmo), when using the method suggested by @pythoncoder it worked as expected. However, the memory...
by MicroP_W691
Mon Mar 09, 2020 12:25 pm
Forum: General Discussion and Questions
Topic: MemoryView, uctypes.struct, array or other built-in Data Structure... Which is quickest?
Replies: 3
Views: 4632

MemoryView, uctypes.struct, array or other built-in Data Structure... Which is quickest?

Hi all, I am working with CAN-Bus Data coming in at over 100hz (in bursts) and need to store all the messages as quickly as possible so that the next message can be read from the CAN Chip Buffer. But which way is the quickest way to store this data in micropython? For those who haven't worked with C...