pythoncoder wrote: ↑Sun Apr 08, 2018 8:03 am
The MicroPython library is largely a subset of the CPython one so porting an application to Unix MicroPython can involve some work. But it then doesn't usually take much effort to backport it to CPython.
Running on a mixture of bare metal hardware platforms can involve a degree of hardware specific code. Pin definitions and the disparate approaches of
pyb and
machine come to mind here.
Yep, xPython is only platform transparent as long as you don't involve platform-specific things such as pins. That was the exact reason I don't use any raspberry pi GPIO pins for anything other than some trivial tasks such as a button. I would design boards with USB-serial chips and MCU so they do the digital interface with sensors, instead of the computer via Python. MicroPython is extremely useful on MCUs but also extremely limited if you wish to use on computers (I didn't know this option even existed, will investigate). No or hard-to-find well-documented exception handling, for instance, prevents developers from preparing programs for exceptions say from networking. Everything is assuming ideal situations in sample code, like that of Arduino. That will work for hours or even for days in reality but will break down when you think you've done a good job. I'd like to see MicroPython tying up loose ends like these. In Arduino, many things have begin but no end.
For now I'll have two versions, one for cPython and another for MicroPython. They look very different on the init part (starting serial port, starting sd, mounting sd, setting up network etc.) but then start to look the same on actual processing part and then exception handling is different. There is no __str__() for exceptions
Good thing is I'm already done writing processing part so it's just the tweaking, such as MicroPython doesn't have this and I'll use that, then back port to cPython to use only that.
One example: MicroPython can't turn byte string into float but cPython 3.x can. OK, then I'll add encode() to both script versions.