Notes on porting code to pyboard

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
Posts: 70
Joined: Wed Oct 14, 2015 5:07 pm

Notes on porting code to pyboard

Post by Peter.Kenyon » Thu Dec 17, 2015 4:02 pm

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.

User avatar
Posts: 4242
Joined: Fri Jul 18, 2014 8:01 am
Location: UK

Re: Notes on porting code to pyboard

Post by pythoncoder » Fri Dec 18, 2015 10:43 am

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".
Peter Hinch

Post Reply