[Microbit-Python] Say hola to microperi [WIP]

Joe Glancy joe.t.glancy at gmail.com
Sat May 14 15:58:03 EDT 2016


Myself and Andrew (Mulholland, @gbaman on GitHub - credit to him for first
starting this) have been working on something similar to David's mb_remote
module for Python, called microperi (micro-peripheral, as that is what the
micro:bit becomes :). It is currently (and very much) an alpha
work-in-progress, and I'm only informing everyone here about it because we
need testers and, more importantly, feedback.

It lives at https://github.com/JoeGlancy/microperi, and because none of the
install methods (pip3/python3 setup.py install) work properly as of now,
the best way to try it is just create your scripts in the same directory
where the docs (README, CONTRIBUTING etc) are and use `import microperi`
(check out the example in the README for a bit of a better howto).

It exposes almost all of the micro:bit's MicroPython `microbit` module,
which is completely available through a microperi.Microbit object. This is
actually one of the things that I'd like feedback about; see below for more
information (I don't think I've explained this too well, but it's the best
I could think of and word). If you just want to try it out, get cloning and
give it a whirl. Anything you spot as a bug or something you feel needs to
be improved/implemented, just create an issue or submit a PR (check
CONTRIBUTING.rst first though).

We decided on the Microbit object (instead of one pre-set object called
`microperi.microbit`, which it actually was originally) so that multiple
micro:bits can be used at the same time. The constructor is:

microperi.Microbit(port=None)

If port is not specified, the module will automatically detect the first
available micro:bit and use that one (Nick, the finding code is from
microrepl - could you comment on licensing please?). Otherwise, `port` must
be a string determining the serial port which the micro:bit is connected to
(e.g: /dev/ttyACM0, COM1, etc).

Usual usage of the object is along the following lines (or, more literal,
line):

microbit = microperi.Microbit()

and then things like the microbit.Image class are available through
`microbit.Image`. However, if I were to call the micro:bit object a
different name in my script (such as "uBit"), the Image class would be
accessible as uBit.Image, which deviates from the MicroPython API. However,
we did not want to place things like the Image & pin classes in somewhere
like `microperi.microbit.Class_name` because then you'd have a bit of a
mess like so:

from microperi import *
uBit = Microbit()
solid = microbit.Image.SNAKE
uBit.display.show(solid)

because some things (e.g: microbit.i2c.read) would be accessible through
`uBit.i2c.read`, and others (e.g: microbit.Image) would be accessible
through `microbit.Image`, when they both should be under `microbit.X`, if
you understand what I mean.

The best solution for this currently is just calling the object `microbit`,
and then everything will be as it should, but if you don't some things will
be in different places.

Anyway, I hope that this module will prove itself useful for people and
perhaps even in the classroom, as it notably allows not only use of the
microbit module but also every other Python 3 module out there, allowing
much more powerful (possibly IoT integrated?) scripts to be created on a
much more powerful machine. I look forward to any feedback, and hope for a
proper, stable release (with documentation of some sort) sometime soon.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/microbit/attachments/20160514/eae034bf/attachment.html>


More information about the Microbit mailing list