Page 1 of 1

Notes on porting code to pyboard

Posted: Thu Dec 17, 2015 4:02 pm
by Peter.Kenyon
Just spent a pleasant afternoon porting some BBB code to the pyboard.
The code presents a socket interface and controls various devices on the i2c bus.
Instead of a socket I just used input and stdout

The package structure and imports was flawless, I was expecting all sorts of issues but none

Logging was a problem so I used micropython.lib logging code.
A couple of points
I used warn which wasnt implemented (warning is)
logging.getLogger() didnt have a default positional arg
Log class doesnt implement setLevel - easy to add

I also used the collections.deque which was fine
would be nice to have clear() tho

The main gotcha was the time.time() function which I used in my Uart millisecond timeouts.
In python3 world this returned a double with the fractional seconds on the pyboard this is just an integer.

The help command used "{0:<12} {1}".format( key, d[key].help[0]) which wasn't formatted correctly.
so I just used

Code: Select all

def rpad(s, width):
    return s + ' ' * (width-len(s))
Anyway wasnt too painful, and there are only a few places where the code is different.

Re: Notes on porting code to pyboard

Posted: Fri Dec 18, 2015 10:43 am
by pythoncoder
MicroPython doesn't support doubles, just floats, so time.time() is necessarily different. As I understand it the restrictions on the string format() command are in the interests of keeping things "micro".